man: Add dpkg-build-api behavior for Rules-Requires-Root field defaults
[dpkg.git] / scripts / t / mk.t
bloba31eef72eb361e6dd6a3e62226336733c3179537
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 tests => 12;
20 use Test::Dpkg qw(:paths);
22 use File::Spec::Functions qw(rel2abs);
24 use Dpkg ();
25 use Dpkg::ErrorHandling;
26 use Dpkg::IPC;
27 use Dpkg::Vendor;
29 my $srcdir = rel2abs($ENV{srcdir} || '.');
30 my $datadir = test_get_data_path();
32 # Turn these into absolute names so that we can safely switch to the test
33 # directory with «make -C».
34 $ENV{$_} = rel2abs($ENV{$_}) foreach qw(srcdir DPKG_DATADIR DPKG_ORIGINS_DIR);
36 # Any parallelization from the parent should be ignored, we are testing
37 # the makefiles serially anyway.
38 delete $ENV{MAKEFLAGS};
40 # Delete other variables that can affect the tests.
41 delete $ENV{$_} foreach grep { m/^DEB_/ } keys %ENV;
43 # Set architecture variables to not require dpkg nor gcc.
44 $ENV{PATH} = "$srcdir/t/mock-bin:$ENV{PATH}";
46 $ENV{DEB_BUILD_PATH} = rel2abs($datadir);
48 sub test_makefile {
49 my ($makefile, $desc) = @_;
51 $desc //= 'default';
53 spawn(exec => [ $Dpkg::PROGMAKE, '-C', $datadir, '-f', $makefile ],
54 wait_child => 1, nocheck => 1);
55 ok($? == 0, "makefile $makefile computes all values correctly ($desc)");
58 sub cmd_get_vars {
59 my (@cmd) = @_;
60 my %var;
62 open my $cmd_fh, '-|', @cmd or subprocerr($cmd[0]);
63 while (<$cmd_fh>) {
64 chomp;
65 my ($key, $value) = split /=/, $_, 2;
66 $var{$key} = $value;
68 close $cmd_fh or subprocerr($cmd[0]);
70 return %var;
73 # Test makefiles.
75 my %arch = cmd_get_vars($ENV{PERL}, "$srcdir/dpkg-architecture.pl", '-f');
77 while (my ($k, $v) = each %arch) {
78 delete $ENV{$k};
79 $ENV{"TEST_$k"} = $v;
81 test_makefile('architecture.mk', 'without envvars');
82 while (my ($k, $v) = each %arch) {
83 $ENV{$k} = $v;
85 test_makefile('architecture.mk', 'with envvars');
87 test_makefile('buildapi.mk');
89 $ENV{DEB_BUILD_OPTIONS} = 'parallel=16';
90 $ENV{TEST_DEB_BUILD_OPTION_PARALLEL} = '16';
91 test_makefile('buildopts.mk');
92 delete $ENV{DEB_BUILD_OPTIONS};
93 delete $ENV{TEST_DEB_BUILD_OPTION_PARALLEL};
95 my %buildflag = cmd_get_vars($ENV{PERL}, "$srcdir/dpkg-buildflags.pl");
97 while (my ($var, $flags) = each %buildflag) {
98 delete $ENV{$var};
99 $ENV{"TEST_$var"} = $flags;
101 test_makefile('buildflags.mk');
103 my %buildtools = (
104 AS => 'as',
105 CPP => 'gcc -E',
106 CC => 'gcc',
107 CXX => 'g++',
108 OBJC => 'gcc',
109 OBJCXX => 'g++',
110 F77 => 'gfortran',
111 FC => 'gfortran',
112 LD => 'ld',
113 STRIP => 'strip',
114 OBJCOPY => 'objcopy',
115 OBJDUMP => 'objdump',
116 NM => 'nm',
117 AR => 'ar',
118 RANLIB => 'ranlib',
119 PKG_CONFIG => 'pkgconf',
122 while (my ($var, $tool) = each %buildtools) {
123 delete $ENV{$var};
124 $ENV{"TEST_$var"} = "$ENV{DEB_HOST_GNU_TYPE}-$tool";
125 delete $ENV{"${var}_FOR_BUILD"};
126 $ENV{"TEST_${var}_FOR_BUILD"} = "$ENV{DEB_BUILD_GNU_TYPE}-$tool";
128 test_makefile('buildtools.mk', 'without envvars');
130 $ENV{DEB_BUILD_OPTIONS} = 'nostrip';
131 $ENV{TEST_STRIP} = ':';
132 $ENV{TEST_STRIP_FOR_BUILD} = ':';
133 test_makefile('buildtools.mk', 'with envvars');
134 delete $ENV{DEB_BUILD_OPTIONS};
136 foreach my $tool (keys %buildtools) {
137 delete $ENV{${tool}};
138 delete $ENV{"${tool}_FOR_BUILD"};
141 delete $ENV{SOURCE_DATE_EPOCH};
142 # Timestamp in seconds since the epoch from date in test debian/changelog
143 # entry: «Tue, 04 Aug 2015 16:13:50 +0200».
144 $ENV{TEST_SOURCE_DATE_EPOCH} = 1438697630;
145 test_makefile('pkg-info.mk');
147 $ENV{SOURCE_DATE_EPOCH} = 100;
148 $ENV{TEST_SOURCE_DATE_EPOCH} = 100;
149 test_makefile('pkg-info.mk');
151 test_makefile('vendor.mk');
152 test_makefile('vendor-v0.mk');
153 test_makefile('vendor-v1.mk');