mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
perf build: Make mypy build test opt-out (NO_MYPY=1)
Commit 168910d0f9 ("perf build: Add mypy build tests") added a
compile-time mypy type check for Python files in tools/perf, but left it
opt-in via MYPY=1.
Now that mypy issues across tools/perf/python, tools/perf/pmu-events,
and tools/perf/tests/shell/lib have been cleaned up, enable the mypy
check by default when mypy is installed on the system, with an opt-out
via NO_MYPY=1 (matching NO_SHELLCHECK=1 and other perf build feature
flags). Also configure MYPYPATH in Makefile.perf so scripts can resolve
perf.pyi type stubs and local modules, pass --ignore-missing-imports so
optional third-party packages do not fail default builds, and remove
*.mypy_log files during `make clean`.
Assisted-by: Antigravity:gemini-3.1-pro
Signed-off-by: Ian Rogers <irogers@google.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
1331150d7d
commit
b3e9c396d0
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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))) \
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user