From cd47cfeda8bdf6916a6516f877343189103c1f2f79c09e4f4fede99a43f55e35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Chv=C3=A1tal?= Date: Thu, 18 Jan 2018 12:04:08 +0000 Subject: [PATCH] - Add patch to build and work with python3: * libpfm-python3.patch - Build the python parts using singlespec macros to allow switching as needed OBS-URL: https://build.opensuse.org/package/show/devel:libraries:c_c++/libpfm?expand=0&rev=28 --- libpfm-python3.patch | 63 ++++++++++++++++++++++++++++++++++++++++++++ libpfm.changes | 8 ++++++ libpfm.spec | 38 +++++++++++++++++++++----- 3 files changed, 102 insertions(+), 7 deletions(-) create mode 100644 libpfm-python3.patch diff --git a/libpfm-python3.patch b/libpfm-python3.patch new file mode 100644 index 0000000..ee9de48 --- /dev/null +++ b/libpfm-python3.patch @@ -0,0 +1,63 @@ +Index: libpfm-4.9.0/python/src/pmu.py +=================================================================== +--- libpfm-4.9.0.orig/python/src/pmu.py ++++ libpfm-4.9.0/python/src/pmu.py +@@ -26,7 +26,7 @@ from perfmon import * + + def public_members(self): + s = "{ " +- for k, v in self.__dict__.iteritems(): ++ for k, v in self.__dict__.items(): + if not k[0] == '_': + s += "%s : %s, " % (k, v) + s += " }" +@@ -94,8 +94,8 @@ if __name__ == '__main__': + for pmu in s.pmus: + info = pmu.info + if info.flags.is_present: +- print info.name, info.size, info.nevents ++ print(info.name, info.size, info.nevents) + for e in pmu.events(): +- print e.info.name, e.info.code ++ print(e.info.name, e.info.code) + for a in e.attrs(): +- print '\t\t', a.name, a.code ++ print('\t\t', a.name, a.code) +Index: libpfm-4.9.0/python/sys.py +=================================================================== +--- libpfm-4.9.0.orig/python/sys.py ++++ libpfm-4.9.0/python/sys.py +@@ -48,7 +48,7 @@ if __name__ == '__main__': + if options.events: + events = options.events.split(",") + else: +- raise "You need to specify events to monitor" ++ raise Exception("You need to specify events to monitor") + + s = perfmon.SystemWideSession(cpus, events) + +@@ -60,4 +60,4 @@ if __name__ == '__main__': + for c in cpus: + for i in range(0, len(events)): + count = struct.unpack("L", s.read(c, i))[0] +- print """CPU%d: %s\t%lu""" % (c, events[i], count) ++ print("""CPU%d: %s\t%lu""" % (c, events[i], count)) +Index: libpfm-4.9.0/python/self.py +=================================================================== +--- libpfm-4.9.0.orig/python/self.py ++++ libpfm-4.9.0/python/self.py +@@ -40,7 +40,7 @@ if __name__ == '__main__': + if options.events: + events = options.events.split(",") + else: +- raise "You need to specify events to monitor" ++ raise Exception("You need to specify events to monitor") + + s = perfmon.PerThreadSession(int(os.getpid()), events) + s.start() +@@ -55,4 +55,4 @@ if __name__ == '__main__': + # read the counts + for i in range(0, len(events)): + count = struct.unpack("L", s.read(i))[0] +- print """%s\t%lu""" % (events[i], count) ++ print("""%s\t%lu""" % (events[i], count)) diff --git a/libpfm.changes b/libpfm.changes index 3097d59..d70f6ad 100644 --- a/libpfm.changes +++ b/libpfm.changes @@ -1,3 +1,11 @@ +------------------------------------------------------------------- +Wed Jan 17 15:52:07 UTC 2018 - tchvatal@suse.com + +- Add patch to build and work with python3: + * libpfm-python3.patch +- Build the python parts using singlespec macros to allow switching + as needed + ------------------------------------------------------------------- Wed Jan 17 15:30:33 UTC 2018 - tchvatal@suse.com diff --git a/libpfm.spec b/libpfm.spec index 1507326..2d63182 100644 --- a/libpfm.spec +++ b/libpfm.spec @@ -16,6 +16,8 @@ # +%global python_config CONFIG_PFMLIB_NOPYTHON=y +%{?!python_module:%define python_module() python-%{**} python3-%{**}} %define vname libpfm4 Name: libpfm Version: 4.9.0 @@ -26,7 +28,9 @@ Group: Development/Libraries/C and C++ Url: http://perfmon2.sourceforge.net/ Source: http://downloads.sourceforge.net/project/perfmon2/libpfm4/%{name}-%{version}.tar.gz Source1: baselibs.conf -BuildRequires: python-devel +Patch0: libpfm-python3.patch +BuildRequires: %{python_module devel} +BuildRequires: python-rpm-macros BuildRequires: swig >= 2.0.5 %description @@ -64,16 +68,26 @@ Requires: %{name}-devel = %{version} %description devel-static This package contains the static variant of libpfm. -%package -n python-%{name} +%package -n python2-%{name} Summary: Python bindings for libpfm and perf_event_open system call Group: Development/Libraries/Python Requires: %{vname} = %{version} -%description -n python-%{name} +%description -n python2-%{name} This package provides python bindings for the libpfm4 package and the perf_event_open system call. +%package -n python3-%{name} +Summary: Python3 bindings for libpfm and perf_event_open system call +Group: Development/Libraries/Python +Requires: %{vname} = %{version} + +%description -n python3-%{name} +This package provides python3 bindings for the libpfm4 package and the perf_event_open system call. + + %prep %setup -q +%patch0 -p1 # disable werror sed -i \ -e 's:-Werror::g' \ @@ -81,11 +95,14 @@ sed -i \ %build export CFLAGS="%{optflags}" -%global python_config CONFIG_PFMLIB_NOPYTHON=n make %{?_smp_mflags} %{python_config} +pushd python +%python_build +popd + %install -%global python_config CONFIG_PFMLIB_NOPYTHON=n PYTHON_PREFIX="%{buildroot}/%{py_prefix}" +%global python_config %{python_config} make \ PREFIX="%{buildroot}/%{_prefix}" \ LIBDIR="%{buildroot}/%{_libdir}" \ @@ -99,6 +116,10 @@ install -D -p -m 0755 examples/showevtinfo \ install -D -p -m 0755 perf_examples/evt2raw \ %{buildroot}/%{_bindir}/evt2raw +pushd python +%python_install +popd + # temp hack to fix rpmlint file-contains-buildroot for *.pyc # http://lists.opensuse.org/opensuse-factory/2012-01/msg00235.html find "%{buildroot}/%{python_sitearch}/" -name '*.pyc' -delete @@ -122,7 +143,10 @@ python -c 'import compileall; compileall.compile_dir("%{buildroot}%{python_sitea %files devel-static %{_libdir}/lib*.a -%files -n python-%{name} -%{python_sitearch}/* +%files -n python2-%{name} +%{python2_sitearch}/* + +%files -n python3-%{name} +%{python3_sitearch}/* %changelog