[dpkg] 130/200: Dpkg::BuildOptions: Add new parse_features() method
Ximin Luo
infinity0 at debian.org
Wed Apr 5 15:17:28 UTC 2017
This is an automated email from the git hooks/post-receive script.
infinity0 pushed a commit to branch master
in repository dpkg.
commit dad593660d922abce634542b43e9d56b03228a8c
Author: Guillem Jover <guillem at debian.org>
Date: Thu Jan 26 00:06:35 2017 +0100
Dpkg::BuildOptions: Add new parse_features() method
This has been refactored from Dpkg::Vendor::Debian, to have a generic
option parser.
---
debian/changelog | 2 ++
scripts/Dpkg/BuildOptions.pm | 45 +++++++++++++++++++++++++++++++++++++++++--
scripts/Dpkg/Vendor/Debian.pm | 35 ++++++---------------------------
scripts/t/Dpkg_BuildOptions.t | 38 +++++++++++++++++++++++++++++++++++-
4 files changed, 88 insertions(+), 32 deletions(-)
diff --git a/debian/changelog b/debian/changelog
index 4488de0..a5f4ab1 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -34,6 +34,8 @@ dpkg (1.18.19) UNRELEASED; urgency=medium
bogus POD documentation to match the code.
- Add new Auto-Built-Package field to Dpkg::Control::Fields.
- Add a new debug() reporting function, and switch code to use it.
+ - Add new Dpkg::BuildOption parse_features() method refactored from
+ Dpkg::Vendor::Debian.
* Documentation:
- Cleanup software requirements in README.
- Move control member file references from dpkg(1) to deb(5).
diff --git a/scripts/Dpkg/BuildOptions.pm b/scripts/Dpkg/BuildOptions.pm
index 1ffebe5..057dfc1 100644
--- a/scripts/Dpkg/BuildOptions.pm
+++ b/scripts/Dpkg/BuildOptions.pm
@@ -1,5 +1,5 @@
# Copyright © 2007 Frank Lichtenheld <djpig at debian.org>
-# Copyright © 2008, 2012-2015 Guillem Jover <guillem at debian.org>
+# Copyright © 2008, 2012-2017 Guillem Jover <guillem at debian.org>
# Copyright © 2010 Raphaël Hertzog <hertzog at debian.org>
#
# This program is free software; you can redistribute it and/or modify
@@ -20,7 +20,7 @@ package Dpkg::BuildOptions;
use strict;
use warnings;
-our $VERSION = '1.01';
+our $VERSION = '1.02';
use Dpkg::Gettext;
use Dpkg::ErrorHandling;
@@ -155,6 +155,43 @@ sub has {
return exists $self->{options}{$key};
}
+=item $bo->parse_features($option, $use_feature)
+
+Parse the $option values, as a set of known features to enable or disable,
+as specified in the $use_feature hash reference.
+
+Each feature is prefixed with a ‘B<+>’ or a ‘B<->’ character as a marker
+to enable or disable it. The special feature “B<all>” can be used to act
+on all known features.
+
+Unknown of malformed features will emit warnings.
+
+=cut
+
+sub parse_features {
+ my ($self, $option, $use_feature) = @_;
+
+ foreach my $feature (split(/,/, $self->get($option) // '')) {
+ $feature = lc $feature;
+ if ($feature =~ s/^([+-])//) {
+ my $value = ($1 eq '+') ? 1 : 0;
+ if ($feature eq 'all') {
+ $use_feature->{$_} = $value foreach keys %{$use_feature};
+ } else {
+ if (exists $use_feature->{$feature}) {
+ $use_feature->{$feature} = $value;
+ } else {
+ warning(g_('unknown %s feature in %s variable: %s'),
+ $option, $self->{envvar}, $feature);
+ }
+ }
+ } else {
+ warning(g_('incorrect value in %s option of %s variable: %s'),
+ $option, $self->{envvar}, $feature);
+ }
+ }
+}
+
=item $string = $bo->output($fh)
Return a string representation of the build options suitable to be
@@ -191,6 +228,10 @@ sub export {
=head1 CHANGES
+=head2 Version 1.02 (dpkg 1.18.19)
+
+New method: $bo->parse_features().
+
=head2 Version 1.01 (dpkg 1.16.1)
Enable to use another environment variable instead of DEB_BUILD_OPTIONS.
diff --git a/scripts/Dpkg/Vendor/Debian.pm b/scripts/Dpkg/Vendor/Debian.pm
index 8ab8ffd..d719ee6 100644
--- a/scripts/Dpkg/Vendor/Debian.pm
+++ b/scripts/Dpkg/Vendor/Debian.pm
@@ -1,5 +1,5 @@
# Copyright © 2009-2011 Raphaël Hertzog <hertzog at debian.org>
-# Copyright © 2009, 2011-2015 Guillem Jover <guillem at debian.org>
+# Copyright © 2009, 2011-2017 Guillem Jover <guillem at debian.org>
#
# Hardening build flags handling derived from work of:
# Copyright © 2009-2011 Kees Cook <kees at debian.org>
@@ -91,37 +91,14 @@ sub run_hook {
}
}
-sub _parse_build_options {
- my ($self, $variable, $area, $use_feature) = @_;
-
- # Adjust features based on user or maintainer's desires.
- my $opts = Dpkg::BuildOptions->new(envvar => $variable);
- foreach my $feature (split(/,/, $opts->get($area) // '')) {
- $feature = lc($feature);
- if ($feature =~ s/^([+-])//) {
- my $value = ($1 eq '+') ? 1 : 0;
- if ($feature eq 'all') {
- $use_feature->{$_} = $value foreach keys %{$use_feature};
- } else {
- if (exists $use_feature->{$feature}) {
- $use_feature->{$feature} = $value;
- } else {
- warning(g_('unknown %s feature in %s variable: %s'),
- $area, $variable, $feature);
- }
- }
- } else {
- warning(g_('incorrect value in %s option of %s variable: %s'),
- $area, $variable, $feature);
- }
- }
-}
-
sub _parse_feature_area {
my ($self, $area, $use_feature) = @_;
- $self->_parse_build_options('DEB_BUILD_OPTIONS', $area, $use_feature);
- $self->_parse_build_options('DEB_BUILD_MAINT_OPTIONS', $area, $use_feature);
+ # Adjust features based on user or maintainer's desires.
+ my $opts = Dpkg::BuildOptions->new(envvar => 'DEB_BUILD_OPTIONS');
+ $opts->parse_features($area, $use_feature);
+ $opts = Dpkg::BuildOptions->new(envvar => 'DEB_BUILD_MAINT_OPTIONS');
+ $opts->parse_features($area, $use_feature);
}
sub _add_qa_flags {
diff --git a/scripts/t/Dpkg_BuildOptions.t b/scripts/t/Dpkg_BuildOptions.t
index 6960235..a5a9996 100644
--- a/scripts/t/Dpkg_BuildOptions.t
+++ b/scripts/t/Dpkg_BuildOptions.t
@@ -16,7 +16,7 @@
use strict;
use warnings;
-use Test::More tests => 24;
+use Test::More tests => 28;
use Dpkg::ErrorHandling;
@@ -71,3 +71,39 @@ is($dbo->output(), 'foobar noopt', 'output');
$dbo = Dpkg::BuildOptions->new(envvar => 'OTHER_VARIABLE');
is($dbo->get('parallel'), 5, 'import from other variable, check parallel');
ok($dbo->has('noopt'), 'import from other variable, check noopt');
+
+my %theme = (
+ metal => undef,
+ pink => undef,
+ rusty => undef,
+ sky => undef,
+);
+my %theme_ref;
+
+$dbo = Dpkg::BuildOptions->new();
+
+$theme_ref{$_} = 1 foreach keys %theme;
+$dbo->set('theme', '+all');
+$dbo->parse_option('theme', \%theme);
+is_deeply(\%theme, \%theme_ref, 'features set with +all');
+
+$theme{$_} = undef foreach keys %theme;
+$theme_ref{$_} = 1 foreach keys %theme;
+$theme_ref{rusty} = 0;
+$dbo->set('theme', '+all,-rusty');
+$dbo->parse_option('theme', \%theme);
+is_deeply(\%theme, \%theme_ref, 'features set with +all,-rusty');
+
+$theme{$_} = undef foreach keys %theme;
+$theme_ref{$_} = 0 foreach keys %theme;
+$theme_ref{metal} = 1;
+$dbo->set('theme', '-all,+metal');
+$dbo->parse_option('theme', \%theme);
+is_deeply(\%theme, \%theme_ref, 'features set with +all,-rusty');
+
+$theme{$_} = $theme_ref{$_} = undef foreach keys %theme;
+$theme_ref{pink} = 1;
+$theme_ref{sky} = 0;
+$dbo->set('theme', '+pink,-sky');
+$dbo->parse_option('theme', \%theme);
+is_deeply(\%theme, \%theme_ref, 'features set with +pink,-sky');
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/dpkg.git
More information about the Reproducible-commits
mailing list