-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoinbrew
executable file
·2024 lines (1863 loc) · 67.8 KB
/
coinbrew
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
#!/usr/bin/env bash
# Author: Ted Ralphs ([email protected])
# Copyright 2016-2019, Ted Ralphs
# Released Under the Eclipse Public License
#
# TODO
# - fix dependency-tracking or remove it from configure
# - Add option to update all current checkouts (like fetch, but no version checks)
# - Read config.site
# - Make it possible to build a series of projects
# - Provide an option to build Python extensions
# - Provide an option to download dependencies in binary format (this is started)
# - Make autostash work better https://stackoverflow.com/questions/53049088/can-git-remind-me-about-or-auto-apply-a-stash-when-switching-back-into-the-corre/53050054
# script debugging
#set -x
#PS4='${LINENO}:${PWD}: '
###################################################################################
# First, we have a bunch of helper functions.
# The main script starts after all the function definitions.
###################################################################################
function help {
echo "Usage: coinbrew <command> <name|URL@version> --option value ..."
echo " Run without arguments for interactive mode"
echo
echo "Commands:"
echo
echo " fetch: Clone repos of project and dependencies"
echo " options: --ssh checkout git projects using ssh protocol rather than https"
echo " --skip,-s <'proj1 proj2'> skip listed projects"
echo " --no-third-party don't fetch third party source (run getter-scripts)"
echo " --skip-update skip updating projects that are already checked out (useful if you have local changes)"
echo " --skip-dependencies don't fetch dependencies, only main project"
echo " --latest-release Fetch latest releases of projects"
echo " --time check out project and all dependencies at a time stamp"
echo " --auto-stash stash changes before switching versions (experimental)"
echo " --no-rebase Pull without rebase (default is with rebase)"
echo
echo " build: Configure, build, test (optional), and install all projects"
echo " options: --configure-help (print help on build configuration"
echo " --xxx=yyy (will be passed through to configure)"
echo " VAR=xxx (will be passed through to configure)"
echo " --parallel-jobs,-j <n> build in parallel with maximum 'n' jobs (default: 1)"
echo " --build-dir,-b </dir/to/build/in> where to build (default: $PWD/build)"
echo " --tests,-t <all|main|none> which tests to do before install (default: all)"
echo " --verbosity,-v <1-4> set verbosity level (default: 1)"
echo " --reconfigure re-run configure"
echo " --prefix,-p </dir/to/install> where to install (default: $PWD/dist)"
echo " --skip-dependencies don't build dependencies, only main project"
echo " --no-third-party don't build third party projects"
echo " --static build static executables on Linux and OS X"
echo " --download-binary <'proj1 proj2'> list of binary packages to download"
echo " --platform <string> string specifying platform (required for binaries)"
echo
echo " install: Install all projects in location specified by prefix. This is done"
echo " done automatically after build, so probably not useful in general."
echo
echo " uninstall: Uninstall all projects"
echo
echo " download: Download project binaries (experimental, limited projects supported)"
echo " options: --platform <string> string specifying platform (required for binaries)"
echo " --prefix,-p </dir/to/install> where to install (default: $PWD/dist)"
echo
echo "General options:"
echo " --debug,-d Turn on debugging output (this should be the first option specified)"
echo " --no-prompt,-n Suppress interactive prompts"
echo " --help,-h Print help"
echo
}
###################################################################################
# Helpers to switch directories
###################################################################################
function pushd_ {
pushd $1 > /dev/null
}
function popd_ {
popd > /dev/null
}
###################################################################################
# Helper to print status messages
###################################################################################
function print_action {
echo
echo "##################################################"
echo "### $1 "
echo "##################################################"
echo
}
###################################################################################
# Parse command-line arguments to the script
###################################################################################
function parse_args {
while (( "$#" ))
do
arg=$1
shift
legacy_format=false
case $arg in
*=*)
option=${arg%%=*}
option_arg=${arg#*=}
legacy_format=true
;;
-*)
option=$arg
if [ "$#" = 0 ]; then
option_arg=
else
if [[ "$1" == -* ]]; then
option_arg=
else
option_arg=$1
fi
fi
;;
*)
option=$arg
option_arg=
;;
esac
case $option in
-p|--prefix)
if [ x"$option_arg" != x ]; then
case $option_arg in
[\\/$]* | ?:[\\/]* | NONE | '' )
prefix=$option_arg
;;
*)
prefix=$PWD/$option_arg
;;
esac
if [ $legacy_format = false ]; then
shift
fi
elif [ x"$build_dir" != x ]; then
case $build_dir in
[\\/$]* | ?:[\\/]* | NONE | '' )
prefix=$build_dir
;;
*)
prefix=$PWD/$build_dir
;;
esac
else
echo "No path provided for --prefix"
exit 3
fi
;;
-b|--build-dir)
if [ x"$option_arg" != x ]; then
case $option_arg in
[\\/$]* | ?:[\\/]* | NONE | '' )
build_dir=$option_arg
;;
*)
build_dir=$PWD/$option_arg
;;
esac
else
echo "No path provided for --build-dir"
exit 3
fi
if [ $legacy_format = false ]; then
shift
fi
;;
-j|--parallel-jobs)
if [ x"$option_arg" != x ]; then
jobs=$option_arg
else
echo "No number specified for --parallel-jobs"
exit 3
fi
if [ $legacy_format = false ]; then
shift
fi
;;
--threads)
echo "The 'threads' argument has been re-named 'parallel-jobs'."
echo "Please re-run with correct argument name"
exit 3
;;
-v|--verbosity)
if [ x"$option_arg" != x ]; then
verbosity=$option_arg
else
echo "No verbosity specified for --verbosity"
exit 3
fi
if [ $legacy_format = false ]; then
shift
fi
;;
--main-proj)
if [ x"$option_arg" != x ]; then
main_proj=$option_arg
else
echo "No main project specified for --main-proj."
exit 3
fi
if [ $legacy_format = false ]; then
shift
fi
;;
--main-proj-version)
if [ x"$option_arg" != x ]; then
main_proj_version=$option_arg
else
echo "No main project version specified for --main-proj-version."
exit 3
fi
if [ $legacy_format = false ]; then
shift
fi
;;
--main-proj-sha)
if [ x"$option_arg" != x ]; then
main_proj_sha=$option_arg
else
echo "No main project specified for --main-proj-sha."
exit 3
fi
if [ $legacy_format = false ]; then
shift
fi
;;
-s|--skip)
if [ x"$option_arg" != x ]; then
coin_skip_projects=$option_arg
else
echo "No projects specified with --skip."
exit 3
fi
if [ $legacy_format = false ]; then
shift
fi
;;
--time)
if [ x"$option_arg" != x ]; then
checkout_time=$option_arg
else
echo "No checkout time specified with --time."
exit 3
fi
if [ $legacy_format = false ]; then
shift
fi
;;
-t|--tests)
if [ x"$option_arg" != x ]; then
run_tests=$option_arg
else
echo "No argument specified with --tests."
exit 3
fi
if [ $legacy_format = false ]; then
shift
fi
;;
--download-binary)
if [ x"$option_arg" != x ]; then
download_projs=$option_arg
download=true
else
echo "No argument specified with --download-binary"
exit 3
fi
if [ $legacy_format = false ]; then
shift
fi
;;
--platform)
if [ x"$option_arg" != x ]; then
platform=$option_arg
else
echo "No argument specified with --platform"
exit 3
fi
if [ $legacy_format = false ]; then
shift
fi
;;
--enable-msvc)
configure_options["$arg"]=""
disable_uninstalled=false
;;
--disable-pkg-config)
configure_options["$arg"]=""
disable_uninstalled=false
;;
--enable-debug)
configure_options["$arg"]=""
enable_debug=true
;;
--static)
configure_options["--disable-shared"]=""
configure_options["LT_LDFLAGS=-all-static"]=""
configure_options["LDFLAGS=-static"]=""
;;
-h|--help)
help
exit 0
;;
--test)
run_tests=main
;;
--test-all)
run_tests=all
;;
-c|--configure-help)
configure_help=true
no_prompt=true
;;
--skip-dependencies)
skip_dependencies=true
;;
--sparse)
sparse=true
;;
--ssh)
ssh_checkout=true
;;
-d|--debug)
set -x
;;
--rebuild)
rebuild=true
;;
--reconfigure)
reconfigure=true
;;
--no-third-party)
get_third_party=false
;;
-n|--no-prompt)
no_prompt=true
;;
--skip-update)
skip_update=true
;;
--auto-stash)
auto_stash=true
;;
--latest-release)
get_latest_release=true
;;
--no-rebase)
rebase=false
;;
--off-line)
offline=true
;;
fetch)
num_actions+=1
fetch=true
;;
build)
num_actions+=1
build=true
;;
install)
num_actions+=1
install=true
;;
uninstall)
num_actions+=1
uninstall=true
;;
download)
num_actions+=1
download=true
;;
*)
# Look for things that seem to be arguments for configure
if [[ "$arg" == *=* ]] || [[ "$arg" == --* ]]; then
configure_options["$arg"]=""
else
slug=$(echo $arg | sed 's|https://github.com/||' | sed 's|[email protected]:||')
#Now look for the version number after the last ":" or "@"
#We support both formats for now. If there is any "@", then
#the format is the one with version after "@", otherwise, it
#is the version with ":"
if [[ $slug == *@* ]]; then
main_proj=${arg%@*}
main_proj_version=${arg##*@}
elif [[ $slug == *:* ]]; then
main_proj=${arg%:*}
main_proj_version=${arg##*:}
echo "Warning: specifying version after ':' is deprecated and will be removed in a future version. Use '@'."
else
main_proj=$arg
fi
if [ $(echo $main_proj_version | awk -F"/" "{print NF}") = "1" ]; then
if [ $(echo $main_proj_version | awk -F"." "{print NF}") = "2" ]; then
main_proj_version="stable/$main_proj_version"
elif [ $(echo $main_proj_version | awk -F"." "{print NF}") = "3" ]; then
main_proj_version="releases/$main_proj_version"
fi
fi
if [ "$main_proj_version" = "current" ]; then
keep_current=true
fi
fi
;;
esac
done
}
###################################################################################
# Find out if we're supposed to skip any projects
###################################################################################
function find_skip_projects {
for c in ${!configure_options[@]} ; do
if [[ $c == --without-* ]]; then
found_project=true
proj_name=$(echo "$c" | cut -d '-' -f 4)
proj_name=${proj_name,,}
case $proj_name in
asl)
proj_dir="ThirdParty/ASL"
;;
blas)
proj_dir="ThirdParty/Blas"
;;
filtersqp)
proj_dir="ThirdParty/FilterSQP"
;;
glpk)
proj_dir="ThirdParty/Glpk"
;;
hsl)
proj_dir="ThirdParty/HSL"
;;
lapack)
proj_dir="ThirdParty/Lapack"
;;
metis)
proj_dir="ThirdParty/Metis"
;;
mumps)
proj_dir="ThirdParty/Mumps"
;;
scip)
proj_dir="ThirdParty/SCIP"
;;
alps)
proj_dir="Alps"
;;
bcp)
proj_dir="Bcp"
;;
bcps)
proj_dir="Bcps"
;;
blis)
proj_dir="Blis"
;;
bonmin)
proj_dir="Bonmin"
;;
cbc)
proj_dir="Cbc"
;;
cgl)
proj_dir="Cgl"
;;
clp)
proj_dir="Clp"
;;
coinmp)
proj_dir="CoinMP"
;;
coinutils)
proj_dir="CoinUtils"
;;
couenne)
proj_dir="Couenne"
;;
dip)
proj_dir="Dip"
;;
disco)
proj_dir="DisCO"
;;
dylp)
proj_dir="DyLP"
;;
flopcpp)
proj_dir="FlopCpp"
;;
ipopt)
proj_dir="Ipopt"
;;
mibs)
proj_dir="MibS"
;;
os)
proj_dir="OS"
;;
osi)
proj_dir="Osi"
;;
symphony)
proj_dir="SYMPHONY"
;;
smi)
proj_dir="Smi"
;;
vol)
proj_dir="Vol"
;;
cppad)
proj_dir="cppad"
;;
amd|cholmod)
found_project=false
;;
*)
echo "Warning: Unknown project $proj_name"
found_project=false
;;
esac
if [ $found_project = "true" ]; then
coin_skip_projects="${coin_skip_projects:-} $proj_dir"
fi
fi
done
}
###################################################################################
# Determine whether we're supposed to build the project
###################################################################################
function should_build {
TMP_IFS=$IFS
unset IFS
for i in $coin_skip_projects
do
if [ $1 = $i ]; then
IFS=$TMP_IFS
return 1
fi
done
if [ $(echo $dir | cut -d '/' -f 1) = ThirdParty ]; then
if [ $(echo $dir | cut -d '/' -f 2) = HSL ]; then
if [ ! -f $dir/coinhsl/common/deps.f ]; then
IFS=$TMP_IFS
return 1
fi
elif ([ -e $dir ] && [ ! -e $dir/.build ]) ||
[ $get_third_party = false ]; then
IFS=$TMP_IFS
return 1
fi
fi
IFS=$TMP_IFS
return 0
}
###################################################################################
# Determine whether we're supposed to fetch the project
###################################################################################
function should_fetch {
if [ -d $dir ] && ([ $skip_update = true ] || [ $fetch != true ]); then
return 1
fi
TMP_IFS=$IFS
unset IFS
for i in $coin_skip_projects
do
if [ $dir = $i ]; then
IFS=$TMP_IFS
return 1
fi
done
IFS=$TMP_IFS
return 0
}
###################################################################################
# Determine the version currently checked out in a git repo
###################################################################################
function get_version_git {
current_rev=$(git rev-parse HEAD)
if [[ "$(git show-ref --tags | fgrep $current_rev)" == *releases* ]]; then
git show-ref --tags | fgrep $current_rev | fgrep releases | cut -d '/' -f 4
elif [[ "$(git show-ref --heads | fgrep $current_rev)" == *stable* ]]; then
git show-ref --heads | fgrep $current_rev | fgrep stable | cut -d '/' -f 4
elif [ "$(git show-ref --heads | fgrep $current_rev)" != "" ]; then
git show-ref --heads | fgrep $current_rev | cut -d '/' -f 3
else
echo $current_rev
fi
}
###################################################################################
# Determine version from an SVN URL (there are still some SVN URLs in Dependencies
###################################################################################
function get_version_svn {
if [ $proj = "BuildTools" ] &&
[ $(echo $1 | cut -d '/' -f 6) = 'ThirdParty' ]; then
if [ $(echo $1 | cut -d '/' -f 8) = trunk ]; then
echo "trunk"
else
echo $1 | cut -d '/' -f 8-9
fi
elif [ $proj = "CHiPPS" ]; then
if [ $(echo $1 | cut -d '/' -f 7) = trunk ]; then
echo "trunk"
else
echo $1 | cut -d '/' -f 7-8
fi
elif [ $proj = "Data" ]; then
if [ $(echo $1 | cut -d '/' -f 7) = trunk ]; then
echo "trunk"
else
echo $1 | cut -d '/' -f 7-8
fi
elif [ $proj = "CoinBazaar" ]; then
if [ $(echo $1 | cut -d '/' -f 9) = trunk ]; then
echo "trunk"
else
echo $1 | cut -d '/' -f 8-9
fi
else
if [ $(echo $1 | cut -d '/' -f 6) = trunk ]; then
echo "trunk"
else
echo $1 | cut -d '/' -f 6-7
fi
fi
}
###################################################################################
# Convert an SVN URL to a git URL
###################################################################################
function svn2git {
# Convert SVN URL to a Github one and check out with git
if [ $proj = "BuildTools" ] || [ $proj = "Data" ]; then
if [ $ssh_checkout = "false" ]; then
new_url="https://github.com/coin-or-tools/"
else
new_url="[email protected]:coin-or-tools/"
fi
elif [ $proj = "CoinBazaar" ]; then
if [ $ssh_checkout = "false" ]; then
new_url="https://github.com/coin-or-bazaar/"
else
new_url="[email protected]:coin-or-bazaar/"
fi
else
if [ $ssh_checkout = "false" ]; then
new_url="https://github.com/coin-or/"
else
new_url="[email protected]:coin-or/"
fi
fi
if [ $(echo $dir | cut -d "/" -f 1) = "ThirdParty" ]; then
new_url+=$(echo $dir | sed s"|/|-|")
elif [ $proj = "Data" ]; then
new_url+=$(echo $dir | sed s"|/|-|")
elif [ $proj = "CHiPPS" ]; then
if [ $dir = "Alps" ]; then
new_url+="CHiPPS-ALPS"
elif [ $dir = "Bcps" ]; then
new_url+="CHiPPS-BiCePS"
else
new_url+="CHiPPS-BLIS"
fi
elif [ $proj = "FlopC++" ]; then
new_url+="FlopCpp"
elif [ $proj = "CoinBazaar" ]; then
if [ $dir = "examples" ]; then
new_url+="ApplicationTemplates"
fi
else
new_url+=$proj
fi
echo $new_url
}
###################################################################################
# Prompt user for what actionas to perform
###################################################################################
function prompt_for_action {
# Prompt user for what actions to perform
echo "Please choose an action by typing 1-4."
echo " 1. Fetch source code of a project and its dependencies."
echo " 2. Build a project and its dependencies."
echo " 3. Install a project and its dependencies."
echo " 4. Help"
echo -n "=> "
read choice
case $choice in
1)
fetch=true
;;
2)
build=true
echo "Please specify a build directory (can be relative or absolute)."
echo -n "=> "
read user_build_dir
case $user_build_dir in
[\\/$]* | ?:[\\/]* | NONE | '' )
build_dir=$user_build_dir
;;
*)
build_dir=$PWD/$user_build_dir
;;
esac
;;
3)
install=true
echo "Please specify an install directory (can be relative or absolute)."
echo -n "=> "
read prefix
;;
4)
help
exit 0
;;
esac
}
###################################################################################
# Prompt user for main project
###################################################################################
function prompt_for_main {
# Prompt user to pick a main project or return error
echo
echo "Please choose a main project to fetch/build by typing 1-18"
echo "or simply type the repository name of another project not"
echo "listed here."
echo " 1. Osi"
echo " 2. Clp"
echo " 3. Cbc"
echo " 4. DyLP"
echo " 5. FlopC++"
echo " 6. Vol"
echo " 7. SYMPHONY"
echo " 8. Smi"
echo " 9. CoinMP"
echo " 10. Bcp"
echo " 11. Ipopt"
echo " 12. Alps"
echo " 13. BiCePS"
echo " 14. Blis"
echo " 15. Dip"
echo " 16. Bonmin"
echo " 17. Couenne"
echo " 18. Optimization Services"
echo " 19. MibS"
echo " 20. DisCO"
echo " 21. All"
echo " 22. Let me enter another project"
echo -n "=> "
read choice
echo
case $choice in
1) main_proj=Osi;;
2) main_proj=Clp;;
3) main_proj=Cbc;;
4) main_proj=DyLP;;
5) main_proj=FlopCpp;;
6) main_proj=Vol;;
7) main_proj=SYMPHONY;;
8) main_proj=Smi;;
9) main_proj=CoinMP;;
10) main_proj=Bcp;;
11) main_proj=Ipopt;;
12) main_proj=CHiPPS-ALPS;;
13) main_proj=CHiPPS-BiCePS;;
14) main_proj=CHiPPS-BLIS;;
15) main_proj=Dip;;
16) main_proj=Bonmin;;
17) main_proj=Couenne;;
18) main_proj=OS;;
19) main_proj=MibS;;
20) main_proj=DisCO;;
21) main_proj=COIN-OR-OptimizationSuite;;
22)
echo "Enter the name or URL of the project"
echo -n "=> "
read choice2
main_proj=$choice2
;;
*) main_proj=$choice;;
esac
}
###################################################################################
# Ask user whether to fetch
###################################################################################
function prompt_for_fetch {
echo "Fetch now? y/n"
got_choice=false
while [ $got_choice = "false" ]; do
echo -n "=> "
read choice
case $choice in
y|n) got_choice=true;;
*) ;;
esac
done
case $choice in
y)
fetch="true"
;;
n)
;;
esac
}
###################################################################################
# Ask user what verion to install
###################################################################################
function prompt_for_version {
echo
echo "You haven't specified a project version"
echo "It appears that the last 10 releases of $main_proj are"
git ls-remote --tags $main_proj_url | fgrep releases | fgrep -v -e "^{}" | \
cut -d '/' -f 4 | sort -nr -t. -k1,1 -k2,2 -k3,3 | head -10
echo "Do you want to work with the latest release? (y/n)"
got_choice=false
while [ $got_choice = "false" ]; do
echo -n "=> "
read choice
case $choice in
y|n) got_choice=true;;
*) ;;
esac
done
case $choice in
y) main_proj_version=releases/$(git ls-remote --tags $main_proj_url | fgrep releases | \
cut -d '/' -f 4 | sort -nr -t. -k1,1 -k2,2 -k3,3 | \
head -1)
;;
n) echo "Please enter another version name in the form of"
echo 'master', 'releases/x.y.z', or 'stable/x.y'
echo -n "=> "
read choice
main_proj_version=$choice
;;
esac
echo
}
###################################################################################
# Ask user what to do when there are new configuration options for rebuild
###################################################################################
function prompt_for_rebuild {
echo "Please choose one of the following options."
echo " The indicated action will be performed for you AUTOMATICALLY"
echo "1. Run the build again with the previously specified options."
echo " This can also be accomplished invoking the build"
echo " command without any arguments."
echo "2. Configure in a new build directory (whose name you will be"
echo " prmpted to specify) with new options."
echo "3. Re-configure in the same build directory with the new"
echo " options. This option is not recommended unless you know"
echo " what you're doing!."
echo "4. Quit"
echo
got_choice=false
while [ $got_choice = "false" ]; do
echo "Please type 1, 2, 3, or 4"
echo -n "=> "
read choice
case $choice in
1|2|3|4) got_choice=true;;
*) ;;
esac
done
case $choice in
1) ;;
2)
echo "Please enter a new build directory:"
echo -n "=> "
read dir
if [ x"$dir" != x ]; then
case $dir in
[\\/$]* | ?:[\\/]* | NONE | '' )
build_dir=$dir
;;
*)
build_dir=$PWD/$dir
;;
esac
fi
;;
3)
rm $build_dir/.config/$main_proj-$main_proj_version
reconfigure=true
;;
4)
exit 0
esac
}
###################################################################################
# Fetch or update one project
###################################################################################
function fetch_proj {
current_rev=
if [ -d $dir ]; then
# If the project is already checked out, then check whether the checked out
# version is the correct one. Switch if necessary. Otherwise, just update
pushd_ $dir
current_version=$(get_version_git)
current_rev=$(git rev-parse HEAD)
if [ $get_latest_release = "true" ] && [[ $version != releases/* ]]; then
if [[ $version != stable/* ]]; then
echo "Warning: Dependency is not a stable version, will not be converted to release"
else
version=$(git tag --list "${version/stable/releases}*" \
| sort -V | tail -1)
fi
fi
if [ $keep_current = "true" ]; then
version=$current_version
fi
if [[ $version != *$current_version ]] ||
([ "$sha" != "" ] && [[ $current_rev != $sha* ]]) ||
[ "$checkout_time" != "" ]; then
git fetch --tags
if [ "$sha" != "" ]; then
print_action "Switching $dir to SHA $sha"
stashed=false
if [ $auto_stash = true ]; then
if [[ $(git stash save) == "No" ]]; then
stashed=false
fi
fi
git checkout $sha
if [ $auto_stash = true ] && [ $stashed = true ]; then
# We should check whether this succeeds somehow...
git stash pop
fi
elif [ x"$checkout_time" != x ]; then
print_action "Checking out $dir version $version as of $checkout_time"
git checkout $(git rev-list -n 1 --first-parent --before="$checkout_time" \
remotes/origin/$version)
else
if [ $rebase = "true" ]; then
print_action "Switching $dir to $version and rebasing"
else