From: Ian Rogers <irogers@google.com>
To: benh@debian.org, acme@kernel.org, namhyung@kernel.org
Cc: linux-perf-users@vger.kernel.org,
linux-trace-kernel@vger.kernel.org, mingo@redhat.com,
peterz@infradead.org, rostedt@goodmis.org, tglozar@redhat.com,
Ian Rogers <irogers@google.com>
Subject: [PATCH v2 2/2] perf tools: Put Python bytecode in output directory
Date: Mon, 21 Sep 2026 10:57:19 -0700 [thread overview]
Message-ID: <20260921175719.846883-2-irogers@google.com> (raw)
In-Reply-To: <20260921175719.846883-1-irogers@google.com>
From: Ben Hutchings <benh@debian.org>
The PMU events are processed into C sources by Python scripts, which
normally results in writing bytecode for each module into the source
tree. This prevents a fully out-of-tree build.
To fix this, set $PYTHONPYCACHEPREFIX to relocate the bytecode cache
directory in an out-of-tree build. Note, this environment variable is
only supported by python 3.8+, but the file Documentation/Changes
states the minimum supported python for builds is 3.9.x. In an in-tree
build in tools/perf setting the variable causes a single __pycache__
directory in the source tree.
Expand python-clean to also clean the __pycache__ and perf.pyi.
Signed-off-by: Ben Hutchings <benh@debian.org>
Signed-off-by: Ian Rogers <irogers@google.com>
---
v2: Rebase. Add clean step and commit message comment wrt older python
versions (Sashiko). Make setting the environment variable true for
in-tree builds, that simplifies the clean.
---
tools/perf/Makefile.perf | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 438102bcae6c..715642630067 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__
ifneq ($(quiet),)
python_setup_quiet=--quiet
@@ -919,7 +920,12 @@ $(INSTALL_DOC_TARGETS):
### Cleaning rules
python-clean:
- $(python-clean)
+ $(call QUIET_CLEAN, python) $(RM) -r $(PYTHON_EXTBUILD) $(OUTPUT)__pycache__ \
+ $(OUTPUT)python/perf*.so
+ @if [ "$(abspath python/perf.pyi)" != "$(abspath $(OUTPUT)python/perf.pyi)" ]; \
+ then \
+ $(RM) $(OUTPUT)python/perf.pyi; \
+ fi
$(LIBAPI_OUTPUT) $(LIBBPF_OUTPUT) $(LIBPERF_OUTPUT) $(LIBSUBCMD_OUTPUT) $(LIBSYMBOL_OUTPUT):
$(Q)$(MKDIR) -p $@
--
2.55.0.1082.g2b9226bbc0-goog
next prev parent reply other threads:[~2026-09-21 17:57 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-21 14:34 [PATCH 0/3] Fix out-of-tree build of some tools Ben Hutchings
2026-05-21 14:35 ` [PATCH 1/3] rtla: Fix output files in source tree Ben Hutchings
2026-05-21 14:48 ` Steven Rostedt
2026-05-21 14:53 ` sashiko-bot
2026-05-21 14:35 ` [PATCH 2/3] perf tools: Put Python egg info in output directory Ben Hutchings
2026-05-21 14:35 ` [PATCH 3/3] perf tools: Put Python bytecode " Ben Hutchings
2026-05-21 15:18 ` sashiko-bot
2026-05-21 17:50 ` [PATCH 0/3] Fix out-of-tree build of some tools Ian Rogers
2026-09-15 23:08 ` Ian Rogers
2026-09-21 17:57 ` [PATCH v2 1/2] perf tools: Put Python egg info in output directory Ian Rogers
2026-09-21 17:57 ` Ian Rogers [this message]
2026-09-21 18:05 ` [PATCH v2 2/2] perf tools: Put Python bytecode " sashiko-bot
2026-09-21 18:12 ` Ian Rogers
2026-09-21 18:03 ` [PATCH v2 1/2] perf tools: Put Python egg info " sashiko-bot
2026-09-28 16:12 ` Ian Rogers
2026-09-28 16:26 ` Arnaldo Carvalho de Melo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260921175719.846883-2-irogers@google.com \
--to=irogers@google.com \
--cc=acme@kernel.org \
--cc=benh@debian.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tglozar@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox