-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmake_spack
More file actions
executable file
·378 lines (352 loc) · 13.8 KB
/
make_spack
File metadata and controls
executable file
·378 lines (352 loc) · 13.8 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
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
#!/bin/bash
#
# Script to make a Fermi-ized spack repository
#
find_ourselves() {
spackbindir=`echo $0 | sed -e 's;make_spack$;;' `
case x$spackbindir in
x/*) ;;
x*) spackbindir="$PWD/$spackbindir"
esac
}
clone_repos() {
if [ "$spack_release" != "fnal-develop" ]; then
# Trigger attempt to use a branch corresponding to the
# $spack_release branch requested for Spack.
maybe_change_branch=1
else
unset maybe_change_branch
fi
while read ddir branch repo branch_prefix branch_suffix
do
if [ "$repo" = "$spack_repo" ] ; then
repo_type=spack
unset maybe_change_branch
elif [[ "${ddir#$dir/}" == etc/* ]]; then
repo_type=etc
elif [[ "${ddir#$dir/var/spack/}" == extensions/* ]]; then
repo_type=extensions
elif [[ "${ddir#$dir/var/spack/}" == repos/* ]] ||
[ -f "$ddir/repo.yaml" ]; then
if $no_recipes; then
continue
fi
repo_type=recipes
else
unset repo_type
fi
if [ -n "$maybe_change_branch" ]; then
default_branch="$branch"
branch="${spack_release%-fermi}"
if [[ "$branch" == v[0-9]* ]]; then
branch="$branch_prefix$branch$branch_suffix"
fi
if [ "$branch" = "$default_branch" ]; then
unset $default_branch
fi
else
unset default_branch
fi
clone_branch=${default_branch:-$branch}
if [ -e "$ddir/.git" ]; then
if [ -n "$repo_type" ]; then
eval "upgrade_repo=\$upgrade_$repo_type"
else
unset upgrade_repo
fi
current_branch=$(git -C "$ddir" branch --show-current)
if (( upgrade_repo )); then
if [ "$current_branch" = "$branch" ]; then
if $verbose; then
echo "$(date --iso-8601=seconds) Updating Git repository at $ddir"
fi
if ! git -C "$ddir" pull; then
echo "$(date --iso-8601=seconds) Unable to update Git repository at" 1>&2
echo "$(date --iso-8601=seconds) $ddir" 1>&2
echo "$(date --iso-8601=seconds) Fix manually" 1>&2
fi
else
echo "$(date --iso-8601=seconds) Refusing to update Git repository from branch $current_branch to $branch at" 1>&2
echo "$(date --iso-8601=seconds) $ddir" 1>&2
echo "$(date --iso-8601=seconds) Fix manually" 1>&2
fi
else
echo "$(date --iso-8601=seconds) Using existing repository on branch $current_branch at "
echo "$(date --iso-8601=seconds) $ddir"
echo "$(date --iso-8601=seconds) U${repo_type:+se --upgrade-$repo_type or u}pgrade manually"
fi
else
if $verbose; then
echo "$(date --iso-8601=seconds) Cloning Git repository on branch $clone_branch at"
echo "$(date --iso-8601=seconds) $ddir"
fi
if ! git clone -b $clone_branch --depth $depth $repo $ddir; then
echo "$(date --iso-8601=seconds) Unable to clone Git repository on branch $clone_branch at" 1>&2
echo "$(date --iso-8601=seconds) $ddir" 1>&2
echo "$(date --iso-8601=seconds) Fix manually" 1>&2
[ -z "$default_branch" ] || {
git -C $ddir switch $branch >/dev/null 2>&1 &&
$verbose &&
echo "$(date --iso-8601=seconds) switched from $clone_branch to $branch based on selection of Spack branch $spack_release"
}
fi
fi
# if we added a repository not in repos.yaml, add it
pstr=$(uname -s | tr A-Z a-z)
if [ $repo_type = "recipes" ]
then
repof=$dir/etc/spack/$pstr/repos.yaml
config_ddir=$(echo $ddir | sed -e "s;$dir;\$spack;")
if grep "\\$config_ddir" $repof > /dev/null
then
:
else
echo "adding $ddir to repos.yaml"
echo "- $config_ddir" >> $repof
fi
fi
done <<EOF
$dir $spack_release $spack_repo
$dir/etc/spack/linux main https://github.com/FNALssi/fermi-etc-spack-linux.git spack-
$dir/var/spack/extensions/spack-freeze main https://github.com/FNALssi/spack-freeze.git
$dir/var/spack/extensions/spack-installdir main https://github.com/FNALssi/spack-installdir.git
$dir/var/spack/extensions/spack-intersection main https://github.com/FNALssi/spack-intersection.git
$dir/var/spack/extensions/spack-linuxexternals main https://github.com/FNALssi/spack-linuxexternals.git
$dir/var/spack/extensions/spack-localbuildcache main https://github.com/FNALssi/spack-localbuildcache.git
$dir/var/spack/extensions/spack-subspack main https://github.com/FNALssi/spack-subspack.git
$dir/var/spack/extensions/spack-mpd main https://github.com/FNALssi/spack-mpd.git
$dir/var/spack/extensions/spack-subspack main https://github.com/FNALssi/spack-subspack.git
$dir/var/spack/repos/fnal_art develop https://github.com/FNALssi/fnal_art.git
$dir/var/spack/repos/scd_recipes master https://github.com/fnal-fife/scd_recipes.git
$dir/var/spack/repos/nusofthep-spack-recipes main https://github.com/NuSoftHEP/nusofthep-spack-recipes.git
$dir/var/spack/repos/larsoft-spack-recipes main https://github.com/LArSoft/larsoft-spack-recipes.git
$dir/var/spack/repos/artdaq-spack develop https://github.com/art-daq/artdaq-spack.git
$experiment_repos
EOF
}
add_fermi_patches() {
# if we're not a something-fermi release of spack, try to apply our fermi patches
case $spack_release in
*fermi*) ;;
*fnal*) ;;
*) (
cd $SPACK_ROOT
tag=$(git describe --tag)
newbranch="${tag}-fermi"
git checkout -b $newbranch
for pf in $(echo $spackbindir/../patches/*.patch)
do
patch -p1 < $pf
done
git commit -am "bootstrap patches"
)
;;
esac
}
add_fermi_setups() {
#
# * symlink setup-env.{csh,sh} to $SPACK_ROOT
# * set SPACK environment variables we want
#
echo source $dir/share/spack/setup-env.sh > $dir/setup-env.sh
echo source $dir/share/spack/setup-env.csh > $dir/setup-env.csh
while read var val
do
echo setenv $var $val >> $dir/share/spack/setup-env.csh
echo export $var=$val >> $dir/share/spack/setup-env.sh
done <<EOF
SPACK_SKIP_MODULES true
SPACK_DISABLE_LOCAL_CONFIG true
EOF
# source the setup...
source $dir/share/spack/setup-env.sh
}
preferred_scope() {
# pick the per-os scope for this instance of spack
# this has historicaly been a moving target, so try the newest to oldest.
# if we don't find one, just use "site"
osstr=$(spack arch -o)
platstr=$(spack arch -p)
for sstr in "include:$osstr" "site/$platstr/$osstr" "site/$osstr" "site"
do
if spack config --scope=$sstr get compilers > /dev/null 2>&1
then
echo $sstr
return
fi
done
}
do_padding() {
if $padding; then
echo "turning on padding."
spack config --scope=$(preferred_scope) add config:install_tree:padded_length:255
else
spack config --scope=$(preferred_scope) rm config:install_tree:padded_length
fi
}
query_packages() {
if $query_packages; then
osstr=$(spack arch -o)
spack linuxexternals --scope=$(preferred_scope)
else
true
fi
}
usage() {
echo "Usage: $0 [options] -[utp] /base/directory"
echo " options:"
echo " --experiment exp_name customize for experiment"
echo " --upgrade upgrade spack instance (deprecated, ignored)"
echo " --upgrade-etc git pull latest etc areas"
echo " --upgrade-extensions git pull latest extensions"
echo " --upgrade-recipes git pull recipe repositories"
echo " --upgrade-spack git pull spack itself"
echo " --no-buildcache do not use buildcache for packages"
echo " --query-packages search for system packages instead of stock list"
echo " --spack_release ver set spack release to install"
echo " --spack_repo url set spack repository to install from"
echo " --depth n git clone depth (default 1 for speed)"
echo " --minimal minimal install"
echo " --verbose lots of debugging"
echo " -u fermi use 'unified' layout (deprecated)"
echo " -t fermi use 'traditional' layout (deprecated)"
echo " -p plain use spack default layout (default, deprecated)"
echo " -m short for --minimal"
echo " -v short for --verbose"
echo ""
echo " make a spack instance with given layout"
} 1>&2
get_from_bootstrap() {
grep "^$1=" $spackbindir/bootstrap | sed -e 's/.*=//'
}
get_experiment_repos() {
experiment_repos=""
for exp in $experiment_list
do
case $exp in
mu2e)
experiment_repos="$experiment_repos
$dir/var/spack/repos/mu2e-spack main https://github.com/Mu2e/mu2e-spack.git"
;;
larsoft)
experiment_repos="$experiment_repos
$dir/var/spack/repos/nusofthep-spack-recipes main https://github.com/NuSoftHEP/nusofthep-spack-recipes.git
$dir/var/spack/repos/larsoft-spack-recipes main https://github.com/LArSoft/larsoft-spack-recipes.git"
;;
dune)
experiment_repos="$experiment_repos
$dir/var/spack/repos/nusofthep-spack-recipes main https://github.com/NuSoftHEP/nusofthep-spack-recipes.git
$dir/var/spack/repos/larsoft-spack-recipes main https://github.com/LArSoft/larsoft-spack-recipes.git
$dir/var/spack/repos/dune_spack main https://github.com/DUNE/dune_spack"
;;
nova)
;;
esac
done
}
parse_args() {
spack_repo=$(get_from_bootstrap default_spack_repo)
spack_release=$(get_from_bootstrap default_spack_version)
use_buildcache=true
minimal=false
upgrading=false
padding=false
layout=unified
query_packages=false
repovers=""
verbose=false
depth=1
no_recipes=false
experiment_list=""
origargs="$*"
if x=$(getopt --longoptions help,depth,with_padding,experiment:,upgrade,upgrade-etc,upgrade-extensions,upgrade-recipes,upgrade-spack,spack_release:,minimal,no-recipe-repos,no_buildcache,repover,spack_repo:,query-packages,verbose --options mptuv -- "$@")
then
eval set : $x
shift
else
usage
exit 1
fi
while echo x$1 | grep x- > /dev/null
do
case "x$1" in
x--help) usage; exit 0;;
x--depth) depth=$2; shift;;
x--with_padding) padding=true; shift ;;
x--upgrade) echo "Deprecated option --upgrade ignored: use --upgrade-{etc,extensions,recipes,spack} "; shift;;
x--upgrade-*) eval upgrade_${1##*-}=1; shift;;
x--spack_release) spack_release=$2; shift; shift ;;
x--experiment) experiment_list="$experiment_list $2"; shift; shift ;;
x--spack_repo) spack_repo=$2; shift; shift;;
x--minimal) minimal=true; shift ;;
x--query-packages) query_packages=true; shift ;;
x--help) usage; exit;;
x--no_buildcache) use_buildcache=false; shift;;
x--no-recipe-repos) no_recipes=true; shift;;
x--repover) repovers="$repovers $2"; shift; shift;;
x-v|x--verbose) verbose=true; shift;;
x-u) echo "Deprecated option -u ignored"; shift;;
x-t) echo "Deprecated option -t ignored"; shift;;
x-p) echo "Deprecated option -p ignored (-p is already the default behavior)" ; shift;;
x-m) echo "Deprecated option -m ignored"; shift;;
x--) shift; break;;
esac
done
dir=$1
if [ -z "$dir" ]
then
usage
exit 1
fi
if $verbose
then
echo "$(date --iso-8601=seconds) Starting make_spack $origargs"
set -x
fi
}
do_spack_bootstrap() {
osstr=$(spack arch -o)
# for the 1.0.x.alpha bootstrap, we need to hide our mirrors
# with old packages from "spack bootstrap now"...
mfl="$(find $SPACK_ROOT/etc \( -name defaults -prune \) -o \( -name mirrors.yaml -print \))"
for mf in $mfl; do mv $mf $mf.hide; done
spack clean --all
spack bootstrap root '$spack/var/bootstraps/$os'
spack -d bootstrap now
# ... and put them back when we're done
for mf in $mfl; do mv $mf.hide $mf; done
}
do_keys() {
# get the keys from our buildcaches
# this doesn't seem to happen consistently, so trying doing
# it twice, which shouldn't hurt in any case
spack buildcache keys --install --force --trust
sleep 1
spack buildcache keys --install --force --trust
}
do_experiment_mirrors() {
for exp in $experiment_list
do
mf="$dir/etc/spack/linux/mirrors.yaml"
case $exp in
mu2e)
echo " mu2e: https://spack-cache-1.fnal.gov/binaries/mu2e" >> $mf
;;
esac
done
}
main() {
: starting: $*
find_ourselves
parse_args "$@"
get_experiment_repos
clone_repos
add_fermi_setups
add_fermi_patches
do_padding
do_experiment_mirrors
do_spack_bootstrap
do_keys
query_packages
}
main "$@"