diff --git a/tools/perf/Build b/tools/perf/Build index e18c80a5c1bc..37d603faea6d 100644 --- a/tools/perf/Build +++ b/tools/perf/Build @@ -88,7 +88,7 @@ endif $(OUTPUT)%.mypy_log: % $(call rule_mkdir) - $(Q)$(call echo-cmd,test)mypy "$<" > $@ || (cat $@ && rm $@ && false) + $(Q)$(call echo-cmd,test)$(MYPY) "$<" > $@ || (cat $@ && rm $@ && false) perf-y += $(MYPY_TEST_LOGS) diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf index e91d6138330e..fbb5dfb67089 100644 --- a/tools/perf/Makefile.perf +++ b/tools/perf/Makefile.perf @@ -126,6 +126,8 @@ include ../scripts/utilities.mak # Define GEN_VMLINUX_H to generate vmlinux.h from the BTF. # # Define NO_SHELLCHECK if you do not want to run shellcheck during build +# +# Define NO_MYPY if you do not want to run mypy during build # As per kernel Makefile, avoid funny character set dependencies unexport LC_ALL @@ -259,9 +261,24 @@ ifneq ($(SHELLCHECK),) endif endif -# Runs mypy on perf python files -ifeq ($(MYPY),1) - MYPY := $(shell which mypy 2> /dev/null) +# Runs mypy on perf python files. +# Wait until after the fixdep bootstrap sub-make (force_fixdep != 1) so +# command-line overrides (MYPY=1, MYPY=/custom/path, NO_MYPY=1) reach the +# main Makefile.perf pass intact, then strip MYPY=% from MAKEOVERRIDES +# (substituting escaped spaces so multi-word overrides like MYPY="mypy --strict" +# are removed as a single token) so child Makefile.build sub-makes inherit the +# MYPYPATH-wrapped export MYPY environment variable. +ifneq ($(force_fixdep),1) + MAKEOVERRIDES := $(subst __SPACE__,\ ,$(filter-out MYPY=%,$(subst \ ,__SPACE__,$(MAKEOVERRIDES)))) + ifeq ($(NO_MYPY),1) + override MYPY := + else ifeq ($(filter-out 1,$(MYPY)),) + override MYPY := $(shell which mypy 2> /dev/null) + endif + + ifneq ($(MYPY),) + override MYPY := MYPYPATH=$(srctree)/tools/perf/python $(MYPY) --ignore-missing-imports + endif endif # Runs pylint on perf python files @@ -945,7 +962,8 @@ clean:: $(LIBAPI)-clean $(LIBBPF)-clean $(LIBSUBCMD)-clean $(LIBSYMBOL)-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 '*.a' -delete -o \ - -name '\.*.cmd' -delete -o -name '\.*.d' -delete -o -name '*.shellcheck_log' -delete + -name '\.*.cmd' -delete -o -name '\.*.d' -delete -o -name '*.shellcheck_log' -delete -o \ + -name '*.mypy_log' -delete $(Q)$(RM) $(OUTPUT).config-detected $(call QUIET_CLEAN, core-progs) $(RM) $(ALL_PROGRAMS) perf perf-read-vdso32 \ perf-read-vdsox32 $(OUTPUT)$(LIBJVMTI).so diff --git a/tools/perf/pmu-events/Build b/tools/perf/pmu-events/Build index 372773b998e4..c3542e5ae46f 100644 --- a/tools/perf/pmu-events/Build +++ b/tools/perf/pmu-events/Build @@ -187,7 +187,7 @@ JEVENTS_DEPS := $(OUT_JSON) $(GEN_JSON) $(JEVENTS_PY) $(METRIC_PY) $(EMPTY_PMU_E ifdef MYPY define MYPY_RULE $(2): $(1) - $$(Q)$$(call echo-cmd,test)mypy $(1) > $(2) || (cat $(2) && rm $(2) && false) + $$(Q)$$(call echo-cmd,test)$$(MYPY) $(1) > $(2) || (cat $(2) && rm $(2) && false) endef $(foreach src,$(wildcard pmu-events/*.py), \ $(eval dest := $(patsubst pmu-events/%,$(OUTPUT)pmu-events/%.mypy_log,$(src))) \ diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build index 81c311b131b7..cd7b62a6c1b8 100644 --- a/tools/perf/tests/Build +++ b/tools/perf/tests/Build @@ -104,7 +104,7 @@ endif $(OUTPUT)%.mypy_log: % $(call rule_mkdir) - $(Q)$(call echo-cmd,test)mypy "$<" > $@ || (cat $@ && rm $@ && false) + $(Q)$(call echo-cmd,test)$(MYPY) "$<" > $@ || (cat $@ && rm $@ && false) perf-test-y += $(MYPY_TEST_LOGS) diff --git a/tools/perf/util/Build b/tools/perf/util/Build index a4618e4e4848..f922794e8108 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -426,7 +426,7 @@ endif $(OUTPUT)%.mypy_log: % $(call rule_mkdir) - $(Q)$(call echo-cmd,test)mypy "$<" > $@ || (cat $@ && rm $@ && false) + $(Q)$(call echo-cmd,test)$(MYPY) "$<" > $@ || (cat $@ && rm $@ && false) perf-util-y += $(MYPY_TEST_LOGS)