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