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/>.
20 use Test::Dpkg qw(:needs test_neutralize_checksums);
22 use File::Spec::Functions qw(rel2abs);
24 use File::Path qw(make_path);
28 use Dpkg::Build::Types;
31 test_needs_command('fakeroot');
35 my $srcdir = rel2abs($ENV{srcdir} || '.');
36 my $datadir = "$srcdir/t/dpkg_buildpackage";
37 my $tmpdir = 't.tmp/dpkg_buildpackage';
39 $ENV{$_} = rel2abs($ENV{$_}) foreach qw(DPKG_DATADIR DPKG_ORIGINS_DIR);
41 # Any parallelization from the parent should be ignored, we are testing
42 # the makefiles serially anyway.
43 delete $ENV{MAKEFLAGS};
45 # Delete variables that can affect the tests.
46 delete $ENV{SOURCE_DATE_EPOCH};
48 # Delete other variables that can affect the tests.
49 delete $ENV{$_} foreach grep { m/^DEB_/ } keys %ENV;
55 my $tmpl_format = <<'TMPL_FORMAT';
59 my $tmpl_changelog = <<'TMPL_CHANGELOG';
60 ${source-name} (${source-version}) ${suite}; urgency=${urgency}
62 * Entry. Closes: #12345
64 -- ${maintainer} Thu, 30 Jun 2016 20:15:12 +0200
67 my $tmpl_control = <<'TMPL_CONTROL';
68 Source: ${source-name}
69 Section: ${source-section}
70 Priority: ${source-priority}
71 Maintainer: ${maintainer}
73 Package: test-binary-all
75 Description: architecture independent binary package
77 Package: test-binary-any
79 Description: architecture dependent binary package
82 my $tmpl_rules = <<'TMPL_RULES';
85 DI := debian/${binary-name-all}
86 DA := debian/${binary-name-any}
94 build: build-indep build-arch
96 binary-indep: build-indep
99 dpkg-gencontrol -P$(DI) -p${binary-name-all}
100 dpkg-deb --build $(DI) ..
102 binary-arch: build-arch
104 mkdir -p $(DA)/DEBIAN
105 dpkg-gencontrol -P$(DA) -p${binary-name-any}
106 dpkg-deb --build $(DA) ..
108 binary: binary-indep binary-arch
110 .PHONY: clean build-indep build-arch build binary-indexp binary-arch binary
113 my %default_substvars = (
114 'source-name' => 'test-source',
115 'source-version' => 0,
116 'source-section' => 'test',
117 'source-priority' => 'optional',
118 'binary-name-all' => 'test-binary-all',
119 'binary-name-any' => 'test-binary-any',
120 'suite' => 'unstable',
122 'maintainer' => 'Dpkg Developers <debian-dpkg@lists.debian.org>',
127 my ($pathname, $tmpl, $substvars) = @_;
129 open my $fh, '>', $pathname or die;
130 print { $fh } $substvars->substvars($tmpl);
138 my $substvars = Dpkg::Substvars->new();
139 foreach my $var (%default_substvars) {
140 my $value = $options{$var} // $default_substvars{$var};
142 $substvars->set_as_auto($var, $value);
145 my $source = $substvars->get('source-name');
146 my $version = $substvars->get('source-version');
147 my $basename = "$source\_$version";
148 my $dirname = $basename =~ tr/_/-/r;
150 make_path("$dirname/debian/source");
152 gen_from_tmpl("$dirname/debian/source/format", $tmpl_format, $substvars);
153 gen_from_tmpl("$dirname/debian/changelog", $tmpl_changelog, $substvars);
154 gen_from_tmpl("$dirname/debian/control", $tmpl_control, $substvars);
155 gen_from_tmpl("$dirname/debian/rules", $tmpl_rules, $substvars);
162 my $filename = shift;
164 my $expected_file = "$datadir/$filename";
165 my $generated_file = $filename;
167 test_neutralize_checksums($generated_file);
169 my $res = compare($expected_file, $generated_file);
171 system "diff -u $expected_file $generated_file >&2";
173 ok($res == 0, "generated file matches expected one ($expected_file)");
178 my ($basename, $type) = @_;
179 my $dirname = $basename =~ tr/_/-/r;
181 set_build_type($type, 'buildtype', nocheck => 1);
182 my $typename = get_build_options_from_type();
187 spawn(exec => [ $ENV{PERL}, "$srcdir/dpkg-buildpackage.pl",
189 '--unsigned-source', '--unsigned-changes',
190 '--unsigned-buildinfo',
191 "--build=$typename", '--check-command=' ],
192 error_to_string => \$stderr,
193 wait_child => 1, nocheck => 1);
196 ok($? == 0, "dpkg-buildpackage --build=$typename succeeded");
197 diag($stderr) unless $? == 0;
199 if (build_has_all(BUILD_ARCH_DEP)) {
200 # Rename the file to preserve on consecutive invocations.
201 move("$basename\_amd64.changes", "$basename\_$typename.changes");
204 if (build_has_all(BUILD_SOURCE)) {
205 test_diff("$basename.dsc");
208 test_diff("$basename\_$typename.changes");
211 my $basename = gen_source();
213 test_build($basename, BUILD_SOURCE);
214 test_build($basename, BUILD_ARCH_INDEP);
215 test_build($basename, BUILD_ARCH_DEP);
216 test_build($basename, BUILD_BINARY);
217 test_build($basename, BUILD_FULL);