forked from Exawind/exawind-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.bash
221 lines (187 loc) · 5.27 KB
/
core.bash
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#!/bin/bash
__EXAWIND_CORE_DIR=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)
# Array holding exact module/spack descriptor for a dependency
declare -A EXAWIND_MODMAP
# Build directories that must be removed when performing cmake_full
declare -a _EXAWIND_PROJECT_CMAKE_RMEXTRA_
exawind_help ()
{
cat <<EOF
Exawind build script
Usage:
${0} <task> <arguments>
With no tasks provided, the script will configure the project and compile the code
Available tasks:
cmake - configure the project
cmake_full - configure project after removing CMakeCache
make - compile the code
ctest - run tests (if available)
run - run arbitrary command using the environment used to compile the code
EOF
}
exawind_save_func ()
{
local orig_func=$(declare -f $1)
local new_func="$2${orig_func#$1}"
eval "$new_func"
}
exawind_env ()
{
local srcdir=${__EXAWIND_CORE_DIR}
if [ -z "$EXAWIND_SYSTEM" ] ; then
echo "EXAWIND_SYSTEM variable has not been defined"
exit 1
fi
local sys=${EXAWIND_SYSTEM}
local compiler=${EXAWIND_COMPILER:-gcc}
source ${srcdir}/envs/${sys}.bash
exawind_env_${compiler}
}
exawind_load_deps ()
{
for dep in $@ ; do
root_dir_var="$(echo $dep | sed -e 's/\([-a-zA-Z0-9_]*\).*/\1/;s/-/_/' | tr '[:lower:]' '[:upper:]')_ROOT_DIR"
if [ -z ${!root_dir_var} ] ; then
module load ${EXAWIND_MODMAP[$dep]:-$dep}
fi
done
}
exawind_cmake_full ()
{
set +e
rm -rf CMakeCache.txt CMakeFiles *.cmake *Makefile* *.ninja
if [ "${#_EXAWIND_PROJECT_CMAKE_RMEXTRA_[@]}" -gt 0 ] ; then
rm -rf "${_EXAWIND_PROJECT_CMAKE_RMEXTRA_[@]}"
fi
set -e
exawind_cmake "$@"
}
exawind_cmake ()
{
local cmake_option=" "
if [ ! -e "CMakeCache.txt" ] ; then
make_type=${EXAWIND_MAKE_TYPE:-make}
case ${make_type} in
"ninja")
cmake_option="-G Ninja"
;;
"make")
cmake_option="-G 'Unix Makefiles'"
;;
*)
echo "!!ERROR!! Unknown CMake generator provided: ${make_type}"
;;
esac
fi
if [ "$(uname)" = "Darwin" -a "$(type -t exawind_cmake_osx)" = "function" ] ; then
exawind_cmake_osx "${cmake_option}" "$@"
elif [ "$(type -t exawind_cmake_${EXAWIND_SYSTEM})" = "function" ] ; then
exawind_cmake_${EXAWIND_SYSTEM} "${cmake_option}" "$@"
else
exawind_cmake_base "${cmake_option}" "$@"
fi
}
exawind_guess_make_type ()
{
if [ -e "CMakeCache.txt" ] ; then
echo "$(awk -F '=' '/CMAKE_MAKE_PROGRAM:FILEPATH/ { print $2 }' CMakeCache.txt)"
else
echo "make"
fi
}
exawind_make ()
{
local num_tasks=${EXAWIND_NUM_JOBS:-$EXAWIND_NUM_JOBS_DEFAULT}
local make_type=$(exawind_guess_make_type)
if [ "$#" == "0" ] ; then
extra_args="-j ${num_tasks}"
else
extra_args="$@"
fi
case ${make_type} in
*ninja)
command ${make_type} ${extra_args}
;;
*make)
command ${make_type} ${extra_args} 2>&1 | tee make_output.log
;;
*)
echo "!!ERROR!! Invalid make type detected"
exit 1
esac
}
exawind_ctest ()
{
export OMP_NUM_THREADS=${OMP_NUM_THREADS:-1};
export OMP_PROC_BIND=${OMP_PROC_BIND:-true};
export OMP_PLACES=${OMP_PLACES:-threads}
local num_tasks=${EXAWIND_NUM_JOBS:-$EXAWIND_NUM_JOBS_DEFAULT}
if [ "$#" == "0" ] ; then
extra_args="-j ${num_tasks}"
else
extra_args="$@"
fi
command ctest ${extra_args}
}
exawind_run ()
{
export OMP_NUM_THREADS=${OMP_NUM_THREADS:-1};
export OMP_PROC_BIND=${OMP_PROC_BIND:-true};
export OMP_PLACES=${OMP_PLACES:-threads}
echo "+ $@"
eval "$@"
}
exawind_load_user_configs ()
{
local cfgname=${EXAWIND_CFGFILE:-exawind-config}
local global_cfg=${EXAWIND_CONFIG:-${EXAWIND_PROJECT_DIR}/${EXAWIND_CFGFILE}.sh}
local cfgfiles=(
${HOME}/.${cfgname}
${global_cfg}
$(pwd)/${cfgname}.sh
)
for cfg in ${cfgfiles[@]}; do
if [ -f ${cfg} ] ; then
echo "==> Loading options from ${cfg}"
source ${cfg}
fi
done
}
exawind_rpath_dirs ()
{
local rpath_dirs=""
for dep in "$@" ; do
root_dir_var="$(echo $dep | sed -e 's/\([-a-zA-Z0-9_]*\).*/\1/;s/-/_/' | tr '[:lower:]' '[:upper:]')_ROOT_DIR"
libpath=${!root_dir_var}/lib
if [ -d ${libpath} ] ; then
rpath_dirs=${libpath}:${rpath_dirs}
fi
lib64path=${!root_dir_var}/lib64
if [ -d ${lib64path} ] ; then
rpath_dirs=${lib64path}:${rpath_dirs}
fi
done
echo $rpath_dirs
}
exawind_main ()
{
if [ "$#" == "0" ] ; then
exawind_env && exawind_proj_env && exawind_cmake && exawind_make
else
subcmd=$1
case ${subcmd} in
"-h" | "--help" | "-?")
exawind_help
exit 0
;;
*)
shift
exawind_env && exawind_proj_env && exawind_${subcmd} "$@"
if [ $? = 127 ] ; then
echo "ERROR: ${subcmd} is not a valid command."
exawind_help
fi
;;
esac
fi
}