From 1ecc312721105f103078046bc73b63eb057f0871 Mon Sep 17 00:00:00 2001 From: Juerg Haefliger Date: Thu, 23 Jan 2025 17:06:34 +0100 Subject: [PATCH] UBUNTU: [Packaging] linux-tools: Fix python perf library packaging 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/-/foo -> -tools-/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 Acked-by: Agathe Porte Signed-off-by: Timo Aaltonen (backported from commit e3092e36b13ccf423258b2232cff0c4d5841d426 plucky:linux) [juergh: Changed $(DEB_SOURCE) -> $(src_pkg_name)] Signed-off-by: Juerg Haefliger Acked-by: Kevin Becker Acked-by: Agathe Porte Signed-off-by: Koichiro Den --- 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 25fec719e243..ef07269722ed 100644 --- a/debian/rules.d/2-binary-arch.mk +++ b/debian/rules.d/2-binary-arch.mk @@ -738,8 +738,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"]