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
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
102 build: build-indep build-arch
104 binary-indep: build-indep
106 mkdir -p $(DI)/DEBIAN
107 dpkg-gencontrol -P$(DI) -p${binary-name-all}
108 dpkg-deb --build $(DI) ..
110 binary-arch: build-arch
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
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',
130 'maintainer' => 'Dpkg Developers <debian-dpkg@lists.debian.org>',
135 my ($pathname, $tmpl, $substvars) = @_;
137 file_dump($pathname, $substvars->substvars($tmpl));
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);
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);
177 system "diff -u $expected_file $generated_file >&2";
179 ok($res == 0, "generated file matches expected one ($expected_file)");
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();
206 my @hook_opts = map {
207 "--hook-$_=$datadir/hook a=%a p=%p v=%v s=%s u=%u >>../$basename\_$typename.hook"
211 spawn
(exec => [ $ENV{PERL
}, "$srcdir/dpkg-buildpackage.pl",
212 "--admindir=$datadir/dpkgdb",
214 '--ignore-builtin-builddeps',
220 error_to_string
=> \
$stderr,
221 wait_child
=> 1, nocheck
=> 1);
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
);