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