From f56131976ea7e0945101a3ce97256dc1280cc0d3 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Mon, 1 May 2023 13:43:26 -0400 Subject: Add clang formatting infrastructure Prep for reformatting the codebase. --- .clang-format | 4 ++++ Makefile.am | 4 ++++ ci/codestyle.sh | 7 +++++++ ci/gh-install.sh | 1 + ci/rpmostree.sh | 2 +- 5 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..59902b6c --- /dev/null +++ b/.clang-format @@ -0,0 +1,4 @@ +Language: Cpp +BasedOnStyle: GNU +ColumnLimit: 100 +ForEachMacros: ['GLNX_HASH_TABLE_FOREACH', 'GLNX_HASH_TABLE_FOREACH_V', 'GLNX_HASH_TABLE_FOREACH_KV', 'GLNX_HASH_TABLE_FOREACH_IT'] diff --git a/Makefile.am b/Makefile.am index 50282156..cccf6ae7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -132,6 +132,10 @@ include Makefile-bash.am release-tag: cd $(srcdir) && git $(srcdir) tag -m "Release $(VERSION)" v$(VERSION) +.PHONY: clang-format +clang-format: + git ls-files '**.c' '**.cxx' '**.h' '**.hpp' | xargs clang-format -i + embed_dependency=tar -C $(srcdir) --append --exclude='.git/*' --transform="s,^embedded-dependencies/,ostree-embeddeps-$${GITVERSION}/embedded-dependencies/," --file=$${TARFILE_TMP} git_version_rpm = $$(cd $(srcdir) && git describe | sed -e 's,-,\.,g' -e 's,^v,,') diff --git a/ci/codestyle.sh b/ci/codestyle.sh index 1cf0a23c..850661e5 100755 --- a/ci/codestyle.sh +++ b/ci/codestyle.sh @@ -15,6 +15,13 @@ done echo "ok" fi +# Will uncomment this once we reformat +#if command -v clang-format; then +# echo -n "checking clang-format... " +# git ls-files '**.c' '**.cxx' '**.h' '**.hpp' | xargs clang-format --Werror --dry-run +# echo "ok" +#fi + echo -n 'grep-based static analysis... ' patterns=(glnx_fd_close) for pat in "${patterns[@]}"; do diff --git a/ci/gh-install.sh b/ci/gh-install.sh index c2928665..966edb28 100755 --- a/ci/gh-install.sh +++ b/ci/gh-install.sh @@ -71,6 +71,7 @@ case "$ID" in build-essential bubblewrap ca-certificates + clang-format cpio debhelper dh-exec diff --git a/ci/rpmostree.sh b/ci/rpmostree.sh index 0a5f5df9..554cde69 100755 --- a/ci/rpmostree.sh +++ b/ci/rpmostree.sh @@ -22,7 +22,7 @@ pkg_install rpm-ostree && rpm -e rpm-ostree pkg_install ostree{,-devel,-grub2} createrepo_c /usr/bin/jq python3-pyyaml \ libubsan libasan libtsan elfutils fuse sudo python3-gobject-base \ selinux-policy-devel selinux-policy-targeted python3-createrepo_c \ - rsync python3-rpm parallel clang rustfmt-preview + rsync python3-rpm parallel clang rustfmt-preview clang-tools-extra # From rpm-ostree/ci/vmcheck-provision.sh pkg_install openssh-clients ansible -- cgit v1.2.1