Meta/Dothem: do not barf if /dev/shm is not writable
[git] / Dothem
1 #!/bin/sh
2
3 NWD=contrib/workdir/git-new-workdir
4
5 inst_prefix=$(
6         IFS=:
7         for p in $PATH
8         do
9                 probed=${p%/git-active/bin}
10                 if test "$probed" != "$p"
11                 then
12                         echo "$probed"
13                         exit
14                 fi
15         done
16         echo $HOME
17 )
18
19 force= with_dash= M= install= nodoc= notest= bootstrap= branches= jobs=
20 scratch=
21 while   case "$1" in
22         --pedantic | --locale=* | --loose) M="$M $1" ;;
23         --force) force=$1 ;;
24         --dash) with_dash=y ;;
25         --noinstall) install=noinstall ;;
26         --nodoc) nodoc=y ;;
27         --notest) notest=y ;;
28         --test=*) test="$1" ;;
29         --scratch) scratch=y ;;
30         --bootstrap) bootstrap=y ;;
31         --base=*) BUILDBASE=${1#*=} ;;
32         --branches=*) branches=${1#*=} ;;
33         -j*) jobs=$1 ;;
34         -*) echo >&2 "Unknown option: $1"; exit 1 ;;
35         *) break ;;
36         esac
37 do
38         shift
39 done
40
41 for TRASH in /dev/shm /tmp ""
42 do
43         if test -n "$TRASH" &&
44            mkdir -p "$TRASH/testpen" 2>/dev/null &&
45            test -w "TRASH/testpen"
46         then
47                 TRASH="--root=$(cd "$TRASH/testpen" && /bin/pwd)"
48                 break
49         fi
50 done
51
52 sh -c 'asciidoc --version >/dev/null 2>&1' || nodoc=y
53 GIT_TEST_OPTS="$TRASH${GIT_TEST_OPTS+" $GIT_TEST_OPTS"}"
54 export GIT_TEST_OPTS
55
56 test -f /bin/dash || with_dash=
57 if test -z "$BUILDBASE"
58 then
59         if test -d "$inst_prefix/buildfarm"
60         then
61                 BUILDBASE="$inst_prefix/buildfarm"
62         elif test -d "../buildfarm"
63         then
64                 BUILDBASE=../buildfarm
65         else
66                 echo >&2 "Buildbase unknown"
67                 exit 1
68         fi
69 fi
70 test -n "$branches" || branches='next master maint jch pu'
71 test -n "$jobs" || jobs=-j2
72
73 find_installed () {
74         branch=$1
75         test -f "$inst_prefix/git-$branch/bin/git" &&
76         installed=$($inst_prefix/git-$branch/bin/git version) &&
77         if version=$(expr "$installed" : '.*\.g\([0-9a-f]*\)$')
78         then
79                 :
80         elif version=v$(expr "$installed" : \
81                 'git version \(.*\)\.rc[0-9]*$')
82         then
83                 version="$version"-$(expr "$installed" : \
84                         'git version .*\.\(rc[0-9]*\)$')
85         else
86                 version=v$(expr "$installed" : 'git version \(.*\)')
87         fi &&
88         git rev-parse --verify "$version^0" 2>/dev/null
89 }
90
91 installed_source_trees=" "
92 for branch in $branches
93 do
94         if      v=$(find_installed $branch) &&
95                 test -n "$v" &&
96                 v=$(git rev-parse --verify "$v^{tree}" 2>/dev/null)
97         then
98                 installed_source_trees="$installed_source_trees$v "
99         fi
100 done
101
102 for branch in $branches
103 do
104         echo "** $branch **"
105         revision=$(git show-ref -s --verify "refs/heads/$branch") || {
106                 echo "** No $branch"
107                 continue
108         }
109
110         if test ! -d "$BUILDBASE/$branch"
111         then
112                 if test -z "$bootstrap"
113                 then
114                         echo "** No $BUILDBASE/$branch"
115                         continue
116                 fi
117                 "$NWD" . "$BUILDBASE/$branch" $branch &&
118                 ln -s "$(pwd)/Meta" "$BUILDBASE/$branch/Meta" || {
119                         echo "** Failed to bootstrap $BUILDBASE/$branch"
120                         continue
121                 }
122         fi
123
124         private=$(git rev-parse -q --verify private-$branch 2>/dev/null)
125         case $? in 0|1) ;; *) exit $? ;; esac
126
127         version=$(find_installed $branch)
128         if      test "z$version" = "z$revision"
129         then
130                 echo "* up-to-date version is already installed from $branch"
131                 test -n "$force" || continue
132         fi
133
134         vtree=$(git rev-parse --verify "$version^{tree}")
135         rtree=$(git rev-parse --verify "$revision^{tree}")
136         (
137                 skip_test=$notest skip_doc=$nodoc
138                 case "$force" in
139                 ?*)
140                         ;;
141                 '')
142                         case "$installed_source_trees" in
143                         *" $rtree "*)
144                                 skip_test=1
145                                 ;;
146                         esac
147                         if test "z$vtree" = "z$rtree"
148                         then
149                                 skip_test=1
150                                 skip_doc=1
151                         fi
152                         dvtree=$(git rev-parse --verify "$version:Documentation/")
153                         drtree=$(git rev-parse --verify "$revision:Documentation/")
154                         if test "z$dvtree" = "z$drtree"
155                         then
156                                 skip_doc=1
157                         fi
158                         case "$branch, $branches " in
159                         jch,*' next '*)
160                                 if git diff --quiet --exit-code jch next
161                                 then
162                                         skip_test=1
163                                 fi
164                                 ;;
165                         esac
166                         ;;
167                 esac
168
169                 case "$skip_test" in
170                 ?*)     dotest= ;;
171                 '')     dotest=test ;;
172                 esac
173
174                 cd "$BUILDBASE/$branch"
175                 git reset --hard  &&
176                 case "$(git symbolic-ref HEAD)" in
177                 "refs/heads/$branch")
178                         : ;;
179                 *)
180                         git checkout "$branch" &&
181                         git reset --hard || exit
182                 esac &&
183
184                 case "$scratch" in
185                 '')
186                         ;;
187                 y)
188                         Meta/Make clean
189                         ;;
190                 esac &&
191
192                 case "$private" in
193                 '')
194                         ;;
195                 ?*)
196                         git merge --squash --no-commit "$private" || {
197                                 echo >&2 "** Cannot apply private edition changes"
198                                 git reset --hard
199                         }
200                         ;;
201                 esac &&
202
203                 save=$(git rev-parse HEAD) &&
204
205                 Meta/Make $M ${test+"$test"} $jobs -- ${with_dash:+SHELL_PATH=/bin/dash} $dotest &&
206
207                 {
208                         test -n "$skip_doc" ||
209                         if test "$save" = "$(git rev-parse HEAD)"
210                         then
211                                 Meta/Make $M $jobs -- doc &&
212                                 Meta/Make $M -- install-man install-html
213                         else
214                                 echo >&2 "Head moved--not installing docs"
215                         fi
216                 } &&
217
218                 {
219                         test z$install = znoinstall ||
220                         if test "$save" = "$(git rev-parse HEAD)"
221                         then
222                                 Meta/Make $M -- ${with_dash:+SHELL_PATH=/bin/dash} install
223                         else
224                                 echo >&2 "Head moved--not installing"
225                         fi
226                 } || exit $?
227
228                 git reset --hard
229         ) </dev/null || exit $?
230
231         installed_source_trees="$installed_source_trees$rtree "
232 done