[SRU][O][N][PATCH v2 2/3] UBUNTU: [Packaging] linux-tools: Fix python perf library packaging
Juerg Haefliger
juerg.haefliger at canonical.com
Thu Jan 23 16:06:34 UTC 2025
BugLink: https://bugs.launchpad.net/bugs/2089411
This currently doesn't work for derivatives because there's a level
of indirection missing and the top-level wrapper is looking in the
wrong place for the .so library.
It should be like this:
foo -> linux-tools/<abi>-<flavor>/foo -> <source>-tools-<abi>/foo
The previous commit took care of the missing indirection. This commit
fixes the wrapper to look in the correct directory for the library.
While at it, run it through black and make the wrapper and the .so
library non-executable.
Signed-off-by: Juerg Haefliger <juerg.haefliger at canonical.com>
Acked-by: Agathe Porte <agathe.porte at canonical.com>
Signed-off-by: Timo Aaltonen <timo.aaltonen at canonical.com>
(backported from commit e3092e36b13ccf423258b2232cff0c4d5841d426 plucky:linux)
[juergh: Changed $(DEB_SOURCE) -> $(src_pkg_name)]
Signed-off-by: Juerg Haefliger <juerg.haefliger at canonical.com>
---
debian/rules.d/2-binary-arch.mk | 4 ++--
debian/rules.d/3-binary-indep.mk | 2 +-
debian/tools/python-perf.py | 27 +++++++++++++--------------
3 files changed, 16 insertions(+), 17 deletions(-)
diff --git a/debian/rules.d/2-binary-arch.mk b/debian/rules.d/2-binary-arch.mk
index 54c9228e5145..1d8625885dee 100644
--- a/debian/rules.d/2-binary-arch.mk
+++ b/debian/rules.d/2-binary-arch.mk
@@ -734,8 +734,8 @@ ifeq ($(do_tools_perf_jvmti),true)
install -m755 $(builddirpa)/tools/perf/libperf-jvmti.so $(toolspkgdir)/usr/lib/$(src_pkg_name)-tools-$(abi_release)
endif
ifeq ($(do_tools_perf_python),true)
- install -d $(toolspkgdir)/usr/lib/python3/dist-packages/$(src_pkg_name)-tools-$(abi_release)
- install -m755 $(builddirpa)/tools/perf/python/perf*.so $(toolspkgdir)/usr/lib/python3/dist-packages/$(src_pkg_name)-tools-$(abi_release)
+ install -d $(toolspkgdir)/usr/lib/$(src_pkg_name)-tools-$(abi_release)/lib
+ install -m644 $(builddirpa)/tools/perf/python/perf.*.so $(toolspkgdir)/usr/lib/$(src_pkg_name)-tools-$(abi_release)/lib
endif
endif
ifeq ($(do_tools_bpftool),true)
diff --git a/debian/rules.d/3-binary-indep.mk b/debian/rules.d/3-binary-indep.mk
index 75b8e457b7d0..ab9377497c15 100644
--- a/debian/rules.d/3-binary-indep.mk
+++ b/debian/rules.d/3-binary-indep.mk
@@ -113,7 +113,7 @@ ifeq ($(do_tools_common),true)
ifeq ($(do_tools_perf_python),true)
# Python wrapper module for python-perf
install -d $(toolspython)/perf
- install -m755 debian/tools/python-perf.py $(toolspython)/perf/__init__.py
+ install -m644 debian/tools/python-perf.py $(toolspython)/perf/__init__.py
endif
ifeq ($(do_cloud_tools),true)
ifeq ($(do_tools_hyperv),true)
diff --git a/debian/tools/python-perf.py b/debian/tools/python-perf.py
index d572fece82aa..d1991d677dcb 100644
--- a/debian/tools/python-perf.py
+++ b/debian/tools/python-perf.py
@@ -2,31 +2,30 @@ import os
import importlib.util
from glob import glob
+
class KernelNotFoundError(Exception):
def __init__(self):
kernel_version = os.uname().release
- super().__init__(f"WARNING: python perf module not found for kernel {kernel_version}\n\n"
- f"You may need to install the following packages for this specific kernel:\n"
- f" linux-tools-{kernel_version}-generic\n"
- f"You may also want to install of the following package to keep up to date:\n"
- f" linux-tools-generic")
+ flavor = kernel_version.split("-", 2)[2]
+ super().__init__(
+ f"\nWARNING: python perf module not found for kernel {kernel_version}\n\n"
+ f" You may need to install the following package for this specific kernel:\n"
+ f" linux-tools-{kernel_version}\n\n"
+ f" You may also want to install the following package to keep up to date:\n"
+ f" linux-tools-{flavor}"
+ )
-# Extract ABI number from kernel version
-def _get_abi_version():
- _kernel_version = os.uname().release
- _parts = _kernel_version.split("-")
- return "-".join(_parts[:-1])
# Load the actual python-perf module for the running kernel
-_abi_version = _get_abi_version()
-_perf_dir = f"/usr/lib/python3/dist-packages/linux-tools-{_abi_version}"
+_kernel_version = os.uname().release
+_perf_dir = f"/usr/lib/linux-tools/{_kernel_version}/lib"
if not os.path.exists(_perf_dir):
raise KernelNotFoundError()
-_perf_lib = glob(os.path.join(_perf_dir, "*.so"))[-1]
+_perf_lib = glob(os.path.join(_perf_dir, "perf.*.so"))[-1]
_spec = importlib.util.spec_from_file_location("perf", _perf_lib)
_perf = importlib.util.module_from_spec(_spec)
_spec.loader.exec_module(_perf)
# Expose the 'perf' module.
-__all__ = ['perf']
+__all__ = ["perf"]
--
2.43.0
More information about the kernel-team
mailing list