Browse code

Add a form of variable expansion for the repositories file. The idea is there, that you can specify a download host in the .bootstrap.local folder, so that you can use mulle-bootstrap more easily with multiple git hosts.

Nat! authored on 29-07-2016 16:54:04
Showing 7 changed files
... ...
@@ -3,6 +3,9 @@
3 3
 
4 4
 * Fix tar install, which was broken
5 5
 * Fix some wordings
6
+* You can now put configuration setting like variables into the URL. Like so:
7
+   https://${host:-www.mulle-kybernetik.com}:foo.git. Define the host like
8
+   a regular fetch setting. `echo "x.y.com" > .bootstrap/host`
6 9
 
7 10
 
8 11
 1.0
... ...
@@ -1736,6 +1736,9 @@ build_clones()
1736 1736
       for clone in ${clones}
1737 1737
       do
1738 1738
          IFS="$old"
1739
+
1740
+         clone="`expanded_setting "${clone}"`"
1741
+
1739 1742
          name="`canonical_clone_name "${clone}"`"
1740 1743
          srcdir="`get_source_dir "${name}"`"
1741 1744
          if [ -d "${srcdir}" ]
... ...
@@ -1764,6 +1767,8 @@ build_clones()
1764 1767
          do
1765 1768
             IFS="$old"
1766 1769
 
1770
+            clone="`expanded_setting "${clone}"`"
1771
+
1767 1772
             name="`canonical_name_from_clone "${clone}"`"
1768 1773
             srcdir="`get_source_dir "${name}"`"
1769 1774
 
... ...
@@ -62,6 +62,9 @@ embedded_repositories()
62 62
       for clone in ${clones}
63 63
       do
64 64
          IFS="${old}"
65
+
66
+         clone="`expanded_setting "${clone}"`"
67
+
65 68
          name="`canonical_name_from_clone "${clone}"`"
66 69
          dir="${name}"
67 70
          echo "${dir}"
... ...
@@ -685,19 +685,15 @@ checkout_repository()
685 685
 
686 686
 clone_repository()
687 687
 {
688
-   local clone
689
-
690
-   clone="${1}"
691
-
692 688
    local name
693 689
    local url
694 690
    local branch
695 691
    local scm
696 692
 
697
-   name="`canonical_name_from_clone "${clone}"`"
698
-   url="`url_from_clone "${clone}"`"
699
-   branch="`branch_from_clone "${clone}"`"
700
-   scm="`scm_from_clone "${clone}"`"
693
+   name="$1"
694
+   url="$2"
695
+   branch="$3"
696
+   scm="$4"
701 697
 
702 698
    local tag
703 699
    local dstdir
... ...
@@ -770,6 +766,8 @@ clone_repositories()
770 766
          do
771 767
             IFS="${old}"
772 768
 
769
+            clone="`expanded_setting "${clone}"`"
770
+
773 771
             # avoid superflous updates
774 772
             match="`echo "${fetched}" | grep -x "${clone}"`"
775 773
             # could remove prefixes here https:// http://
... ...
@@ -779,7 +777,13 @@ clone_repositories()
779 777
                fetched="${fetched}
780 778
 ${clone}"
781 779
 
782
-               clone_repository "${clone}"
780
+               name="`canonical_name_from_clone "${clone}"`"
781
+               url="`url_from_clone "${clone}"`"
782
+               branch="`branch_from_clone "${clone}"`"
783
+               scm="`scm_from_clone "${clone}"`"
784
+
785
+               clone_repository "${name}" "${url}" "${branch}" "${scm}"
786
+
783 787
                if [ $? -eq 1 ]
784 788
                then
785 789
                   stop=0
... ...
@@ -796,6 +800,8 @@ ${clone}"
796 800
    do
797 801
       IFS="${old}"
798 802
 
803
+      clone="`expanded_setting "${clone}"`"
804
+
799 805
       name="`canonical_name_from_clone "${clone}"`"
800 806
       url="`url_from_clone "${clone}"`"
801 807
       branch="`branch_from_clone "${clone}"`"
... ...
@@ -903,6 +909,8 @@ clone_embedded_repositories()
903 909
       do
904 910
          IFS="${old}"
905 911
 
912
+         clone="`expanded_setting "${clone}"`"
913
+
906 914
          clone_embedded_repository "${dstprefix}" "${clone}"
907 915
       done
908 916
 
... ...
@@ -1136,6 +1144,8 @@ update_repositories()
1136 1144
          do
1137 1145
             IFS="${old}"
1138 1146
 
1147
+            clone="`expanded_setting "${clone}"`"
1148
+
1139 1149
             # avoid superflous updates
1140 1150
             match="`echo "${updated}" | grep -x "${clone}"`"
1141 1151
 
... ...
@@ -1158,7 +1168,7 @@ ${clone}"
1158 1168
                      rval=$?
1159 1169
                   else
1160 1170
                      scm="`scm_from_clone "${clone}"`"
1161
-                     clone_repository  "${name}" "${url}" "${branch}" "${scm}"
1171
+                     clone_repository "${name}" "${url}" "${branch}" "${scm}"
1162 1172
                      rval=1
1163 1173
                   fi
1164 1174
 
... ...
@@ -1208,6 +1218,9 @@ update_embedded_repositories()
1208 1218
       for clone in ${clones}
1209 1219
       do
1210 1220
          IFS="${old}"
1221
+
1222
+         clone="`expanded_setting "${clone}"`"
1223
+
1211 1224
          name="`canonical_name_from_clone "${clone}"`"
1212 1225
          url="`url_from_clone "${clone}"`"
1213 1226
          branch="`branch_from_clone "${clone}"`"
... ...
@@ -695,17 +695,52 @@ find_xcodeproj()
695 695
 }
696 696
 
697 697
 
698
+
699
+#
700
+# expands ${LOGNAME} and ${LOGNAME:-foo}
701
+#
702
+expand_environment_variables()
703
+{
704
+    local string
705
+
706
+    string="$1"
707
+
708
+    local key
709
+    local value
710
+    local prefix
711
+    local suffix
712
+    local next
713
+
714
+    key="`echo "${string}" | sed -n 's/^\(.*\)\${\([A-Za-z_][A-Za-z0-9_:-]*\)}\(.*\)$/\2/p'`"
715
+    if [ ! -z "${key}" ]
716
+    then
717
+       prefix="`echo "${string}" | sed 's/^\(.*\)\${\([A-Za-z_][A-Za-z0-9_:-]*\)}\(.*\)$/\1/'`"
718
+       suffix="`echo "${string}" | sed 's/^\(.*\)\${\([A-Za-z_][A-Za-z0-9_:-]*\)}\(.*\)$/\3/'`"
719
+       value="`eval echo \$\{${key}\}`"
720
+       next="${prefix}${value}${suffix}"
721
+       if [ "${next}" != "${string}" ]
722
+       then
723
+          expand_environment_variables "${prefix}${value}${suffix}"
724
+          return
725
+       fi
726
+    fi
727
+    echo "$1"
728
+}
729
+
730
+
698 731
 # deal with stuff like
699 732
 # foo
700 733
 # https://www./foo.git
701 734
 # host:foo
702 735
 #
736
+
703 737
 canonical_clone_name()
704 738
 {
705 739
    local  url
706 740
 
707 741
    url="$1"
708 742
 
743
+
709 744
    # cut off scheme part
710 745
 
711 746
    case "$url" in
... ...
@@ -114,6 +114,7 @@ refresh_repositories_settings()
114 114
          do
115 115
             IFS="${old}"
116 116
 
117
+            clone="`expanded_setting "${clone}"`"
117 118
             # avoid superflous updates
118 119
             match="`echo "${refreshed}" | grep -x "${clone}"`"
119 120
             # could remove prefixes here https:// http://
... ...
@@ -424,6 +425,9 @@ refresh_repositories()
424 425
       for clone in ${clones}
425 426
       do
426 427
          IFS="${old}"
428
+
429
+         clone="`expanded_setting "${clone}"`"
430
+
427 431
          name="`canonical_name_from_clone "${clone}"`"
428 432
          dstdir="${CLONESFETCH_SUBDIR}/${name}"
429 433
 
... ...
@@ -461,6 +465,8 @@ _refresh_embedded_repositories()
461 465
       do
462 466
          IFS="${old}"
463 467
 
468
+         clone="`expanded_setting "${clone}"`"
469
+
464 470
          ensure_clones_directory
465 471
 
466 472
          name="`canonical_name_from_clone "${clone}"`"
... ...
@@ -574,6 +574,50 @@ ${result}"
574 574
 }
575 575
 
576 576
 
577
+#
578
+# expands ${setting} and ${setting:-foo}
579
+#
580
+expanded_setting()
581
+{
582
+   local string
583
+
584
+   string="$1"
585
+
586
+   local key
587
+   local value
588
+   local prefix
589
+   local suffix
590
+   local next
591
+   local default
592
+   local tmp
593
+
594
+   key="`echo "${string}" | sed -n 's/^\(.*\)\${\([A-Za-z_][A-Za-z0-9_:-]*\)}\(.*\)$/\2/p'`"
595
+   if [ -z "${key}" ]
596
+   then
597
+      echo "$1"
598
+      return
599
+   fi
600
+
601
+   prefix="`echo "${string}" | sed 's/^\(.*\)\${\([A-Za-z_][A-Za-z0-9_:-]*\)}\(.*\)$/\1/'`"
602
+   suffix="`echo "${string}" | sed 's/^\(.*\)\${\([A-Za-z_][A-Za-z0-9_:-]*\)}\(.*\)$/\3/'`"
603
+
604
+   tmp="`echo "${key}" | sed -n 's/^\([A-Za-z_][A-Za-z0-9_]*\)[:][-]\(.*\)$/\1/p'`"
605
+   if [ ! -z "${tmp}" ]
606
+   then
607
+      default="`echo "${key}" | sed -n 's/^\([A-Za-z_][A-Za-z0-9_]*\)[:][-]\(.*\)$/\2/p'`"
608
+      key="${tmp}"
609
+   fi
610
+
611
+   value="`read_fetch_setting "${key}" "${default}"`"
612
+   next="${prefix}${value}${suffix}"
613
+   if [ "${next}" = "${string}" ]
614
+   then
615
+      fail "${string} expands to itself"
616
+   fi
617
+   expanded_setting "${next}"
618
+}
619
+
620
+
577 621
 ###
578 622
 #
579 623
 #