Merge ~zhsj/ubuntu/+source/dpkg:respect-maint-opt into ubuntu/+source/dpkg:ubuntu/devel

Proposed by Shengjing Zhu
Status: Merged
Merge reported by: Shengjing Zhu
Merged at revision: c67657df5792f70e1f8f4e16eed2c83d14f01c48
Proposed branch: ~zhsj/ubuntu/+source/dpkg:respect-maint-opt
Merge into: ubuntu/+source/dpkg:ubuntu/devel
Diff against target: 109 lines (+58/-4)
3 files modified
debian/changelog (+7/-0)
scripts/Dpkg/Vendor/Ubuntu.pm (+24/-3)
scripts/t/Dpkg_BuildFlags_Ubuntu.t (+27/-1)
Reviewer Review Type Date Requested Status
Marius Gripsgard  (community) Approve
Canonical Foundations Team Pending
Review via email: mp+435646@code.launchpad.net

Commit message

Dpkg::Vendor::Ubuntu: Respect options env when override features

LP: #2002582

To post a comment you must log in.
Revision history for this message
Marius Gripsgard  (mariogrip) wrote :

Works as expected for me, fixes the issue.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/debian/changelog b/debian/changelog
2index db724e8..244ec39 100644
3--- a/debian/changelog
4+++ b/debian/changelog
5@@ -1,3 +1,10 @@
6+dpkg (1.21.17ubuntu6) lunar; urgency=medium
7+
8+ * Dpkg::Vendor::Ubuntu: Respect options env when override features
9+ (LP: #2002582)
10+
11+ -- Shengjing Zhu <shengjing.zhu@canonical.com> Thu, 12 Jan 2023 14:48:10 +0800
12+
13 dpkg (1.21.17ubuntu5) lunar; urgency=medium
14
15 * scripts/Dpkg/Vendor/Debian.pm: Fix FTBFS caused by some typos and
16diff --git a/scripts/Dpkg/Vendor/Ubuntu.pm b/scripts/Dpkg/Vendor/Ubuntu.pm
17index 930695c..3b95136 100644
18--- a/scripts/Dpkg/Vendor/Ubuntu.pm
19+++ b/scripts/Dpkg/Vendor/Ubuntu.pm
20@@ -168,14 +168,35 @@ sub set_build_features {
21
22 $self->SUPER::set_build_features($flags);
23
24+ my %default_feature = (
25+ optimize => {
26+ lto => 0,
27+ },
28+ );
29+
30+
31 require Dpkg::Arch;
32 my $arch = Dpkg::Arch::get_host_arch();
33
34 if (any { $_ eq $arch } qw(amd64 arm64 ppc64el s390x)) {
35- $flags->set_feature('optimize', 'lto', 1);
36+ $default_feature{optimize}{lto} = 1;
37 if (_lto_disabled()) {
38- $flags->set_feature('optimize', 'lto', 0);
39- }
40+ $default_feature{optimize}{lto} = 0;
41+ }
42+ }
43+
44+ my $opts_build = Dpkg::BuildOptions->new(envvar => 'DEB_BUILD_OPTIONS');
45+ my $opts_maint = Dpkg::BuildOptions->new(envvar => 'DEB_BUILD_MAINT_OPTIONS');
46+
47+ foreach my $area (sort keys %default_feature) {
48+ $opts_build->parse_features($area, $default_feature{$area});
49+ $opts_maint->parse_features($area, $default_feature{$area});
50+ }
51+
52+ foreach my $area (sort keys %default_feature) {
53+ while (my ($feature, $enabled) = each %{$default_feature{$area}}) {
54+ $flags->set_feature($area, $feature, $enabled);
55+ }
56 }
57
58 if ($arch eq 'ppc64el' && $flags->get_option_value('optimize-level') != 0) {
59diff --git a/scripts/t/Dpkg_BuildFlags_Ubuntu.t b/scripts/t/Dpkg_BuildFlags_Ubuntu.t
60index 193e492..2f8827f 100644
61--- a/scripts/t/Dpkg_BuildFlags_Ubuntu.t
62+++ b/scripts/t/Dpkg_BuildFlags_Ubuntu.t
63@@ -16,7 +16,7 @@
64 use strict;
65 use warnings;
66
67-use Test::More tests => 18;
68+use Test::More tests => 21;
69
70 BEGIN {
71 use_ok('Dpkg::BuildFlags');
72@@ -42,6 +42,15 @@ sub test_ltoflag
73 "LDFLAGS contains LTO flags on $ENV{DEB_HOST_ARCH}");
74 }
75
76+sub test_no_ltoflag
77+{
78+ my $bf = shift;
79+
80+ # Test the LTO flags not enabled.
81+ ok($bf->get('LDFLAGS') !~ m/-flto=auto -ffat-lto-objects/,
82+ "LDFLAGS doesn't contains LTO flags on $ENV{DEB_HOST_ARCH}");
83+}
84+
85 my $bf;
86
87 # Force loading the Dpkg::Vendor::Ubuntu module.
88@@ -65,4 +74,21 @@ $bf = Dpkg::BuildFlags->new();
89 test_optflag($bf, '-O3');
90 test_ltoflag($bf);
91
92+# Test the optimization flag not enabled for riscv64.
93+$ENV{DEB_HOST_ARCH} = 'riscv64';
94+$bf = Dpkg::BuildFlags->new();
95+
96+test_no_ltoflag($bf);
97+
98+# Test the optimization flag overrided by DEB_BUILD_MAINT_OPTIONS.
99+$ENV{DEB_BUILD_MAINT_OPTIONS} = 'optimize=+lto';
100+$bf = Dpkg::BuildFlags->new();
101+
102+test_ltoflag($bf);
103+
104+$ENV{DEB_HOST_ARCH} = 'amd64';
105+$ENV{DEB_BUILD_MAINT_OPTIONS} = 'optimize=-lto';
106+$bf = Dpkg::BuildFlags->new();
107+test_no_ltoflag($bf);
108+
109 1;

Subscribers

People subscribed via source and target branches