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

[Lint] using variables of Makefile.common

parent 0a63c0e6
No related branches found
No related tags found
No related merge requests found
...@@ -24,8 +24,21 @@ ...@@ -24,8 +24,21 @@
# Code prettyfication and lint # # Code prettyfication and lint #
################################ ################################
SED?=sed ################################
ISED?=sed -i ## Default variables
OCP_INDENT ?= ocp-indent
# Default values necessary for
# LINT_MAKEFILE=<this-makefile> make -f <this-makefile> <lint-target>`
# Otherwise theses variables are defined into share/Makefile.common
SED ?= LC_ALL=C sed
ISED ?= sed -i
GIT ?= git
MKDIR ?= mkdir -p
MV ?= mv
RM ?= rm -f
TOUCH ?= touch
############ ############
...@@ -45,24 +58,24 @@ endif ...@@ -45,24 +58,24 @@ endif
################################ ################################
## CHECK ocp-indent VERSION ## CHECK $(OCP_INDENT)VERSION
.lint/check-ocp-indent-version: .lint/check-ocp-indent-version:
if command -v ocp-indent >/dev/null; then \ if command -v $(OCP_INDENT) >/dev/null; then \
if [ -z "$(shell ocp-indent --version)" ]; then echo "warning: ocp-indent returned an empty string, assuming it is the correct version"; \ if [ -z "$(shell $(OCP_INDENT) --version)" ]; then echo "warning: $(OCP_INDENT) returned an empty string, assuming it is the correct version"; \
else \ else \
$(eval ocp_version_major := $(shell ocp-indent --version | $(SED) -E "s/^([0-9]+)\.[0-9]+\..*/\1/")) \ $(eval ocp_version_major := $(shell $(OCP_INDENT) --version | $(SED) -E "s/^([0-9]+)\.[0-9]+\..*/\1/")) \
$(eval ocp_version_minor := $(shell ocp-indent --version | $(SED) -E "s/^[0-9]+\.([0-9]+)\..*/\1/")) \ $(eval ocp_version_minor := $(shell $(OCP_INDENT) --version | $(SED) -E "s/^[0-9]+\.([0-9]+)\..*/\1/")) \
if [ "$(ocp_version_major)" -lt 1 -o "$(ocp_version_minor)" -lt 7 ]; then \ if [ "$(ocp_version_major)" -lt 1 -o "$(ocp_version_minor)" -lt 7 ]; then \
echo "error: ocp-indent 1.7.0 required for linting (got $(ocp_version_major).$(ocp_version_minor))"; \ echo "error: $(OCP_INDENT) 1.7.0 required for linting (got $(ocp_version_major).$(ocp_version_minor))"; \
exit 1; \ exit 1; \
fi; \ fi; \
fi; \ fi; \
else \ else \
exit 1; \ exit 1; \
fi; fi;
mkdir -p $(dir $@) $(MKDIR) $(dir $@)
touch $@ $(TOUCH) $@
############### ###############
## Main target ## Main target
...@@ -89,7 +102,7 @@ endif ...@@ -89,7 +102,7 @@ endif
.PHONY: clean-lint .PHONY: clean-lint
clean-lint: clean-lint:
echo "Cleaning LINT targets..." echo "Cleaning LINT targets..."
rm -rf .lint $(RM) -r .lint
clean:: clean-lint clean:: clean-lint
...@@ -101,22 +114,22 @@ ifeq ($(LINT_FILE),) ...@@ -101,22 +114,22 @@ ifeq ($(LINT_FILE),)
.PHONY: check-eoleof .PHONY: check-eoleof
check-eoleof: check-eoleof:
git ls-files -z \ $(GIT) ls-files -z \
| git check-attr --stdin -z check-eoleof \ | $(GIT) check-attr --stdin -z check-eoleof \
| $(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 --null -IXX sh -c '$(LINT.make) LINT_FILE="XX" check-eoleof || exit 255' | xargs --null -IXX sh -c '$(LINT.make) LINT_FILE="XX" check-eoleof || exit 255'
.PHONY: check-syntax .PHONY: check-syntax
check-syntax: check-syntax:
git ls-files -z \ $(GIT) ls-files -z \
| git check-attr --stdin -z check-syntax \ | $(GIT) check-attr --stdin -z check-syntax \
| $(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 --null -IXX sh -c '$(LINT.make) LINT_FILE="XX" check-syntax || exit 255' | xargs --null -IXX sh -c '$(LINT.make) LINT_FILE="XX" check-syntax || exit 255'
.PHONY: check-indent .PHONY: check-indent
check-indent: check-indent:
git ls-files -z \ $(GIT) ls-files -z \
| git check-attr --stdin -z check-indent \ | $(GIT) check-attr --stdin -z check-indent \
| $(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 --null -IXX sh -c '$(LINT.make) LINT_FILE="XX" check-indent || exit 255' | xargs --null -IXX sh -c '$(LINT.make) LINT_FILE="XX" check-indent || exit 255'
...@@ -163,23 +176,23 @@ endif ...@@ -163,23 +176,23 @@ endif
$(LINT_FILE.check-indent): .lint/%.check-indent: % .lint/check-ocp-indent-version $(LINT_FILE.check-indent): .lint/%.check-indent: % .lint/check-ocp-indent-version
echo "Check indent: $<" echo "Check indent: $<"
ocp-indent $< > $<.tmp $(OCP_INDENT) $< > $<.tmp
if cmp -s $< $<.tmp; \ if cmp -s $< $<.tmp; \
then rm -f $<.tmp; \ then $(RM) $<.tmp; \
else \ else \
echo "File $< is not indented correctly."; \ echo "File $< is not indented correctly."; \
echo "Please run: make LINT_FILE=$< fix-indent";\ echo "Please run: make LINT_FILE=$< fix-indent";\
rm $<.tmp; \ $(RM) $<.tmp; \
exit 1; \ exit 1; \
fi fi
mkdir -p $(dir $@) $(MKDIR) $(dir $@)
touch $@ $(TOUCH) $@
$(LINT_FILE.fix-indent): .lint/%.fix-indent: % .lint/check-ocp-indent-version $(LINT_FILE.fix-indent): .lint/%.fix-indent: % .lint/check-ocp-indent-version
echo "Fixes indent: $<" echo "Fixes indent: $<"
ocp-indent -i $< $(OCP_INDENT) -i $<
mkdir -p $(dir $@) $(MKDIR) $(dir $@)
touch .lint/$<.check-indent # no more need of check-indent $(TOUCH) .lint/$<.check-indent # no more need of check-indent
############################### ###############################
## EOL EOF ASPECT (included by check-syntax target) ## EOL EOF ASPECT (included by check-syntax target)
...@@ -198,14 +211,14 @@ $(LINT_FILE.check-eoleof): .lint/%.check-eoleof: % ...@@ -198,14 +211,14 @@ $(LINT_FILE.check-eoleof): .lint/%.check-eoleof: %
echo "Please run: make LINT_FILE=$< fix-eoleof"; \ echo "Please run: make LINT_FILE=$< fix-eoleof"; \
exit 1 ; \ exit 1 ; \
fi fi
mkdir -p $(dir $@) $(MKDIR) $(dir $@)
touch $@ $(TOUCH) $@
$(LINT_FILE.fix-eoleof): .lint/%.fix-eoleof: % $(LINT_FILE.fix-eoleof): .lint/%.fix-eoleof: %
echo "Fixes EOL EOF: $<" echo "Fixes EOL EOF: $<"
$(ISED) -e '$$a\' $< $(ISED) -e '$$a\' $<
mkdir -p $(dir $@) $(MKDIR) $(dir $@)
touch .lint/$<.check-eoleof # no more need of this checking $(TOUCH) .lint/$<.check-eoleof # no more need of this checking
%.fix-eoleof: LC_ALL = C %.fix-eoleof: LC_ALL = C
...@@ -233,8 +246,8 @@ $(LINT_FILE.check-syntax): .lint/%.check-syntax: % ...@@ -233,8 +246,8 @@ $(LINT_FILE.check-syntax): .lint/%.check-syntax: %
echo "Please run: make LINT_FILE=$< fix-syntax"; \ echo "Please run: make LINT_FILE=$< fix-syntax"; \
exit 1 ; \ exit 1 ; \
fi fi
mkdir -p $(dir $@) $(MKDIR) $(dir $@)
touch $@ $(TOUCH) $@
$(LINT_FILE.fix-syntax): .lint/%.fix-syntax: % $(LINT_FILE.fix-syntax): .lint/%.fix-syntax: %
echo "Fixes syntax: $<" echo "Fixes syntax: $<"
...@@ -246,11 +259,11 @@ $(LINT_FILE.fix-syntax): .lint/%.fix-syntax: % ...@@ -246,11 +259,11 @@ $(LINT_FILE.fix-syntax): .lint/%.fix-syntax: %
else \ else \
while tail -n -1 $< | grep -l -e '^[ \t]*$$'; do \ while tail -n -1 $< | grep -l -e '^[ \t]*$$'; do \
head -n -1 $< > $<.tmp; \ head -n -1 $< > $<.tmp; \
mv $<.tmp $<; \ $(MV) $<.tmp $<; \
done; \ done; \
fi fi
mkdir -p $(dir $@) $(MKDIR) $(dir $@)
touch .lint/$<.check-syntax # no more need of check-syntax $(TOUCH) .lint/$<.check-syntax # no more need of check-syntax
# Avoid a UTF-8 locale at all cost: in such setting, sed does not work # Avoid a UTF-8 locale at all cost: in such setting, sed does not work
# reliably if you happen to have latin-1 encoding somewhere, # reliably if you happen to have latin-1 encoding somewhere,
......
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