Skip to content

Commit

Permalink
scripts: introduce env_use_destdir.sh helper
Browse files Browse the repository at this point in the history
Set-up environment variables in order to use DESTDIR in Python, Ruby,
etc. This makes testing Python scripts easier.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
  • Loading branch information
fishilico authored and bachradsusi committed Jan 21, 2019
1 parent dbcada0 commit 9e0ed5c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
5 changes: 1 addition & 4 deletions .travis.yml
Expand Up @@ -129,10 +129,7 @@ script:
- make all $EXPLICIT_MAKE_VARS -k

# Set up environment variables for the tests
- export LD_LIBRARY_PATH="$DESTDIR/usr/lib:$DESTDIR/lib"
- export PATH="$DESTDIR/usr/sbin:$DESTDIR/usr/bin:$DESTDIR/sbin:$DESTDIR/bin:$PATH"
- export PYTHONPATH="$DESTDIR$($PYTHON -c "from distutils.sysconfig import *;print(get_python_lib(prefix='/usr'))")"
- export RUBYLIB="$DESTDIR/$($RUBY -e 'puts RbConfig::CONFIG["vendorlibdir"]'):$DESTDIR/$($RUBY -e 'puts RbConfig::CONFIG["vendorarchdir"]')"
- . ./scripts/env_use_destdir

# Show variables (to help debugging issues)
- echo "$LD_LIBRARY_PATH"
Expand Down
36 changes: 36 additions & 0 deletions scripts/env_use_destdir
@@ -0,0 +1,36 @@
#!/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"

# shellcheck disable=SC2155
export PYTHONPATH="$DESTDIR$(${PYTHON:-python} -c "from distutils.sysconfig import *;print(get_python_lib(prefix='/usr'))")"

# 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

0 comments on commit 9e0ed5c

Please sign in to comment.