Skip to content
Snippets Groups Projects
Commit 45f21d26 authored by Patrick Baudin's avatar Patrick Baudin
Browse files

[Linting] Allows LINT_DIFF=<commit/branch> make <lint|check-xxx|fix-xxx>

parent a0a7f3c5
No related branches found
No related tags found
No related merge requests found
...@@ -33,8 +33,11 @@ ...@@ -33,8 +33,11 @@
# - make LINT_DIR=<subdir> <lint-target> # - make LINT_DIR=<subdir> <lint-target>
# It is possible to force the action to given files: # It is possible to force the action to given files:
# - make LINT_FILE=<file> <lint-target> # - make LINT_FILE=<file> <lint-target>
# or to the files modified between HEAD and a specific branch/commit:
# - make LINT_DIFF=<branch/commit> <lint-target>
# Notes: # Notes:
# - when LINT_FILE is given, .gitattributes and LINT_DIR are ignored; # - when LINT_FILE is given, .gitattributes, LINT_DIFF and LINT_DIR are ignored;
# - when LINT_DIFF is given, LINT_DIR is ignored (but .gitattributes is used);
# - to use fix-utf8 target, the variable LINT_FROM_ENCODING=<from-encoding-name> # - to use fix-utf8 target, the variable LINT_FROM_ENCODING=<from-encoding-name>
# has to be set. # has to be set.
...@@ -57,6 +60,8 @@ CLANG_FORMAT ?= clang-format ...@@ -57,6 +60,8 @@ CLANG_FORMAT ?= clang-format
# Default values necessary for # Default values necessary for
# LINT_MAKEFILE=<this-makefile> make -f <this-makefile> <lint-target>` # LINT_MAKEFILE=<this-makefile> make -f <this-makefile> <lint-target>`
# Otherwise theses variables are defined into share/Makefile.common # Otherwise theses variables are defined into share/Makefile.common
GREP ?= grep
TR ?= tr
SED ?= LC_ALL=C sed SED ?= LC_ALL=C sed
ISED ?= sed -i ISED ?= sed -i
FIND ?= find FIND ?= find
...@@ -119,7 +124,7 @@ endif ...@@ -119,7 +124,7 @@ endif
echo "error: $(CLANG_FORMAT) must be installed"; \ echo "error: $(CLANG_FORMAT) must be installed"; \
exit 1; \ exit 1; \
fi; fi;
mkdir -p $(dir $@) $(MKDIR) $(dir $@)
$(TOUCH) $@ $(TOUCH) $@
############### ###############
...@@ -178,6 +183,13 @@ ifeq ($(LINT_FILE),) ...@@ -178,6 +183,13 @@ ifeq ($(LINT_FILE),)
LINT.dir=$(wildcard $(LINT_DIR)) LINT.dir=$(wildcard $(LINT_DIR))
ifeq ($(LINT_DIFF),)
FILE_LIST=$(GIT) ls-files $(LINT.dir) -z
else
$(info [LINT] Looking at files modified from branch/commit: '$(LINT_DIFF)')
FILE_LIST=$(GIT) diff --name-status --cached $(LINT_DIFF) | $(GREP) -v "^D" | $(SED) "s/^.[ \t]*//" | $(TR) '\n' '\000'
endif
#### check-XXX targets #### check-XXX targets
# Same list on both lines # Same list on both lines
...@@ -188,7 +200,7 @@ LINT.check-targets= \ ...@@ -188,7 +200,7 @@ LINT.check-targets= \
# Generic rule # Generic rule
$(LINT.check-targets): $(LINT.check-targets):
echo "[LINT] Checking from GIT attribute $@..." echo "[LINT] Checking from GIT attribute $@..."
$(GIT) ls-files $(LINT.dir) -z \ $(FILE_LIST) \
| $(GIT) check-attr --stdin -z $@ \ | $(GIT) check-attr --stdin -z $@ \
| $(SED) -zne 'x;n;n;s/^set$$//;t print;b;:print;x;p' \ | $(SED) -zne 'x;n;n;s/^set$$//;t print;b;:print;x;p' \
| $(XARGS) -0 -IXX sh -c '$(LINT.make) LINT_FILE="XX" $@ || exit 255' | $(XARGS) -0 -IXX sh -c '$(LINT.make) LINT_FILE="XX" $@ || exit 255'
...@@ -203,7 +215,7 @@ LINT.fix-targets= \ ...@@ -203,7 +215,7 @@ LINT.fix-targets= \
# Generic rule # Generic rule
$(LINT.fix-targets): $(LINT.fix-targets):
echo "[LINT] Fixing from GIT attribute $(patsubst fix-%,check-%,$@)..." echo "[LINT] Fixing from GIT attribute $(patsubst fix-%,check-%,$@)..."
$(GIT) ls-files $(LINT.dir) -z \ $(FILE_LIST) \
| $(GIT) check-attr --stdin -z $(patsubst fix-%,check-%,$@) \ | $(GIT) check-attr --stdin -z $(patsubst fix-%,check-%,$@) \
| $(SED) -zne 'x;n;n;s/^set$$//;t print;b;:print;x;p' \ | $(SED) -zne 'x;n;n;s/^set$$//;t print;b;:print;x;p' \
| $(XARGS) -0 -IXX sh -c '$(LINT.make) LINT_FILE="XX" $@ || exit 255' | $(XARGS) -0 -IXX sh -c '$(LINT.make) LINT_FILE="XX" $@ || exit 255'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment