bt2: run swig by hand instead of through "setup.py build_ext"
authorSimon Marchi <simon.marchi@efficios.com>
Wed, 17 Jul 2019 03:04:06 +0000 (23:04 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 18 Jul 2019 05:26:40 +0000 (01:26 -0400)
commite7d63bf32268fcaf9e1f5724cf4def49f3f9c081
tree3231175c18c6c9a7f13974565b1db7ed290cfc70
parent8c102541166f7494fd8142593fe498ca9bf567b4
bt2: run swig by hand instead of through "setup.py build_ext"

When we build the bt2 Python module, we call "setup.py build_ext", which
runs swig to generate the .c file from .i files and builds the native
library.  We then run "setup.py build" to copy the Python files over to
build_lib directory.

However, "setup.py build" insists on running "build_ext" itself, seeing
that we have an ext_modules entry in our setup.py.  This results in the
.i -> .so process being run twice.  It's a bit wasteful to do the
process twice, but in itself it's not a big problem.

A bigger problem is that the second time swig is ran (through "setup.py
build"), it is done without honoring the SWIG Makefile variable. Here, I
have configured my build to use SWIG=/tmp/swig/bin/swig, and the two
swig invocations are:

    /tmp/swig/bin/swig -python -I/home/simark/src/babeltrace/include -o bt2/native_bt_wrap.c bt2/native_bt.i
    swig -python -I/home/simark/src/babeltrace/include -o bt2/native_bt_wrap.c bt2/native_bt.i

This means that trying to use a custom swig executable through the SWIG
configuration variable will not work, as it will always be overwritten
by the output of the "swig" in the path.

I haven't found a way to get the right swig executable to be used the
second time:

- "setup.py build" doesn't have a --swig option
- We can't use swig= in setup.py
- We can't override using an environment variable

The solution I found was to run swig ourselves to generate the .c file,
and feed that to the native extension built with distutils.  We now
don't need to call build_ext explicitly, since the call done through
"build" is sufficient.  It therefore fixes both problems: swigging and
building the library is now done only once, and the right swig
executable is used.

Change-Id: I9ed9d22fae1f5675d42af08e77607515dfdf788a
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1711
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
src/bindings/python/bt2/Makefile.am
src/bindings/python/bt2/setup.py.in
This page took 0.024809 seconds and 4 git commands to generate.