chiark / gitweb /
dgit: New fetch algorithm - try to tolerate in-archive copies
[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-guess-e-source-e-targets () {
42         local some_act=$1
43         case "$some_act" in
44         sbuild*" --no-arch-all"*)
45                 e_source=true;  e_targets='build-arch binary-arch'      ;;
46         build-source)
47                 e_source=true;  e_targets=''                            ;;
48         *" -b") e_source=false; e_targets='build binary'                ;;
49         *" -B") e_source=false; e_targets='build-arch binary-arch'      ;;
50         *" -A") e_source=false; e_targets='build-indep binary-indep'    ;;
51         *" -S") e_source=true;  e_targets=' '                           ;;
52         *" -F") e_source=true;  e_targets='build binary'                ;;
53         *" -G") e_source=true;  e_targets='build-arch binary-arch'      ;;
54         *" -g") e_source=true;  e_targets='build-indep binary-indep'    ;;
55         *)      e_source=true;  e_targets='build binary'                ;;
56         esac
57 }
58
59 bm-quirk-sbuild-after-act () {
60         # sbuild likes to run the package clean target in the chroot,
61         # which isn't necessary in our case.  We don't disable it in
62         # dgit because we want to do what sbuild does, in case there
63         # are packages which don't build unless their clean target was
64         # run.  We know it must be running it in the chroot because we
65         # provide sbuild with the dsc, not the tree, so we simply
66         # ignore all executions of the clean target by schroot.
67         local arch=$(dpkg-architecture -qDEB_BUILD_ARCH)
68         local sblog=../example_1.0_$arch.build
69         if [ -e $sblog ]; then
70                 sed '
71                         s/^EXAMPLE RULES TARGET clean/HOOK SUPPRESSED &/;
72                 ' <$sblog >>$bmlog
73         else
74                 echo "SBUILD LOG FILE ($sblog) MISSING"
75         fi
76 }
77
78 bm-report-source () {
79         if "$@"; then
80                 echo >&4 "SOURCE EXISTS"
81         else
82                 echo >&4 "SOURCE MISSING"
83         fi
84 }
85
86 bm-build-deps-ok () {
87         case "$branch" in
88         *bad-build-deps*)       return 1        ;;
89         *)                      return 0        ;;
90         esac
91 }
92
93 bm-compute-expected () {
94         require_fail=unexpect # or required
95         tolerate_fail=unexpect # or tolerate
96
97         exec 4>$bmexp
98         echo >&4 "$heading"
99
100         case $cleanmode in
101         git)            echo >&4 'BUILD-MODES PROGRAM git clean -xdf' ;;
102         git-ff)         echo >&4 'BUILD-MODES PROGRAM git clean -xdff' ;;
103         check)          echo >&4 'BUILD-MODES PROGRAM git clean -xdn' ;;
104         dpkg-source-d)  echo >&4 "EXAMPLE RULES TARGET clean" ;;
105         dpkg-source)    bm-build-deps-ok || tolerate_fail=tolerate
106                         echo >&4 "EXAMPLE RULES TARGET clean"
107                         ;;
108         none)           ;;
109         *)              fail "t-compute-expected-run $cleanmode ??" ;;
110         esac
111
112         if [ "x$e_targets" != x ]; then
113                 # e_targets can be " " to mean `/may/ fail due to b-d'
114                 bm-build-deps-ok || tolerate_fail=tolerate
115         fi
116
117         for t in $e_targets; do
118                 bm-build-deps-ok || require_fail=required
119                 echo >&4 "EXAMPLE RULES TARGET $t"
120         done
121
122         bm-report-source $e_source
123
124         exec 4>&-
125 }
126
127 bm-run-one () {
128         local args="$DGIT_TEST_BM_BASEARGS --clean=$cleanmode $real_act"
129
130         bmid="$act,$cleanmode,$branch"
131         bmid=${bmid// /_}
132
133         heading="===== [$bmid] dgit $args ====="
134
135         bmlog=$tmp/run.$bmid.output
136         bmexp=$tmp/run.$bmid.expected
137         bmgot=$tmp/run.$bmid.results
138
139         bm-compute-expected
140
141         git checkout $branch
142         git clean -xdf # since we might not do any actual cleaning
143
144         dsc='../example_1.0.dsc'
145         rm -f $dsc
146
147         set +o pipefail
148         t-dgit --rm-old-changes --git=$tmp/stunt-git $args 2>&1 | tee $bmlog
149         local ps="${PIPESTATUS[*]}"
150         set -o pipefail
151
152         $bm_quirk_after_act
153
154         exec 4>$bmgot
155         echo >&4 "$heading"
156
157         case $ps in
158         "0 0")  actual_status=success ;;
159         *" 0")  actual_status=failure; echo >&4 "OPERATION FAILED"; ;;
160         *)      fail "tee failed" ;;
161         esac
162
163         case "$require_fail-$tolerate_fail-$actual_status" in
164         required-********-failure) echo >>$bmexp "REQUIRED FAILURE" ;;
165         ********-tolerate-failure) echo >>$bmexp "TOLERATED FAILURE" ;;
166         unexpect-********-success) ;;
167         *)      fail "RF=$require_fail TF=$tolerate_fail AS=$actual_status" ;;
168         esac
169
170         egrep >&4 '^EXAMPLE RULES TARGET|^BUILD-MODES' $bmlog || [ $? = 1 ]
171
172         bm-report-source [ -e $dsc ]
173
174         exec 4>&-
175
176         $bm_quirk_before_diff
177
178         [ $actual_status = failure ] || diff -U10 $bmexp $bmgot
179 }
180
181 bm-act-iterate () {
182         for cleanmode in $cleanmodes; do
183                 for branch in $bm_branches; do
184                         bm-run-one
185                 done
186         done
187         : bm-act-iterate done.
188 }
189
190 bm-alwayssplit () {
191         local t=${0##*/}
192         DGIT_TEST_BM_BASEARGS+=' --always-split-source-build'
193         export DGIT_TEST_BM_BASEARGS
194         t-chain-test "${t%%-asplit}"
195 }