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 :paths test_neutralize_checksums);
22 use File
::Spec
::Functions
qw(rel2abs);
24 use File
::Path
qw(make_path);
32 test_needs_command
('fakeroot');
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}";
57 my $tmpl_format = <<'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
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
77 Description
: architecture independent binary
package
79 Package
: test
-binary
-any
81 Description
: architecture dependent binary
package
84 my $tmpl_rules = <<'TMPL_RULES';
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
99 build: build-indep build-arch
101 binary-indep: build-indep
103 mkdir -p $(DI)/DEBIAN
104 dpkg-gencontrol -P$(DI) -p${binary-name-all}
105 dpkg-deb --build $(DI) ..
107 binary-arch: build-arch
109 mkdir -p $(DA)/DEBIAN
110 dpkg-gencontrol -P$(DA) -p${binary-name-any}
111 dpkg-deb --build $(DA) ..
113 binary: binary-indep binary-arch
115 .PHONY: clean build-indep build-arch build binary-indexp binary-arch binary
118 my %default_substvars = (
119 'source-name' => 'test-source',
120 'source-version' => 0,
121 'source-section' => 'test',
122 'source-priority' => 'optional',
123 'binary-name-all' => 'test-binary-all',
124 'binary-name-any' => 'test-binary-any',
125 'suite' => 'unstable',
127 'maintainer' => 'Dpkg Developers <debian-dpkg@lists.debian.org>',
132 my ($pathname, $tmpl, $substvars) = @_;
134 file_dump($pathname, $substvars->substvars($tmpl));
141 my $substvars = Dpkg::Substvars->new();
142 foreach my $var (%default_substvars) {
143 my $value = $options{$var} // $default_substvars{$var};
145 $substvars->set_as_auto($var, $value);
148 my $source = $substvars->get('source-name');
149 my $version = $substvars->get('source-version');
150 my $basename = "$source\_$version";
151 my $dirname = $basename =~ tr/_/-/r;
153 make_path("$dirname/debian/source");
155 gen_from_tmpl("$dirname/debian/source/format", $tmpl_format, $substvars);
156 gen_from_tmpl("$dirname/debian/changelog", $tmpl_changelog, $substvars);
157 gen_from_tmpl("$dirname/debian/control", $tmpl_control, $substvars);
158 gen_from_tmpl("$dirname/debian/rules", $tmpl_rules, $substvars);
165 my $filename = shift;
167 my $expected_file = "$datadir/$filename";
168 my $generated_file = $filename;
170 test_neutralize_checksums($generated_file);
172 my $res = compare($expected_file, $generated_file);
174 system "diff -u $expected_file $generated_file >&2";
176 ok($res == 0, "generated file matches expected one ($expected_file)");
181 my ($basename, $type) = @_;
182 my $dirname = $basename =~ tr/_/-/r;
184 set_build_type($type, 'buildtype', nocheck => 1);
185 my $typename = get_build_options_from_type();
203 my @hook_opts = map {
204 "--hook-$_=$datadir/hook a=%a p=%p v=%v s=%s u=%u >>../$basename\_$typename.hook"
208 spawn
(exec => [ $ENV{PERL
}, "$srcdir/dpkg-buildpackage.pl",
209 "--admindir=$datadir/dpkgdb",
211 '--ignore-builtin-builddeps',
217 error_to_string
=> \
$stderr,
218 wait_child
=> 1, nocheck
=> 1);
221 ok
($?
== 0, "dpkg-buildpackage --build=$typename succeeded");
222 diag
($stderr) unless $?
== 0;
224 if (build_has_all
(BUILD_ARCH_DEP
)) {
225 # Rename the file to preserve on consecutive invocations.
226 move
("$basename\_amd64.changes", "$basename\_$typename.changes");
229 test_diff
("$basename\_$typename.hook");
231 if (build_has_all
(BUILD_SOURCE
)) {
232 test_diff
("$basename.dsc");
235 test_diff
("$basename\_$typename.changes");
238 my $basename = gen_source
();
240 test_build
($basename, BUILD_SOURCE
);
241 test_build
($basename, BUILD_ARCH_INDEP
);
242 test_build
($basename, BUILD_ARCH_DEP
);
243 test_build
($basename, BUILD_BINARY
);
244 test_build
($basename, BUILD_FULL
);