summaryrefslogtreecommitdiff
path: root/scripts/Dpkg
diff options
context:
space:
mode:
authorGuillem Jover <guillem@debian.org>2017-01-26 00:06:35 +0100
committerGuillem Jover <guillem@debian.org>2017-01-26 23:26:33 +0100
commitdad593660d922abce634542b43e9d56b03228a8c (patch)
treecac271260a548b16f62d916a487dce555a7a3936 /scripts/Dpkg
parent8ae966ae7d3635b8359829085db4262923ceae96 (diff)
downloaddpkg-dad593660d922abce634542b43e9d56b03228a8c.tar.gz
Dpkg::BuildOptions: Add new parse_features() method
This has been refactored from Dpkg::Vendor::Debian, to have a generic option parser.
Diffstat (limited to 'scripts/Dpkg')
-rw-r--r--scripts/Dpkg/BuildOptions.pm45
-rw-r--r--scripts/Dpkg/Vendor/Debian.pm35
2 files changed, 49 insertions, 31 deletions
diff --git a/scripts/Dpkg/BuildOptions.pm b/scripts/Dpkg/BuildOptions.pm
index 1ffebe56c..057dfc1e3 100644
--- a/scripts/Dpkg/BuildOptions.pm
+++ b/scripts/Dpkg/BuildOptions.pm
@@ -1,5 +1,5 @@
# Copyright © 2007 Frank Lichtenheld <djpig@debian.org>
-# Copyright © 2008, 2012-2015 Guillem Jover <guillem@debian.org>
+# Copyright © 2008, 2012-2017 Guillem Jover <guillem@debian.org>
# Copyright © 2010 Raphaël Hertzog <hertzog@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 8ab8ffd9c..d719ee6bd 100644
--- a/scripts/Dpkg/Vendor/Debian.pm
+++ b/scripts/Dpkg/Vendor/Debian.pm
@@ -1,5 +1,5 @@
# Copyright © 2009-2011 Raphaël Hertzog <hertzog@debian.org>
-# Copyright © 2009, 2011-2015 Guillem Jover <guillem@debian.org>
+# Copyright © 2009, 2011-2017 Guillem Jover <guillem@debian.org>
#
# Hardening build flags handling derived from work of:
# Copyright © 2009-2011 Kees Cook <kees@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 {