Dpkg::Vendor::Debian: Move time64 buildflags feature from future to abi
[dpkg.git] / scripts / t / mk.t
blob6f992010053387ce459c52d7f9d3b61e99a7ae92
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 => 11;
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 $ENV{DEB_BUILD_OPTIONS} = 'parallel=16';
88 $ENV{TEST_DEB_BUILD_OPTION_PARALLEL} = '16';
89 test_makefile('buildopts.mk');
90 delete $ENV{DEB_BUILD_OPTIONS};
91 delete $ENV{TEST_DEB_BUILD_OPTION_PARALLEL};
93 my %buildflag = cmd_get_vars($ENV{PERL}, "$srcdir/dpkg-buildflags.pl");
95 while (my ($var, $flags) = each %buildflag) {
96 delete $ENV{$var};
97 $ENV{"TEST_$var"} = $flags;
99 test_makefile('buildflags.mk');
101 my %buildtools = (
102 AS => 'as',
103 CPP => 'gcc -E',
104 CC => 'gcc',
105 CXX => 'g++',
106 OBJC => 'gcc',
107 OBJCXX => 'g++',
108 GCJ => 'gcj',
109 F77 => 'gfortran',
110 FC => 'gfortran',
111 LD => 'ld',
112 STRIP => 'strip',
113 OBJCOPY => 'objcopy',
114 OBJDUMP => 'objdump',
115 NM => 'nm',
116 AR => 'ar',
117 RANLIB => 'ranlib',
118 PKG_CONFIG => 'pkgconf',
121 while (my ($var, $tool) = each %buildtools) {
122 delete $ENV{$var};
123 $ENV{"TEST_$var"} = "$ENV{DEB_HOST_GNU_TYPE}-$tool";
124 delete $ENV{"${var}_FOR_BUILD"};
125 $ENV{"TEST_${var}_FOR_BUILD"} = "$ENV{DEB_BUILD_GNU_TYPE}-$tool";
127 test_makefile('buildtools.mk', 'without envvars');
129 $ENV{DEB_BUILD_OPTIONS} = 'nostrip';
130 $ENV{TEST_STRIP} = ':';
131 $ENV{TEST_STRIP_FOR_BUILD} = ':';
132 test_makefile('buildtools.mk', 'with envvars');
133 delete $ENV{DEB_BUILD_OPTIONS};
135 foreach my $tool (keys %buildtools) {
136 delete $ENV{${tool}};
137 delete $ENV{"${tool}_FOR_BUILD"};
140 delete $ENV{SOURCE_DATE_EPOCH};
141 # Timestamp in seconds since the epoch from date in test debian/changelog
142 # entry: «Tue, 04 Aug 2015 16:13:50 +0200».
143 $ENV{TEST_SOURCE_DATE_EPOCH} = 1438697630;
144 test_makefile('pkg-info.mk');
146 $ENV{SOURCE_DATE_EPOCH} = 100;
147 $ENV{TEST_SOURCE_DATE_EPOCH} = 100;
148 test_makefile('pkg-info.mk');
150 test_makefile('vendor.mk');
151 test_makefile('vendor-v0.mk');
152 test_makefile('vendor-v1.mk');