-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwcdo.rc
484 lines (378 loc) · 11.5 KB
/
wcdo.rc
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
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
#!/bin/bash
# A bash rc file for use inside a wcdo image.
PS1="[$wcdo_simg]\u@\h:\W> "
# some general helpers
goto () {
pushd $1 >& /dev/null
}
goback () {
popd >& /dev/null
}
path-remove () {
local IFS=':'
local NEWPATH
local DIR
local PATHVARIABLE=${2:-PATH}
for DIR in ${!PATHVARIABLE} ; do
if [ "$DIR" != "$1" ] ; then
NEWPATH=${NEWPATH:+$NEWPATH:}$DIR
fi
done
export $PATHVARIABLE="$NEWPATH"
}
path-prepend () {
path-remove "$1" "$2"
local PATHVARIABLE="${2:-PATH}"
export $PATHVARIABLE="$1${!PATHVARIABLE:+:${!PATHVARIABLE}}"
}
path-append () {
path-remove "$1" "$2"
local PATHVARIABLE="${2:-PATH}"
export $PATHVARIABLE="${!PATHVARIABLE:+${!PATHVARIABLE}:}$1"
}
path-find () {
local IFS=':'
local DIR=''
local PATHVARIABLE="${2:-PATH}"
for DIR in ${!PATHVARIABLE}
do
local maybe="$DIR/$1"
if [ -f "$maybe" ] ; then
echo "$maybe"
fi
done
}
fhicl-find () {
path-find $1 FHICL_FILE_PATH
}
wcdo-wirecell-path-help () {
cat 1>&2 <<EOF
Set or display the WIRECELL_PATH
usage: wcdo-wirecell-path [ default <path> <path> ... ]
With no argument, print the current path.
A special "<path>" given as the literal string "default" will cause
the default directories for the container to be used.
Otherwise a <path> argument is prepended.
Note: the UPS product "wirecell" destroys the WIRECELL_PATH so this
function will be useful after any "setup" of "wirecell" UPS product.
EOF
}
wcdo-wirecell-path () {
if [ -z "$1" ] ; then
echo "WIRECELL_PATH=$WIRECELL_PATH"
return
fi
# set this, but warning that calling "setup" with the "wirecell"
# UPS product will likely destroy it.
for one in $@
do
if [ "$one" = "wcdo" -o "$one" = "default" ] ; then
for one in ${wcdo_wct_data} ${wcdo_wct_cfg}
do
path-prepend $one WIRECELL_PATH
done
else
path-prepend $one WIRECELL_PATH
fi
done
export WIRECELL_PATH
}
##
## UPS helpers
##
wcdo-ups-init-help () {
cat 1>&2 <<EOF
Try to initialize local UPS products area.
usage wcdo-ups-init
This will hunt for the UPS "setup" script in a few places. It will
also try to prime the $wcdo_ups_products area if needed.
EOF
}
wcdo-ups-init () {
if [ -n "$SETUP_UPS" ] ; then
return
fi
for maybe in "$wcdo_ups_products" /cvmfs/larsoft.opensciencegrid.org/products
do
if [ -f "$maybe/setup" ] ; then
echo "Using UPS from: $maybe" 1>&2
source "$maybe/setup"
return
fi
done
echo "unable to initialize UPS products area" 1>&2
}
# Return a version for newest package
wcdo-ups-version () {
local pkg="${1:-larsoft}"
ups list -aK+ "$pkg" | tail -1 | awk '{print $2}' | sed -e 's/"//g'
}
# Return the quals for a most reacent package
wcdo-ups-quals () {
local pkg="${1:-larsoft}"
ups list -aK+ "$pkg" | tail -1 | awk '{print $4}' | sed -e 's/"//g'
}
# declare a UPS product
wcdo-ups-declare-help () {
cat 1>&2 <<EOF
Prepare an empty UPS product area based on an existing one.
usage: wcdo-ups-declare package newversion
An example:
wcdo-ups-declare wirecell DEVEL
Note, an existing version of this package must already be "setup".
To find a suitable version
ups list -aK+ wirecell
setup <package> <version> -q <quals>
EOF
}
wcdo-ups-declare () {
local pkg="${1}"
local ver="${2}"
if [ -z "$ver" ] ; then
wcdo-ups-declare-help
return
fi
local PKG=$(echo $pkg | awk '{print toupper($0)}')
envstr=$(env | grep "^SETUP_${PKG}=")
if [ -z "$envstr" ] ; then
echo "Must first 'setup' and existing version of ${pkg}" 1>&2
return
fi
path-prepend $wcdo_ups_products PRODUCTS
local relver=$(echo "$envstr" | awk '{print $2}')
local relquals=$(echo "$envstr" | awk '{print $8}')
local reldir=$(env | grep "^${PKG}_DIR" | tr '=' ' ' | awk '{print $2}')
local tabfile="$reldir/ups/${pkg}.table"
if [ ! -f "$tabfile" ] ; then
echo "Can not find table file: $tabfile"
return
fi
local upsdir="${wcdo_ups_products}/${pkg}/${ver}/ups"
if [ ! -d "$upsdir" ] ; then
mkdir -p "$upsdir"
fi
cp "$tabfile" "$upsdir"
set -x
ups declare wirecell ${ver} \
-f $(ups flavor) \
-q ${relquals} \
-r "${pkg}/${ver}" \
-z "$wcdo_ups_products" \
-U ups \
-m "${pkg}.table"
set +x
dirname $upsdir
}
# configure WCT source for building against UPS externals.
wcdo-ups-wct-configure-source-help () {
cat 1>&2 <<EOF
Configure WCT source using UPS environment.
wcdo-ups-wct-configure
You must first set up a UPS environment which includes all externals
needed by WCT. There are two recomended ways to do this:
1) No installation: use "ups list -aK+ wirecell" and pick a recent
release to "setup".
2) With install: use wcdo-ups-declare to make a UPS product in which
to install and then "setup" this.
EOF
}
wcdo-ups-wct-configure-source () {
if [ -z "$UPS_DIR" ] ; then
echo "Must first setup UPS"
return
fi
if [ -z "$WIRECELL_VERSION" ] ; then
echo "Must first 'setup wirecell' to a version declared in the local UPS products area"
echo 'try: ups list -aK+ wirecell | grep $(ups flavor)'
echo "try: wcdo-ups-declare wirecell <version> ..."
return
fi
if [ ! -d "$wcdo_ups_products/wirecell/$WIRECELL_VERSION" ] ; then
echo "Must first 'setup wirecell' to a version declared in the local UPS products area"
echo "try wcdo-ups-declare wirecell <version> ..."
return
fi
goto $wcdo_wct_dev
if [ ! -f wcb ] ; then
echo "wcdo-ups-wct-configure-source: no WCT source: $(wcdo_wct_dev)"
return
fi
# no better way?
if [ -n "$SETUP_CLANG" ] ; then
export CC=clang
export CXX=clang++
fi
./wcb configure \
--with-tbb=no \
--with-jsoncpp="$JSONCPP_FQ_DIR" \
--with-jsonnet="$JSONNET_FQ_DIR" \
--with-eigen-include="$EIGEN_DIR/include/eigen3" \
--with-root="$ROOTSYS" \
--with-fftw="$FFTW_FQ_DIR" \
--with-fftw-include="$FFTW_INC" \
--with-fftw-lib="$FFTW_LIBRARY" \
--boost-includes="$BOOST_INC" \
--boost-libs="$BOOST_LIB" \
--boost-mt \
--prefix=$WIRECELL_FQ_DIR || return 1
echo "wcdo-ups-wct-configure-source:"
echo -e "\twill install to $WIRECELL_FQ_DIR"
echo -e "\tleaving you in source directory.\n\ttype 'goback' to return to your previous directory"
echo -e "\tready to run:\n\t./wcb -p --notests install"
}
# Modify all product_deps files to set a different version for a package.
wcdo-mrb-fsck-ups-help () {
cat 1>&2 <<EOF
Fix the version for a package in all ups/products_deps file in all MRB
source packages.
usage: wcdo-mrb-fsck-ups package version
EOF
}
wcdo-mrb-fsck-ups () {
local pkg="$1"; shift;
local ver="$1"; shift
if [ -z "$SETUP_UPS" ] ; then
echo "must setup ups first"
return
fi
wcdo-mrb-init
local base="$MRB_TOP"
if [ ! -d "$base/srcs/" ] ; then
echo "wcdo-mrb-fsck-ups: no sources in $base"
return
fi
for pd in $base/srcs/*/ups/product_deps
do
echo -e "\t$pd"
sed -e "s/^${pkg}\b.*/${pkg}\t${ver}/" -i $pd
done
echo "wcdo-mrb-fsck-ups: before running 'mrbsetenv' you must run:"
echo -e "\tunsetup $pkg"
}
wcdo-ups-pullproducts-help () {
cat 1>&2 <<EOF
Download and install UPS products.
usage: wcdo-ups-pullproducts [pullProducts args]
The arguments are identical to the "pullProducts" script. This script
will download pullProducts if needed.
The nominal location for UPS products in a wcdo container is
/wcdo/lib/ups
Example:
wcdo-ups-pullproducts /wcdo/lib/ups slf7 larsoft-v07_07_01 s70-e17 prof
EOF
}
wcdo-ups-pullproducts () {
local ppurl="http://scisoft.fnal.gov/scisoft/bundles/tools/pullProducts"
if [ -d /cvmfs ] ; then
echo "Warning: you have /cvmfs are you sure you want to pull UPS products?"
echo "Hit Ctrl-c to cancel"
sleep 1
fi
if [ "$(readlink -f $1)" != "$(readlink -f $wcdo_ups_products)" ] ; then
echo "Warning: running pullProducts in unconventional directory: $1"
fi
goto "$1"
if [ ! -f pullProducts ] ; then
wget "$ppurl"
fi
chmod +x pullProducts
./pullProducts $@
goback
}
# Initialize an MRB-controlled development area and environment to use it.
wcdo-mrb-init-help () {
cat 1>&2 <<EOF
Initialize MRB-controlled development area.
usage: wcdo-mrb-init [name [version [quals]]]
If an option is not given then a variable is consulted:
wcdo_mrb_project_<option>
When successful, this function modifies your environment and leave
your current working directory to be that of the top of the
MRB-controlled development area.
EOF
}
wcdo-mrb-init () {
if [ -z "$SETUP_UPS" ] ; then
echo "must setup ups first"
return
fi
local proj="${1:-$wcdo_mrb_project_name}" ; shift
local pver="${1:-$wcdo_mrb_project_version}" ; shift
local quals="${1:-$wcdo_mrb_project_quals}" ; shift
if [ -z "$proj" ] ; then
echo "Must define wcdo_mrb_* variables in your wcdo project file"
wcdo-mrb-init-help
return
fi
local quals_="$(echo $quals | tr ':' '_')"
goto "$wcdo_mrb_dev"
export MRB_PROJECT="$proj"
setup mrb
setup "$proj" "$pver" -q "$quals"
# first time through
if [ -z "$MRB_TOP" ] ; then
PS1="[mrb]$PS1"
fi
local localsetup="localProducts_${proj}_${pver}_${quals_}/setup"
if [ ! -f "$localsetup" ] ; then
mrb newDev
fi
source "$localsetup"
echo "wcdo-mrb-init: "
echo -e "\tenvironment modified and cd'ed to: $(pwd)"
echo -e "\ttype 'goback' to return to your original directory"
}
wcdo-mrb-goto-help () {
cat 1>&2 <<EOF
Change to MRB-controlled development area, initializing if needed.
usage: wcdo-mrb-goto
EOF
}
wcdo-mrb-goto () {
if [ -z "$MRB_TOP" ] ; then
wcdo-mrb-init
fi
goto $MRB_TOP
}
# Add a source package to an MRB area
wcdo-mrb-add-source-help () {
cat 1>&2 <<EOF
Add source packages to the MRB-controlled development area
usage: wcdo-mrb-add-source <package> <branch> <commitish>
<package> the git repo and local directory name, eg "larwirecell"
<branch> a local branch name, eg "myuser_myfeature"
<committish> the git commit or version tag or similar to start your local branch"
hint: "ups list -aK+ <packagename>"
EOF
}
wcdo-mrb-add-source () {
local pkg="$1"; shift
local feature="$1"; shift
local committish="$1"; shift
if [ -z "$SETUP_UPS" ] ; then
echo "must setup ups first"
return
fi
if [ -z "$pkg" ] ; then
wcdo-mrb-add-source-help
return
fi
if [ -z "$MRB_TOP" ] ; then
wcdo-mrb-init
fi
goto "${MRB_SOURCE}"
if [ -d "$pkg" ] ; then
echo "wcdo-mrb-add-source: package source \"$pkg\" already exists"
return
fi
mrb g "$pkg"
cd "$pkg"
local branch="${feature}"
if git branch -a | grep "\b$branch\b" > /dev/null ; then
echo "wcdo-mrb-add-source: starting branch exists, using it: $branch"
else
echo "wcdo-mrb-add-source: creating starting branch $branch from $committish"
git checkout -b "$branch" "$committish"
fi
popd > /dev/null 2>&1
}