Просмотр исходного кода

dpkg-source: add new --print-format command

This new command prints the source format that would be used to build the
source package if "dpkg-source -b directory" was called (in the same
conditions and with the same options).
Raphaël Hertzog лет назад: 16
Родитель
Сommit
f22c0f006f
3 измененных файлов с 25 добавлено и 9 удалено
  1. 2 0
      debian/changelog
  2. 6 0
      man/dpkg-source.1
  3. 17 9
      scripts/dpkg-source.pl

+ 2 - 0
debian/changelog

@@ -76,6 +76,8 @@ dpkg (1.15.5) UNRELEASED; urgency=low
     Thanks to Courtney Bane for the patch. Closes: #551829
     Thanks to Courtney Bane for the patch. Closes: #551829
   * Optimize dpkg-source -b by avoiding many diff calls when not required.
   * Optimize dpkg-source -b by avoiding many diff calls when not required.
     Thanks to Mike Hommey for the idea. Closes: #554689
     Thanks to Mike Hommey for the idea. Closes: #554689
+  * Add new option --print-format to dpkg-source to be able to know by advance
+    the source format that would be used during a build.
 
 
   [ Updated dpkg translations ]
   [ Updated dpkg translations ]
   * Czech (Miroslav Kure).
   * Czech (Miroslav Kure).

+ 6 - 0
man/dpkg-source.1

@@ -62,6 +62,12 @@ the format indicated in \fBdebian/source/format\fP,
 "1.0", "3.0 (native)". See section \fBSOURCE PACKAGE FORMATS\fP for an
 "1.0", "3.0 (native)". See section \fBSOURCE PACKAGE FORMATS\fP for an
 extensive description of the various source package formats.
 extensive description of the various source package formats.
 
 
+.TP
+.RI "\fB\-\-print\-format\fP " directory
+Print the source format that would be used to build the source package if
+\fBdpkg\-source \-b \fIdirectory\fR was called (in the same conditions and
+with the same options).
+
 .TP
 .TP
 .BR \-h ", " \-\-help
 .BR \-h ", " \-\-help
 Show the usage message and exit.
 Show the usage message and exit.

+ 17 - 9
scripts/dpkg-source.pl

@@ -71,9 +71,11 @@ my @cmdline_formats;
 while (@ARGV && $ARGV[0] =~ m/^-/) {
 while (@ARGV && $ARGV[0] =~ m/^-/) {
     $_ = shift(@ARGV);
     $_ = shift(@ARGV);
     if (m/^-b$/) {
     if (m/^-b$/) {
-        setopmode('build');
+        setopmode('-b');
     } elsif (m/^-x$/) {
     } elsif (m/^-x$/) {
-        setopmode('extract');
+        setopmode('-x');
+    } elsif (m/^--print-format$/) {
+	setopmode('--print-format');
     } elsif (m/^--format=(.*)$/) {
     } elsif (m/^--format=(.*)$/) {
         push @cmdline_formats, $1;
         push @cmdline_formats, $1;
     } elsif (m/^-Z(.*)$/) {
     } elsif (m/^-Z(.*)$/) {
@@ -142,10 +144,10 @@ unless (defined($options{'opmode'})) {
     usageerr(_g("need -x or -b"));
     usageerr(_g("need -x or -b"));
 }
 }
 
 
-if ($options{'opmode'} eq 'build') {
+if ($options{'opmode'} =~ /^(-b|--print-format)$/) {
 
 
     if (not scalar(@ARGV)) {
     if (not scalar(@ARGV)) {
-	usageerr(_g("-b needs a directory"));
+	usageerr(_g("%s needs a directory"), $options{'opmode'});
     }
     }
     my $dir = File::Spec->catdir(shift(@ARGV));
     my $dir = File::Spec->catdir(shift(@ARGV));
     stat($dir) || syserr(_g("cannot stat directory %s"), $dir);
     stat($dir) || syserr(_g("cannot stat directory %s"), $dir);
@@ -268,7 +270,12 @@ if ($options{'opmode'} eq 'build') {
         $srcpkg->upgrade_object_type(); # Fails if format is unsupported
         $srcpkg->upgrade_object_type(); # Fails if format is unsupported
         my ($res, $msg) = $srcpkg->can_build($dir);
         my ($res, $msg) = $srcpkg->can_build($dir);
         last if $res;
         last if $res;
-        info(_g("source format `%s' discarded: %s"), $format, $msg);
+        info(_g("source format `%s' discarded: %s"), $format, $msg)
+	    unless $options{'opmode'} eq "--print-format";
+    }
+    if ($options{'opmode'} eq "--print-format") {
+	print $fields->{'Format'} . "\n";
+	exit(0);
     }
     }
     info(_g("using source format `%s'"), $fields->{'Format'});
     info(_g("using source format `%s'"), $fields->{'Format'});
 
 
@@ -290,7 +297,7 @@ if ($options{'opmode'} eq 'build') {
 		       substvars => $substvars);
 		       substvars => $substvars);
     exit(0);
     exit(0);
 
 
-} elsif ($options{'opmode'} eq 'extract') {
+} elsif ($options{'opmode'} eq '-x') {
 
 
     # Check command line
     # Check command line
     unless (scalar(@ARGV)) {
     unless (scalar(@ARGV)) {
@@ -344,7 +351,7 @@ if ($options{'opmode'} eq 'build') {
 
 
 sub setopmode {
 sub setopmode {
     if (defined($options{'opmode'})) {
     if (defined($options{'opmode'})) {
-	usageerr(_g("only one of -x or -b allowed, and only once"));
+	usageerr(_g("only one of -x, -b or --print-format allowed, and only once"));
     }
     }
     $options{'opmode'} = $_[0];
     $options{'opmode'} = $_[0];
 }
 }
@@ -369,8 +376,9 @@ sub usage {
 Commands:
 Commands:
   -x <filename>.dsc [<output-dir>]
   -x <filename>.dsc [<output-dir>]
                            extract source package.
                            extract source package.
-  -b <dir>
-                           build source package.
+  -b <dir>                 build source package.
+  --print-format <dir>     print the source format that would be
+                           used to build the source package.
 
 
 Build options:
 Build options:
   -c<controlfile>          get control info from this file.
   -c<controlfile>          get control info from this file.