chiark / gitweb /
dgit: clean_tree_check: Reorganise command construction
[dgit.git] / tests / lib-build-modes
1
2 bm-prep-ownpackage-branches () {
3         cat <<'END' >$tmp/stunt-git
4 #!/bin/sh -e
5 case "$*" in
6 *clean*) echo >&2 "BUILD-MODES PROGRAM git $*" ;;
7 esac
8 exec git "$@"
9 END
10         chmod +x $tmp/stunt-git
11
12         bm_branches="$1"
13 }
14
15 bm-prep () {
16         t-tstunt-parsechangelog
17         t-tstunt dpkg-deb
18
19         t-prep-newpackage example 1.0
20
21         cd $p
22
23         git checkout -b bad-build-deps indep-arch
24         perl -pe 's/Build-Depends.*/$&, x-dgit-no-such-package/' \
25                 -i debian/control
26         git commit -a -m bad-build-deps
27
28         bm-prep-ownpackage-branches 'indep-arch bad-build-deps'
29
30         if zgrep 'dpkg-buildpackage: Make dependency checks fatal for -S' \
31                 /usr/share/doc/dpkg-dev/changelog.gz; then
32                         dpkgbuildpackage_deps_for_clean=true
33         else
34                         dpkgbuildpackage_deps_for_clean=false
35         fi
36
37         cleanmodes_default="git none dpkg-source dpkg-source-d"
38         cleanmodes_all="$cleanmodes_default git-ff check"
39         cleanmodes="$cleanmodes_default"
40 }
41
42 bm-gbp-example-acts () {
43         t-gbp-example-prep
44
45         git checkout -b for-build-modes qc/quilt-tip-2
46         # build-modes cannot cope with branches containing /
47
48         bm-prep-ownpackage-branches for-build-modes
49
50         cleanmodes='git dpkg-source'
51
52         for act in "$@"; do
53                 bm-guess-e-source-e-targets "$act"
54                 real_act="--quilt=gbp $act"
55                 case "$act" in
56                 sbuild*)    bm_quirk_after_act=bm-quirk-sbuild-after-act ;;
57                 gbp-*)      real_act="$real_act --git-ignore-branch" ;;
58                 *)          bm_quirk_after_act='' ;;
59                 esac
60                 bm-act-iterate
61         done
62 }
63
64 bm-guess-e-source-e-targets () {
65         local some_act=$1
66         case "$some_act" in
67         sbuild*" --no-arch-all"*)
68                 e_source=true;  e_targets='build-arch binary-arch'      ;;
69         build-source)
70                 e_source=true;  e_targets=''                            ;;
71         *" -b") e_source=false; e_targets='build binary'                ;;
72         *" -B") e_source=false; e_targets='build-arch binary-arch'      ;;
73         *" -A") e_source=false; e_targets='build-indep binary-indep'    ;;
74         *" -S") e_source=true;  e_targets=' '                           ;;
75         *" -F") e_source=true;  e_targets='build binary'                ;;
76         *" -G") e_source=true;  e_targets='build-arch binary-arch'      ;;
77         *" -g") e_source=true;  e_targets='build-indep binary-indep'    ;;
78         *)      e_source=true;  e_targets='build binary'                ;;
79         esac
80 }
81
82 bm-quirk-sbuild-after-act () {
83         # sbuild likes to run the package clean target in the chroot,
84         # which isn't necessary in our case.  We don't disable it in
85         # dgit because we want to do what sbuild does, in case there
86         # are packages which don't build unless their clean target was
87         # run.  We know it must be running it in the chroot because we
88         # provide sbuild with the dsc, not the tree, so we simply
89         # ignore all executions of the clean target by schroot.
90         local arch; arch=$(dpkg-architecture -qDEB_BUILD_ARCH)
91         local sblog=$bpd/example_${v}_$arch.build
92         if [ -e $sblog ]; then
93                 sed '
94                         s/^EXAMPLE RULES TARGET clean/HOOK SUPPRESSED &/;
95                 ' <$sblog >>$bmlog
96         else
97                 echo "SBUILD LOG FILE ($sblog) MISSING"
98         fi
99 }
100
101 bm-report-test () {
102         local desc=$1; shift
103         if "$@"; then
104                 echo >&4 "$desc EXISTS"
105         else
106                 echo >&4 "$desc MISSING"
107         fi
108 }
109
110 bm-build-deps-ok () {
111         case "$branch" in
112         *bad-build-deps*)       return 1        ;;
113         *)                      return 0        ;;
114         esac
115 }
116
117 bm-compute-expected () {
118         require_fail=unexpect # or required
119         tolerate_fail=unexpect # or tolerate
120
121         exec 4>$bmexp
122         echo >&4 "$heading"
123
124         local eff_cleanmode=$cleanmode
125
126         case "$e_targets" in
127         *[^\ ]*)
128                 ;;
129         *)
130                 # if no build is going to be run, dgit will only check
131                 # cleanliness rather than actually cleaning
132                 eff_cleanmode=C$cleanmode
133                 ;;
134         esac
135
136         case "$act" in
137         sbuild*)
138                 # dgit sbuild will only check cleanliness
139                 # because it doesn't need to to make a .dsc for sbuild
140                 eff_cleanmode=C$cleanmode
141                 ;;
142         esac
143
144         # we are running the builder in-tree ?
145         # when we have --include-dirty, we will want to check
146         # that too and reset eff_cleanmode to $cleanmode
147
148         case $eff_cleanmode in
149         git)            echo >&4 'BUILD-MODES PROGRAM git clean -xdf' ;;
150         git-ff)         echo >&4 'BUILD-MODES PROGRAM git clean -xdff' ;;
151         check|Ccheck)   echo >&4 'BUILD-MODES PROGRAM git clean -dn -x' ;;
152         dpkg-source-d)  echo >&4 "EXAMPLE RULES TARGET clean" ;;
153         dpkg-source)    bm-build-deps-ok || tolerate_fail=tolerate
154                         echo >&4 "EXAMPLE RULES TARGET clean"
155                         ;;
156         none)           ;;
157         C*)             echo "TODO bm eff_cleanmode=$eff_cleanmode" ;;
158         *)              fail "t-compute-expected-run $cleanmode ??" ;;
159         esac
160
161         if [ "x$e_targets" != x ]; then
162                 # e_targets can be " " to mean `/may/ fail due to b-d'
163                 bm-build-deps-ok || tolerate_fail=tolerate
164         fi
165
166         for t in $e_targets; do
167                 bm-build-deps-ok || require_fail=required
168                 echo >&4 "EXAMPLE RULES TARGET $t"
169         done
170
171         bm-report-test "SOURCE FILE" $e_source
172         bm-report-test "SOURCE IN CHANGES" $e_source
173         bm-report-test "DEBS IN CHANGES" expr "$e_targets" : '.*binary.*'
174
175         exec 4>&-
176 }
177
178 bm-run-one () {
179         local args="$DGIT_TEST_BM_BASEARGS --clean=$cleanmode $real_act"
180
181         bmid="$act,$cleanmode,$branch"
182         bmid=${bmid// /_}
183
184         rm -f $bpd/${p}_{v}_*.changes
185
186         heading="===== [$bmid] dgit $args ====="
187
188         bmlog=$tmp/run.$bmid.output
189         bmexp=$tmp/run.$bmid.expected
190         bmgot=$tmp/run.$bmid.results
191
192         bm-compute-expected
193
194         git checkout $branch
195         git clean -xdf # since we might not do any actual cleaning
196
197         dsc="$bpd/example_$v.dsc"
198         rm -f $dsc
199
200         set +o pipefail
201         t-dgit --rm-old-changes --git=$tmp/stunt-git $args 2>&1 | tee $bmlog
202         local ps="${PIPESTATUS[*]}"
203         set -o pipefail
204
205         $bm_quirk_after_act
206
207         exec 4>$bmgot
208         echo >&4 "$heading"
209
210         case $ps in
211         "0 0")  actual_status=success ;;
212         *" 0")  actual_status=failure; echo >&4 "OPERATION FAILED"; ;;
213         *)      fail "tee failed" ;;
214         esac
215
216         case "$require_fail-$tolerate_fail-$actual_status" in
217         required-********-failure) echo >>$bmexp "REQUIRED FAILURE" ;;
218         ********-tolerate-failure) echo >>$bmexp "TOLERATED FAILURE" ;;
219         unexpect-********-success) ;;
220         *)      fail "RF=$require_fail TF=$tolerate_fail AS=$actual_status" ;;
221         esac
222
223         egrep >&4 '^EXAMPLE RULES TARGET|^BUILD-MODES' $bmlog || [ $? = 1 ]
224
225         bm-report-test "SOURCE FILE" [ -e $dsc ]
226
227         if [ $actual_status = success ]; then
228                 local changes; changes=$(echo $bpd/example_${v}_*.changes)
229                 case "$changes" in
230                 *' '*)  fail "build generated ambiguous .changes: $changes" ;;
231                 esac
232
233                 perl -ne 'print if m/^files:/i ... m/^\S/' \
234                         <$changes >$changes.files
235
236                 bm-report-test "SOURCE IN CHANGES" grep '\.dsc$' $changes.files
237                 bm-report-test "DEBS IN CHANGES" grep '\.deb$' $changes.files
238         fi
239
240         exec 4>&-
241
242         $bm_quirk_before_diff
243
244         [ $actual_status = failure ] || diff -U10 $bmexp $bmgot
245 }
246
247 bm-act-iterate () {
248         for cleanmode in $cleanmodes; do
249                 for branch in $bm_branches; do
250                         bm-run-one
251                 done
252         done
253         : bm-act-iterate done.
254 }
255
256 bm-buildproductsdir-nonworking () {
257         t-git-config dgit.default.build-products-dir ../bpd-dummy
258 }