Skip to content

Commit

Permalink
pylibfdt/meson.build: fix Python library being rebuilt during install
Browse files Browse the repository at this point in the history
User @sharkcz noted that when the '--quiet' flag is removed from
./setup.py, the following can be seen from the `./setup.py install`
stage.

  Running custom install script 'dtc/g/pylibfdt/../setup.py --top-builddir \
    dtc/g/redhat-linux-build install --prefix=/usr/local --root=$DESTDIR'
  running install
  ...
  building '_libfdt' extension
  swigging dtc/g/pylibfdt/../pylibfdt/libfdt.i to \
    dtc/g/pylibfdt/../pylibfdt/libfdt_wrap.c
  swig -python -Idtc/g/pylibfdt/../libfdt -o \
    dtc/g/pylibfdt/../pylibfdt/libfdt_wrap.c dtc/g/pylibfdt/../pylibfdt/libfdt.i
  gcc -fno-strict-overflow -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 \
    -DNDEBUG -fexceptions -fexceptions -fexceptions -fPIC -DPY_SSIZE_T_CLEAN \
    -Idtc/g/pylibfdt/../libfdt -I/usr/include/python3.12 -c \
    dtc/g/pylibfdt/../pylibfdt/libfdt_wrap.c -o \
    build/temp.linux-ppc64le-cpython-312dtc/g/pylibfdt/../pylibfdt/libfdt_wrap.o
  creating build/lib.linux-ppc64le-cpython-312
  gcc -shared build/temp.linux-ppc64le-cpython-312dtc/g/pylibfdt/../pylibfdt/libfdt_wrap.o \
    -Ldtc/g/redhat-linux-build/libfdt -L/usr/lib64 -lfdt -o \
    build/lib.linux-ppc64le-cpython-312/_libfdt.cpython-312-powerpc64le-linux-gnu.so
  copying dtc/g/pylibfdt/../pylibfdt/libfdt.py -> build/lib.linux-ppc64le-cpython-312

Meaning the python library is getting recompiled during the `meson
install` phase. This causes build issues as Meson does not set the
compiler and linker flags during the install phase.

The reason the library is getting rebuilt is during the normal build
with "build_ext", the `--build-lib` flag gets passed which changes the
default output build directory. But there is no equivalent option for
the "install" command. Install instead looks in the default directory
"./build" and so does not find the previously built library.

Since we can't fix the "install" command, drop the --build-lib flag.
This causes setup.py to compile the libraries at
`<meson-build>/build/lib.linux-x86_64-cpython-312/`. We must also then
fix run_tests.sh to find the library build directory as it's
machine-dependent.

Fixes: #135
Signed-off-by: Brandon Maier <[email protected]>
  • Loading branch information
blmaier committed Jun 23, 2024
1 parent c17d76a commit 56e0e88
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pylibfdt/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pylibfdt = custom_target(
input: 'libfdt.i',
depends: libfdt,
output: '_libfdt.so',
command: [setup_py, 'build_ext', '--build-lib=' + meson.current_build_dir()],
command: [setup_py, 'build_ext'],
build_by_default: true,
)

Expand Down
1 change: 0 additions & 1 deletion tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ if not py.found()
else
env += [
'PYTHON=' + py.full_path(),
'PYTHONPATH=' + meson.project_source_root() / 'pylibfdt',
]
endif
if not yaml.found()
Expand Down
6 changes: 6 additions & 0 deletions tests/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ if [ -z "$TEST_LIBDIR" ]; then
fi
export LD_LIBRARY_PATH="$TEST_LIBDIR"

# Find the python module that distutils builds under a machine-specific path
PYLIBFDT_BUILD=$(echo ../build/lib.*)
if [ -e "$PYLIBFDT_BUILD" ]; then
export PYTHONPATH="$PYTHONPATH:$PYLIBFDT_BUILD"
fi

export QUIET_TEST=1
STOP_ON_FAIL=0

Expand Down

0 comments on commit 56e0e88

Please sign in to comment.