From: Raphael Hertzog Date: Fri, 11 Jan 2008 23:13:15 +0000 (+0100) Subject: Define list of valid debian/control fields in Dpkg::Fields X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=637f5a032fc5c20bf3159b3dc6d332b19a270e66;p=dpkg Define list of valid debian/control fields in Dpkg::Fields * scripts/Dpkg/Fields.pm: Define variables containing authoritative list of fields for debian/control (one for source stanza, one for package stanza). * scripts/dpkg-genchanges.pl, scripts/dpkg-gencontrol.pl, scripts/dpkg-source.pl: Use the new variables to properly ignore valid fields. Some related cleanup. --- diff --git a/ChangeLog b/ChangeLog index e1aa4bb3..f281082c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2008-01-12 Raphael hertzog + + * scripts/Dpkg/Fields.pm: Define variables containing + authoritative list of fields for debian/control (one for source + stanza, one for package stanza). + * scripts/dpkg-genchanges.pl, scripts/dpkg-gencontrol.pl, + scripts/dpkg-source.pl: Use the new variables to properly ignore + valid fields. Some related cleanup. + 2008-01-11 Raphael Hertzog * scripts/dpkg-gencontrol.pl: Also force version in ${binary:Version} diff --git a/scripts/Dpkg/Fields.pm b/scripts/Dpkg/Fields.pm index 97d6c465..06500b49 100644 --- a/scripts/Dpkg/Fields.pm +++ b/scripts/Dpkg/Fields.pm @@ -4,9 +4,32 @@ use strict; use warnings; use Exporter; -our @ISA = qw(Exporter); -our @EXPORT_OK = qw(capit set_field_importance sort_field_by_importance); +use Dpkg::Deps qw(@src_dep_fields @pkg_dep_fields); +our @ISA = qw(Exporter); +our @EXPORT_OK = qw(capit set_field_importance sort_field_by_importance + %control_src_fields %control_pkg_fields $control_src_field_regex + $control_pkg_field_regex); +our %EXPORT_TAGS = ('list' => [qw(%control_src_fields %control_pkg_fields + $control_src_field_regex $control_pkg_field_regex)]); + +# Some variables (list of fields) +our %control_src_fields; +our %control_pkg_fields; +$control_src_fields{$_} = 1 foreach (qw(Bugs + Homepage Origin Maintainer Priority Section Source Standards-Version + Uploaders Vcs-Browser Vcs-Arch Vcs-Bzr Vcs-Cvs Vcs-Darcs Vcs-Git Vcs-Hg + Vcs-Mtn Vcs-Svn)); +$control_src_fields{$_} = 1 foreach (@src_dep_fields); +$control_pkg_fields{$_} = 1 foreach (qw(Architecture Bugs Description Essential + Homepage Installer-Menu-Item Kernel-Version Package Package-Type + Priority Section Subarchitecture Tag)); +$control_pkg_fields{$_} = 1 foreach (@pkg_dep_fields); + +our $control_src_field_regex = "(?:" . join("|", keys %control_src_fields) . ")"; +our $control_pkg_field_regex = "(?:" . join("|", keys %control_pkg_fields) . ")"; + +# Some functions sub capit { my @pieces = map { ucfirst(lc) } split /-/, $_[0]; return join '-', @pieces; diff --git a/scripts/dpkg-genchanges.pl b/scripts/dpkg-genchanges.pl index 625f3c74..20e546bd 100755 --- a/scripts/dpkg-genchanges.pl +++ b/scripts/dpkg-genchanges.pl @@ -11,7 +11,7 @@ use Dpkg::Gettext; use Dpkg::ErrorHandling qw(warning error failure unknown internerr syserr subprocerr usageerr); use Dpkg::Arch qw(get_host_arch debarch_eq debarch_is); -use Dpkg::Fields qw(capit set_field_importance sort_field_by_importance); +use Dpkg::Fields qw(:list capit set_field_importance sort_field_by_importance); use Dpkg::Compression; use Dpkg::Control; use Dpkg::Cdata; @@ -230,16 +230,17 @@ foreach $_ (keys %{$src_fields}) { my $v = $src_fields->{$_}; if (m/^Source$/) { set_source_package($v); + } elsif (m/^Section$|^Priority$/i) { + $sourcedefault{$_} = $v; + } elsif (m/^Maintainer$/i) { + $fields->{$_} = $v; + } elsif (s/^X[BS]*C[BS]*-//i) { # Include XC-* fields + $fields->{$_} = $v; + } elsif (m/^X[BS]+-/i || m/^$control_src_field_regex$/i) { + # Silently ignore valid fields + } else { + unknown(_g('general section of control info file')); } - elsif (m/^Section$|^Priority$/i) { $sourcedefault{$_}= $v; } - elsif (m/^Maintainer$/i) { $fields->{$_} = $v; } - elsif (s/^X[BS]*C[BS]*-//i) { $fields->{$_} = $v; } - elsif (m/^X[BS]+-/i || - m/^Build-(Depends|Conflicts)(-Indep)?$/i || - m/^(Standards-Version|Uploaders|Homepage|Origin|Bugs)$/i || - m/^Vcs-(Browser|Arch|Bzr|Cvs|Darcs|Git|Hg|Mtn|Svn)$/i) { - } - else { &unknown(_g('general section of control info file')); } } # Scan control info of all binary packages @@ -275,7 +276,7 @@ foreach my $pkg ($control->get_packages()) { $f2seccf{$_} = $v foreach (@f); } elsif (m/^Priority$/) { $f2pricf{$_} = $v foreach (@f); - } elsif (s/^X[BS]*C[BS]*-//i) { + } elsif (s/^X[BS]*C[BS]*-//i) { # Include XC-* fields $fields->{$_} = $v; } elsif (m/^Architecture$/) { if (not is_sourceonly) { @@ -289,13 +290,10 @@ foreach my $pkg ($control->get_packages()) { $v = ''; } push(@archvalues,$v) unless !$v || $archadded{$v}++; - } elsif (m/^(Package|Package-Type|Kernel-Version|Essential)$/ || - m/^(Homepage|Tag|Installer-Menu-Item|Subarchitecture)$/i || - m/^(Pre-Depends|Depends|Recommends|Suggests|Provides)$/ || - m/^(Enhances|Conflicts|Breaks|Replaces)$/ || - m/^X[BS]+-/i) { + } elsif (m/^$control_pkg_field_regex$/ || m/^X[BS]+-/i) { + # Silently ignore valid fields } else { - &unknown(_g("package's section of control info file")); + unknown(_g("package's section of control info file")); } } } @@ -313,7 +311,7 @@ foreach $_ (keys %{$changelog}) { } elsif (s/^X[BS]*C[BS]*-//i) { $fields->{$_} = $v; } elsif (!m/^X[BS]+-/i) { - &unknown(_g("parsed version of changelog")); + unknown(_g("parsed version of changelog")); } } diff --git a/scripts/dpkg-gencontrol.pl b/scripts/dpkg-gencontrol.pl index 3321c537..beeed4bf 100755 --- a/scripts/dpkg-gencontrol.pl +++ b/scripts/dpkg-gencontrol.pl @@ -11,7 +11,7 @@ use Dpkg::ErrorHandling qw(warning error failure unknown internerr syserr subprocerr usageerr); use Dpkg::Arch qw(get_host_arch debarch_eq debarch_is); use Dpkg::Deps qw(@pkg_dep_fields %dep_field_type); -use Dpkg::Fields qw(capit set_field_importance); +use Dpkg::Fields qw(:list capit set_field_importance); use Dpkg::Control; use Dpkg::Substvars; use Dpkg::Vars; @@ -147,30 +147,23 @@ my %pkg_dep_fields = map { $_ => 1 } @pkg_dep_fields; my $src_fields = $control->get_source(); foreach $_ (keys %{$src_fields}) { my $v = $src_fields->{$_}; - if (m/^(Origin|Bugs|Maintainer)$/) { - $fields->{$_} = $v; - } elsif (m/^(Section|Priority|Homepage)$/) { + if (m/^(Origin|Bugs|Maintainer|Section|Priority|Homepage)$/) { $fields->{$_} = $v; } elsif (m/^Source$/) { set_source_package($v); + } elsif (s/^X[CS]*B[CS]*-//i) { # Include XB-* fields + $fields->{$_} = $v; + } elsif (m/^X[CS]+-/i || m/^$control_src_field_regex$/i) { + # Silently ignore valid fields + } else { + unknown(_g('general section of control info file')); } - elsif (s/^X[CS]*B[CS]*-//i) { $fields->{$_} = $v; } - elsif (m/^X[CS]+-/i || - m/^Build-(Depends|Conflicts)(-Indep)?$/i || - m/^(Standards-Version|Uploaders)$/i || - m/^Vcs-(Browser|Arch|Bzr|Cvs|Darcs|Git|Hg|Mtn|Svn)$/i) { - } - else { &unknown(_g('general section of control info file')); } } # Scan binary package foreach $_ (keys %{$pkg}) { my $v = $pkg->{$_}; - if (m/^(Package|Package-Type|Description|Homepage|Tag|Essential)$/ || - m/^(Section$|Priority)$/ || - m/^(Subarchitecture|Kernel-Version|Installer-Menu-Item)$/) { - $fields->{$_} = $v; - } elsif (exists($pkg_dep_fields{$_})) { + if (exists($pkg_dep_fields{$_})) { # Delay the parsing until later } elsif (m/^Architecture$/) { my $host_arch = get_host_arch(); @@ -191,10 +184,12 @@ foreach $_ (keys %{$pkg}) { $host_arch, "@archlist"); $fields->{$_} = $host_arch; } - } elsif (s/^X[CS]*B[CS]*-//i) { - $fields->{$_}= $v; + } elsif (m/^$control_pkg_field_regex$/) { + $fields->{$_} = $v; + } elsif (s/^X[CS]*B[CS]*-//i) { # Include XB-* fields + $fields->{$_} = $v; } elsif (!m/^X[CS]+-/i) { - &unknown(_g("package's section of control info file")); + unknown(_g("package's section of control info file")); } } @@ -211,7 +206,7 @@ foreach $_ (keys %{$changelog}) { } elsif (s/^X[CS]*B[CS]*-//i) { $fields->{$_} = $v; } elsif (!m/^X[CS]+-/i) { - &unknown(_g("parsed version of changelog")); + unknown(_g("parsed version of changelog")); } } diff --git a/scripts/dpkg-source.pl b/scripts/dpkg-source.pl index f8445a1e..46056e7b 100755 --- a/scripts/dpkg-source.pl +++ b/scripts/dpkg-source.pl @@ -10,7 +10,7 @@ use Dpkg::ErrorHandling qw(warning warnerror error failure unknown $warnable_error $quiet_warnings); use Dpkg::Arch qw(debarch_eq); use Dpkg::Deps qw(@src_dep_fields %dep_field_type); -use Dpkg::Fields qw(capit set_field_importance); +use Dpkg::Fields qw(:list capit set_field_importance); use Dpkg::Compression; use Dpkg::Cdata; use Dpkg::Control; @@ -311,9 +311,9 @@ if ($opmode eq 'build') { } elsif (m/^(Standards-Version|Origin|Maintainer|Homepage)$/i || m/^Vcs-(Browser|Arch|Bzr|Cvs|Darcs|Git|Hg|Mtn|Svn)$/i) { $fields->{$_} = $v; - } - elsif (m/^Uploaders$/i) { ($fields->{$_} = $v) =~ s/[\r\n]//g; } - elsif (m/^Build-(Depends|Conflicts)(-Indep)?$/i) { + } elsif (m/^Uploaders$/i) { + ($fields->{$_} = $v) =~ s/[\r\n]//g; # Merge in a single-line + } elsif (m/^Build-(Depends|Conflicts)(-Indep)?$/i) { my $dep; my $type = $dep_field_type{capit($_)}; $dep = Dpkg::Deps::parse($v, union => $type eq 'union'); @@ -322,10 +322,13 @@ if ($opmode eq 'build') { $dep->simplify_deps($facts); $dep->sort(); $fields->{$_} = $dep->dump(); + } elsif (s/^X[BC]*S[BC]*-//i) { # Include XS-* fields + $fields->{$_} = $v; + } elsif (m/^$control_src_field_regex$/i || m/^X[BC]+-/i) { + # Silently ignore valid fields + } else { + unknown(_g('general section of control info file')); } - elsif (s/^X[BC]*S[BC]*-//i) { $fields->{$_} = $v; } - elsif (m/^(Section|Priority|Files|Bugs)$/i || m/^X[BC]+-/i) { } - else { &unknown(_g('general section of control info file')); } } # Scan control info of binary packages @@ -360,16 +363,12 @@ if ($opmode eq 'build') { } } $fields->{'Architecture'}= join(' ',@sourcearch); - } elsif (s/^X[BC]*S[BC]*-//i) { + } elsif (s/^X[BC]*S[BC]*-//i) { # Include XS-* fields $fields->{$_} = $v; - } elsif (m/^(Package|Package-Type|Essential|Kernel-Version)$/ || - m/^(Homepage|Subarchitecture|Installer-Menu-Item)$/i || - m/^(Pre-Depends|Depends|Provides)$/i || - m/^(Recommends|Suggests|Conflicts|Replaces)$/i || - m/^(Breaks|Enhances|Description|Tag|Section|Priority)$/i || - m/^X[BC]+-/i) { + } elsif (m/^$control_pkg_field_regex$/ || + m/^X[BC]+-/i) { # Silently ignore valid fields } else { - &unknown(_g("package's section of control info file")); + unknown(_g("package's section of control info file")); } } } @@ -388,7 +387,7 @@ if ($opmode eq 'build') { } elsif (m/^(Maintainer|Changes|Urgency|Distribution|Date|Closes)$/i || m/^X[BS]+-/i) { } else { - &unknown(_g("parsed version of changelog")); + unknown(_g("parsed version of changelog")); } }