From 5fb2ef86c87de7b4821fca99d7db15af2d5ec204 Mon Sep 17 00:00:00 2001 From: Raphael Hertzog Date: Tue, 1 Jan 2008 15:50:01 +0100 Subject: [PATCH] Dpkg::Vars: New module handling the global variable $sourcepackage * scripts/Dpkg/Vars.pm: New module exporting $sourcepackage and set_source_package to replace the $sourcepackage and setsourcepackage of controllib.pl. * scripts/dpkg-genchanges.pl: Updated to use Dpkg::Vars. * scripts/dpkg-gencontrol.pl: Likewise. * scripts/dpkg-source.pl: Likewise. --- ChangeLog | 6 +++++ scripts/Dpkg/Vars.pm | 53 ++++++++++++++++++++++++++++++++++++++ scripts/dpkg-genchanges.pl | 6 ++--- scripts/dpkg-gencontrol.pl | 6 ++--- scripts/dpkg-source.pl | 9 +++---- 5 files changed, 69 insertions(+), 11 deletions(-) create mode 100644 scripts/Dpkg/Vars.pm diff --git a/ChangeLog b/ChangeLog index fa122b14..7be0ffae 100644 --- a/ChangeLog +++ b/ChangeLog @@ -41,6 +41,12 @@ * scripts/dpkg-source.pl, scripts/dpkg-buildpackage.pl: Use the new check_version. + * scripts/Dpkg/Vars.pm (set_source_package): New function to set + and check the global variable $sourcepackage (replacing + controllib's setsourcepackage). + * scripts/dpkg-genchanges.pl, scripts/dpkg-gencontrol.pl, + scripts/dpkg-source.pl: Use the new set_source_package. + 2007-12-28 Raphael Hertzog * scripts/Dpkg/ErrorHandling.pm (syntaxerr): New function to diff --git a/scripts/Dpkg/Vars.pm b/scripts/Dpkg/Vars.pm new file mode 100644 index 00000000..d9fc1273 --- /dev/null +++ b/scripts/Dpkg/Vars.pm @@ -0,0 +1,53 @@ +# Copyright 2007 Raphaël Hertzog + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +package Dpkg::Vars; + +use strict; +use warnings; + +use Dpkg::ErrorHandling qw(error); +use Dpkg::Gettext; + +use Exporter; +our @ISA = qw(Exporter); +our @EXPORT = qw($sourcepackage set_source_package); + +our $sourcepackage; + +sub check_package_name { + my $name = shift || ''; + $name =~ m/[^-+.0-9a-z]/o && + error(_g("source package name `%s' contains illegal character `%s'"), + $name, $&); + $name =~ m/^[0-9a-z]/o || + error(_g("source package name `%s' starts with non-alphanum"), $name); +} + +sub set_source_package { + my $v = shift; + + check_package_name($v); + if (defined($sourcepackage)) { + $v eq $sourcepackage || + error(_g("source package has two conflicting values - %s and %s"), + $sourcepackage, $v); + } else { + $sourcepackage = $v; + } +} + +1; diff --git a/scripts/dpkg-genchanges.pl b/scripts/dpkg-genchanges.pl index 972a288b..165d28b4 100755 --- a/scripts/dpkg-genchanges.pl +++ b/scripts/dpkg-genchanges.pl @@ -16,12 +16,12 @@ use Dpkg::Compression; use Dpkg::Control; use Dpkg::Cdata; use Dpkg::Substvars; +use Dpkg::Vars; push(@INC,$dpkglibdir); require 'controllib.pl'; our (%fi); -our $sourcepackage; textdomain("dpkg-dev"); @@ -233,7 +233,7 @@ my $src_fields = $control->get_source(); foreach $_ (keys %{$src_fields}) { my $v = $src_fields->{$_}; if (m/^Source$/) { - setsourcepackage($v); + set_source_package($v); } elsif (m/^Section$|^Priority$/i) { $sourcedefault{$_}= $v; } elsif (m/^Maintainer$/i) { $fields->{$_} = $v; } @@ -310,7 +310,7 @@ for $_ (keys %fi) { if (s/^L //) { if (m/^Source$/i) { - setsourcepackage($v); + set_source_package($v); } elsif (m/^Maintainer$/i) { $fields->{"Changed-By"} = $v; } elsif (m/^(Version|Changes|Urgency|Distribution|Date|Closes)$/i) { diff --git a/scripts/dpkg-gencontrol.pl b/scripts/dpkg-gencontrol.pl index a86baa84..104f8591 100755 --- a/scripts/dpkg-gencontrol.pl +++ b/scripts/dpkg-gencontrol.pl @@ -14,12 +14,12 @@ use Dpkg::Deps qw(@pkg_dep_fields %dep_field_type); use Dpkg::Fields qw(capit set_field_importance); use Dpkg::Control; use Dpkg::Substvars; +use Dpkg::Vars; push(@INC,$dpkglibdir); require 'controllib.pl'; our %fi; -our $sourcepackage; textdomain("dpkg-dev"); @@ -155,7 +155,7 @@ foreach $_ (keys %{$src_fields}) { } elsif (m/^(Section|Priority|Homepage)$/) { $fields->{$_} = $v; } elsif (m/^Source$/) { - setsourcepackage($v); + set_source_package($v); } elsif (s/^X[CS]*B[CS]*-//i) { $fields->{$_} = $v; } elsif (m/^X[CS]+-/i || @@ -206,7 +206,7 @@ for $_ (keys %fi) { if (s/^L //) { if (m/^Source$/) { - setsourcepackage($v); + set_source_package($v); } elsif (m/^Version$/) { $sourceversion = $v; $fields->{$_} = $v unless defined($forceversion); diff --git a/scripts/dpkg-source.pl b/scripts/dpkg-source.pl index 2cbbd292..6fee10e1 100755 --- a/scripts/dpkg-source.pl +++ b/scripts/dpkg-source.pl @@ -16,6 +16,7 @@ use Dpkg::Cdata; use Dpkg::Control; use Dpkg::Substvars; use Dpkg::Version qw(check_version); +use Dpkg::Vars; my @filesinarchive; my %dirincluded; @@ -116,7 +117,6 @@ push (@INC, $dpkglibdir); require 'controllib.pl'; our (%fi); -our $sourcepackage; our @src_dep_fields; textdomain("dpkg-dev"); @@ -312,7 +312,7 @@ if ($opmode eq 'build') { foreach $_ (keys %{$src_fields}) { my $v = $src_fields->{$_}; if (m/^Source$/i) { - setsourcepackage($v); + set_source_package($v); } elsif (m/^(Standards-Version|Origin|Maintainer|Homepage)$/i || m/^Vcs-(Browser|Arch|Bzr|Cvs|Darcs|Git|Hg|Mtn|Svn)$/i) { $fields->{$_} = $v; @@ -384,7 +384,7 @@ if ($opmode eq 'build') { if (s/^L //) { if (m/^Source$/) { - setsourcepackage($v); + set_source_package($v); } elsif (m/^Version$/) { check_version($v); $fields->{$_} = $v; @@ -859,8 +859,7 @@ if ($opmode eq 'build') { $dscformat=$fields->{'Format'}; } - $sourcepackage = $fields->{'Source'}; # XXX: should use setsourcepackage?? - checkpackagename( $sourcepackage ); + set_source_package($fields->{'Source'}); my $version = $fields->{'Version'}; my $baseversion; -- 2.39.5