/
rpath_wrapper_template.sh.in
69 lines (59 loc) · 2.92 KB
/
rpath_wrapper_template.sh.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
##
# Copyright 2016-2021 Ghent University
#
# This file is part of EasyBuild,
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),
# with support of Ghent University (http://ugent.be/hpc),
# the Flemish Supercomputer Centre (VSC) (https://www.vscentrum.be),
# Flemish Research Foundation (FWO) (http://www.fwo.be/en)
# and the Department of Economy, Science and Innovation (EWI) (http://www.ewi-vlaanderen.be/en).
#
# https://github.com/easybuilders/easybuild
#
# EasyBuild is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation v2.
#
# EasyBuild is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with EasyBuild. If not, see <http://www.gnu.org/licenses/>.
##
# Template wrapper script for compiler/linker commands,
# which calls out to a Python script (rpath_args.py) to preprocess
# the list of command line arguments, injecting -rpath flags, etc.,
# before actually calling the original compiler/linker command.
#
# author: Kenneth Hoste (HPC-UGent)
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
}
# command name
CMD=`basename $0`
log "found CMD: $CMD | original command: %(orig_cmd)s | orig args: '$(echo \"$@\")'"
# 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);
# * -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
# 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' ':')
# call original command with modified list of command line arguments
log "running '%(orig_cmd)s $(echo ${CMD_ARGS[@]})'"
%(orig_cmd)s "${CMD_ARGS[@]}"