tools/perf: Add new CONFIG_SHELLCHECK for detecting shellcheck binary
PATCH 1/2 tools/perf: Add new CONFIG_SHELLCHECK for detecting shellcheck binary
shellcheck tool can detect coding/formatting issues on shell scripts. In perf directory "tests/shell", there are lot of shell test scripts and this tool can detect coding/formatting issues on these scripts.
Example to use shellcheck for severity level for
errors and warnings, below command is used:
# for F in $(find tests/shell/ -perm -o=x -name '*.sh'); do shellcheck -S warning $F; done
# echo $?
0This testing needs to be automated into the build so that it can avoid regressions and also run the check for newly added during build test itself. Add a new feature check to detect presence of shellcheck. Add CONFIG_SHELLCHECK feature check in the build to avoid not having shellcheck breaking the build.
--- tools/build/Makefile.feature | 6 ++++-- tools/build/feature/Makefile | 8 +++++++- tools/perf/Makefile.config | 10 ++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-)
tools/build/Makefile.feature +4 -2
@@ -72,7 +72,8 @@ FEATURE_TESTS_BASIC := \ libzstd \ disassembler-four-args \ disassembler-init-styled \ - file-handle + file-handle \ + shellcheck # FEATURE_TESTS_BASIC + FEATURE_TESTS_EXTRA is the complete list # of all feature tests
@@ -138,7 +139,8 @@ FEATURE_DISPLAY ?= \ get_cpuid \ bpf \ libaio \ - libzstd + libzstd \ + shellcheck # # Declare group members of a feature to display the logical OR of the detection
tools/build/feature/Makefile +7 -1
@@ -76,7 +76,8 @@ FILES= \ test-libzstd.bin \ test-clang-bpf-co-re.bin \ test-file-handle.bin \ - test-libpfm4.bin + test-libpfm4.bin \ + test-shellcheck.bin FILES := $(addprefix $(OUTPUT),$(FILES))
@@ -92,6 +93,8 @@ __BUILD = $(CC) $(CFLAGS) -MD -Wall -Werror -o $@ $(patsubst %.bin,%.c,$(@F)) $( __BUILDXX = $(CXX) $(CXXFLAGS) -MD -Wall -Werror -o $@ $(patsubst %.bin,%.cpp,$(@F)) $(LDFLAGS) BUILDXX = $(__BUILDXX) > $(@:.bin=.make.output) 2>&1 + BUILD_BINARY = sh -c $1 > $(@:.bin=.make.output) 2>&1 + ############################### $(OUTPUT)test-all.bin:
@@ -207,6 +210,9 @@ $(OUTPUT)test-libslang-include-subdir.bin: $(OUTPUT)test-libtraceevent.bin: $(BUILD) -ltraceevent +$(OUTPUT)test-shellcheck.bin: + $(BUILD_BINARY) "shellcheck --version" + $(OUTPUT)test-libtracefs.bin: $(BUILD) $(shell $(PKG_CONFIG) --cflags libtraceevent 2>/dev/null) -ltracefs
tools/perf/Makefile.config +10 -0
@@ -779,6 +779,16 @@ ifndef NO_SLANG endif endif +ifneq ($(NO_SHELLCHECK),1) + $(call feature_check,shellcheck) + ifneq ($(feature-shellcheck), 1) + msg := $(warning No shellcheck found. please install ShellCheck); + else + $(call detected,CONFIG_SHELLCHECK) + NO_SHELLCHECK := 0 + endif +endif + ifdef GTK2 FLAGS_GTK2=$(CFLAGS) $(LDFLAGS) $(EXTLIBS) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null) $(call feature_check,gtk2)
Signature · 1 line
2.31.1
PATCH 2/2 tools/perf: Add perf binary dependent rule for shellcheck log in Makefile.perf
Add rule in new Makefile "tests/Makefile.tests" for running shellcheck on shell test scripts. This automates below shellcheck into the build.
$ for F in $(find tests/shell/ -perm -o=x -name '*.sh'); do shellcheck -S warning $F; done
CONFIG_SHELLCHECK check is added to avoid build breakage in the absence of shellcheck binary. Update Makefile.perf to contain new rule for "SHELLCHECK_TEST" which is for making shellcheck test as a dependency on perf binary. Added "tests/Makefile.tests" to run shellcheck on shellscripts in tests/shell. The make rule "SHLLCHECK_RUN" ensures that, every time during make, shellcheck will be run only on modified files during subsequent invocations. By this, if any newly added shell scripts or fixes in existing scripts breaks coding/formatting style, it will get captured during the perf build.
--- tools/perf/Makefile.perf | 12 +++++++++++- tools/perf/tests/Makefile.tests | 24 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 tools/perf/tests/Makefile.tests
tools/perf/Makefile.perf +11 -1
@@ -667,7 +667,16 @@ $(PERF_IN): prepare FORCE $(PMU_EVENTS_IN): FORCE prepare $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=pmu-events obj=pmu-events -$(OUTPUT)perf: $(PERFLIBS) $(PERF_IN) $(PMU_EVENTS_IN) +# Runs shellcheck on perf test shell scripts +ifeq ($(CONFIG_SHELLCHECK),y) +SHELLCHECK_TEST: FORCE prepare + $(Q)$(MAKE) -f $(srctree)/tools/perf/tests/Makefile.tests +else +SHELLCHECK_TEST: + @: +endif + +$(OUTPUT)perf: $(PERFLIBS) $(PERF_IN) $(PMU_EVENTS_IN) SHELLCHECK_TEST $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) \ $(PERF_IN) $(PMU_EVENTS_IN) $(LIBS) -o $@
@@ -1129,6 +1138,7 @@ bpf-skel-clean: $(call QUIET_CLEAN, bpf-skel) $(RM) -r $(SKEL_TMP_OUT) $(SKELETONS) clean:: $(LIBAPI)-clean $(LIBBPF)-clean $(LIBSUBCMD)-clean $(LIBSYMBOL)-clean $(LIBPERF)-clean fixdep-clean python-clean bpf-skel-clean tests-coresight-targets-clean + $(Q)$(MAKE) -f $(srctree)/tools/perf/tests/Makefile.tests clean $(call QUIET_CLEAN, core-objs) $(RM) $(LIBPERF_A) $(OUTPUT)perf-archive $(OUTPUT)perf-iostat $(LANG_BINDINGS) $(Q)find $(or $(OUTPUT),.) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete $(Q)$(RM) $(OUTPUT).config-detected
tools/perf/tests/Makefile.tests new file +24 -0
@@ -0,0 +1,24 @@ +# SPDX-License-Identifier: GPL-2.0 +# Athira Rajeev <[email protected]>, 2023 +-include $(OUTPUT).config-detected + +log_file = $(OUTPUT)shellcheck_test.log +PROGS = $(subst ./,,$(shell find tests/shell -perm -o=x -type f -name '*.sh')) +DEPS = $(addprefix output/,$(addsuffix .dep,$(basename $(PROGS)))) +DIRS = $(shell echo $(dir $(DEPS)) | xargs -n1 | sort -u | xargs) + +.PHONY: all +all: SHELLCHECK_RUN + @: + +SHELLCHECK_RUN: $(DEPS) $(DIRS) + +output/%.dep: %.sh | $(DIRS) + $(call rule_mkdir) + $(Q)$(call frecho-cmd,test)@touch $@ + $(Q)$(call frecho-cmd,test)@shellcheck -S warning $(subst output/,./,$(patsubst %.dep, %.sh, $@)) 1> ${log_file} && ([[ ! -s ${log_file} ]]) +$(DIRS): + @mkdir -p $@ + +clean: + @rm -rf $(log_file) output
Signature · 1 line
2.31.1
Namhyung Kim
maintainerHello,
Quoted 74 lines · Athira Rajeev
shellcheck tool can detect coding/formatting issues on shell scripts. In perf directory "tests/shell", there are lot of shell test scripts and this tool can detect coding/formatting issues on these scripts.
Example to use shellcheck for severity level for
errors and warnings, below command is used:# for F in $(find tests/shell/ -perm -o=x -name '*.sh'); do shellcheck -S warning $F; done # echo $? 0This testing needs to be automated into the build so that it can avoid regressions and also run the check for newly added during build test itself. Add a new feature check to detect presence of shellcheck. Add
CONFIG_SHELLCHECKfeature check in the build to avoid not having shellcheck breaking the build.Signed-off-by Athira Rajeev <[email protected]>--- tools/build/Makefile.feature | 6 ++++-- tools/build/feature/Makefile | 8 +++++++- tools/perf/Makefile.config | 10 ++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-)tools/build/Makefile.feature +4
-2@@ -72,7 +72,8 @@ FEATURE_TESTS_BASIC := \ libzstd \ disassembler-four-args \ disassembler-init-styled \ - file-handle + file-handle \ + shellcheck # FEATURE_TESTS_BASIC + FEATURE_TESTS_EXTRA is the complete list # of all feature tests@@ -138,7 +139,8 @@ FEATURE_DISPLAY ?= \ get_cpuid \ bpf \ libaio \ - libzstd + libzstd \ + shellcheck # # Declare group members of a feature to display the logical OR of the detectiontools/build/feature/Makefile +4
-1@@ -76,7 +76,8 @@ FILES= \ test-libzstd.bin \ test-clang-bpf-co-re.bin \ test-file-handle.bin \ - test-libpfm4.bin + test-libpfm4.bin \ + test-shellcheck.bin FILES := $(addprefix $(OUTPUT),$(FILES))@@ -92,6 +93,8 @@ __BUILD = $(CC) $(CFLAGS) -MD -Wall -Werror -o $@ $(patsubst %.bin,%.c,$(@F)) $( __BUILDXX = $(CXX) $(CXXFLAGS) -MD -Wall -Werror -o $@ $(patsubst %.bin,%.cpp,$(@F)) $(LDFLAGS) BUILDXX = $(__BUILDXX) > $(@:.bin=.make.output) 2>&1 + BUILD_BINARY = sh -c $1 > $(@:.bin=.make.output) 2>&1 + ############################### $(OUTPUT)test-all.bin:
tools/build/feature/Makefile $(OUTPUT)test-libslang-include-subdir.bin: · line 214
Quoted 5 lines
tools/build/feature/Makefile +2
-0@@ -207,6 +210,9 @@ $(OUTPUT)test-libslang-include-subdir.bin: $(OUTPUT)test-libtraceevent.bin: $(BUILD) -ltraceevent +$(OUTPUT)test-shellcheck.bin: + $(BUILD_BINARY) "shellcheck --version"
I don't think it'd generate the .bin file.
Anyway, it's a binary file already. Can we check it with command -v and get rid of the feature test?
Thanks,
Namhyung
Quoted 28 lines
tools/build/feature/Makefile +1
-0+ $(OUTPUT)test-libtracefs.bin: $(BUILD) $(shell $(PKG_CONFIG) --cflags libtraceevent 2>/dev/null) -ltracefstools/perf/Makefile.config +10
-1@@ -779,6 +779,16 @@ ifndef NO_SLANG endif endif +ifneq ($(NO_SHELLCHECK),1) + $(call feature_check,shellcheck) + ifneq ($(feature-shellcheck), 1) + msg := $(warning No shellcheck found. please install ShellCheck); + else + $(call detected,CONFIG_SHELLCHECK) + NO_SHELLCHECK := 0 + endif +endif + ifdef GTK2 FLAGS_GTK2=$(CFLAGS) $(LDFLAGS) $(EXTLIBS) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null) $(call feature_check,gtk2) --2.31.1
Namhyung Kim
maintainerRe: [PATCH 2/2] tools/perf: Add perf binary dependent rule for shellcheck log in Makefile.perf
In reply to Athira RajeevQuoted 6 lines · Athira Rajeev
Add rule in new
Makefile"tests/Makefile.tests" for running shellcheck on shell test scripts. This automates below shellcheck into the build.$ for F in $(find tests/shell/ -perm -o=x -name '*.sh'); do shellcheck -S warning $F; done
I think you can do it if $(shell command -v shellcheck) returns non-empty string (the path to the shellcheck). Then the feature test logic can be gone.
Quoted 11 lines
CONFIG_SHELLCHECKcheck is added to avoid build breakage in the absence of shellcheck binary. Update Makefile.perf to contain new rule for "SHELLCHECK_TEST" which is for making shellcheck test as a dependency on perf binary. Added "tests/Makefile.tests" to run shellcheck on shellscripts in tests/shell. The make rule "SHLLCHECK_RUN" ensures that, every time during make, shellcheck will be run only on modified files during subsequent invocations. By this, if any newly added shell scripts or fixes in existing scripts breaks coding/formatting style, it will get captured during the perf build.
Can you show me the example output?
Quoted 53 lines
Signed-off-by Athira Rajeev <[email protected]>--- tools/perf/Makefile.perf | 12 +++++++++++- tools/perf/tests/Makefile.tests | 24 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 tools/perf/tests/Makefile.teststools/perf/Makefile.perf +11
-1@@ -667,7 +667,16 @@ $(PERF_IN): prepare FORCE $(PMU_EVENTS_IN): FORCE prepare $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=pmu-events obj=pmu-events -$(OUTPUT)perf: $(PERFLIBS) $(PERF_IN) $(PMU_EVENTS_IN) +# Runs shellcheck on perf test shell scripts +ifeq ($(CONFIG_SHELLCHECK),y) +SHELLCHECK_TEST: FORCE prepare + $(Q)$(MAKE) -f $(srctree)/tools/perf/tests/Makefile.tests +else +SHELLCHECK_TEST: + @: +endif + +$(OUTPUT)perf: $(PERFLIBS) $(PERF_IN) $(PMU_EVENTS_IN) SHELLCHECK_TEST $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) \ $(PERF_IN) $(PMU_EVENTS_IN) $(LIBS) -o $@@@ -1129,6 +1138,7 @@ bpf-skel-clean: $(call QUIET_CLEAN, bpf-skel) $(RM) -r $(SKEL_TMP_OUT) $(SKELETONS) clean:: $(LIBAPI)-clean $(LIBBPF)-clean $(LIBSUBCMD)-clean $(LIBSYMBOL)-clean $(LIBPERF)-clean fixdep-clean python-clean bpf-skel-clean tests-coresight-targets-clean + $(Q)$(MAKE) -f $(srctree)/tools/perf/tests/Makefile.tests clean $(call QUIET_CLEAN, core-objs) $(RM) $(LIBPERF_A) $(OUTPUT)perf-archive $(OUTPUT)perf-iostat $(LANG_BINDINGS) $(Q)find $(or $(OUTPUT),.) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete $(Q)$(RM) $(OUTPUT).config-detectedtools/perf/tests/Makefile.tests new file +9
-0@@ -0,0 +1,24 @@ +# SPDX-License-Identifier: GPL-2.0 +# Athira Rajeev <[email protected]>, 2023 +-include $(OUTPUT).config-detected + +log_file = $(OUTPUT)shellcheck_test.log +PROGS = $(subst ./,,$(shell find tests/shell -perm -o=x -type f -name '*.sh')) +DEPS = $(addprefix output/,$(addsuffix .dep,$(basename $(PROGS)))) +DIRS = $(shell echo $(dir $(DEPS)) | xargs -n1 | sort -u | xargs) +
tools/perf/tests/Makefile.tests line 19
Quoted 10 lines
tools/perf/tests/Makefile.tests new file +10
-0+.PHONY: all +all: SHELLCHECK_RUN + @: + +SHELLCHECK_RUN: $(DEPS) $(DIRS) + +output/%.dep: %.sh | $(DIRS) + $(call rule_mkdir) + $(Q)$(call frecho-cmd,test)@touch $@ + $(Q)$(call frecho-cmd,test)@shellcheck -S warning $(subst output/,./,$(patsubst %.dep, %.sh, $@)) 1> ${log_file} && ([[ ! -s ${log_file} ]])
This line is too long, please wrap it with some backslashes.
Thanks,
Namhyung
Quoted 8 lines
tools/perf/tests/Makefile.tests new file +5
-1+$(DIRS): + @mkdir -p $@ + +clean: + @rm -rf $(log_file) output --2.31.1
Quoted 90 lines · Namhyung Kim
Hello,
Quoted 75 lines · Athira Rajeev
shellcheck tool can detect coding/formatting issues on shell scripts. In perf directory "tests/shell", there are lot of shell test scripts and this tool can detect coding/formatting issues on these scripts.
Example to use shellcheck for severity level for
errors and warnings, below command is used:# for F in $(find tests/shell/ -perm -o=x -name '*.sh'); do shellcheck -S warning $F; done # echo $? 0This testing needs to be automated into the build so that it can avoid regressions and also run the check for newly added during build test itself. Add a new feature check to detect presence of shellcheck. Add
CONFIG_SHELLCHECKfeature check in the build to avoid not having shellcheck breaking the build.Signed-off-by Athira Rajeev <[email protected]>---
tools/build/Makefile.feature | 6 ++++-- tools/build/feature/Makefile | 8 +++++++- tools/perf/Makefile.config | 10 ++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-)tools/build/Makefile.feature +4
-2@@ -72,7 +72,8 @@ FEATURE_TESTS_BASIC := \ libzstd \ disassembler-four-args \ disassembler-init-styled \ - file-handle + file-handle \ + shellcheck # FEATURE_TESTS_BASIC + FEATURE_TESTS_EXTRA is the complete list # of all feature tests@@ -138,7 +139,8 @@ FEATURE_DISPLAY ?= \ get_cpuid \ bpf \ libaio \ - libzstd + libzstd \ + shellcheck # # Declare group members of a feature to display the logical OR of the detectiontools/build/feature/Makefile +4
-1@@ -76,7 +76,8 @@ FILES= \ test-libzstd.bin \ test-clang-bpf-co-re.bin \ test-file-handle.bin \ - test-libpfm4.bin + test-libpfm4.bin \ + test-shellcheck.bin FILES := $(addprefix $(OUTPUT),$(FILES))@@ -92,6 +93,8 @@ __BUILD = $(CC) $(CFLAGS) -MD -Wall -Werror -o $@ $(patsubst %.bin,%.c,$(@F)) $( __BUILDXX = $(CXX) $(CXXFLAGS) -MD -Wall -Werror -o $@ $(patsubst %.bin,%.cpp,$(@F)) $(LDFLAGS) BUILDXX = $(__BUILDXX) > $(@:.bin=.make.output) 2>&1 + BUILD_BINARY = sh -c $1 > $(@:.bin=.make.output) 2>&1 + ###############################$(OUTPUT)test-all.bin:
tools/build/feature/Makefile +0
-0@@ -207,6 +210,9 @@ $(OUTPUT)test-libslang-include-subdir.bin:$(OUTPUT)test-libtraceevent.bin:
Quoted 4 lines
$(BUILD) -ltraceevent+$(OUTPUT)test-shellcheck.bin:
+ $(BUILD_BINARY) "shellcheck --version"I don't think it'd generate the .bin file.
Quoted 5 lines
Anyway, it's a binary file already. Can we check it with
command -vand get rid of the feature test?Thanks,
Namhyung
Hi Namhyung,
Thanks for the review. Sure, I will check on this
Athira
Quoted 29 lines
Quoted 29 lines
+
$(OUTPUT)test-libtracefs.bin:$(BUILD) $(shell $(PKG_CONFIG) --cflags libtraceevent 2>/dev/null) -ltracefstools/perf/Makefile.config +0
-0@@ -779,6 +779,16 @@ ifndef NO_SLANG endifendif
tools/perf/Makefile.config +10
-0+ifneq ($(NO_SHELLCHECK),1) + $(call feature_check,shellcheck) + ifneq ($(feature-shellcheck), 1) + msg := $(warning No shellcheck found. please install ShellCheck); + else + $(call detected,CONFIG_SHELLCHECK) + NO_SHELLCHECK := 0 + endif +endif +ifdef GTK2
FLAGS_GTK2=$(CFLAGS) $(LDFLAGS) $(EXTLIBS) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null) $(call feature_check,gtk2)
--
2.31.1
Re: [PATCH 2/2] tools/perf: Add perf binary dependent rule for shellcheck log in Makefile.perf
In reply to Namhyung KimQuoted 11 lines · Namhyung Kim
Quoted 5 lines · Athira Rajeev
Add rule in new
Makefile"tests/Makefile.tests" for running shellcheck on shell test scripts. This automates below shellcheck into the build.
Quoted 5 lines
Quoted 1 line
$ for F in $(find tests/shell/ -perm -o=x -name '*.sh'); do shellcheck -S warning $F; doneI think you can do it if $(shell command -v shellcheck) returns non-empty string (the path to the shellcheck). Then the feature test logic can be gone.
Ok, I will try this.
Quoted 13 lines
Quoted 12 lines
CONFIG_SHELLCHECKcheck is added to avoid build breakage in the absence of shellcheck binary. Update Makefile.perf to contain new rule for "SHELLCHECK_TEST" which is for making shellcheck test as a dependency on perf binary. Added "tests/Makefile.tests" to run shellcheck on shellscripts in tests/shell. The make rule "SHLLCHECK_RUN" ensures that, every time during make, shellcheck will be run only on modified files during subsequent invocations. By this, if any newly added shell scripts or fixes in existing scripts breaks coding/formatting style, it will get captured during the perf build.
Quoted 1 line
Can you show me the example output?
Sure, I will add it.
Quoted 58 lines
Quoted 58 lines
Signed-off-by Athira Rajeev <[email protected]>---
tools/perf/Makefile.perf| 12 +++++++++++-tools/perf/tests/Makefile.tests| 24 ++++++++++++++++++++++++2 files changed, 35 insertions(+), 1 deletion(-)create mode 100644
tools/perf/tests/Makefile.teststools/perf/Makefile.perf +0
-0@@ -667,7 +667,16 @@ $(PERF_IN): prepare FORCE$(PMU_EVENTS_IN): FORCE prepare
$(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=pmu-events obj=pmu-events-$(OUTPUT)perf: $(PERFLIBS) $(PERF_IN) $(PMU_EVENTS_IN)
tools/perf/Makefile.perf +10
-0+# Runs shellcheck on perf test shell scripts +ifeq ($(CONFIG_SHELLCHECK),y) +SHELLCHECK_TEST: FORCE prepare + $(Q)$(MAKE) -f $(srctree)/tools/perf/tests/Makefile.tests +else +SHELLCHECK_TEST: + @: +endif + +$(OUTPUT)perf: $(PERFLIBS) $(PERF_IN) $(PMU_EVENTS_IN) SHELLCHECK_TEST $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) \ $(PERF_IN) $(PMU_EVENTS_IN) $(LIBS) -o $@@@ -1129,6 +1138,7 @@ bpf-skel-clean: $(call QUIET_CLEAN, bpf-skel) $(RM) -r $(SKEL_TMP_OUT) $(SKELETONS)clean:: $(LIBAPI)-clean $(LIBBPF)-clean $(LIBSUBCMD)-clean $(LIBSYMBOL)-clean $(LIBPERF)-clean fixdep-clean python-clean bpf-skel-clean tests-coresight-targets-clean
tools/perf/Makefile.perf +1
-0+ $(Q)$(MAKE) -f $(srctree)/tools/perf/tests/Makefile.tests clean $(call QUIET_CLEAN, core-objs) $(RM) $(LIBPERF_A) $(OUTPUT)perf-archive $(OUTPUT)perf-iostat $(LANG_BINDINGS) $(Q)find $(or $(OUTPUT),.) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete $(Q)$(RM) $(OUTPUT).config-detectedtools/perf/tests/Makefile.tests new file +13
-0@@ -0,0 +1,24 @@ +# SPDX-License-Identifier: GPL-2.0 +# Athira Rajeev <[email protected]>, 2023 +-include $(OUTPUT).config-detected + +log_file = $(OUTPUT)shellcheck_test.log +PROGS = $(subst ./,,$(shell find tests/shell -perm -o=x -type f -name '*.sh')) +DEPS = $(addprefix output/,$(addsuffix .dep,$(basename $(PROGS)))) +DIRS = $(shell echo $(dir $(DEPS)) | xargs -n1 | sort -u | xargs) + +.PHONY: all +all: SHELLCHECK_RUN + @: +
Quoted 8 lines
tools/perf/tests/Makefile.tests line 19
Quoted 6 lines
tools/perf/tests/Makefile.tests new file +6
-0+SHELLCHECK_RUN: $(DEPS) $(DIRS) + +output/%.dep: %.sh | $(DIRS) + $(call rule_mkdir) + $(Q)$(call frecho-cmd,test)@touch $@ + $(Q)$(call frecho-cmd,test)@shellcheck -S warning $(subst output/,./,$(patsubst %.dep, %.sh, $@)) 1> ${log_file} && ([[ ! -s ${log_file} ]])This line is too long, please wrap it with some backslashes.
Ok
I will address all the comments in next version
Thanks
Athira
Quoted 12 lines
Thanks,
NamhyungQuoted 7 lines
tools/perf/tests/Makefile.tests new file +5
-1+$(DIRS): + @mkdir -p $@ + +clean: + @rm -rf $(log_file) output --2.31.1
Re: [PATCH 2/2] tools/perf: Add perf binary dependent rule for shellcheck log in Makefile.perf
Quoted 104 lines · Athira Rajeev
Quoted 12 lines · Namhyung Kim
Quoted 5 lines · Athira Rajeev
Add rule in new
Makefile"tests/Makefile.tests" for running shellcheck on shell test scripts. This automates below shellcheck into the build.Quoted 5 lines
Quoted 1 line
$ for F in $(find tests/shell/ -perm -o=x -name '*.sh'); do shellcheck -S warning $F; doneI think you can do it if $(shell command -v shellcheck) returns non-empty string (the path to the shellcheck). Then the feature test logic can be gone.
Ok, I will try this.
Quoted 13 lines
Quoted 12 lines
CONFIG_SHELLCHECKcheck is added to avoid build breakage in the absence of shellcheck binary. Update Makefile.perf to contain new rule for "SHELLCHECK_TEST" which is for making shellcheck test as a dependency on perf binary. Added "tests/Makefile.tests" to run shellcheck on shellscripts in tests/shell. The make rule "SHLLCHECK_RUN" ensures that, every time during make, shellcheck will be run only on modified files during subsequent invocations. By this, if any newly added shell scripts or fixes in existing scripts breaks coding/formatting style, it will get captured during the perf build.Quoted 1 line
Can you show me the example output?
Sure, I will add it.
Quoted 58 lines
Quoted 58 lines
Signed-off-by Athira Rajeev <[email protected]>---
tools/perf/Makefile.perf| 12 +++++++++++-tools/perf/tests/Makefile.tests| 24 ++++++++++++++++++++++++2 files changed, 35 insertions(+), 1 deletion(-)create mode 100644
tools/perf/tests/Makefile.teststools/perf/Makefile.perf +0
-0@@ -667,7 +667,16 @@ $(PERF_IN): prepare FORCE$(PMU_EVENTS_IN): FORCE prepare
$(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=pmu-events obj=pmu-events-$(OUTPUT)perf: $(PERFLIBS) $(PERF_IN) $(PMU_EVENTS_IN)
tools/perf/Makefile.perf +10
-0+# Runs shellcheck on perf test shell scripts +ifeq ($(CONFIG_SHELLCHECK),y) +SHELLCHECK_TEST: FORCE prepare + $(Q)$(MAKE) -f $(srctree)/tools/perf/tests/Makefile.tests +else +SHELLCHECK_TEST: + @: +endif + +$(OUTPUT)perf: $(PERFLIBS) $(PERF_IN) $(PMU_EVENTS_IN) SHELLCHECK_TEST $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) \ $(PERF_IN) $(PMU_EVENTS_IN) $(LIBS) -o $@@@ -1129,6 +1138,7 @@ bpf-skel-clean: $(call QUIET_CLEAN, bpf-skel) $(RM) -r $(SKEL_TMP_OUT) $(SKELETONS)clean:: $(LIBAPI)-clean $(LIBBPF)-clean $(LIBSUBCMD)-clean $(LIBSYMBOL)-clean $(LIBPERF)-clean fixdep-clean python-clean bpf-skel-clean tests-coresight-targets-clean
tools/perf/Makefile.perf +1
-0+ $(Q)$(MAKE) -f $(srctree)/tools/perf/tests/Makefile.tests clean $(call QUIET_CLEAN, core-objs) $(RM) $(LIBPERF_A) $(OUTPUT)perf-archive $(OUTPUT)perf-iostat $(LANG_BINDINGS) $(Q)find $(or $(OUTPUT),.) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete $(Q)$(RM) $(OUTPUT).config-detectedtools/perf/tests/Makefile.tests new file +13
-0@@ -0,0 +1,24 @@ +# SPDX-License-Identifier: GPL-2.0 +# Athira Rajeev <[email protected]>, 2023 +-include $(OUTPUT).config-detected + +log_file = $(OUTPUT)shellcheck_test.log +PROGS = $(subst ./,,$(shell find tests/shell -perm -o=x -type f -name '*.sh')) +DEPS = $(addprefix output/,$(addsuffix .dep,$(basename $(PROGS)))) +DIRS = $(shell echo $(dir $(DEPS)) | xargs -n1 | sort -u | xargs) + +.PHONY: all +all: SHELLCHECK_RUN + @: +Quoted 8 lines
tools/perf/tests/Makefile.tests line 19
Quoted 6 lines
tools/perf/tests/Makefile.tests new file +6
-0+SHELLCHECK_RUN: $(DEPS) $(DIRS) + +output/%.dep: %.sh | $(DIRS) + $(call rule_mkdir) + $(Q)$(call frecho-cmd,test)@touch $@ + $(Q)$(call frecho-cmd,test)@shellcheck -S warning $(subst output/,./,$(patsubst %.dep, %.sh, $@)) 1> ${log_file} && ([[ ! -s ${log_file} ]])This line is too long, please wrap it with some backslashes.
Quoted 3 lines
Ok
I will address all the comments in next version
Hi Namhyung,
While working on V2 for the Makefile changes and testing, came across three issues with latest scripts in perf-tools-next. I have addressed those in below patchset:
https://lore.kernel.org/linux-perf-users/[email protected]/T/#m7b3dc8a96467058e1b392183190baed47ae0eb75
[PATCH 0/3] Fix for shellcheck issues with latest scripts in tests/shell
For the Makefile.perf changes, I will send V2 separately addressing review comments
Thanks
Athira
Quoted 15 lines
Thanks
AthiraQuoted 12 lines
Thanks,
NamhyungQuoted 7 lines
tools/perf/tests/Makefile.tests new file +5
-1+$(DIRS): + @mkdir -p $@ + +clean: + @rm -rf $(log_file) output --2.31.1