Re: perf install-python_ext installing .o files in python site-packages

From: Jiri Olsa
Date: Fri Feb 26 2016 - 16:14:45 EST

On Fri, Feb 26, 2016 at 03:38:09PM -0500, Josh Boyer wrote:
> Hi Arnaldo,
> We've had a report [1] that the python-perf package in Fedora installs
> a handful of .o files in /usr/lib64/python2.7/site-packages/. This is
> true on Linus' latest tree, but it goes back to arriving with the 4.2
> kernel.
> Digging around a bit, it seems the files installed are those that are
> found as relative paths in the utils/python-ext-sources directory:
> /usr/lib64/python2.7/site-packages/bitmap.o
> /usr/lib64/python2.7/site-packages/find_bit.o
> /usr/lib64/python2.7/site-packages/hweight.o
> /usr/lib64/python2.7/site-packages/rbtree.o
> None of those files should really be installed at all, as they're
> temporary object files used to build
> As far as I can tell, this is a side effect of using the python
> distutils module with it's script. The sources are listed
> there so they get included, but then the build_ext functionality
> interprets it as e.g.:
> -c ../lib/hweight.c -o python_ext_build/tmp/../lib/hweight.o
> That leaves it in the lib/ directory of the build output alongside the
> final instead of python_ext_build/tmp/util/ like the rest of
> the object files. It happens to be an unfortunate coincidence that
> install-lib looks in said .../lib/ directory and we just happen to
> conflict with that naming. So when install-python_ext is called, it
> simply copies everything in that directory, including the .o files.
> I'm not enough of a python wizard to figure out how to fix this
> quickly. We could remove the .o files in the .spec file, but that
> seems hacky and this should probably be fixed in the perf build
> system.
> Ideas?

looks like the python extension build system mixes
up the '../lib' source files with final lib, which
by 'accident' is located in '../lib' as well ;-)

using full paths for sources sorted this for me (patch attached)

but that will end up with following build tree:


not sure we want to come up with some 'nicer' solution


diff --git a/tools/perf/util/ b/tools/perf/util/
index 1833103768cb..6c4bb2ea3594 100644
--- a/tools/perf/util/
+++ b/tools/perf/util/
@@ -22,6 +22,7 @@ cflags = getenv('CFLAGS', '').split()
# switch off several checks (need to be at the end of cflags list)
cflags += ['-fno-strict-aliasing', '-Wno-write-strings', '-Wno-unused-parameter' ]

+src_perf = getenv('srctree') + '/tools/perf'
build_lib = getenv('PYTHON_EXTBUILD_LIB')
build_tmp = getenv('PYTHON_EXTBUILD_TMP')
libtraceevent = getenv('LIBTRACEEVENT')
@@ -30,6 +31,8 @@ libapikfs = getenv('LIBAPI')
ext_sources = [f.strip() for f in file('util/python-ext-sources')
if len(f.strip()) > 0 and f[0] != '#']

+ext_sources = map(lambda x: '%s/%s' % (src_perf, x) , ext_sources)
perf = Extension('perf',
sources = ext_sources,
include_dirs = ['util/include'],