ソースを参照

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.
Raphael Hertzog 18 年 前
コミット
5fb2ef86c8
共有5 個のファイルを変更した69 個の追加11 個の削除を含む
  1. 6 0
      ChangeLog
  2. 53 0
      scripts/Dpkg/Vars.pm
  3. 3 3
      scripts/dpkg-genchanges.pl
  4. 3 3
      scripts/dpkg-gencontrol.pl
  5. 4 5
      scripts/dpkg-source.pl

+ 6 - 0
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  <hertzog@debian.org>
 
 	* scripts/Dpkg/ErrorHandling.pm (syntaxerr): New function to

+ 53 - 0
scripts/Dpkg/Vars.pm

@@ -0,0 +1,53 @@
+# Copyright 2007 Raphaël Hertzog <hertzog@debian.org>
+
+# 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;

+ 3 - 3
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) {

+ 3 - 3
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);

+ 4 - 5
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;