This is an automated email from the git hooks/post-receive script. guillem pushed a commit to branch main in repository dpkg.
View the commit online: https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=5f6e45fbbd0637d4d9cc35b9a4ee4d494c1418b4 commit 5f6e45fbbd0637d4d9cc35b9a4ee4d494c1418b4 (HEAD -> main) Author: Guillem Jover <[email protected]> AuthorDate: Fri Jan 6 20:51:30 2023 +0100 Dpkg::BuildFlags: Fix strip method to always work with duplicates The regex was not correctly matching at the beginning of the line with leading spaces, which could be left by a previous replacement from the same s/// operator. Instead switch to split the flag value and filter based on a hash, which means we do not need to care about such space issues anymore. This change should not change the semantics for space separated options in the flags, as the code was already splitting the passed values on spaces, and then remapping on the entire flag value. Improve strip unit tests to cover all these cases. Closes: #1028044 --- scripts/Dpkg/BuildFlags.pm | 12 ++++++------ scripts/t/Dpkg_BuildFlags.t | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/scripts/Dpkg/BuildFlags.pm b/scripts/Dpkg/BuildFlags.pm index 4370c2545..5975bb07a 100644 --- a/scripts/Dpkg/BuildFlags.pm +++ b/scripts/Dpkg/BuildFlags.pm @@ -378,12 +378,12 @@ if $maint is defined and true. sub strip { my ($self, $flag, $value, $src, $maint) = @_; - foreach my $tostrip (split(/\s+/, $value)) { - next unless length $tostrip; - $self->{flags}->{$flag} =~ s/(^|\s+)\Q$tostrip\E(\s+|$)/ /g; - } - $self->{flags}->{$flag} =~ s/^\s+//g; - $self->{flags}->{$flag} =~ s/\s+$//g; + + my %strip = map { $_ => 1 } split /\s+/, $value; + + $self->{flags}->{$flag} = join q{ }, grep { + ! exists $strip{$_} + } split q{ }, $self->{flags}{$flag}; $self->{origin}->{$flag} = $src if defined $src; $self->{maintainer}->{$flag} = $maint if $maint; } diff --git a/scripts/t/Dpkg_BuildFlags.t b/scripts/t/Dpkg_BuildFlags.t index d2d3d7aee..c6e0ef8ff 100644 --- a/scripts/t/Dpkg_BuildFlags.t +++ b/scripts/t/Dpkg_BuildFlags.t @@ -16,7 +16,7 @@ use strict; use warnings; -use Test::More tests => 28; +use Test::More tests => 34; BEGIN { $ENV{DEB_BUILD_ARCH} = 'amd64'; @@ -39,6 +39,41 @@ is($bf->get('DPKGFLAGS'), '-Wflag -fsome', 'get stripped flag'); is($bf->get_origin('DPKGFLAGS'), 'user', 'flag has a user origin'); ok(!$bf->is_maintainer_modified('DPKGFLAGS'), 'strip marked flag as non-maint modified'); +my @strip_tests = ( + { + value => '-fsingle', + strip => '-fsingle', + exp => '', + }, { + value => '-fdupe -fdupe', + strip => '-fdupe', + exp => '', + }, { + value => '-Wa -fdupe -fdupe -Wb', + strip => '-fdupe', + exp => '-Wa -Wb', + }, { + value => '-fdupe -Wa -Wb -fdupe', + strip => '-fdupe', + exp => '-Wa -Wb', + }, { + value => '-fdupe -Wa -fdupe -Wb', + strip => '-fdupe', + exp => '-Wa -Wb', + }, { + value => '-Wa -fdupe -Wb -fdupe', + strip => '-fdupe', + exp => '-Wa -Wb', + } +); + +foreach my $test (@strip_tests) { + $bf->set('DPKGSTRIPFLAGS', $test->{value}, 'system'); + $bf->strip('DPKGSTRIPFLAGS', $test->{strip}, 'user', undef); + is($bf->get('DPKGSTRIPFLAGS'), $test->{exp}, + "strip flag '$test->{strip}' from '$test->{value}' to '$test->{exp}'"); +} + $bf->append('DPKGFLAGS', '-Wl,other', 'vendor', 0); is($bf->get('DPKGFLAGS'), '-Wflag -fsome -Wl,other', 'get appended flag'); is($bf->get_origin('DPKGFLAGS'), 'vendor', 'flag has a vendor origin'); -- Dpkg.Org's dpkg

