-
Notifications
You must be signed in to change notification settings - Fork 0
/
larrel
executable file
·670 lines (631 loc) · 15.9 KB
/
larrel
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
#!/bin/sh
# David Adams
# October, 2014
#
# Script to build an LBNE release.
THISDIR=`dirname $0`
OLDPROD=larsoft
NEWPROD=lbnecode
TOPDIR=`pwd`
HISTFILE=$TOPDIR/history
COMHISTFILE=$TOPDIR/comhistory
DBG=
HELP=
README=
ENVCHK=
REMDIR=
REMALL=
DIRMAK=
CHKOUT=
VERUPD=
BUILD=
QUAL=e7:prof
Test=
OLDVERS=
NEWVERS=
COMMIT=
ENDFLOW=
PUSHBRA=
PUSHTAG=
UPSPROD=
SHOW=
while getopts 'ghHerRdcvbtClpPuo:n:q:s:' flag; do
case "${flag}" in
g) DBG='true' ;;
h) HELP='true' ;;
H) README='true' ;;
e) ENVCHK='true' ;;
r) REMDIR='true' ;;
R) REMALL='true' ;;
d) DIRMAK='true' ;;
c) CHKOUT='true' ;;
v) VERUPD='true' ;;
b) BUILD='true' ;;
t) TEST='true' ;;
C) COMMIT='true' ;;
l) COMMIT='true'; ENDFLOW='true' ;;
p) PUSHBRA='true'; PUSHTAG='true' ;;
P) PUSHTAG='true' ;;
u) UPSPROD='true' ;;
o) OLDVERS="${OPTARG}" ;;
n) NEWVERS="${OPTARG}" ;;
q) QUAL="${OPTARG}" ;;
s) SHOW="${OPTARG}" ;;
*) "ERROR: Unexpected option ${flag}"; exit 1 ;;
esac
done
# For option -H, display README.md and exit.
if [ -n "$README" ]; then
cat $THISDIR/README.md
exit 0
fi
# For option -R, remove everything and exit.
if [ -n "$REMALL" ]; then
echo -e $LINE
echo Removing development area.
rm -rf workdir
rm -f $HISTFILE
rm -f $COMHISTFILE
rm -rf oldversion.txt
rm -rf newversion.txt
rm -rf ups*.log
exit 0
fi
# For option -s ARG, show ARG and exit.
if [ -n "$SHOW" ]; then
echo $LINE
echo Show options:
if ! cd $TOPDIR/workdir/srcs/lbnecode 1>/dev/null 2>&1; then
echo First use option -c to check out $NEWPROD.
exit 1
fi
if [ "$SHOW" = help ]; then
echo " gitstatus - local git status"
echo " gitdiff - local git diffs"
echo " localbranches - list branches in local checkout"
echo "remotebranches - list branches in remote repository"
echo " localtags - list tags in local repository"
echo " remotetags - list tags in remote repository"
else if [ "$SHOW" = remotetags ]; then
git ls-remote --tags origin | grep -v "\^{}"$
else if [ "$SHOW" = localtags ]; then
git show-ref --tags
else if [ "$SHOW" = remotebranches ]; then
git branch -r
else if [ "$SHOW" = localbranches ]; then
git branch
echo Local repository changes:
else if [ "$SHOW" = gitstatus ]; then
echo "----------------------------"
git status
echo "----------------------------"
else if [ "$SHOW" = gitdiff ]; then
echo "----------------------------"
git diff
echo "----------------------------"
else if [ "$SHOW" = q ]; then
echo "----------------------------"
echo QUAL=$QUAL
echo "----------------------------"
else
echo ERROR: Invalid show option: $SHOW
echo ERROR: Use $0 -s help to list all options.
exit 1
fi; fi; fi; fi; fi; fi; fi; fi
exit 0
fi
# Determine which stage we process through.
STAGE4=$BUILD$TEST$COMMIT$ENDFLOW$PUSHBRA$PUSHTAG
STAGE3=$CHKOUT$VERUPD$STAGE4
STAGE2=$UPSPROD$STAGE3
STAGE1=$REMDIR$REMALL$OLDVERS$NEWVERS$DIRMAK$STAGE2
if [ -n "$DBG" ]; then
echo Stage 1: $STAGE1
echo Stage 2: $STAGE2
echo Stage 3: $STAGE3
echo Stage 4: $STAGE4
fi
if [ -z "$STAGE1" ]; then
HELP='true'
fi
# Show help and exit.
if [ -n "$HELP" ]; then
echo "Usage: $0 [-hgerRdcbtlp] [-o OLDVERS][-n NEWVERS][-q QUAL]"
echo " -h: Help (this message)."
echo " -H: Display instructions (README.md)."
echo " -g: Enable debugging messgages."
echo " -e: Check environment"
echo " -r: Remove existing development area."
echo " -R: Remove everything and exit."
echo " -d: Create new development area."
echo " -c: Check out product source."
echo " -v: Start flow and update version in checked-out code."
echo " -b: Build product."
echo " -t: Test product."
echo " -C: Commit local changes."
echo " -l: Commit local changes and end flow."
echo " -p: Push changes to development and release branches."
echo " -P: Push changes only to release branch (used when push to development fails)."
echo " -u: Make UPS product"
echo " -o OLDVERS: Set the version for the old product (larsoft)"
echo " -n NEWVERS: Set the version for the new product (lbnecode)"
exit 0
fi
LINE="\n===================================="
# Source the initialization script.
echo -e $LINE
echo Initializing
source $THISDIR/lbneinit.sh
# For option -e, we display some of the environment.
if [ -n "$ENVCHK" ]; then
echo -e $LINE
echo Checking environment
for NAME in setup git mrb mrbsetenv; do
if ! type $NAME >/dev/null 2>&1; then
echo ERROR: Initialization failed: $NAME not found.
exit 1
else
echo Found command $NAME
fi
done
fi
# For option -r, we remove any previous builds.
if [ -n "$REMDIR" ]; then
echo -e $LINE
echo Removing development area.
rm -rf workdir
rm -f $HISTFILE
rm -f $COMHISTFILE
fi
# Retrieve the old (larsoft) version.
# For option -o, the value is taken from the command line.
echo -e $LINE
echo Setting old product version
OLDVERSFILENAME=$TOPDIR/oldversion.txt
if [ -r $OLDVERSFILENAME ]; then
OLDVERSFILE=`cat $OLDVERSFILENAME`
if [ -n "$OLDVERSFILE" -a "$OLDVERS" != "$OLDVERSFILE" ]; then
if [ -z "$OLDVERS" ]; then
OLDVERS=$OLDVERSFILE
else
echo "ERROR: Requested old version does not match previous value:"
echo " $OLDVERS != $OLDVERSFILE"
exit 1
if [ -n "$OLDVERS" ]; then
OLDVERS=$OLDVERSFILE
fi
fi
fi
else
if [ -n "$OLDVERS" ]; then
echo $OLDVERS >$OLDVERSFILENAME
echo setoldversion >> $HISTFILE
fi
fi
echo "Old product and version: $OLDPROD $OLDVERS"
# Retrieve the new (lbnecode) version.
# For option -o, the value is taken from the command line.
echo -e $LINE
echo Setting new product version
NEWVERSFILENAME=$TOPDIR/newversion.txt
if [ -r $NEWVERSFILENAME ]; then
NEWVERSFILE=`cat $NEWVERSFILENAME`
if [ -n "$NEWVERSFILE" -a "$NEWVERS" != "$NEWVERSFILE" ]; then
if [ -z "$NEWVERS" ]; then
NEWVERS=$NEWVERSFILE
else
echo "ERROR: Requested new version does not match previous value:"
echo " $NEWVERS != $NEWVERSFILE"
exit 1
if [ -n "$NEWVERS" ]; then
NEWVERS=$NEWVERSFILE
fi
fi
fi
else
if [ -n "$NEWVERS" ]; then
echo $NEWVERS >$NEWVERSFILENAME
echo setnewversion >> $HISTFILE
fi
fi
if [ -z "$OLDVERS" ]; then
echo "Use -o to set old version."
exit 1
fi
if [ -z "$NEWVERS" ]; then
echo "Use -n to set new version."
exit 1
fi
echo "New product and version: $NEWPROD $NEWVERS"
# Add header to the command history file.
echo >>$COMHISTFILE
echo "# "`date` >>$COMHISTFILE
echo "# $0 $*" >>$COMHISTFILE
# For -r, create the working directory.
if [ ! -r workdir ]; then
echo -e $LINE
echo Creating workdir
COM="mkdir workdir"
echo $COM >> $COMHISTFILE
if ! $COM; then
echo ERROR: Unable to create workdir
exit 1
fi
echo createdworkdir >> $HISTFILE
fi
# Move to the working directory.
COM="cd $TOPDIR/workdir"
echo $COM >>$COMHISTFILE
$COM
# For option -d, create the development area.
if [ -n "$DIRMAK" -a -z "$UPSPROD" ]; then
echo -e $LINE
echo Creating development area.
if [ -z "$OLDVERS" ]; then
echo "ERROR: Use -o to set old version."
exit 1
fi
if [ -z "$QUAL" ]; then
"ERROR: Product qualifier must defined."
exit 1
fi
if [ -r srcs ]; then
echo "ERROR: Development area already exists"
exit 1
fi
COM="mrb newDev -v $OLDVERS -q $QUAL"
echo $COM >>$COMHISTFILE
if ! $COM; then
echo "ERROR: Command failed: $COM"
exit 1
fi
echo creatednewdev >> $HISTFILE
fi
# Exit stage 1.
if [ -z "$STAGE2" ]; then
echo -e $LINE
if [ -n "$DBG" ]; then echo Exiting before stage 2; fi
echo Done
exit 0
fi
# Check that development are exists or we are doing UPS build.
if [ ! -r srcs -a -z "$UPSPROD" ]; then
echo "ERROR: Use -d to create development area"
exit 1
fi
echo Development area: `pwd`
# Find the current platform (slf5, slf6, ...)
# Or we can use this:
# setup cetpkgsupport
# get-directory-name os
PLATFORM=
#SLF5=`lsb_release -a | grep 5.4`
#SLF6=`lsb_release -a | grep 6.4`
#if test -n "$SLF5" -a -z "$SLF6"; then
#PLATFORM=slf5
#else if test -z "$SLF5" -a -n "$SLF6"; then
#PLATFORM=slf6
#fi; fi
PLATFORM=`get-directory-name os`
# For option -u, build UPS product.
if [ -n "$UPSPROD" ]; then
echo -e $LINE
echo Building UPS product $NEWPROD $NEWVERS
if test -z "$PLATFORM"; then
echo Platform could not be determined.
exit 1
fi
RELDIR=`echo reldir-$PLATFORM-$QUAL | sed 's/:/-/g'`
echo Release directory: $RELDIR
if [ -r $RELDIR ]; then
echo Release directory already exists.
echo Delete workdir/$RELDIR it before to rebuilding release.
exit 1
fi
rm -rf $RELDIR
if ! mkdir $RELDIR; then
echo "ERROR: Unable to to create release directory."
exit 1
fi
COM="cd $RELDIR"
echo $COM >>$COMHISTFILE
$COM
echo $RELDIR >>$HISTFILE
echo MRB_SOURCE=$MRB_SOURCE
COM="mrb newDev -v $OLDVERS -q $QUAL"
echo $COM>>$COMHISTFILE
if ! $COM; then
echo "ERROR: Unable to make development area for $OLDVERS"
exit 1
fi
echo MRB_SOURCE=$MRB_SOURCE
for DIR in localProducts*; do
echo " $DIR"
COM="source $DIR/setup"
$COM
echo $COM>>$COMHISTFILE
done
COM="cd $MRB_SOURCE"
$COM
echo $COM>>$COMHISTFILE
UPSLOG=$TOPDIR/workdir/$RELDIR/upscheckout.log
COM="mrb gitCheckout -t $NEWVERS $NEWPROD"
echo Checking out $NEWPROD $NEWVERS. Log is $UPSLOG.
#if ! mrb gitCheckout -t $NEWVERS $NEWPROD >$LOG 2>&1; then
echo $COM>>$COMHISTFILE
if ! $COM >>$UPSLOG 2>&1; then
echo "ERROR: Unable to check out $NEWPROD $NEWVERS"
exit 1
fi
if grep ^error: $UPSLOG; then
echo "ERROR: Error checking out $NEWPROD $NEWVERS:"
grep ^error: $UPSLOG
exit 1
fi
echo MRB_SOURCE=$MRB_SOURCE
COM="cd $MRB_BUILDDIR"
$COM
echo $COM>>$COMHISTFILE
COM=mrbsetenv
$COM
echo $COM>>$COMHISTFILE
UPSLOG=$TOPDIR/workdir/$RELDIR/upsbuild.log
echo Building. Log is $UPSLOG
mrb b >$UPSLOG 2>&1
UPSLOG=$TOPDIR/workdir/$RELDIR/upsmake.log
echo Making product. Log is $UPSLOG
mrb makePackage >$UPSLOG 2>&1
echo -e $LINE
if [ -n "$DBG" ]; then echo Exiting after product build; fi
ls $TOPDIR/workdir/$RELDIR/build_*/$NEWPROD-*.tar*
echo Done
exit 0
fi
# Exit stage 2.
if [ -z "$STAGE3" ]; then
echo -e $LINE
if [ -n "$DBG" ]; then echo Exiting before stage 3; fi
echo Done
exit 0
fi
# Set up larsoft.
echo -e $LINE
echo Setting up $OLDPROD
if [ -n "$DBG" ]; then echo "=====Command: setup $OLDPROD $OLDVERS -q $QUAL"; fi
COM="setup $OLDPROD $OLDVERS -q $QUAL"
echo $COM >>$COMHISTFILE
if ! $COM; then
echo Setup failed for $OLDPROD $OLDVERS
exit 1
fi
# Set up installed products (lbnecode).
echo -e $LINE
echo Setting up local products
for DIR in localProducts*; do
echo " $DIR"
if [ -n "$DBG" ]; then echo "=====Command: source $DIR/setup"; fi
COM="source $DIR/setup"
echo $COM >>$COMHISTFILE
$COM
done
echo MRB_SOURCE=$MRB_SOURCE
COM="cd $MRB_SOURCE"
echo $COM >>$COMHISTFILE
$COM
# For option -c, check out lbnecode.
# Otherwise move to the area where it was previously checked out.
if [ -n "$CHKOUT" ]; then
echo -e $LINE
echo Checking out $NEWPROD
if [ -r $NEWPROD ]; then
echo "ERROR: $NEWPROD is already checked out."
exit 1
fi
COM="mrb gitCheckout $NEWPROD"
echo $COM >>$COMHISTFILE
if ! $COM; then
echo ERROR: Checkout failed
exit 1
fi
echo checkout >> $HISTFILE
COM="cd $NEWPROD"
echo $COM >>$COMHISTFILE
$COM
echo "Listing branches:"
git branch
else
echo -e $LINE
echo Moving to product area.
COM="cd $NEWPROD"
echo $COM >>$COMHISTFILE
if ! $COM; then
echo ERROR: Product area not found.
echo "ERROR: Use larrsoft -c to check out $NEWPROD"
exit 1
fi
fi
# For option -v, start a gitflow release.
if [ -n "$VERUPD" ]; then
echo -e $LINE
echo Starting flow
if grep startflow $HISTFILE 1>/dev/null 2>&1; then
echo ERROR: Flow is already started.
exit 1
fi
if true; then
echo
echo Switching to master
COM="git checkout master"
$COM
fi
echo
echo Starting flow.
COM="git flow release start $NEWVERS"
echo $COM >>$COMHISTFILE
if ! $COM; then
echo "ERROR: Error creating gitflow release."
exit 1
fi
echo startflow >> $HISTFILE
echo "Listing branches:"
git branch
fi
# For option -v, update the lbnecode versions of lbnecode and larsoft.
if [ -n "$VERUPD" ]; then
echo -e $LINE
echo Setting $NEWPROD version to $NEWVERS
if grep versionupdate2 $HISTFILE 1>/dev/null 2>&1; then
echo ERROR: Version has already been updated.
exit 1
fi
COM="mrb uv $NEWPROD $NEWVERS"
echo $COM >>$COMHISTFILE
$COM
echo versionupdate >> $HISTFILE
echo
echo Local repository changes:
echo "----------------------------"
git diff ups/product_deps
echo "----------------------------"
fi
# Exit stage 3.
if [ -z "$STAGE4" ]; then
echo -e $LINE
if [ -n "$DBG" ]; then echo Exiting before stage 4; fi
echo Done
exit 0
fi
# Do MRB setup.
echo -e $LINE
echo Setting up for build or test...
COM="cd $MRB_BUILDDIR"
echo $COM >>$COMHISTFILE
$COM
COM=mrbsetenv
echo $COM >>$COMHISTFILE
if ! $COM; then
echo ERROR: mrbsetenv failed.
exit 1
fi
# For option -b, build lbnecode.
if [ -n "$BUILD" ]; then
echo -e $LINE
echo Building...
COM="mrb build"
echo $COM >>$COMHISTFILE
if ! $COM; then
echo Build failed.
echo buildfailed >> $HISTFILE
exit 1
fi
echo buildpassed >> $HISTFILE
fi
# For option -t, test lbnecode.
if [ -n "$TEST" ]; then
echo -e $LINE
echo Testing...
COM="mrb test"
echo $COM >>$COMHISTFILE
if ! $COM; then
echo Test failed.
echo testfailed >> $HISTFILE
exit 1
fi
echo testpassed >> $HISTFILE
fi
# For option -C (and -l), commit changes to the release branch.
if [ -n "$COMMIT" ]; then
echo -e $LINE
echo Committing flow...
if grep committed $HISTFILE 1>/dev/null 2>&1; then
echo Commit is already done.
else
COM="cd $MRB_SOURCE/$NEWPROD"
echo $COM >>$COMHISTFILE
$COM
echo
echo Show branches:
git branch
echo
echo Committing...
COM="git commit -a -m Set_package_version_to_$NEWVERS"
echo $COM >>$COMHISTFILE
if ! $COM; then
echo ERROR: Git commit failed.
exit 1
fi
echo committed >> $HISTFILE
fi
fi
# For option -l, end gitflow release:
# --copy changes to develop and master branches,
# --create tag, and
# --delete release branch.
if [ -n "$ENDFLOW" ]; then
echo -e $LINE
echo Finishing flow...
cd $MRB_SOURCE/$NEWPROD
echo "***************"
# Capture the current git editor and change the value to something
# that always succeeds without changing the file.
OLDEDITOR=`git config --global core.editor`
COMED1="git config --global core.editor true"
COMED2="git config --global core.editor $OLDEDITOR"
COM="git flow release finish -m Ended_flow_for_${NEWPROD}_$NEWVERS $NEWVERS"
$COMED1
echo $COM >>$COMHISTFILE
if ! $COM; then
echo ERROR: Finishing flow failed.
git config --global core.editor $OLDEDITOR
$COMED2
exit 1
fi
$COMED2
echo "%%%%%%%%%%%%%%%"
echo flowfinished >> $HISTFILE
fi
DRYRUN="--dry-run"
DRYRUN=
# For option -p, push the branch changes back to the repository.
if [ -n "$PUSHBRA" ]; then
echo -e $LINE
echo Pushing branches...
COM="cd $MRB_SOURCE/$NEWPROD"
echo $COM >>$COMHISTFILE
$COM
echo
echo master...
COM="git push $DRYRUN origin master"
echo $COM >>$COMHISTFILE
if ! $COM; then
echo ERROR: Branch push to master failed.
exit 1
fi
echo
echo develop...
COM="git push $DRYRUN origin develop"
echo $COM >>$COMHISTFILE
if ! $COM; then
echo ERROR: Branch push to develop failed.
echo Continuing after error...
fi
echo branchespushed >> $HISTFILE
fi
# For option -p or -P, push the new tag back to the repository.
if [ -n "$PUSHTAG" ]; then
echo -e $LINE
echo Pushing tags...
COM="cd $MRB_SOURCE/$NEWPROD"
echo $COM >>$COMHISTFILE
$COM
COM="git push $DRYRUN --tags"
echo $COM >>$COMHISTFILE
if ! $COM; then
echo ERROR: Tag push failed.
exit 1
fi
echo tagpushed >> $HISTFILE
fi
echo -e $LINE
if [ -n "$DBG" ]; then echo Exiting after all stages; fi
echo Done 3