po: Update German man pages translation
[dpkg.git] / scripts / t / dpkg_buildpackage.t
blob29679640cf3fc59ca3800cd62a528a167004fac6
1 #!/usr/bin/perl
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <https://www.gnu.org/licenses/>.
16 use strict;
17 use warnings;
19 use Test::More;
20 use Test::Dpkg qw(:needs :paths test_neutralize_checksums);
22 use File::Spec::Functions qw(rel2abs);
23 use File::Compare;
24 use File::Path qw(make_path);
25 use File::Copy;
27 use Dpkg::File;
28 use Dpkg::IPC;
29 use Dpkg::BuildTypes;
30 use Dpkg::Substvars;
32 test_needs_command('fakeroot');
34 plan tests => 17;
36 my $srcdir = rel2abs($ENV{srcdir} || '.');
37 my $datadir = "$srcdir/t/dpkg_buildpackage";
38 my $tmpdir = test_get_temp_path();
40 $ENV{$_} = rel2abs($ENV{$_}) foreach qw(DPKG_DATADIR DPKG_ORIGINS_DIR);
42 # Any parallelization from the parent should be ignored, we are testing
43 # the makefiles serially anyway.
44 delete $ENV{MAKEFLAGS};
46 # Delete variables that can affect the tests.
47 delete $ENV{SOURCE_DATE_EPOCH};
49 # Delete other variables that can affect the tests.
50 delete $ENV{$_} foreach grep { m/^DEB_/ } keys %ENV;
52 # Set architecture variables to not require dpkg nor gcc.
53 $ENV{PATH} = "$srcdir/t/mock-bin:$ENV{PATH}";
55 chdir $tmpdir;
57 my $tmpl_format = <<'TMPL_FORMAT';
58 3.0 (native)
59 TMPL_FORMAT
61 my $tmpl_changelog = <<'TMPL_CHANGELOG';
62 ${source-name} (${source-version}) ${suite}; urgency=${urgency}
64 * Entry. Closes: #12345
66 -- ${maintainer} Thu, 30 Jun 2016 20:15:12 +0200
67 TMPL_CHANGELOG
69 my $tmpl_control = <<'TMPL_CONTROL';
70 Source: ${source-name}
71 Section: ${source-section}
72 Priority: ${source-priority}
73 Maintainer: ${maintainer}
75 Package: test-binary-all
76 Architecture: all
77 Description: architecture independent binary package
79 Package: test-binary-any
80 Architecture: any
81 Description: architecture dependent binary package
82 TMPL_CONTROL
84 my $tmpl_rules = <<'TMPL_RULES';
85 #!/usr/bin/make -f
87 DI := debian/${binary-name-all}
88 DA := debian/${binary-name-any}
90 # fakeroot confuses ASAN link order check.
91 export ASAN_OPTIONS = verify_asan_link_order=0
92 # Do not fail due to leaks, as the code is still using lots of
93 # static variables and error variables.
94 export LSAN_OPTIONS = exitcode=0
96 clean:
97 rm -f debian/files
98 rm -rf $(DI) $(DA)
100 build-indep:
101 build-arch:
102 build: build-indep build-arch
104 binary-indep: build-indep
105 rm -rf $(DI)
106 mkdir -p $(DI)/DEBIAN
107 dpkg-gencontrol -P$(DI) -p${binary-name-all}
108 dpkg-deb --build $(DI) ..
110 binary-arch: build-arch
111 rm -rf $(DA)
112 mkdir -p $(DA)/DEBIAN
113 dpkg-gencontrol -P$(DA) -p${binary-name-any}
114 dpkg-deb --build $(DA) ..
116 binary: binary-indep binary-arch
118 .PHONY: clean build-indep build-arch build binary-indexp binary-arch binary
119 TMPL_RULES
121 my %default_substvars = (
122 'source-name' => 'test-source',
123 'source-version' => 0,
124 'source-section' => 'test',
125 'source-priority' => 'optional',
126 'binary-name-all' => 'test-binary-all',
127 'binary-name-any' => 'test-binary-any',
128 'suite' => 'unstable',
129 'urgency' => 'low',
130 'maintainer' => 'Dpkg Developers <debian-dpkg@lists.debian.org>',
133 sub gen_from_tmpl
135 my ($pathname, $tmpl, $substvars) = @_;
137 file_dump($pathname, $substvars->substvars($tmpl));
140 sub gen_source
142 my (%opts) = @_;
144 my $substvars = Dpkg::Substvars->new();
145 foreach my $var (%default_substvars) {
146 my $value = $opts{$var} // $default_substvars{$var};
148 $substvars->set_as_auto($var, $value);
151 my $source = $substvars->get('source-name');
152 my $version = $substvars->get('source-version');
153 my $basename = "$source\_$version";
154 my $dirname = $basename =~ tr/_/-/r;
156 make_path("$dirname/debian/source");
158 gen_from_tmpl("$dirname/debian/source/format", $tmpl_format, $substvars);
159 gen_from_tmpl("$dirname/debian/changelog", $tmpl_changelog, $substvars);
160 gen_from_tmpl("$dirname/debian/control", $tmpl_control, $substvars);
161 gen_from_tmpl("$dirname/debian/rules", $tmpl_rules, $substvars);
163 return $basename;
166 sub test_diff
168 my $filename = shift;
170 my $expected_file = "$datadir/$filename";
171 my $generated_file = $filename;
173 test_neutralize_checksums($generated_file);
175 my $res = compare($expected_file, $generated_file);
176 if ($res) {
177 system "diff -u $expected_file $generated_file >&2";
179 ok($res == 0, "generated file matches expected one ($expected_file)");
182 sub test_build
184 my ($basename, $type) = @_;
185 my $dirname = $basename =~ tr/_/-/r;
187 set_build_type($type, 'buildtype', nocheck => 1);
188 my $typename = get_build_options_from_type();
190 my $stderr;
192 my @hook_names = qw(
193 preinit
194 init
195 preclean
196 source
197 build
198 binary
199 buildinfo
200 changes
201 postclean
202 check
203 sign
204 done
206 my @hook_opts = map {
207 "--hook-$_=$datadir/hook a=%a p=%p v=%v s=%s u=%u >>../$basename\_$typename.hook"
208 } @hook_names;
210 chdir $dirname;
211 spawn(exec => [ $ENV{PERL}, "$srcdir/dpkg-buildpackage.pl",
212 "--admindir=$datadir/dpkgdb",
213 '--host-arch=amd64',
214 '--ignore-builtin-builddeps',
215 '--no-sign',
216 "--build=$typename",
217 '--check-command=',
218 @hook_opts,
220 error_to_string => \$stderr,
221 wait_child => 1, nocheck => 1);
222 chdir '..';
224 ok($? == 0, "dpkg-buildpackage --build=$typename succeeded");
225 diag($stderr) unless $? == 0;
227 if (build_has_all(BUILD_ARCH_DEP)) {
228 # Rename the file to preserve on consecutive invocations.
229 move("$basename\_amd64.changes", "$basename\_$typename.changes");
232 test_diff("$basename\_$typename.hook");
234 if (build_has_all(BUILD_SOURCE)) {
235 test_diff("$basename.dsc");
238 test_diff("$basename\_$typename.changes");
241 my $basename = gen_source();
243 test_build($basename, BUILD_SOURCE);
244 test_build($basename, BUILD_ARCH_INDEP);
245 test_build($basename, BUILD_ARCH_DEP);
246 test_build($basename, BUILD_BINARY);
247 test_build($basename, BUILD_FULL);