Kaynağa Gözat

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 yıl önce
ebeveyn
işleme
f22c0f006f
3 değiştirilmiş dosya ile 25 ekleme ve 9 silme
  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
   * Optimize dpkg-source -b by avoiding many diff calls when not required.
     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 ]
   * 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
 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
 .BR \-h ", " \-\-help
 Show the usage message and exit.

+ 17 - 9
scripts/dpkg-source.pl

@@ -71,9 +71,11 @@ my @cmdline_formats;
 while (@ARGV && $ARGV[0] =~ m/^-/) {
     $_ = shift(@ARGV);
     if (m/^-b$/) {
-        setopmode('build');
+        setopmode('-b');
     } elsif (m/^-x$/) {
-        setopmode('extract');
+        setopmode('-x');
+    } elsif (m/^--print-format$/) {
+	setopmode('--print-format');
     } elsif (m/^--format=(.*)$/) {
         push @cmdline_formats, $1;
     } elsif (m/^-Z(.*)$/) {
@@ -142,10 +144,10 @@ unless (defined($options{'opmode'})) {
     usageerr(_g("need -x or -b"));
 }
 
-if ($options{'opmode'} eq 'build') {
+if ($options{'opmode'} =~ /^(-b|--print-format)$/) {
 
     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));
     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
         my ($res, $msg) = $srcpkg->can_build($dir);
         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'});
 
@@ -290,7 +297,7 @@ if ($options{'opmode'} eq 'build') {
 		       substvars => $substvars);
     exit(0);
 
-} elsif ($options{'opmode'} eq 'extract') {
+} elsif ($options{'opmode'} eq '-x') {
 
     # Check command line
     unless (scalar(@ARGV)) {
@@ -344,7 +351,7 @@ if ($options{'opmode'} eq 'build') {
 
 sub setopmode {
     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];
 }
@@ -369,8 +376,9 @@ sub usage {
 Commands:
   -x <filename>.dsc [<output-dir>]
                            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:
   -c<controlfile>          get control info from this file.