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