Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions easybuild/scripts/rpath_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,10 @@
##
"""
Utility script used by RPATH wrapper script;
output is statements that define the following environment variables
* $CMD_ARGS: new list of command line arguments to pass

Usage:
rpath_args.py <cmd> <rpath_filter> <rpath_include> <args...>
output is a list of arguments to be passed to the wrapped command, one per line

author: Kenneth Hoste (HPC-UGent)
author: Alexander Grund (TU Dresden)
"""
import os
import re
Expand Down Expand Up @@ -185,8 +182,5 @@ def add_rpath_flag(lib_path, rpath_filter, rpath_lib_paths, cmd_args_rpath, ldfl
# add -rpath flags in front
cmd_args = cmd_args_rpath + cmd_args

# wrap all arguments into single quotes to avoid further bash expansion
cmd_args = ["'%s'" % a.replace("'", "''") for a in cmd_args]

# output: statement to define $CMD_ARGS
print("CMD_ARGS=(%s)" % ' '.join(cmd_args))
print('\0'.join(cmd_args), end='')
28 changes: 10 additions & 18 deletions easybuild/scripts/rpath_wrapper_template.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -30,41 +30,33 @@
# before actually calling the original compiler/linker command.
#
# author: Kenneth Hoste (HPC-UGent)
# author: Alexander Grund (TU Dresden)

set -e

# logging function
function log {
# escape percent signs, since this is a template script
# that will templated using Python string templating
echo "($$) [$(date "+%%Y-%%m-%%d %%H:%%M:%%S")] $1" >> %(rpath_wrapper_log)s
echo "($$) [$(date "+%%Y-%%m-%%d %%H:%%M:%%S")] $1" >> '%(rpath_wrapper_log)s'
}

# command name
CMD=`basename $0`
TOPDIR=`dirname $0`
CMD=$(basename $0)

log "found CMD: $CMD | original command: %(orig_cmd)s | orig args: '$(echo \"$@\")'"
log "found CMD: $CMD | original command: %(orig_cmd)s | orig args: $*)"

# rpath_args.py script spits out statement that defines $CMD_ARGS
# options for 'python' command (see https://docs.python.org/3/using/cmdline.html#miscellaneous-options)
# * -E: ignore all $PYTHON* environment variables that might be set (like $PYTHONPATH);
# * -I: isolated mode: ignore all $PYTHON* environment variables (like $PYTHONPATH) and user site-packages directory
# * -O: run Python in optimized mode (remove asserts, ignore stuff under __debug__ guard);
# * -s: don’t add the user site-packages directory to sys.path;
# * -S: disable the import of the module site and the site-dependent manipulations of sys.path that it entails;
# (once we only support Python 3, we can (also) use -I (isolated mode)
log "%(python)s -E -O -s -S %(rpath_args_py)s $CMD '%(rpath_filter)s' '%(rpath_include)s' $(echo \"$@\")'"
rpath_args_out=$(%(python)s -E -O -s -S %(rpath_args_py)s $CMD '%(rpath_filter)s' '%(rpath_include)s' "$@")

log "rpath_args_out:
$rpath_args_out"

# define $CMD_ARGS by evaluating output of rpath_args.py script
eval $rpath_args_out
log "%(python)s -I -O -S %(rpath_args_py)s $CMD '%(rpath_filter)s' '%(rpath_include)s' $*"
readarray -d '' -t CMD_ARGS < <( %(python)s -E -O -s -S %(rpath_args_py)s $CMD '%(rpath_filter)s' '%(rpath_include)s' "$@" )

# exclude location of this wrapper from $PATH to avoid other potential wrappers calling this wrapper
export PATH=$(echo $PATH | tr ':' '\n' | grep -v "^%(wrapper_dir)s$" | tr '\n' ':')
export PATH=$(echo "$PATH" | tr ':' '\n' | grep -v "^%(wrapper_dir)s$" | tr '\n' ':')

# call original command with modified list of command line arguments
log "running '%(orig_cmd)s $(echo ${CMD_ARGS[@]})'"
%(orig_cmd)s "${CMD_ARGS[@]}"
log "running: %(orig_cmd)s $(echo "${CMD_ARGS[@]}")"
'%(orig_cmd)s' "${CMD_ARGS[@]}"
Loading