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