mirror of
https://github.com/SELinuxProject/selinux
synced 2025-05-15 14:08:00 +00:00
libselinux and libsemanage use: PYTHONLIBDIR ?= $(shell $(PYTHON) -c "from distutils.sysconfig import *; print(get_python_lib(plat_specific=1, prefix='$(PREFIX)'))") while python/semanage and python/sepolgen/src/sepolgen use: PYTHONLIBDIR ?= $(shell $(PYTHON) -c "from distutils.sysconfig import *; print(get_python_lib(prefix='$(PREFIX)'))") This is right: libselinux and libsemanage's Python bindings use native code (thus "plat_specific=1") while the others only install Python files. Nevertheless `scripts/env_use_destdir` only runs the second command when computing `$PYTHONPATH`. When using this script to run `make test` in a minimal Fedora 31 environment, this leads to an error such as: make[2]: Entering directory '/code/python/sepolicy' Traceback (most recent call last): File "test_sepolicy.py", line 117, in <module> import selinux ModuleNotFoundError: No module named 'selinux' Fix this by also adding `get_python_lib(plat_specific=1)` to the computed `$PYTHONPATH`. While at it, preserve `$PYTHONPATH` instead of resetting it. This makes it easier to work with Python virtual environments. Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
43 lines
1.6 KiB
Bash
Executable File
43 lines
1.6 KiB
Bash
Executable File
#!/bin/sh
|
|
# Set-up environment variables to run programs which are built in DESTDIR folder
|
|
#
|
|
# Usage example to use variables in the current shell:
|
|
# $ export DESTDIR=$HOME/selinux-destdir
|
|
# $ make install install-pywrap install-rubywrap
|
|
# $ . ./scripts/env_use_destdir
|
|
# $ make test
|
|
#
|
|
# Or to use variables in a subcommand, for example to run tests:
|
|
# $ export DESTDIR=$HOME/selinux-destdir
|
|
# $ make install install-pywrap install-rubywrap
|
|
# $ ./scripts/env_use_destdir secilc ...
|
|
# $ ./scripts/env_use_destdir make test
|
|
|
|
if [ -z "${DESTDIR:-}" ] ; then
|
|
echo >&2 "Error: variable DESTDIR needs to be defined in order to use this script."
|
|
echo >&2 "Example:"
|
|
# shellcheck disable=SC2164
|
|
echo >&2 " DESTDIR=$(cd "$(dirname -- "$0")/.." ; pwd)/DESTDIR . $0"
|
|
exit 1
|
|
fi
|
|
|
|
export LD_LIBRARY_PATH="$DESTDIR/usr/lib:$DESTDIR/lib"
|
|
export PATH="$DESTDIR/usr/sbin:$DESTDIR/usr/bin:$DESTDIR/sbin:$DESTDIR/bin:$PATH"
|
|
|
|
NEW_PYTHONPATH="$DESTDIR$(${PYTHON:-python3} -c "from distutils.sysconfig import *;print(get_python_lib(plat_specific=1, prefix='/usr'))"):$DESTDIR$(${PYTHON:-python3} -c "from distutils.sysconfig import *;print(get_python_lib(prefix='/usr'))")"
|
|
if [ -n "${PYTHONPATH:-}" ] ; then
|
|
# Prefix the PYTHONPATH with the new directories
|
|
export PYTHONPATH="$NEW_PYTHONPATH:$PYTHONPATH"
|
|
else
|
|
# Define PYTHONPATH
|
|
export PYTHONPATH="$NEW_PYTHONPATH"
|
|
fi
|
|
|
|
# shellcheck disable=SC2155
|
|
export RUBYLIB="$DESTDIR/$(${RUBY:-ruby} -e 'puts RbConfig::CONFIG["vendorlibdir"]'):$DESTDIR/$(${RUBY:-ruby} -e 'puts RbConfig::CONFIG["vendorarchdir"]')"
|
|
|
|
# Run the command given on the command line
|
|
if [ $# -gt 0 ] ; then
|
|
exec "$@"
|
|
fi
|