-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathModuleRecipe
More file actions
148 lines (138 loc) · 5.85 KB
/
Copy pathModuleRecipe
File metadata and controls
148 lines (138 loc) · 5.85 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
MODULEDIR="$INSTALLROOT/etc/modulefiles"
MODULEFILE=$MODULEDIR/$PKGNAME
MODULE_OPTIONS="--bin --lib"
# Emit `prepend-path VAR $PKG_ROOT/SUB` wrapped in a load-time existence guard, so
# the entry is added only when the directory really exists in the deployed tree.
# This keeps PATH / LD_LIBRARY_PATH / PKG_CONFIG_PATH / PYTHONPATH /
# ROOT_INCLUDE_PATH from being padded with non-existent lib / lib64 / site-packages
# directories — shorter variables and fewer dirs for the dynamic loader to stat.
# Mirrors the `[ -d ]` guards bits already uses in the build-time init.sh. The
# single-quoted format keeps $PKG_ROOT, the brackets and the braces literal in the
# generated Tcl; %s are substituted by printf.
function emit_guarded_prepend() { # $1 = path variable, $2 = subdir under $PKG_ROOT
printf 'if {[file isdirectory $PKG_ROOT/%s]} { prepend-path %s $PKG_ROOT/%s }\n' "$2" "$1" "$2"
}
function GenerateModule() {
# --bin prepends $PKG_ROOT/bin to PATH, sets ${PKGNAME}_ROOT
# --lib prepends $PKG_ROOT/lib and $PKG_ROOT/lib64 to LD_LIBRARY_PATH,
# sets ${PKGNAME}_INCLUDE_DIR (lib64 is a no-op if the dir does not exist)
# --inc sets ${PKGNAME}_INCLUDE_DIR
# --cmake prepends $PKG_ROOT to CMAKE_PREFIX_PATH
# --root sets ${PKGNAME}_ROOT
# --python prepends $PKG_ROOT/lib/pythonX.Y/site-packages to PYTHONPATH
# (versioned; requires PYTHON_MAJOR_MINOR to be set, e.g. via PythonRecipe)
# --root-inc prepends $PKG_ROOT/include to ROOT_INCLUDE_PATH
# (used by ROOT's ACLiC/cling to locate headers; add for all HEP libraries)
# --pylib prepends $PKG_ROOT/lib to PYTHONPATH
# (for packages that install .py files directly under lib/, e.g. ROOT/PyROOT)
# --pysite prepends $PKG_ROOT/lib/python/site-packages to PYTHONPATH
# (for C++ packages with Python bindings at an unversioned site-packages path)
# --pkgconfig prepends $PKG_ROOT/lib/pkgconfig to PKG_CONFIG_PATH
# (for packages that install .pc files)
HAS_BIN=
HAS_LIB=
HAS_CMAKE=
HAS_ROOT=
HAS_INC=
HAS_PYTHON=
HAS_ROOT_INC=
HAS_PYLIB=
HAS_PYSITE=
HAS_PKGCONFIG=
while [ "X$#" != "X0" ]; do
case $1 in
--bin) HAS_BIN=true; HAS_ROOT=true; shift ;;
--lib) HAS_LIB=true; HAS_INC=true; shift ;;
--inc) HAS_INC=true; shift ;;
--cmake) HAS_CMAKE=true; shift ;;
--root) HAS_ROOT=true; shift ;;
--python) HAS_PYTHON=true; shift ;;
--root-inc) HAS_ROOT_INC=true; shift ;;
--pylib) HAS_PYLIB=true; shift ;;
--pysite) HAS_PYSITE=true; shift ;;
--pkgconfig) HAS_PKGCONFIG=true; shift ;;
*) shift ;;
esac
done
cat << EOF
#%Module1.0
proc ModulesHelp { } {
global version
puts stderr "Modulefile for $PKGNAME $PKGVERSION-@@PKGREVISION@$PKGHASH@@"
}
set version $PKGVERSION-@@PKGREVISION@$PKGHASH@@
module-whatis "Modulefile for $PKGNAME $PKGVERSION-@@PKGREVISION@$PKGHASH@@"
# Dependencies
EOF
printf "if ![ is-loaded 'BASE/1.0' ] {\n module load BASE/1.0\n}"
echo BUILD_REQUIRES=$BUILD_REQUIRES >&2
FULL_BUILD_REQUIRES=${FULL_BUILD_REQUIRES:-$BUILD_REQUIRES}
echo FULL_BUILD_REQUIRES=$FULL_BUILD_REQUIRES >&2
# Dependencies
for x in `env | cut -f1 -d= | grep -v "^DEFAULT_" | grep -v PKGREVISION | grep -v _RECIPE_TOOLS | grep REVISION | sed -e 's/_REVISION//'`; do
REVISION_VALUE=`eval "echo $(echo \\$$(echo ${x}_REVISION))"`
VERSION_VALUE=`eval "echo $(echo \\$$(echo ${x}_VERSION))"`
ROOT_PATH_VALUE=`eval "echo $(echo \\$$(echo ${x}_ROOT))"`
if echo $FULL_BUILD_REQUIRES | tr [:lower:] [:upper:] | tr - _ | tr \ \\n | grep -q "^$x$"; then
echo $x is a build_requires. Skipping loading the associated module. >&2
elif [ -d $ROOT_PATH_VALUE/etc/modulefiles ]; then
for filename in `find $ROOT_PATH_VALUE/etc/modulefiles -type f ! -name '*.*' | xargs -n1 basename`; do
printf "\nif ![ is-loaded \"${REVISION_LABEL:-$filename/$VERSION_VALUE-$REVISION_VALUE}\" ] { module load ${REVISION_LABEL:-$filename/$VERSION_VALUE-$REVISION_VALUE} }"
done
fi
done
printf "\n\nset PKG_ROOT \$::env(BASEDIR)/$PKGNAME/\$version\n"
if [ X$HAS_BIN = Xtrue ]; then
emit_guarded_prepend PATH bin
fi
if [ X$HAS_LIB = Xtrue ]; then
# macOS dyld uses DYLD_LIBRARY_PATH and ignores LD_LIBRARY_PATH; Linux is the
# reverse. Emit only the relevant one for this package's target platform
# (modulefiles are per-architecture). Mirrors the build-time init.sh in bits
# build.py. ARCHITECTURE is set in the build env; fall back to uname. lib /
# lib64 are guarded so only the directory the package actually ships appears.
case "${ARCHITECTURE:-$(uname)}" in
osx*|Darwin)
emit_guarded_prepend DYLD_LIBRARY_PATH lib
emit_guarded_prepend DYLD_LIBRARY_PATH lib64
;;
*)
emit_guarded_prepend LD_LIBRARY_PATH lib
emit_guarded_prepend LD_LIBRARY_PATH lib64
;;
esac
fi
PKGNAME_UPPER=$(echo "${PKGNAME}" | tr '[:lower:]-' '[:upper:]_')
if [ X$HAS_INC = Xtrue ]; then
printf "setenv ${PKGNAME_UPPER}_INCLUDE_DIR \$PKG_ROOT/include\n"
fi
if [ X$HAS_CMAKE = Xtrue ]; then
printf "prepend-path CMAKE_PREFIX_PATH \$PKG_ROOT\n"
fi
if [ X$HAS_ROOT = Xtrue ]; then
printf "setenv ${PKGNAME_UPPER}_ROOT \$PKG_ROOT\n"
fi
if [ X$HAS_PYTHON = Xtrue ] && [ -n "${PYTHON_MAJOR_MINOR:-}" ]; then
emit_guarded_prepend PYTHONPATH "lib/python${PYTHON_MAJOR_MINOR}/site-packages"
fi
if [ X$HAS_ROOT_INC = Xtrue ]; then
emit_guarded_prepend ROOT_INCLUDE_PATH include
fi
if [ X$HAS_PYLIB = Xtrue ]; then
emit_guarded_prepend PYTHONPATH lib
fi
if [ X$HAS_PYSITE = Xtrue ]; then
emit_guarded_prepend PYTHONPATH lib/python/site-packages
fi
if [ X$HAS_PKGCONFIG = Xtrue ]; then
emit_guarded_prepend PKG_CONFIG_PATH lib/pkgconfig
emit_guarded_prepend PKG_CONFIG_PATH lib64/pkgconfig
fi
echo
}
function MakeModule () {
mkdir -p $MODULEDIR
mkdir -p etc/modulefiles
GenerateModule $MODULE_OPTIONS > etc/modulefiles/$PKGNAME
rsync -a --delete etc/modulefiles/ $MODULEDIR
}