[Reproducible-commits] [dpkg] 35/105: Dpkg::Arch: Add new functions to validate and parse architecture names
Niko Tyni
ntyni at moszumanska.debian.org
Mon May 2 13:49:50 UTC 2016
This is an automated email from the git hooks/post-receive script.
ntyni pushed a commit to branch ntyni/reproducible_builds
in repository dpkg.
commit b61fee98a751d163ea99d2667328de6f8b663520
Author: Guillem Jover <guillem at debian.org>
Date: Sun Mar 6 19:26:13 2016 +0100
Dpkg::Arch: Add new functions to validate and parse architecture names
---
debian/changelog | 1 +
scripts/Dpkg/Arch.pm | 42 +++++++++++++++++++++++++++++++++++++++++-
scripts/t/Dpkg_Arch.t | 24 +++++++++++++++++++++++-
3 files changed, 65 insertions(+), 2 deletions(-)
diff --git a/debian/changelog b/debian/changelog
index 99ac2cf..33a0875 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -71,6 +71,7 @@ dpkg (1.18.5) UNRELEASED; urgency=medium
- Check existence of search criteria in Dpkg::Index when checking with a
regex or a string match. Closes: #780906
Base on a patch by Daniel Dehennin <daniel.dehennin at baby-gnu.org>.
+ - Add new functions to validate and parse architecture names in Dpkg::Arch.
* Build system:
- Fix building development documentation.
- Remove unused UA_LIBS variable.
diff --git a/scripts/Dpkg/Arch.pm b/scripts/Dpkg/Arch.pm
index 10e2f85..04b8574 100644
--- a/scripts/Dpkg/Arch.pm
+++ b/scripts/Dpkg/Arch.pm
@@ -32,7 +32,7 @@ use strict;
use warnings;
use feature qw(state);
-our $VERSION = '1.00';
+our $VERSION = '1.01';
our @EXPORT_OK = qw(
get_raw_build_arch
get_raw_host_arch
@@ -43,11 +43,13 @@ our @EXPORT_OK = qw(
debarch_eq
debarch_is
debarch_is_wildcard
+ debarch_is_illegal
debarch_is_concerned
debarch_to_cpuattrs
debarch_to_gnutriplet
debarch_to_debtriplet
debarch_to_multiarch
+ debarch_list_parse
debtriplet_to_debarch
debtriplet_to_gnutriplet
gnutriplet_to_debarch
@@ -533,6 +535,19 @@ sub debarch_is_wildcard($)
return 0;
}
+=item $bool = debarch_is_illegal($arch)
+
+Validate an architecture name.
+
+=cut
+
+sub debarch_is_illegal
+{
+ my ($arch) = @_;
+
+ return $arch !~ m/^(!?[a-zA-Z0-9][a-zA-Z0-9-]*)$/;
+}
+
=item $bool = debarch_is_concerned($arch, @arches)
Evaluate whether a Debian architecture applies to the list of architecture
@@ -568,6 +583,27 @@ sub debarch_is_concerned
return $seen_arch;
}
+=item @array = debarch_list_parse($arch_list, %options)
+
+Parse an architecture list.
+
+=cut
+
+sub debarch_list_parse
+{
+ my $arch_list = shift;
+ my @arch_list = split /\s+/, $arch_list;
+
+ foreach my $arch (@arch_list) {
+ if (debarch_is_illegal($arch)) {
+ error(g_("'%s' is not a legal architecture in list '%s'"),
+ $arch, $arch_list);
+ }
+ }
+
+ return @arch_list;
+}
+
1;
__END__
@@ -576,6 +612,10 @@ __END__
=head1 CHANGES
+=head2 Version 1.01 (dpkg 1.18.5)
+
+New functions: debarch_is_illegal(), debarch_list_parse().
+
=head2 Version 1.00 (dpkg 1.18.2)
Mark the module as public.
diff --git a/scripts/t/Dpkg_Arch.t b/scripts/t/Dpkg_Arch.t
index c147792..dd7954e 100644
--- a/scripts/t/Dpkg_Arch.t
+++ b/scripts/t/Dpkg_Arch.t
@@ -16,11 +16,13 @@
use strict;
use warnings;
-use Test::More tests => 53;
+use Test::More tests => 64;
use_ok('Dpkg::Arch', qw(debarch_to_debtriplet debarch_to_multiarch
debarch_eq debarch_is debarch_is_wildcard
+ debarch_is_illegal
debarch_to_cpuattrs
+ debarch_list_parse
debtriplet_to_debarch gnutriplet_to_debarch
get_host_gnu_type
get_valid_arches));
@@ -87,6 +89,26 @@ ok(debarch_is_wildcard('gnu-any-any'), '<abi>-any-any is a wildcard');
ok(debarch_is_wildcard('any-linux-any'), 'any-<os>-any is a wildcard');
ok(debarch_is_wildcard('any-any-amd64'), 'any-any-<cpu> is a wildcard');
+ok(!debarch_is_illegal('0'), '');
+ok(!debarch_is_illegal('a'), '');
+ok(!debarch_is_illegal('amd64'), '');
+ok(!debarch_is_illegal('!arm64'), '');
+ok(!debarch_is_illegal('kfreebsd-any'), '');
+ok(debarch_is_illegal('!amd64!arm'), '');
+ok(debarch_is_illegal('arch%name'), '');
+ok(debarch_is_illegal('-any'), '');
+ok(debarch_is_illegal('!'), '');
+
+my @arch_new;
+my @arch_ref;
+
+ at arch_ref = qw(amd64 !arm64 linux-i386 !kfreebsd-any);
+ at arch_new = debarch_list_parse('amd64 !arm64 linux-i386 !kfreebsd-any');
+is_deeply(\@arch_new, \@arch_ref, 'parse valid arch list');
+
+eval { @arch_new = debarch_list_parse('!amd64!arm64') };
+ok($@, 'parse concatenated arches failed');
+
is(debarch_to_cpuattrs(undef), undef, 'undef cpu attrs');
is_deeply([ debarch_to_cpuattrs('amd64') ], [ qw(64 little) ], 'amd64 cpu attrs');
--
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