perf tools: Add support to install perf python extension
PATCH 1/1 perf tools: Add support to install perf python extension
Changing the distutils to use their own default 'build' directory.
Such setup makes the install command simple, because using --build-lib and --build-temp does not seem to comply with the way the distutils' install commands expect it.
Also keeping the python/perf.so file, so it could be used for testing as of until now.
--- tools/perf/Makefile | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-)
tools/perf/Makefile +6 -6
@@ -178,9 +178,8 @@ strip-libs = $(filter-out -l%,$(1)) $(OUTPUT)python/perf.so: $(PYRF_OBJS) $(QUIET_GEN)CFLAGS='$(BASIC_CFLAGS)' $(PYTHON_WORD) util/setup.py \ - --quiet build_ext \ - --build-lib='$(OUTPUT)python' \ - --build-temp='$(OUTPUT)python/temp' + --quiet build_ext; \ + cp $$(find build -name 'perf.so') python # # No Perl scripts right now: #
@@ -504,9 +503,7 @@ else PYTHON_WORD := $(call shell-wordify,$(PYTHON)) - python-clean := $(PYTHON_WORD) util/setup.py clean \ - --build-lib='$(OUTPUT)python' \ - --build-temp='$(OUTPUT)python/temp' + python-clean := $(PYTHON_WORD) util/setup.py --quiet clean -a; $(RM) -f python/perf.so ifdef NO_LIBPYTHON $(call disable-python)
@@ -863,6 +860,9 @@ install: all $(INSTALL) scripts/python/*.py -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python' $(INSTALL) scripts/python/bin/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/bin' +install-python_ext: + $(PYTHON_WORD) util/setup.py --quiet install --root='/$(DESTDIR_SQ)' + install-doc: $(MAKE) -C Documentation install
Signature · 1 line
1.7.1
Em Thu, Jul 21, 2011 at 06:45:26PM +0200, Jiri Olsa escreveu:
Quoted 9 lines
Changing the distutils to use their own default 'build' directory.
Such setup makes the install command simple, because using --build-lib and --build-temp does not seem to comply with the way the distutils' install commands expect it.
Also keeping the python/perf.so file, so it could be used for testing as of until now.
Yeah, I gave up when I couldn't get:
$ make O=/tmp/build-dir-for-perf/ -C tools/perf/ install
to work, does it now? Checking...
- Arnaldo
Quoted 44 lines
Signed-off-by Jiri Olsa <[email protected]>--- tools/perf/Makefile | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-)tools/perf/Makefile +6
-6@@ -178,9 +178,8 @@ strip-libs = $(filter-out -l%,$(1)) $(OUTPUT)python/perf.so: $(PYRF_OBJS) $(QUIET_GEN)CFLAGS='$(BASIC_CFLAGS)' $(PYTHON_WORD) util/setup.py \ - --quiet build_ext \ - --build-lib='$(OUTPUT)python' \ - --build-temp='$(OUTPUT)python/temp' + --quiet build_ext; \ + cp $$(find build -name 'perf.so') python # # No Perl scripts right now: #@@ -504,9 +503,7 @@ else PYTHON_WORD := $(call shell-wordify,$(PYTHON)) - python-clean := $(PYTHON_WORD) util/setup.py clean \ - --build-lib='$(OUTPUT)python' \ - --build-temp='$(OUTPUT)python/temp' + python-clean := $(PYTHON_WORD) util/setup.py --quiet clean -a; $(RM) -f python/perf.so ifdef NO_LIBPYTHON $(call disable-python)@@ -863,6 +860,9 @@ install: all $(INSTALL) scripts/python/*.py -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python' $(INSTALL) scripts/python/bin/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/bin' +install-python_ext: + $(PYTHON_WORD) util/setup.py --quiet install --root='/$(DESTDIR_SQ)' + install-doc: $(MAKE) -C Documentation installSignature · 1 line
1.7.1
Quoted 8 lines · Arnaldo Carvalho de Melo
Em Thu, Jul 21, 2011 at 06:45:26PM +0200, Jiri Olsa escreveu:
Quoted 7 lines
Changing the distutils to use their own default 'build' directory.
Such setup makes the install command simple, because using --build-lib and --build-temp does not seem to comply with the way the distutils' install commands expect it.
Quoted 8 lines
Quoted 2 lines
Also keeping the python/perf.so file, so it could be used for testing as of until now.
Yeah, I gave up when I couldn't get:
$ make O=/tmp/build-dir-for-perf/ -C tools/perf/ installto work, does it now? Checking...
nope, I added install-python_ext since it installs to the python system lib area, and it could break standard install
I think there's a way to install python modules under $HOME, maybe we could do that if no DESTDIR is specified.. I can add it later ;)
thanks,
jirka
Quoted 47 lines
- Arnaldo
Quoted 44 lines
Signed-off-by Jiri Olsa <[email protected]>--- tools/perf/Makefile | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-)tools/perf/Makefile +6
-6@@ -178,9 +178,8 @@ strip-libs = $(filter-out -l%,$(1)) $(OUTPUT)python/perf.so: $(PYRF_OBJS) $(QUIET_GEN)CFLAGS='$(BASIC_CFLAGS)' $(PYTHON_WORD) util/setup.py \ - --quiet build_ext \ - --build-lib='$(OUTPUT)python' \ - --build-temp='$(OUTPUT)python/temp' + --quiet build_ext; \ + cp $$(find build -name 'perf.so') python # # No Perl scripts right now: #@@ -504,9 +503,7 @@ else PYTHON_WORD := $(call shell-wordify,$(PYTHON)) - python-clean := $(PYTHON_WORD) util/setup.py clean \ - --build-lib='$(OUTPUT)python' \ - --build-temp='$(OUTPUT)python/temp' + python-clean := $(PYTHON_WORD) util/setup.py --quiet clean -a; $(RM) -f python/perf.so ifdef NO_LIBPYTHON $(call disable-python)@@ -863,6 +860,9 @@ install: all $(INSTALL) scripts/python/*.py -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python' $(INSTALL) scripts/python/bin/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/bin' +install-python_ext: + $(PYTHON_WORD) util/setup.py --quiet install --root='/$(DESTDIR_SQ)' + install-doc: $(MAKE) -C Documentation installSignature · 1 line
1.7.1
Em Thu, Jul 21, 2011 at 08:47:15PM +0200, Jiri Olsa escreveu:
Quoted 12 lines · Arnaldo Carvalho de Melo
Quoted 11 lines
Em Thu, Jul 21, 2011 at 06:45:26PM +0200, Jiri Olsa escreveu:
Quoted 9 lines
Changing the distutils to use their own default 'build' directory.
Such setup makes the install command simple, because using --build-lib and --build-temp does not seem to comply with the way the distutils' install commands expect it.
Also keeping the python/perf.so file, so it could be used for testing as of until now.
Quoted 8 lines
Quoted 5 lines
Yeah, I gave up when I couldn't get:
$ make O=/tmp/build-dir-for-perf/ -C tools/perf/ installto work, does it now? Checking...
nope, I added install-python_ext since it installs to the python system lib area, and it could break standard install
But where is that it picks the binaries built? The problem I was experiencing was that it wasn't obeying O=, just using the source dir as the build dir, effectively building it again, in a different place.
Quoted 3 lines
I think there's a way to install python modules under $HOME, maybe we could do that if no DESTDIR is specified.. I can add it later ;)
Right, but this is not what I was talking about :-)
- Arnaldo
Quoted 17 lines · Arnaldo Carvalho de Melo
Em Thu, Jul 21, 2011 at 08:47:15PM +0200, Jiri Olsa escreveu:
Quoted 16 lines · Arnaldo Carvalho de Melo
Quoted 15 lines
Em Thu, Jul 21, 2011 at 06:45:26PM +0200, Jiri Olsa escreveu:
Quoted 9 lines
Changing the distutils to use their own default 'build' directory.
Such setup makes the install command simple, because using --build-lib and --build-temp does not seem to comply with the way the distutils' install commands expect it.
Also keeping the python/perf.so file, so it could be used for testing as of until now.
Yeah, I gave up when I couldn't get:
$ make O=/tmp/build-dir-for-perf/ -C tools/perf/ install
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
to work, does it now? Checking...
nope, I added install-python_ext since it installs to the python system lib area, and it could break standard install
But where is that it picks the binaries built? The problem I was experiencing was that it wasn't obeying O=, just using the source dir
I haven't checked the 'O=' that much.. will do :)
Quoted 1 line
as the build dir, effectively building it again, in a different place.
I dont have that much experince with python, but here's what I found:
(might be missing something..)
build_ext command
- build_ext will by default create a 'build' directory and put all the stuff in - temp and final dirs/binary
- you can overload this with build-lib/build-temp options
install command
- install does not have option to specify the build-lib directory (but it has the --root option that we need)
- so running just install assumes you have used default 'build' directory and if it does not exist it starts rebuild
- there's another command install_lib, which let's you specify the build-lib.. BUT it wont let you specify the --root option ;)
There's possibility to use setup.cfg file and generate/put options for each command, so at the end we could choose what directory to use.
Also there might be a way to overload distutils class and put our specific options to this new class..
As I checked some of python extension packages, some of them do not use distutils at all.. can't imagine why ;)
jirka
Quoted 8 lines
Quoted 4 lines
I think there's a way to install python modules under $HOME, maybe we could do that if no DESTDIR is specified.. I can add it later ;)
Right, but this is not what I was talking about :-)
- Arnaldo
Em Thu, Jul 21, 2011 at 09:41:50PM +0200, Jiri Olsa escreveu:
Quoted 14 lines · Arnaldo Carvalho de Melo
Quoted 6 lines
Em Thu, Jul 21, 2011 at 08:47:15PM +0200, Jiri Olsa escreveu:
Quoted 2 lines
nope, I added install-python_ext since it installs to the python system lib area, and it could break standard install
But where is that it picks the binaries built? The problem I was experiencing was that it wasn't obeying O=, just using the source dir
I haven't checked the 'O=' that much.. will do :)
Quoted 1 line
as the build dir, effectively building it again, in a different place.
I dont have that much experince with python, but here's what I found:
(might be missing something..)
<SNIP>
Quoted 5 lines
Also there might be a way to overload distutils class and put our specific options to this new class..
As I checked some of python extension packages, some of them do not use distutils at all.. can't imagine why ;)
Ok, we're on the same page with that ';)' ;)
I'd love to use what is 'pythonic', i.e. whatever the python people think we should use and don't bother with all the module build/install details, but since we want to have O= working...
- Arnaldo
PATCH v2 1/1 perf tools: Add support to install perf python extension
Quoted 21 lines · Arnaldo Carvalho de Melo
Em Thu, Jul 21, 2011 at 09:41:50PM +0200, Jiri Olsa escreveu:
Quoted 14 lines · Arnaldo Carvalho de Melo
Quoted 6 lines
Em Thu, Jul 21, 2011 at 08:47:15PM +0200, Jiri Olsa escreveu:
Quoted 2 lines
nope, I added install-python_ext since it installs to the python system lib area, and it could break standard install
But where is that it picks the binaries built? The problem I was experiencing was that it wasn't obeying O=, just using the source dir
I haven't checked the 'O=' that much.. will do :)
Quoted 1 line
as the build dir, effectively building it again, in a different place.
I dont have that much experince with python, but here's what I found:
(might be missing something..)<SNIP>
Quoted 2 lines
Also there might be a way to overload distutils class and put our specific options to this new class..
Quoted 8 lines
Quoted 2 lines
As I checked some of python extension packages, some of them do not use distutils at all.. can't imagine why ;)
Ok, we're on the same page with that ';)' ;)
I'd love to use what is 'pythonic', i.e. whatever the python people think we should use and don't bother with all the module build/install details, but since we want to have O= working...
attached new version, working for me with the O= settings
jirka
---
Subject: [PATCH] perf tools: Add support to install perf python extension
Adding install-python_ext target to install python extension related files. Installation directory is governed by python distutils package and follows the DESTDIR variable settings.
Also moving python extension build output into '$(O)python_ext_build' directory and making it configurable via PYTHON_EXTBUILD variable.
Keeping the '$(O)python/perf.so' file, so it could be used for testing as of until now.
--- tools/perf/Makefile | 19 +++++++++++++------ tools/perf/util/setup.py | 21 ++++++++++++++++++++- 2 files changed, 33 insertions(+), 7 deletions(-)
tools/perf/Makefile +13 -6
@@ -178,9 +178,9 @@ strip-libs = $(filter-out -l%,$(1)) $(OUTPUT)python/perf.so: $(PYRF_OBJS) $(QUIET_GEN)CFLAGS='$(BASIC_CFLAGS)' $(PYTHON_WORD) util/setup.py \ - --quiet build_ext \ - --build-lib='$(OUTPUT)python' \ - --build-temp='$(OUTPUT)python/temp' + --quiet build_ext; \ + mkdir -p $(OUTPUT)python && \ + cp $(PYTHON_EXTBUILD_LIB)perf.so $(OUTPUT)python/ # # No Perl scripts right now: #
@@ -504,9 +504,13 @@ else PYTHON_WORD := $(call shell-wordify,$(PYTHON)) - python-clean := $(PYTHON_WORD) util/setup.py clean \ - --build-lib='$(OUTPUT)python' \ - --build-temp='$(OUTPUT)python/temp' + # python extension build directories + PYTHON_EXTBUILD := $(OUTPUT)python_ext_build/ + PYTHON_EXTBUILD_LIB := $(PYTHON_EXTBUILD)lib/ + PYTHON_EXTBUILD_TMP := $(PYTHON_EXTBUILD)tmp/ + export PYTHON_EXTBUILD_LIB PYTHON_EXTBUILD_TMP + + python-clean := rm -rf $(PYTHON_EXTBUILD) $(OUTPUT)python/perf.so ifdef NO_LIBPYTHON $(call disable-python)
@@ -863,6 +867,9 @@ install: all $(INSTALL) scripts/python/*.py -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python' $(INSTALL) scripts/python/bin/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/bin' +install-python_ext: + $(PYTHON_WORD) util/setup.py --quiet install --root='/$(DESTDIR_SQ)' + install-doc: $(MAKE) -C Documentation install
tools/perf/util/setup.py +20 -1
@@ -3,9 +3,27 @@ from distutils.core import setup, Extension from os import getenv +from distutils.command.build_ext import build_ext as _build_ext +from distutils.command.install_lib import install_lib as _install_lib + +class build_ext(_build_ext): + def finalize_options(self): + _build_ext.finalize_options(self) + self.build_lib = build_lib + self.build_temp = build_tmp + +class install_lib(_install_lib): + def finalize_options(self): + _install_lib.finalize_options(self) + self.build_dir = build_lib + + cflags = ['-fno-strict-aliasing', '-Wno-write-strings'] cflags += getenv('CFLAGS', '').split() +build_lib = getenv('PYTHON_EXTBUILD_LIB') +build_tmp = getenv('PYTHON_EXTBUILD_TMP') + perf = Extension('perf', sources = ['util/python.c', 'util/ctype.c', 'util/evlist.c', 'util/evsel.c', 'util/cpumap.c', 'util/thread_map.c',
@@ -21,4 +39,5 @@ setup(name='perf', author_email='[email protected]', license='GPLv2', url='http://perf.wiki.kernel.org', - ext_modules=[perf]) + ext_modules=[perf], + cmdclass={'build_ext': build_ext, 'install_lib': install_lib})
Signature · 1 line
1.7.1
Commit-ID: 9941c96ad869d10f7e34e03990ce450ab8fcb83d Gitweb: http://git.kernel.org/tip/9941c96ad869d10f7e34e03990ce450ab8fcb83d Author: Jiri Olsa <[email protected]> AuthorDate: Fri, 22 Jul 2011 13:33:07 +0200 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 8 Aug 2011 12:54:26 -0300
perf tools: Add support to install perf python extension
Adding install-python_ext target to install python extension related files. Installation directory is governed by python distutils package and follows the DESTDIR variable settings.
Also moving python extension build output into '$(O)python_ext_build' directory and making it configurable via PYTHON_EXTBUILD variable.
Keeping the '$(O)python/perf.so' file, so it could be used for testing as of until now.
--- tools/perf/Makefile | 19 +++++++++++++------ tools/perf/util/setup.py | 21 ++++++++++++++++++++- 2 files changed, 33 insertions(+), 7 deletions(-)
tools/perf/Makefile +13 -6
@@ -178,9 +178,9 @@ strip-libs = $(filter-out -l%,$(1)) $(OUTPUT)python/perf.so: $(PYRF_OBJS) $(QUIET_GEN)CFLAGS='$(BASIC_CFLAGS)' $(PYTHON_WORD) util/setup.py \ - --quiet build_ext \ - --build-lib='$(OUTPUT)python' \ - --build-temp='$(OUTPUT)python/temp' + --quiet build_ext; \ + mkdir -p $(OUTPUT)python && \ + cp $(PYTHON_EXTBUILD_LIB)perf.so $(OUTPUT)python/ # # No Perl scripts right now: #
@@ -506,9 +506,13 @@ else PYTHON_WORD := $(call shell-wordify,$(PYTHON)) - python-clean := $(PYTHON_WORD) util/setup.py clean \ - --build-lib='$(OUTPUT)python' \ - --build-temp='$(OUTPUT)python/temp' + # python extension build directories + PYTHON_EXTBUILD := $(OUTPUT)python_ext_build/ + PYTHON_EXTBUILD_LIB := $(PYTHON_EXTBUILD)lib/ + PYTHON_EXTBUILD_TMP := $(PYTHON_EXTBUILD)tmp/ + export PYTHON_EXTBUILD_LIB PYTHON_EXTBUILD_TMP + + python-clean := rm -rf $(PYTHON_EXTBUILD) $(OUTPUT)python/perf.so ifdef NO_LIBPYTHON $(call disable-python)
@@ -865,6 +869,9 @@ install: all $(INSTALL) scripts/python/*.py -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python' $(INSTALL) scripts/python/bin/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/bin' +install-python_ext: + $(PYTHON_WORD) util/setup.py --quiet install --root='/$(DESTDIR_SQ)' + install-doc: $(MAKE) -C Documentation install
tools/perf/util/setup.py +20 -1
@@ -3,9 +3,27 @@ from distutils.core import setup, Extension from os import getenv +from distutils.command.build_ext import build_ext as _build_ext +from distutils.command.install_lib import install_lib as _install_lib + +class build_ext(_build_ext): + def finalize_options(self): + _build_ext.finalize_options(self) + self.build_lib = build_lib + self.build_temp = build_tmp + +class install_lib(_install_lib): + def finalize_options(self): + _install_lib.finalize_options(self) + self.build_dir = build_lib + + cflags = ['-fno-strict-aliasing', '-Wno-write-strings'] cflags += getenv('CFLAGS', '').split() +build_lib = getenv('PYTHON_EXTBUILD_LIB') +build_tmp = getenv('PYTHON_EXTBUILD_TMP') + perf = Extension('perf', sources = ['util/python.c', 'util/ctype.c', 'util/evlist.c', 'util/evsel.c', 'util/cpumap.c', 'util/thread_map.c',
@@ -21,4 +39,5 @@ setup(name='perf', author_email='[email protected]', license='GPLv2', url='http://perf.wiki.kernel.org', - ext_modules=[perf]) + ext_modules=[perf], + cmdclass={'build_ext': build_ext, 'install_lib': install_lib})