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