chiark / gitweb /
00f3a0347433c39a11ba3a81ac1c10198369e755
[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=$(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
147         exec 4>&-
148 }
149
150 bm-run-one () {
151         local args="$DGIT_TEST_BM_BASEARGS --clean=$cleanmode $real_act"
152
153         bmid="$act,$cleanmode,$branch"
154         bmid=${bmid// /_}
155
156         heading="===== [$bmid] dgit $args ====="
157
158         bmlog=$tmp/run.$bmid.output
159         bmexp=$tmp/run.$bmid.expected
160         bmgot=$tmp/run.$bmid.results
161
162         bm-compute-expected
163
164         git checkout $branch
165         git clean -xdf # since we might not do any actual cleaning
166
167         dsc="../example_$v.dsc"
168         rm -f $dsc
169
170         set +o pipefail
171         t-dgit --rm-old-changes --git=$tmp/stunt-git $args 2>&1 | tee $bmlog
172         local ps="${PIPESTATUS[*]}"
173         set -o pipefail
174
175         $bm_quirk_after_act
176
177         exec 4>$bmgot
178         echo >&4 "$heading"
179
180         case $ps in
181         "0 0")  actual_status=success ;;
182         *" 0")  actual_status=failure; echo >&4 "OPERATION FAILED"; ;;
183         *)      fail "tee failed" ;;
184         esac
185
186         case "$require_fail-$tolerate_fail-$actual_status" in
187         required-********-failure) echo >>$bmexp "REQUIRED FAILURE" ;;
188         ********-tolerate-failure) echo >>$bmexp "TOLERATED FAILURE" ;;
189         unexpect-********-success) ;;
190         *)      fail "RF=$require_fail TF=$tolerate_fail AS=$actual_status" ;;
191         esac
192
193         egrep >&4 '^EXAMPLE RULES TARGET|^BUILD-MODES' $bmlog || [ $? = 1 ]
194
195         bm-report-test "SOURCE FILE" [ -e $dsc ]
196
197         exec 4>&-
198
199         $bm_quirk_before_diff
200
201         [ $actual_status = failure ] || diff -U10 $bmexp $bmgot
202 }
203
204 bm-act-iterate () {
205         for cleanmode in $cleanmodes; do
206                 for branch in $bm_branches; do
207                         bm-run-one
208                 done
209         done
210         : bm-act-iterate done.
211 }
212
213 bm-alwayssplit () {
214         local t=${0##*/}
215         DGIT_TEST_BM_BASEARGS+=' --always-split-source-build'
216         export DGIT_TEST_BM_BASEARGS
217         t-chain-test "${t%%-asplit}"
218 }