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>
INSTALLED_FILES=$(builddir)/installed_files.txt
INSTALLED_FILES=$(builddir)/installed_files.txt
-STATIC_BINDINGS_DEPS = \
- bt2/logging.c \
- bt2/logging.h \
+SWIG_INTERFACE_FILES = \
+ bt2/native_bt.i \
bt2/native_bt_clock_class.i \
bt2/native_bt_clock_snapshot.i \
bt2/native_bt_component_class.i \
bt2/native_bt_clock_class.i \
bt2/native_bt_clock_snapshot.i \
bt2/native_bt_component_class.i \
bt2/native_bt_field_path.i \
bt2/native_bt_field.i \
bt2/native_bt_graph.i \
bt2/native_bt_field_path.i \
bt2/native_bt_field.i \
bt2/native_bt_graph.i \
bt2/native_bt_logging.i \
bt2/native_bt_message.i \
bt2/native_bt_message_iterator.i \
bt2/native_bt_logging.i \
bt2/native_bt_message.i \
bt2/native_bt_message_iterator.i \
bt2/native_bt_trace_class.i \
bt2/native_bt_trace.i \
bt2/native_bt_value.i \
bt2/native_bt_trace_class.i \
bt2/native_bt_trace.i \
bt2/native_bt_value.i \
- bt2/native_bt_version.i \
+ bt2/native_bt_version.i
+
+STATIC_BINDINGS_DEPS = \
+ $(SWIG_INTERFACE_FILES) \
+ bt2/logging.c \
+ bt2/logging.h \
bt2/clock_class.py \
bt2/clock_snapshot.py \
bt2/component.py \
bt2/clock_class.py \
bt2/clock_snapshot.py \
bt2/component.py \
GENERATED_BINDINGS_DEPS = \
bt2/__init__.py \
GENERATED_BINDINGS_DEPS = \
bt2/__init__.py \
setup.py
BUILD_FLAGS=CC="$(CC)" \
setup.py
BUILD_FLAGS=CC="$(CC)" \
touch $@
build-python-bindings.stamp: copy-static-deps.stamp $(GENERATED_BINDINGS_DEPS)
touch $@
build-python-bindings.stamp: copy-static-deps.stamp $(GENERATED_BINDINGS_DEPS)
- $(BUILD_FLAGS) $(PYTHON) $(builddir)/setup.py build_ext --force --swig "$(SWIG)"
$(BUILD_FLAGS) $(PYTHON) $(builddir)/setup.py build --force
touch $@
$(BUILD_FLAGS) $(PYTHON) $(builddir)/setup.py build --force
touch $@
+swig_verbose = $(swig_verbose_@AM_V@)
+swig_verbose_ = $(swig_verbose_@AM_DEFAULT_V@)
+swig_verbose_0 = @echo " SWIG " $@;
+
+$(builddir)/bt2/native_bt.c: $(SWIG_INTERFACE_FILES)
+ $(swig_verbose)$(SWIG) -python -I"$(top_srcdir)/include" -o "$@" "$<"
+
install-exec-local: build-python-bindings.stamp
@opts="--prefix=$(prefix) --record $(INSTALLED_FILES) --verbose --no-compile $(DISTSETUPOPTS)"; \
if [ "$(DESTDIR)" != "" ]; then \
install-exec-local: build-python-bindings.stamp
@opts="--prefix=$(prefix) --record $(INSTALLED_FILES) --verbose --no-compile $(DISTSETUPOPTS)"; \
if [ "$(DESTDIR)" != "" ]; then \
EXTRA_DIST = $(STATIC_BINDINGS_DEPS)
# clean: generated C and Python files (by SWIG)
EXTRA_DIST = $(STATIC_BINDINGS_DEPS)
# clean: generated C and Python files (by SWIG)
-CLEANFILES = bt2/native_bt.py bt2/native_bt_wrap.c build-python-bindings.stamp copy-static-deps.stamp
+CLEANFILES = bt2/native_bt.py bt2/native_bt.c build-python-bindings.stamp copy-static-deps.stamp
def main():
babeltrace_ext = Extension('bt2._native_bt',
def main():
babeltrace_ext = Extension('bt2._native_bt',
- sources=['bt2/native_bt.i', 'bt2/logging.c'],
+ sources=['bt2/native_bt.c', 'bt2/logging.c'],
libraries=['babeltrace2', 'glib-2.0'],
extra_objects=['@top_builddir@/src/logging/.libs/libbabeltrace2-logging.a',
'@top_builddir@/src/common/.libs/libbabeltrace2-common.a',
libraries=['babeltrace2', 'glib-2.0'],
extra_objects=['@top_builddir@/src/logging/.libs/libbabeltrace2-logging.a',
'@top_builddir@/src/common/.libs/libbabeltrace2-common.a',
- '@top_builddir@/src/py-common/.libs/libbabeltrace2-py-common.a'],
- swig_opts=['-I@top_srcdir@/include'])
+ '@top_builddir@/src/py-common/.libs/libbabeltrace2-py-common.a'])
dist = setup(name='bt2',
version='@PACKAGE_VERSION@',
dist = setup(name='bt2',
version='@PACKAGE_VERSION@',