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