chiark / gitweb /
TODO.BRANCH: Add a todo list item
[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-source () {
101         if "$@"; then
102                 echo >&4 "SOURCE EXISTS"
103         else
104                 echo >&4 "SOURCE MISSING"
105         fi
106 }
107
108 bm-build-deps-ok () {
109         case "$branch" in
110         *bad-build-deps*)       return 1        ;;
111         *)                      return 0        ;;
112         esac
113 }
114
115 bm-compute-expected () {
116         require_fail=unexpect # or required
117         tolerate_fail=unexpect # or tolerate
118
119         exec 4>$bmexp
120         echo >&4 "$heading"
121
122         case $cleanmode in
123         git)            echo >&4 'BUILD-MODES PROGRAM git clean -xdf' ;;
124         git-ff)         echo >&4 'BUILD-MODES PROGRAM git clean -xdff' ;;
125         check)          echo >&4 'BUILD-MODES PROGRAM git clean -xdn' ;;
126         dpkg-source-d)  echo >&4 "EXAMPLE RULES TARGET clean" ;;
127         dpkg-source)    bm-build-deps-ok || tolerate_fail=tolerate
128                         echo >&4 "EXAMPLE RULES TARGET clean"
129                         ;;
130         none)           ;;
131         *)              fail "t-compute-expected-run $cleanmode ??" ;;
132         esac
133
134         if [ "x$e_targets" != x ]; then
135                 # e_targets can be " " to mean `/may/ fail due to b-d'
136                 bm-build-deps-ok || tolerate_fail=tolerate
137         fi
138
139         for t in $e_targets; do
140                 bm-build-deps-ok || require_fail=required
141                 echo >&4 "EXAMPLE RULES TARGET $t"
142         done
143
144         bm-report-source $e_source
145
146         exec 4>&-
147 }
148
149 bm-run-one () {
150         local args="$DGIT_TEST_BM_BASEARGS --clean=$cleanmode $real_act"
151
152         bmid="$act,$cleanmode,$branch"
153         bmid=${bmid// /_}
154
155         heading="===== [$bmid] dgit $args ====="
156
157         bmlog=$tmp/run.$bmid.output
158         bmexp=$tmp/run.$bmid.expected
159         bmgot=$tmp/run.$bmid.results
160
161         bm-compute-expected
162
163         git checkout $branch
164         git clean -xdf # since we might not do any actual cleaning
165
166         dsc="../example_$v.dsc"
167         rm -f $dsc
168
169         set +o pipefail
170         t-dgit --rm-old-changes --git=$tmp/stunt-git $args 2>&1 | tee $bmlog
171         local ps="${PIPESTATUS[*]}"
172         set -o pipefail
173
174         $bm_quirk_after_act
175
176         exec 4>$bmgot
177         echo >&4 "$heading"
178
179         case $ps in
180         "0 0")  actual_status=success ;;
181         *" 0")  actual_status=failure; echo >&4 "OPERATION FAILED"; ;;
182         *)      fail "tee failed" ;;
183         esac
184
185         case "$require_fail-$tolerate_fail-$actual_status" in
186         required-********-failure) echo >>$bmexp "REQUIRED FAILURE" ;;
187         ********-tolerate-failure) echo >>$bmexp "TOLERATED FAILURE" ;;
188         unexpect-********-success) ;;
189         *)      fail "RF=$require_fail TF=$tolerate_fail AS=$actual_status" ;;
190         esac
191
192         egrep >&4 '^EXAMPLE RULES TARGET|^BUILD-MODES' $bmlog || [ $? = 1 ]
193
194         bm-report-source [ -e $dsc ]
195
196         exec 4>&-
197
198         $bm_quirk_before_diff
199
200         [ $actual_status = failure ] || diff -U10 $bmexp $bmgot
201 }
202
203 bm-act-iterate () {
204         for cleanmode in $cleanmodes; do
205                 for branch in $bm_branches; do
206                         bm-run-one
207                 done
208         done
209         : bm-act-iterate done.
210 }
211
212 bm-alwayssplit () {
213         local t=${0##*/}
214         DGIT_TEST_BM_BASEARGS+=' --always-split-source-build'
215         export DGIT_TEST_BM_BASEARGS
216         t-chain-test "${t%%-asplit}"
217 }