[lttng-dev] [PATCH babeltrace v4] Build Python bindings with distutils for consistent installs
v4: Fix DESTDIR behaviour on (un)install targets. This patch changes the build system used to compile and install the Python Bindings. Distutils is used to find the right install directory. When the install directory generated from the install prefix is not in the Python search path (PYTHONPATH), we print a warning explaining what can be done to include it. It uses Distutils which is part of the Python standard library. Signed-off-by: Francis Deslauriers --- .gitignore| 10 +++- bindings/python/Makefile.am | 58 +- bindings/python/babeltrace/Makefile.am| 30 ++ bindings/python/babeltrace/__init__.py.in | 25 bindings/python/setup.py.in | 84 +++ configure.ac | 14 +++-- m4/python_modules.m4 | 23 tests/bin/intersection/bt_python_helper.py.in | 8 +-- 8 files changed, 187 insertions(+), 65 deletions(-) create mode 100644 bindings/python/babeltrace/__init__.py.in create mode 100644 bindings/python/setup.py.in delete mode 100644 m4/python_modules.m4 diff --git a/.gitignore b/.gitignore index a7c9e3c..9259b6f 100644 --- a/.gitignore +++ b/.gitignore @@ -47,8 +47,12 @@ converter/babeltrace-log core formats/ctf/metadata/ctf-parser.output stamp-h1 -bindings/python/babeltrace.i -bindings/python/babeltrace.py -bindings/python/babeltrace_wrap.c +bindings/python/setup.py +bindings/python/installed_files.txt +bindings/python/build +bindings/python/babeltrace/__init__.py +bindings/python/babeltrace/babeltrace.i +bindings/python/babeltrace/babeltrace.py +bindings/python/babeltrace/babeltrace_wrap.c babeltrace.pc babeltrace-ctf.pc diff --git a/bindings/python/Makefile.am b/bindings/python/Makefile.am index d6b3648..0009546 100644 --- a/bindings/python/Makefile.am +++ b/bindings/python/Makefile.am @@ -1,3 +1,59 @@ if USE_PYTHON -SUBDIRS = babeltrace +SUBDIRS = babeltrace . + +INSTALLED_FILES=$(builddir)/installed_files.txt + +AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/include -I$(srcdir)/babeltrace/ + +# Since the shared object used by the python bindings is not built with libtool +# we need to manually set the `rpath` during linkage +AM_LDFLAGS=-L$(top_builddir)/formats/ctf/.libs -L$(top_builddir)/lib/.libs -Wl,-rpath,$(prefix)/lib + +all-local: build-python-bindings.stamp + +$(builddir)/babeltrace/__init__.py: $(srcdir)/babeltrace/__init__.py.in + cd babeltrace && $(MAKE) __init__.py + +$(builddir)/babeltrace/babeltrace.i: $(srcdir)/babeltrace/babeltrace.i.in + cd babeltrace && $(MAKE) babeltrace.i + +BINDINGS_DEPS=setup.py \ + babeltrace/__init__.py \ + babeltrace/babeltrace.i \ + babeltrace/python-complements.c \ + babeltrace/python-complements.h + +BUILD_FLAGS=CC="$(CC)" \ + CFLAGS="$(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(GLIB_CFLAGS) $(AM_CFLAGS)" \ + CPPFLAGS="$(AM_CPPFLAGS) $(CPPFLAGS)" \ + LDFLAGS="$(AM_LDFLAGS) $(LDFLAGS)" + +build-python-bindings.stamp: $(BINDINGS_DEPS) + $(BUILD_FLAGS) $(PYTHON) $(builddir)/setup.py build_ext + $(BUILD_FLAGS) $(PYTHON) $(builddir)/setup.py build + touch $@ + +install-exec-local: build-python-bindings.stamp + @opts="--prefix=$(prefix) --record $(INSTALLED_FILES) --verbose --no-compile $(DISTSETUPOPTS)"; \ + if [ "$(DESTDIR)" != "" ]; then \ + opts="$$opts --root=$(DESTDIR)"; \ + fi; \ + $(PYTHON) $(builddir)/setup.py install $$opts; + +clean-local: + rm -rf $(builddir)/build + +# Distutils' setup.py does not include an uninstall target, we thus need to do +# it manually. We save the path of the files that were installed during the install target +# and delete them during the uninstallation. +uninstall-local: + if [ "$(DESTDIR)" != "" ]; then \ + $(SED) -i "s|^|$(DESTDIR)/|g" $(INSTALLED_FILES); \ + fi + cat $(INSTALLED_FILES) | xargs rm -rf || true + $(GREP) "__init__.py" $(INSTALLED_FILES) | xargs dirname | xargs rm -rf || true + rm -f $(INSTALLED_FILES) + +CLEANFILES = babeltrace/babeltrace_wrap.c babeltrace/babeltrace.py build-python-bindings.stamp +DISTCLEANFILES = setup.py endif diff --git a/bindings/python/babeltrace/Makefile.am b/bindings/python/babeltrace/Makefile.am index 11dcdf0..f612aa6 100644 --- a/bindings/python/babeltrace/Makefile.am +++ b/bindings/python/babeltrace/Makefile.am @@ -1,31 +1,9 @@ +if USE_PYTHON babeltrace.i: babeltrace.i.in sed "s/BABELTRACE_VERSION_STR/Babeltrace $(PACKAGE_VERSION)/g" < \ $(top_srcdir)/bindings/python/babeltrace/babeltrace.i.in > \ $(top_builddir)/bindings/python/babeltrace/babeltrace.i -AM_CFLAGS = $(PYTHON_INCLUDE) -I$(top_srcdir)/include/ \ - -I$(top_srcdir)/bindings/python/babeltrace - -EXTRA_DIST = babeltrace.i.in -nodist_pyth
Re: [lttng-dev] [PATCH babeltrace v4] Build Python bindings with distutils for consistent installs
The tests implemented in python don't seem to work with this patch applied. See if you can reproduce it yourself: ./configure --enable-python-bindings make check Thanks, Jérémie On 6 March 2017 at 12:19, Francis Deslauriers wrote: > v4: Fix DESTDIR behaviour on (un)install targets. > > This patch changes the build system used to compile and install the > Python Bindings. Distutils is used to find the right install directory. > When the install directory generated from the install prefix is not in > the Python search path (PYTHONPATH), we print a warning explaining what > can be done to include it. > It uses Distutils which is part of the Python standard library. > > Signed-off-by: Francis Deslauriers > --- > .gitignore| 10 +++- > bindings/python/Makefile.am | 58 +- > bindings/python/babeltrace/Makefile.am| 30 ++ > bindings/python/babeltrace/__init__.py.in | 25 > bindings/python/setup.py.in | 84 > +++ > configure.ac | 14 +++-- > m4/python_modules.m4 | 23 > tests/bin/intersection/bt_python_helper.py.in | 8 +-- > 8 files changed, 187 insertions(+), 65 deletions(-) > create mode 100644 bindings/python/babeltrace/__init__.py.in > create mode 100644 bindings/python/setup.py.in > delete mode 100644 m4/python_modules.m4 > > diff --git a/.gitignore b/.gitignore > index a7c9e3c..9259b6f 100644 > --- a/.gitignore > +++ b/.gitignore > @@ -47,8 +47,12 @@ converter/babeltrace-log > core > formats/ctf/metadata/ctf-parser.output > stamp-h1 > -bindings/python/babeltrace.i > -bindings/python/babeltrace.py > -bindings/python/babeltrace_wrap.c > +bindings/python/setup.py > +bindings/python/installed_files.txt > +bindings/python/build > +bindings/python/babeltrace/__init__.py > +bindings/python/babeltrace/babeltrace.i > +bindings/python/babeltrace/babeltrace.py > +bindings/python/babeltrace/babeltrace_wrap.c > babeltrace.pc > babeltrace-ctf.pc > diff --git a/bindings/python/Makefile.am b/bindings/python/Makefile.am > index d6b3648..0009546 100644 > --- a/bindings/python/Makefile.am > +++ b/bindings/python/Makefile.am > @@ -1,3 +1,59 @@ > if USE_PYTHON > -SUBDIRS = babeltrace > +SUBDIRS = babeltrace . > + > +INSTALLED_FILES=$(builddir)/installed_files.txt > + > +AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/include -I$(srcdir)/babeltrace/ > + > +# Since the shared object used by the python bindings is not built with > libtool > +# we need to manually set the `rpath` during linkage > +AM_LDFLAGS=-L$(top_builddir)/formats/ctf/.libs -L$(top_builddir)/lib/.libs > -Wl,-rpath,$(prefix)/lib > + > +all-local: build-python-bindings.stamp > + > +$(builddir)/babeltrace/__init__.py: $(srcdir)/babeltrace/__init__.py.in > + cd babeltrace && $(MAKE) __init__.py > + > +$(builddir)/babeltrace/babeltrace.i: $(srcdir)/babeltrace/babeltrace.i.in > + cd babeltrace && $(MAKE) babeltrace.i > + > +BINDINGS_DEPS=setup.py \ > + babeltrace/__init__.py \ > + babeltrace/babeltrace.i \ > + babeltrace/python-complements.c \ > + babeltrace/python-complements.h > + > +BUILD_FLAGS=CC="$(CC)" \ > + CFLAGS="$(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) > $(GLIB_CFLAGS) $(AM_CFLAGS)" \ > + CPPFLAGS="$(AM_CPPFLAGS) $(CPPFLAGS)" \ > + LDFLAGS="$(AM_LDFLAGS) $(LDFLAGS)" > + > +build-python-bindings.stamp: $(BINDINGS_DEPS) > + $(BUILD_FLAGS) $(PYTHON) $(builddir)/setup.py build_ext > + $(BUILD_FLAGS) $(PYTHON) $(builddir)/setup.py build > + touch $@ > + > +install-exec-local: build-python-bindings.stamp > + @opts="--prefix=$(prefix) --record $(INSTALLED_FILES) --verbose > --no-compile $(DISTSETUPOPTS)"; \ > + if [ "$(DESTDIR)" != "" ]; then \ > + opts="$$opts --root=$(DESTDIR)"; \ > + fi; \ > + $(PYTHON) $(builddir)/setup.py install $$opts; > + > +clean-local: > + rm -rf $(builddir)/build > + > +# Distutils' setup.py does not include an uninstall target, we thus need to > do > +# it manually. We save the path of the files that were installed during the > install target > +# and delete them during the uninstallation. > +uninstall-local: > + if [ "$(DESTDIR)" != "" ]; then \ > + $(SED) -i "s|^|$(DESTDIR)/|g" $(INSTALLED_FILES); \ > + fi > + cat $(INSTALLED_FILES) | xargs rm -rf || true > + $(GREP) "__init__.py" $(INSTALLED_FILES) | xargs dirname | xargs rm > -rf || true > + rm -f $(INSTALLED_FILES) > + > +CLEANFILES = babeltrace/babeltrace_wrap.c babeltrace/babeltrace.py > build-python-bindings.stamp > +DISTCLEANFILES = setup.py > endif > diff --git a/bindings/python/babeltrace/Makefile.am > b/bindings/python/babeltrace/Makefile.am > index 11dcdf0..f612aa6 100644 > --- a/bindings/python/babeltrace/Makefile.am > +++ b/bindings