-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbildfcns.sh
executable file
·8073 lines (7510 loc) · 234 KB
/
bildfcns.sh
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
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
######################################################################
#
# bildfcns.sh: A set of methods for configuring and building packages
#
# $Rev$ $Date$
#
######################################################################
######################################################################
#
# Methods
#
######################################################################
#
# Determine whether today is later than some day by a certain number
# of days.
#
# Args:
# 1: The day to compare with in YYYY-MM-DD format
# 2: The number of days that one must be later by
isLaterByDays() {
techo -2 "Comparing to date, $1."
cursecs=`date -u +%s`
case `uname` in
Darwin)
prvsecs=`date -uj -f %Y-%m-%d $1 +%s` # OS X
;;
*)
prvsecs=`date -u --date=$1 +%s` # Linux
;;
esac
days=$((($cursecs - $prvsecs)/86400))
if test $days -ge $BILDER_WAIT_DAYS; then
return 0
fi
return 1
}
#
# Determine whether build time has elapsed
#
# Args
# 1: the project without the version
# 2: the builds
# 3: the installation directory
#
# -i Any builds to ignore
#
isBuildTime() {
# Defaults
local ignorebuilds=
# Parse options
# This syntax is needed to keep parameters quoted
set -- "$@"
OPTIND=1
while getopts "i:" arg; do
case "$arg" in
i) ignorebuilds="$OPTARG";;
esac
done
shift $(($OPTIND - 1))
techo -2 "isBuildTime called with '$*' and ignorebuilds '$ignorebuilds'."
if test -z "$2"; then
return 1
fi
local builds=$2
local instdir=$3
if ! test -f $instdir/installations.txt; then
return 0
fi
if test $BILDER_WAIT_DAYS -gt 0; then
local chkbuilds="$builds"
if test -n "$ignorebuilds"; then
for i in `echo $ignorebuilds | tr ',' ' '`; do
chkbuilds=`echo $chkbuilds | sed -e "s/^$i,//" -e "s/^$i$//g" -e "s/,$i,/,/g" -e "s/,$i$//"`
done
trimvar chkbuilds ','
fi
techo "Checking age of the "$chkbuilds" builds of $1."
local si=false
for i in `echo $chkbuilds | tr ',' ' '`; do
local buildline=`grep "^${1}-" $instdir/installations.txt | grep -- "-$i " | tail -1`
if test -z "$buildline"; then
return 0
fi
BILDER_WAIT_LAST_INSTALL=$buildline
local builddate=`echo $buildline | awk '{print $4}'`
local buildday=`echo $builddate | sed 's/-[0-9][0-9]:.*$//'`
if isLaterByDays $buildday $BILDER_WAIT_DAYS; then
si=true
techo "Project $1-$i not installed in the last $BILDER_WAIT_DAYS days."
break
else
techo "Project $1-$i installed in the last $BILDER_WAIT_DAYS days."
fi
done
if $si; then
return 0
else
techo "All builds of $1 installed in the last $BILDER_WAIT_DAYS days."
return 1
fi
fi
return 0
}
#
# Source function to check some syntax of sourced file
#
# Args:
# 1: the name of the shell file to source
#
bilderSource() {
if test -f $1; then
cmd=`bash -n $1 2>&1`
res=$?
if test $res = 0; then
source $1
else
techo "WARNING: [$FUNCNAME] Syntax error found in script: $1"
techo "WARNING: [$FUNCNAME] $cmd"
fi
else
techo "WARNING: [$FUNCNAME] Bilder unable to find script, $1, to source."
fi
}
#
# Get the modification time of a file
#
getFileModTime() {
case `uname` in
CYGWIN*)
ls -l --time-style=+%F-%T $1 | awk '{print $6}'
;;
Darwin)
stat -f "%Sm" -t %F-%T $1
;;
Linux)
ls -l --time-style=+%F-%T $1 | awk '{print $6}'
;;
esac
}
#
# Print a variable
#
# Args:
# 1: the name of the variable
#
printvar() {
# Assume backslashes are literal
val=`derefpath $1`
if test -n "$val"; then
techo "Variable $1 = \"$val\"."
else
techo "Variable $1 is unset."
fi
}
#
# Make links or shortcuts.
# CYGWIN: make shortcut and link.
# MINGW: make shortcut
# unix: make link
#
# Args:
# 1: the directory
# 2: the original node
# 3: the link
#
mkLink() {
local shortcut
local unix
local linkres
case `uname` in
CYGWIN*)
shortcut=true
unix=true
;;
MINGW*)
shortcut=true
unix=false
;;
*)
shortcut=false
unix=true
;;
esac
if $shortcut; then
local topFolder=$(basename "$2")
cmd="(cd $1; rmall ${topFolder}.lnk ${3}.lnk; mkshortcut -n ${3}.lnk $2)"
techo "$cmd"
eval "$cmd"
linkres=$?
if test $linkres != 0; then
techo "WARNING: Failed to make shortcut ${3}.lnk in directory '$1'."
fi
fi
if $unix; then
cmd="(cd $1; rmall $3; ln -s $2 $3)"
techo "$cmd"
eval "$cmd"
fi
}
#
# Find the value of the variable whose name is in a variable
#
# Args:
# 1: the name of the variable desired
#
deref() {
eval echo $`echo $1`
}
#
# svn action on a node.
# This is to work around a windows/unix incompatibility, such
# that doing "window-svn cygwin-node" or vice-versa does not work as
# neither os-svn understands the file system of the other. So when
# there is an action on a node, one cd's to that node, then executes
# the action. The svn used is $BILDER_SVN, which is the windows
# version on windows.
#
# Use:
# bilderSvn <bilderSvn args> <svn cmd> <svn args> <svn target>
# where the svn args must be of the --foo=bar form.
#
# Args:
# 1: the svn action (co, up, ...)
# 2-n: args to svn in the --foo=bar form followed by a target
#
# Named args
# -q do not echo command
# -r redirect output to stderr
# -2 If USE_2ND_SVNAUTH is true, don't bother trying first checkout
#
bilderSvn() {
# Get the args for bilderSvn
local usesecondauth=false
local redirecttoerr=false
local echocmd=true
# Parse options
# This syntax is needed to keep parameters quoted
if false; then
set -- "$@"
OPTIND=1
while getopts "qr2" arg; do
case "$arg" in
q) echocmd=false;;
r) redirecttoerr=true;;
2) usesecondauth=true;;
esac
done
shift $(($OPTIND - 1))
else
while test -n "$1"; do
case "$1" in
-q) echocmd=false;;
-r) redirecttoerr=true;;
-2) usesecondauth=true;;
*) break;;
esac
shift
done
fi
local svncmd=$1
shift
# Get the args for svn
local svnargs=
while test -n "$1"; do
case "$1" in
-*) svnargs="$svnargs $1";;
*) break;;
esac
shift
done
local origtarget=$1
# Save current directory to go back to if needed
local origdir=`pwd -P`
# Determine directory in which to execute command and what target is needed.
local svntarget=
local execdir=
local targetdir=
if test -z "$origtarget"; then
execdir=$origdir
elif test -d "$origtarget"; then
execdir=`(cd $origtarget; pwd -P)`
elif [[ "$origtarget" =~ :// ]]; then
execdir=.
svnargs="$origtarget"
svntarget=$2
else
targetdir=`dirname $origtarget`
svntarget=`basename $origtarget`
if test -z "$targetdir" || test "$targetdir" = .; then
execdir=$origdir
else
execdir=`(cd $targetdir; pwd -P)`
fi
fi
if test -z "$svntarget" && test "$svncmd" = revert; then
svntarget=.
fi
# Change to target's directory, cleanup and execute command
cd $execdir
$echocmd && techo -2 "In $PWD:" 1>&2
cmd="'$BILDER_SVN' cleanup"
$echocmd && techo -2 "$cmd" 1>&2
eval "$cmd" 1>&2
cmd="'$BILDER_SVN' $svncmd $svnargs $svntarget"
$echocmd && techo -2 "$cmd" 1>&2
# May need to capture output of this command
eval "$cmd"
res=$?
cd $origdir
$echocmd && techo -2 "Back in $PWD." 1>&2
return $res
}
#
# Perform svn cleanup recursively, even on svn:externals, which svn
# doesn't do.
#
# Get the externals, then recursively call ourselves for each one.
#
#
bilderSvnCleanup() {
for dir in `svn pg svn:externals . | awk '{ print $1 }'`; do
cd $dir
bilderSvnCleanup
# At this point, we have to go back up, but if our external dir is of
# the form a/b, then we'll have to do "cd .." twice. We can't use cd -,
# so we just count the number of components and do "cd .." for each one.
components=`echo $dir | tr / ' '`
for slash in $components; do
cd ..
done
done
}
#
# svn version on a node. This
#
# Args:
# 1: the node
#
bilderSvnversion() {
# techo -2 "bilderSvnversion called with '$*'."
BLDR_SVNVERSION=${BLDR_SVNVERSION:-"svnversion"}
local version=
local numargs=$#
local args=
local svnver=`which "$BLDR_SVNVERSION"`
while test -n "$1"; do
# Single quotes not working on cygwin, so removing
if test $# -eq 1; then
techo -2 "bilderSvnversion: Working on last arg, $1." 1>&2
# If using the windows client, convert path if not an option
if [[ "$1" =~ ^- ]]; then
techo -2 "Last arg, $1, is an option. Adding to list." 1>&2
args="$args $1"
elif [[ "$svnver" =~ "Program Files" ]]; then
techo "bilderSvnversion: windows: '$svnver'. Will convert last arg, $1, using cygpath." 1>&2
if node=`cygpath -aw "$1"`; then
args="$args $node"
else
techo "WARNING: [$FUNCNAME] cygpath did not work on $1." 1>&2
args="$args $1"
fi
else
techo -2 "Not using windows: '$svnver'. Will add last arg, $1, to list." 1>&2
args="$args $1"
fi
else
args="$args $1"
fi
shift
done
# Quoting args did not work
if ! version=`"$BLDR_SVNVERSION" $args`; then
techo "Command svnversion failed. BLDR_SVNVERSION = $BLDR_SVNVERSION." 1>&2
version=unknown
fi
version=`echo $version | tr -d '\r' | tr : -`
echo "$version"
}
#
# Get the maker depending on system and build system
#
# Args:
# 1: the build system
#
getMaker() {
local maker
case `uname` in
CYGWIN*)
case "$1" in
qmake | cmake | none)
if which jom 1>/dev/null 2>&1; then
maker=jom
# elif which ninja 1>/dev/null 2>&1; then
# maker=ninja
else
maker=nmake
fi
;;
*)
maker=make
;;
esac
;;
*)
local maker=make
;;
esac
echo $maker
}
#
# Get the flag prefix corresponding to a compiler variable name
#
# Args:
# 1: the compiler variable name (CC, CXX, F77, FC)
#
getCompFlagsPrefix() {
local flagsprfx
case $1 in
CC)
flagsprfx=C
;;
F77)
flagsprfx=F
;;
*)
flagsprfx=$i
;;
esac
echo $flagsprfx
}
#
# Add the default compiler flags for serial and pyc.
#
addDefaultCompFlags() {
# Determine the FLAGS for each compiler
for pre in "" PYC_; do
local cxxcomp=`deref ${pre}CXX`
local cxxbase=
# In case of wrapper, determine base from that
local verline=`$cxxcomp --version 2>/dev/null | head -1`
case "$verline" in
*ICC*) cxxbase=icpc;;
*GCC*) cxxbase=g++;;
esac
# If not determined, use base name
local cxxbase=${cxxbase:-"`basename ${cxxcomp}`"}
case $cxxbase in
clang* | g++*)
eval ${pre}PIC_FLAG=-fPIC
eval ${pre}PIPE_FLAG=-pipe
eval ${pre}O3_FLAG='-O3'
;;
cl*)
eval unset ${pre}PIC_FLAG
eval unset ${pre}PIPE_FLAG
eval unset ${pre}O3_FLAG
;;
icpc*)
eval ${pre}PIC_FLAG=-fPIC
eval ${pre}PIPE_FLAG=-pipe
eval ${pre}O3_FLAG='-O3'
;;
mingw*)
eval unset ${pre}PIC_FLAG
eval unset ${pre}PIPE_FLAG
eval ${pre}O3_FLAG='-O3'
;;
path*)
eval ${pre}PIC_FLAG=-fPIC
eval unset ${pre}PIPE_FLAG
eval ${pre}O3_FLAG='-O3'
;;
xl*)
eval ${pre}PIC_FLAG="-qpic=large"
eval unset ${pre}PIPE_FLAG
eval ${pre}O3_FLAG='-O3'
;;
*)
techo "WARNING: pic and opt3 flags not known for $cxxcomp."
;;
esac
techo -2 "${pre}PIC_FLAG = `deref ${pre}PIC_FLAG`"
techo -2 "${pre}PIPE_FLAG = `deref ${pre}PIPE_FLAG`"
techo -2 "${pre}O3_FLAG = `deref ${pre}O3_FLAG`"
done
# Always add pic and pipe flags
for pre in "" PYC_; do
for i in CC CXX F77 FC; do
if [[ $i =~ ^C ]] && $USE_CCXX_PIC_FLAG || [[ $i =~ ^F ]] && $USE_FORTRAN_PIC_FLAG; then
local compval=`deref ${pre}$i`
if test -n "$compval"; then
local flagsprfx=`getCompFlagsPrefix $i`
local flagsname=${pre}${flagsprfx}FLAGS
local flagsval=`deref ${flagsname}`
local picflag=`deref ${pre}PIC_FLAG`
if test -n "$picflag" && ! echo $flagsval | grep -- "$picflag"; then
flagsval="$flagsval $picflag"
fi
local pipeflag=`deref ${pre}PIPE_FLAG`
if test -n "$pipeflag" && ! echo $flagsval | grep -- "$pipeflag"; then
flagsval="$flagsval $pipeflag"
fi
trimvar flagsval ' '
eval $flagsname="\"$flagsval\""
techo -2 "$flagsname = \"$flagsval\""
fi
fi
done
done
}
#
# Get the top build directory for a package of a version
#
# Args:
# 1: package name
# 2: version
#
getBuildTopdir() {
# Default build directory
local buildtopdir
if test -d $BUILD_DIR/$1-$verval; then
buildtopdir=$BUILD_DIR/$1-$verval
else
mkdir -p $BUILD_DIR/$1
buildtopdir=$BUILD_DIR/$1
fi
echo $buildtopdir
}
#
# convert seconds to hh:mm:ss
#
myTime() {
local secs=$1
local hours=`expr $secs / 3600`
secs=`expr $secs - $hours \* 3600`
local mins=`expr $secs / 60`
local secs=`expr $secs - $mins \* 60`
# Always print hours, as otherwise interpretable as mm:ss.
# if test $hours -gt 0; then
printf "%02d:" $hours
# fi
printf "%02d:%02d\n" $mins $secs
}
#
# Set permissions of a directory (if absolute) or a subdirectory of $INSTALL
# (if relative) to group rw and other just r.
#
# Args:
# 1: The subdirectory to fix or directory if begins with /
#
setOpenPerms() {
case `uname` in
CYGWIN*) # No need on cygwin
return 0
;;
esac
local permdir
if test -n "$1"; then
case "$1" in
/*)
permdir=$1
;;
*)
permdir=$BLDR_INSTALL_DIR/$1
;;
esac
fi
techo "Setting open permissions on $permdir."
local updir=`dirname $permdir`
local dirgroup=
dirgroup=`ls -ld $updir | sed 's/ */ /g' | cut -f 4 -d ' '`
local res=0
local res1=
for i in $permdir; do
if test -d $i; then
cmd="find $i -user $USER -exec chgrp $dirgroup '{}' \;"
techo "$cmd"
eval "$cmd"
# On linux, cannot chmod a link
local mod=
if [[ `uname` =~ Linux ]]; then
mod='\( -type d -or -type f \)'
fi
cmd="find $i -user $USER $mod -exec chmod ug=rwX,o=rX '{}' \;"
techo "$cmd"
eval "$cmd"
res1=$?
if test $res1 != 0; then res=$res1; fi
cmd="find $i -type d -user $USER -exec chmod g+s '{}' \;"
techo "$cmd"
eval "$cmd"
res1=$?
if test $res1 != 0; then res=$res1; fi
else
cmd="chmod ug=rwX,o=rX $i"
techo "$cmd"
$cmd
res=$?
fi
done
return $res
}
#
# Set permissions of a directory (if absolute) or a subdirectory of $INSTALL
# (if relative) to user rw, group r, other none
#
# Args:
# 1: The subdirectory to fix or directory if begins with /
#
setClosedPerms() {
case `uname` in
CYGWIN*) # No need on cygwin
return
;;
esac
local permdir
if test -n "$1"; then
case "$1" in
/*)
permdir=$1
;;
*)
permdir=$BLDR_INSTALL_DIR/$1
;;
esac
fi
techo "Setting closed permissions on $permdir."
local res=0
local res1=
for i in $permdir; do
if test -d $i; then
cmd="find $i -user $USER -exec chmod u=rwX,g=rX,o-rwx '{}' \;"
techo "$cmd"
eval "$cmd"
res1=$?
if test $res1 != 0; then res=$res1; fi
cmd="find $i -type d -user $USER -exec chmod g+s '{}' \;"
techo "$cmd"
eval "$cmd"
res1=$?
if test $res1 != 0; then res=$res1; fi
else
cmd="chmod u=rwX,g=rX,o-rwx $i"
echo $cmd
$cmd
res=$?
fi
done
return $res
}
#
# Check writability of a directory
#
# Args:
# 1: Name of the directory
#
# Named args:
# -c check and report, but do not exit
#
checkDirWritable() {
local exitonfailure=true
# Parse options
# This syntax is needed to keep parameters quoted
set -- "$@"
OPTIND=1
while getopts "c" arg; do
case "$arg" in
c) exitonfailure=false;;
esac
done
shift $(($OPTIND - 1))
if test -z "$1"; then
TERMINATE_ERROR_MSG="ERROR: [$FUNCNAME] Directory not specified."
terminate
fi
local dir=$1
# Create directory if not present.
if test -d $dir; then
: # techo "Directory, $dir, already exists."
else
techo "Creating directory, $dir."
if mkdir -p $dir; then
techo "Directory, $dir, created."
else
techo "NOTE: [$FUNCNAME] Cannot create directory, $dir, on `hostname`."
if $exitonfailure; then
techo "Quitting. (checkDirWritable)"
emailerror "Cannot create directory, $dir."
usage 1
fi
fi
fi
# Determine writability
if ! touch $dir/tmp$$; then
techo "ERROR: [$FUNCNAME] Cannot write to $dir. USER = $USER with groups = `groups`."
if $exitonfailure; then
techo "Quitting."
emailerror "Cannot write to $dir."
if declare -f usage >/dev/null 2>&1; then
usage 1
fi
terminate
fi
fi
rm $dir/tmp$$
# Set directory perms. Must always do, as may have been created by
# mkall-default.sh wrapper, which creates dir with wrong perms.
# Errors (not owner) to /dev/null.
cmd="chmod 2775 $dir"
$cmd 2>/dev/null
# Create subdirs if an installation dir
if test "$dir" = "$BLDR_INSTALL_DIR" -o "$dir" = "$CONTRIB_DIR"; then
local subdirs="bin include share"
if [[ `uname` =~ CYGWIN ]]; then
subdirs="$subdirs Lib Scripts"
else
subdirs="$subdirs lib"
fi
for j in $subdirs; do
if test -d $dir/$j; then
if ! touch $dir/$j/tmp$$; then
techo "WARNING: [$FUNCNAME] Cannot write to $dir/$j. USER = $USER, groups = `groups`."
fi
rm -f $dir/$j/tmp$$
else
mkdir -p $dir/$j
chmod 2775 $dir/$j
fi
done
fi
# Check for unknown version installations
local unks=`(cd $dir; ls -d *unknown* 2>/dev/null)`
if test -n "$unks"; then
techo "WARNING: [$FUNCNAME] $dir has unknown installations, $unks."
fi
# Check for cc4py builds
local c4pys=`(cd $dir; ls -d *-cc4py 2>/dev/null)`
if test -n "$c4pys"; then
techo "WARNING: [$FUNCNAME] $dir has cc4py installations, $c4pys."
techo "WARNING: [$FUNCNAME] Trunk builds no longer needs these."
fi
# Check for cc4py builds
local shctks=`(cd $dir; ls -d *composer*-sersh 2>/dev/null)`
if test -n "$shctks"; then
techo "WARNING: [$FUNCNAME] $dir has sersh composer installations, $shctks."
techo "WARNING: [$FUNCNAME] Trunk builds no longer needs these."
fi
}
#
# Take a name and return a valid bash variable
#
# Args:
# 1: The name used to generate the variable name
#
genbashvar() {
local bashvar=`echo $1 | tr 'a-z./-' 'A-Z___'`
echo $bashvar
}
#
# Remove values from a variable containing comma delimited values
#
# Args:
# 1: the variable
# 2: comma separated list of values to remove
#
rmVals() {
if test -z "$2"; then
return
fi
local var=$1
local vals=`deref $var`
for v in `echo $2 | tr ',' ' '`; do
vals=`echo ,${vals}, | sed -e "s/,${v},/,/"`
done
trimvar vals ','
eval ${var}=$vals
}
#
# Compute the builds from a package by taking the add builds
# minus the no-builds
#
# Args:
# 1: the package
#
computeBuilds() {
buildsvar=`genbashvar $1`_BUILDS
buildsval=`deref $buildsvar`
if test -z "$buildsval"; then
addbuildsvar=`genbashvar $1`_DESIRED_BUILDS
addbuildsval=`deref $addbuildsvar`
nobuildsvar=`genbashvar $1`_NOBUILDS
nobuildsval=`deref $nobuildsvar`
addVals $buildsvar $addbuildsval
rmVals $buildsvar $nobuildsval
trimvar $buildsvar ,
fi
}
#
# Add values to a variable containing comma delimited values
#
# Args:
# 1: the variable
# 2: comma separated list of values to add
#
addVals() {
if test -z "$2"; then
return
fi
local var=$1
local vals=`deref $var`
for v in `echo $2 | tr ',' ' '`; do
if ! echo ${vals} | egrep -q "(^|,)$v($|,)" ; then
vals=${vals},$v
fi
done
trimvar vals ','
eval ${var}=$vals
}
#
# Add a directory to a path-like variable if not already there.
# Convert to cygwin if not path
#
# Args:
# 1: The variable name
# 2: The directory to add
# 3: If "after" add after, otherwise before
#
addtopathvar() {
# Determine the separator
local sep=":"
local addpathcand="$2"
local addpath=
# Find absolute, resolved path, if it exists
case `uname`-$1 in
*-PATH) # cygwin converts PATH and uses colon
# addpathcand may not exist *yet*, so `cd` won't work, in which case this
# returns empty
addpath=`(cd "$addpathcand" 2>/dev/null && pwd -P)`
;;
CYGWIN*)
sep=";"
addpath=`cygpath -aw "$addpathcand" | sed 's?\\\\?\\\\\\\\\\\\\\\\?g'`
;;
esac
# Fallback to given
addpath=${addpath:-"$addpathcand"}
# Remove from path if already present, so added to front
local pathval=`deref $1 | sed "s?$addpath??g"`
local bildersaveval=`deref BILDER_ADDED_${1} | sed "s?$addpath??g"`
local bpvar=BILDER_$1
local bpval=`deref $bpvar | sed "s?$addpath??g"`
if test "$3" = "after"; then
# Add after if not already at end
if ! [[ "${pathval}" =~ "${addpath}"$ ]]; then
eval $1="'${pathval}${sep}${addpath}'"
eval BILDER_ADDED_${1}="'${bildersaveval}${sep}${addpath}'"
eval $bpvar="'${bpval}${sep}${addpath}'"
fi
else
# Add before if not already at beginning
if ! [[ "${pathval}" =~ ^"${addpath}" ]]; then
eval $1="'${addpath}${sep}${pathval}'"
eval BILDER_ADDED_${1}="'${addpath}${sep}${bildersaveval}'"
eval $bpvar="'${addpath}${sep}${bpval}'"
fi
fi
eval trimvar $1 "'${sep}'"
eval trimvar BILDER_ADDED_${1} "'${sep}'"
eval trimvar $bpvar "'${sep}'"
# Print results
pathval=`derefpath $1`
bpval=`derefpath $bpvar`
techo -2 "Variable $bpvar = $bpval, $1 = $pathval (addtopathvar)"
}
#
# Install the configuration files
#
# Args:
# 1: The installation directory for previous mods, to capture them
#
createConfigFiles() {
techo
techo " Bilder Creating configuration files"
techo "======================================"
# Installation directory
local instdir=$BLDR_INSTALL_DIR
if test -n "$1"; then
instdir=$1
fi
# Determine whether module system exists
local havemodules=
if module list 1>/dev/null 2>&1; then
havemodules=true
else
havemodules=false
fi
# Determine whether the python module was loaded
local pymodule=
local havepymodule=false
if $havemodules; then
# JRC to whomever wrote this code
pymodule=`module list 2>&1 | grep ' python/' | sed 's/^.*) //'`
if test -n "$pymodule"; then
havepymodule=true
fi
fi
# Create setup scripts
cd $PROJECT_DIR
rm -f $BUILD_DIR/${BILDER_PROJECT}.sh
case `uname` in
CYGWIN*) sep=';';;
*) sep=':';;
esac
# Path always uses colon
trimvar BILDER_PATH ':'
cat <<EOF >$BUILD_DIR/${BILDER_PROJECT}.sh
#!/bin/bash
EOF
if test -n "$BILDER_PATH"; then
cat <<EOF >>$BUILD_DIR/${BILDER_PROJECT}.sh
export PATH="${BILDER_PATH}:\$PATH"
EOF
fi
# Other paths use semicolon
for i in $BILDER_ADDL_PATHS; do
local bpvar=BILDER_$i
local bpval=`deref $bpvar`
trimvar bpval "${sep}"
if test -n "$bpval"; then
cat <<EOF >>$BUILD_DIR/${BILDER_PROJECT}.sh
export $i="${bpval}${sep}\$$i"
EOF
fi
done
if $havepymodule; then
cat <<EOF >>$BUILD_DIR/${BILDER_PROJECT}.sh
# Load python modules
module unload python 2>/dev/null
module load $pymodule