Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf build: Shellcheck support for OUTPUT directory

Migrate Makefile.tests to Build so that variables like rule_mkdir are
defined via Makefile.build (needed so the output directory can be
created). This requires SHELLCHECK being exported and the clean rule
tweaking to remove the files in find.

Change find "-perm -o=x" as it was failing on my Debian based Linux
kernel tree, switch to using "-executable".

Adding a filename prefix of "." to the shellcheck log files is a pain
and error prone in make, remove this prefix and just add the
shellcheck log files to .gitignore.

Fix the command echo so that running the test is displayed.

Fixes: 1638b11ef8156c85 ("perf tools: Add perf binary dependent rule for shellcheck log in Makefile.perf")
Reviewed-by: Athira Jajeev <atrajeev@linux.vnet.ibm.com>
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20231129213428.2227448-1-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
b809fc65 16438b65

+27 -42
+3
tools/perf/.gitignore
··· 39 39 pmu-events/pmu-events.c 40 40 pmu-events/jevents 41 41 pmu-events/metric_test.log 42 + tests/shell/*.shellcheck_log 43 + tests/shell/coresight/*.shellcheck_log 44 + tests/shell/lib/*.shellcheck_log 42 45 feature/ 43 46 libapi/ 44 47 libbpf/
+10 -20
tools/perf/Makefile.perf
··· 229 229 force_fixdep := $(config) 230 230 endif 231 231 232 + # Runs shellcheck on perf test shell scripts 233 + ifeq ($(NO_SHELLCHECK),1) 234 + SHELLCHECK := 235 + else 236 + SHELLCHECK := $(shell which shellcheck 2> /dev/null) 237 + endif 238 + 232 239 export srctree OUTPUT RM CC CXX LD AR CFLAGS CXXFLAGS V BISON FLEX AWK 233 - export HOSTCC HOSTLD HOSTAR HOSTCFLAGS 240 + export HOSTCC HOSTLD HOSTAR HOSTCFLAGS SHELLCHECK 234 241 235 242 include $(srctree)/tools/build/Makefile.include 236 243 ··· 680 673 $(PMU_EVENTS_IN): FORCE prepare 681 674 $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=pmu-events obj=pmu-events 682 675 683 - # Runs shellcheck on perf test shell scripts 684 - 685 - SHELLCHECK := $(shell which shellcheck 2> /dev/null) 686 - 687 - ifeq ($(NO_SHELLCHECK),1) 688 - SHELLCHECK := 689 - endif 690 - 691 - ifneq ($(SHELLCHECK),) 692 - SHELLCHECK_TEST: FORCE prepare 693 - $(Q)$(MAKE) -f $(srctree)/tools/perf/tests/Makefile.tests 694 - else 695 - SHELLCHECK_TEST: 696 - @: 697 - endif 698 - 699 - $(OUTPUT)perf: $(PERFLIBS) $(PERF_IN) $(PMU_EVENTS_IN) SHELLCHECK_TEST 676 + $(OUTPUT)perf: $(PERFLIBS) $(PERF_IN) $(PMU_EVENTS_IN) 700 677 $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) \ 701 678 $(PERF_IN) $(PMU_EVENTS_IN) $(LIBS) -o $@ 702 679 ··· 1143 1152 $(call QUIET_CLEAN, bpf-skel) $(RM) -r $(SKEL_TMP_OUT) $(SKELETONS) 1144 1153 1145 1154 clean:: $(LIBAPI)-clean $(LIBBPF)-clean $(LIBSUBCMD)-clean $(LIBSYMBOL)-clean $(LIBPERF)-clean fixdep-clean python-clean bpf-skel-clean tests-coresight-targets-clean 1146 - $(Q)$(MAKE) -f $(srctree)/tools/perf/tests/Makefile.tests clean 1147 1155 $(call QUIET_CLEAN, core-objs) $(RM) $(LIBPERF_A) $(OUTPUT)perf-archive $(OUTPUT)perf-iostat $(LANG_BINDINGS) 1148 - $(Q)find $(or $(OUTPUT),.) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete 1156 + $(Q)find $(or $(OUTPUT),.) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete -o -name '*.shellcheck_log' -delete 1149 1157 $(Q)$(RM) $(OUTPUT).config-detected 1150 1158 $(call QUIET_CLEAN, core-progs) $(RM) $(ALL_PROGRAMS) perf perf-read-vdso32 perf-read-vdsox32 $(OUTPUT)$(LIBJVMTI).so 1151 1159 $(call QUIET_CLEAN, core-gen) $(RM) *.spec *.pyc *.pyo */*.pyc */*.pyo $(OUTPUT)common-cmds.h TAGS tags cscope* $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)FEATURE-DUMP $(OUTPUT)util/*-bison* $(OUTPUT)util/*-flex* \
+14
tools/perf/tests/Build
··· 77 77 CFLAGS_dwarf-unwind.o += -fno-optimize-sibling-calls 78 78 79 79 perf-y += workloads/ 80 + 81 + ifdef SHELLCHECK 82 + SHELL_TESTS := $(shell find tests/shell -executable -type f -name '*.sh') 83 + TEST_LOGS := $(SHELL_TESTS:tests/shell/%=shell/%.shellcheck_log) 84 + else 85 + SHELL_TESTS := 86 + TEST_LOGS := 87 + endif 88 + 89 + $(OUTPUT)%.shellcheck_log: % 90 + $(call rule_mkdir) 91 + $(Q)$(call echo-cmd,test)shellcheck -a -S warning "$<" > $@ || (cat $@ && rm $@ && false) 92 + 93 + perf-y += $(TEST_LOGS)
-22
tools/perf/tests/Makefile.tests
··· 1 - # SPDX-License-Identifier: GPL-2.0 2 - # Athira Rajeev <atrajeev@linux.vnet.ibm.com>, 2023 3 - 4 - PROGS := $(shell find tests/shell -perm -o=x -type f -name '*.sh') 5 - FILE_NAME := $(notdir $(PROGS)) 6 - FILE_NAME := $(FILE_NAME:%=.%) 7 - LOGS := $(join $(dir $(PROGS)),$(FILE_NAME)) 8 - LOGS := $(LOGS:%=%.shellcheck_log) 9 - 10 - .PHONY: all 11 - all: SHELLCHECK_RUN 12 - @: 13 - 14 - SHELLCHECK_RUN: $(LOGS) 15 - 16 - .%.shellcheck_log: % 17 - $(call rule_mkdir) 18 - $(Q)$(call frecho-cmd,test)@shellcheck -S warning "$<" > $@ || (cat $@ && rm $@ && false) 19 - 20 - clean: 21 - $(eval log_files := $(shell find . -name '.*.shellcheck_log')) 22 - @rm -rf $(log_files)