Re: [PATCH v2 2/2] perf tools: Put Python bytecode in output directory

From
sashiko-bot@kernel.org
Date
2026-09-21 18:05:44
Also in
linux-perf-users
Reply to
Ian Rogers, 2026-09-21
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] perf: root filesystem pollution or build failure due to stray slash in PYTHONPYCACHEPREFIX
--

commit 3de8bc01d44a9b11e10c327ec26bbff8605926df
Author: Ben Hutchings [off-list ref]

perf tools: Put Python bytecode in output directory

This commit sets the PYTHONPYCACHEPREFIX environment variable to relocate
the Python bytecode cache directory to the output directory during out-of-tree
builds. It also updates the python-clean rule to remove the new cache directory
and perf.pyi.
quoted hunk ↗ jump to hunk
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index a0b23d20d005c..50bde95c78a54 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -397,7 +397,8 @@ PYTHON_EXTBUILD_LIB := $(PYTHON_EXTBUILD)lib/
 PYTHON_EXTBUILD_TMP := $(PYTHON_EXTBUILD)tmp/
 export PYTHON_EXTBUILD_LIB PYTHON_EXTBUILD_TMP
 
-python-clean := $(call QUIET_CLEAN, python) $(RM) -r $(PYTHON_EXTBUILD) $(OUTPUT)python/perf*.so
+# Put Python bytecode in output directory
+export PYTHONPYCACHEPREFIX := $(OUTPUT)/__pycache__
[Severity: Medium]
For in-tree builds where $(OUTPUT) is empty, does the unconditional inclusion
of the slash cause this to evaluate to the absolute path /__pycache__?

When Python 3.8+ runs during the build, it appears it would attempt to write
bytecode files to the root of the filesystem. Could this cause a regression
by breaking the build with permission errors for unprivileged users, or
silently pollute the root filesystem if executed as root?

[ ... ]
quoted hunk ↗ jump to hunk
@@ -919,7 +920,12 @@ $(INSTALL_DOC_TARGETS):
 ### Cleaning rules
 
 python-clean:
-	$(python-clean)
+	$(call QUIET_CLEAN, python) $(RM) -r $(PYTHON_EXTBUILD) $(OUTPUT)__pycache__ \
[Severity: Medium]
Since $(OUTPUT)__pycache__ would evaluate to __pycache__ in the current
directory during in-tree builds, would this fail to clean the incorrectly
placed bytecode directory at the root of the filesystem?
quoted hunk ↗ jump to hunk
+		$(OUTPUT)python/perf*.so
+	@if [ "$(abspath python/perf.pyi)" != "$(abspath $(OUTPUT)python/perf.pyi)" ]; \
+	then \
+		$(RM) $(OUTPUT)python/perf.pyi; \
+	fi
-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260921175719.846883-1-irogers@google.com?part=2
Thread (14 messages) 14 messages, 5 authors, last reply 2026-09-28
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help