]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Extract formatting logic from make (#585)
authorAlexander Lanin <alex@lanin.de>
Sun, 26 Apr 2020 18:13:21 +0000 (20:13 +0200)
committerGitHub <noreply@github.com>
Sun, 26 Apr 2020 18:13:21 +0000 (20:13 +0200)
This way it is executable without running configure first.

dev.mk.in
misc/check_format.sh [new file with mode: 0755]
misc/format.sh [new file with mode: 0755]
misc/run-clang-format

index e5c455792a306f7f3061ca6d2eaf48369df1efe7..250587c377d3bf9d2b8b213e8a1ed495a0e5f256 100644 (file)
--- a/dev.mk.in
+++ b/dev.mk.in
@@ -109,7 +109,7 @@ dist_files = \
     $(built_dist_files)
 
 ifneq ($(shell sed 's/.*"\(.*\)".*/\1/' src/version.cpp 2>/dev/null),$(version))
-  $(shell echo 'extern const char CCACHE_VERSION[]; const char CCACHE_VERSION[] = "$(version)";' >src/version.cpp)
+  $(shell echo 'extern const char CCACHE_VERSION[];\nconst char CCACHE_VERSION[] = "$(version)";' >src/version.cpp)
 endif
 src/version.o: src/version.cpp
 
@@ -202,16 +202,14 @@ shellcheck: test/suites/*.bash
 
 .PHONY: format
 format:
-       @cd $(srcdir) && echo $(non_third_party_headers) $(non_third_party_sources) $(test_sources) | xargs -n1 -P8 \
-           misc/run-clang-format
+       @cd $(srcdir) && misc/format.sh
 
 # Not using parallel execution because target is most likely being run on non-interactive CI system,
 # so no user is waiting for immediate results, and it avoids possibly interleaved output.
 .PHONY: check_format
 check_format:
        @[ -t 1 ] && export cf_diff_color="--color=always"; \
-       cd $(srcdir) && echo $(non_third_party_headers) $(non_third_party_sources) $(test_sources) | xargs -n1 -P1 \
-           misc/run-clang-format --check || \
+       cd $(srcdir) && misc/check_format.sh || \
                { echo; echo "Error: Sources are not formatted with clang-format."; \
                  echo 'Run "make format" or apply the above diff.'; echo; exit 1; } 1>&2
 
diff --git a/misc/check_format.sh b/misc/check_format.sh
new file mode 100755 (executable)
index 0000000..56ee3db
--- /dev/null
@@ -0,0 +1,4 @@
+#!/bin/sh -ex
+
+# xarg returns 1 if any run-clang-format call returns 1.
+find src unittest -path src/third_party -prune -o -regex ".*\.[ch]p?p?" -print0 | xargs -0 -n1 misc/run-clang-format --check
diff --git a/misc/format.sh b/misc/format.sh
new file mode 100755 (executable)
index 0000000..a53acc5
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/sh -ex
+find src unittest -path src/third_party -prune -o -regex ".*\.[ch]p?p?" -exec misc/run-clang-format {} \;
index a59319e40b4b3f20df37fef47867cbdbb0d149a5..27544a8697e7a2201ecfc1fac957f1b5875bc590 100755 (executable)
@@ -28,6 +28,11 @@ if [[ ! -e "$file" ]]; then
     exit 1
 fi
 
+if [[ -d "$file" ]]; then
+    echo "Please pass files and not directories: $file"
+    exit 1
+fi
+
 tmp_file="$file.$$.clang-format.tmp"
 trap "rm -f \"$tmp_file\"" EXIT