2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-31 22:35:33 +00:00

clang-format: rework make indent to check specific commits

Previousely "make indent" checked all files in criu source directory for
codding style flaws. We have several problems with it:

- clang-format default format sometimes changes in new versions of the
package and we need to reformat all our code base each time it happens
- on different systems we may have different versions of clang-format
and on latest criu-dev "make indent" may be still unhappy on your system
- when we want to update clang-format rules ourselves we need to update
all our code base each time
- sometimes clang-format rules are not fitting all our cases, (e.g.: an
option IndentGotoLabels works nice for simple C code, but is a no go for
assembler and C macros) and putting "clang-format off" everywhere is a
mess
- sometimes we intentionally want to break clang-format rules (e.g.:
we want to put function arguments on a new line separating them
"logically" not "mechanically" following 120-char rule like clang-format
does).

This adds a BASE option for "make indent" where all commits in range
BASE..HEAD would be checked with git-clang-format for codding style
flaws. For instance when developing on top of criu-dev, one can use
"make BASE=origin/criu-dev indent" to check all their commits for
compliance with the clang-format rules. Default base is HEAD~1 to make
last commit checked when "make indent" is called. The closest thing to
the old behaviour would then be "make indent BASE=init", note that only
commited files would be checked.

Extra options to git-clang-format may be passed through OPTS variable.

Also reuse "make indent" in github lint workflow.

Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
This commit is contained in:
Pavel Tikhomirov
2023-01-11 11:15:37 +03:00
committed by Andrei Vagin
parent a8b06d03a0
commit d6db3333aa
2 changed files with 9 additions and 11 deletions

View File

@@ -23,16 +23,12 @@ jobs:
- name: Run make indent
run: >
if [ -z "${{github.base_ref}}" ]; then
make indent
if ! make indent OPTS=--diff; then
exit 1
fi
else
git fetch origin ${{github.base_ref}} &&
git clang-format --style file --extensions c,h --quiet origin/${{github.base_ref}}
fi &&
STATUS=$(git status --porcelain) &&
if [ ! -z "$STATUS" ]; then
echo "FAIL: some files are not correctly formatted.";
echo "$STATUS"
git diff
echo "FAIL: please run 'make indent'";
exit 1;
if ! make indent OPTS=--diff BASE=origin/${{github.base_ref}}; then
exit 1
fi
fi

View File

@@ -461,8 +461,10 @@ fetch-clang-format: .FORCE
$(E) ".clang-format"
$(Q) scripts/fetch-clang-format.sh
BASE ?= "HEAD~1"
OPTS ?= "--quiet"
indent:
find . -name '*.[ch]' -type f -print0 | xargs --null --max-args 128 --max-procs 4 clang-format -i
git clang-format --style file --extensions c,h $(OPTS) $(BASE)
.PHONY: indent
include Makefile.install