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

dpkg-source: Rework command parsing and add --build and --extract aliases

This uses the long command names w/o the -- to select the actions to
take, rewords some usage error messages to be more generic and
maintainable (by not listing each command supported), and add the long
aliases for the most common commands.
Guillem Jover лет назад: 11
Родитель
Сommit
8f3c317bf1
3 измененных файлов с 55 добавлено и 45 удалено
  1. 1 0
      debian/changelog
  2. 15 11
      man/dpkg-source.1
  3. 39 34
      scripts/dpkg-source.pl

+ 1 - 0
debian/changelog

@@ -103,6 +103,7 @@ dpkg (1.17.14) UNRELEASED; urgency=low
   * Say arch-wildcard instead of arch-alias in dpkg-architecture --help output.
   * Test suite:
     - Do not leave temporary files behind on failure or when interrupted.
+  * Add --build and --extract command aliases to dpkg-source.
 
   [ Raphaël Hertzog ]
   * Explain better in deb-triggers(5) why interest/activate-noawait should be

+ 15 - 11
man/dpkg-source.1

@@ -38,8 +38,10 @@ separate argument.
 .
 .SH COMMANDS
 .TP
-.BI "\-x " filename ".dsc " \fR[\fPoutput-directory\fR]\fP
-Extract a source package. One non-option argument must be supplied,
+.BR \-x ", " \-\-extract " \fIfilename\fP.dsc [\fIoutput-directory\fP]"
+Extract a source package.
+The \fB\-\-extract\fP alias was added in dpkg 1.17.14.
+One non-option argument must be supplied,
 the name of the Debian source control file
 .RB ( .dsc ).
 An optional second non-option argument may be supplied to specify the
@@ -68,8 +70,10 @@ formats except "1.0"), its name will be stored in
 package use the same format by default.
 
 .TP
-.RI "\fB\-b\fP " directory " [" format-specific-parameters ]
-Build a source package. The first non-option argument is taken as the
+.BR \-b ", " \-\-build " \fIdirectory\fP [\fIformat-specific-parameters\fP]"
+Build a source package.
+The \fB\-\-build\fP alias was added in dpkg 1.17.14.
+The first non-option argument is taken as the
 name of the directory containing the debianized source tree (i.e. with a
 debian sub-directory and maybe changes to the original files).
 Depending on the source package format used to build the package,
@@ -87,8 +91,8 @@ 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 parameters).
+\fBdpkg\-source \-\-build \fIdirectory\fR was called (in the same conditions
+and with the same parameters).
 
 .TP
 .RI "\fB\-\-before\-build\fP " directory
@@ -287,7 +291,7 @@ extracting the original tarball in a separate ".orig" directory and
 regenerating the \fB.diff.gz\fP by comparing the source package
 \fIdirectory\fP with the .orig directory.
 
-.B Build options (with \-b):
+.B Build options (with \-\-build):
 
 If a second non-option argument is supplied it should be the name of the
 original source directory or tarfile or the empty string if the package is
@@ -381,7 +385,7 @@ outside of the debian sub-directory. This option is not allowed in
 \fBdebian/source/local\-options\fP.
 .PP
 
-.B Extract options (with \-x):
+.B Extract options (with \-\-extract):
 
 In all cases any existing original source tree will be removed.
 .TP
@@ -500,7 +504,7 @@ files as well as many temporary files (see default value associated to
 \fB.pc\fP directory used by \fBquilt\fP is ignored during generation of the
 automatic patch.
 
-Note: \fBdpkg\-source\fP \fB\-\-before\-build\fP (and \fB\-b\fP) will
+Note: \fBdpkg\-source\fP \fB\-\-before\-build\fP (and \fB\-\-build\fP) will
 ensure that all patches listed in the series file are applied so that a
 package build always has all patches applied. It does this by finding
 unapplied patches (they are listed in the \fBseries\fP file but not in
@@ -530,7 +534,7 @@ patch must not have supplementary unrecorded changes.
 If the patch generation detects modified binary files, they will be
 automatically added to \fBdebian/source/include\-binaries\fP so that
 they end up in the debian tarball (exactly like \fBdpkg-source
-\-\-include\-binaries \-b\fP would do).
+\-\-include\-binaries \-\-build\fP would do).
 .PP
 .B Build options
 .TP
@@ -726,7 +730,7 @@ included in the debian tarball. Leading and trailing spaces are stripped.
 Lines starting with "#" are comments and are skipped. Empty lines are ignored.
 .SS debian/source/options
 This file contains a list of long options that should be automatically
-prepended to the set of command line options of a \fBdpkg\-source \-b\fR
+prepended to the set of command line options of a \fBdpkg\-source \-\-build\fR
 or \fBdpkg\-source \-\-print\-format\fR call. Options like
 \fB\-\-compression\fR and \fB\-\-compression\-level\fR are well suited for
 this file.

+ 39 - 34
scripts/dpkg-source.pl

@@ -79,29 +79,32 @@ my $diff_ignore_regex = get_default_diff_ignore_regex();
 my @options;
 my @cmdline_options;
 while (@ARGV && $ARGV[0] =~ m/^-/) {
-    $_ = shift(@ARGV);
-    if (m/^-b$/) {
-        setopmode('-b');
-    } elsif (m/^-x$/) {
-        setopmode('-x');
-    } elsif (m/^--(?:before|after)-build$/) {
-        setopmode($_);
-    } elsif (m/^--commit$/) {
-        setopmode($_);
-    } elsif (m/^--print-format$/) {
-	setopmode('--print-format');
+    my $arg = shift @ARGV;
+
+    if ($arg eq '-b' or $arg eq '--build') {
+        setopmode('build');
+    } elsif ($arg eq '-x' or $arg eq '--extract') {
+        setopmode('extract');
+    } elsif ($arg eq '--before-build') {
+        setopmode('before-build');
+    } elsif ($arg eq '--after-build') {
+        setopmode('after-build');
+    } elsif ($arg eq '--commit') {
+        setopmode('commit');
+    } elsif ($arg eq '--print-format') {
+        setopmode('print-format');
 	report_options(info_fh => \*STDERR); # Avoid clutter on STDOUT
     } else {
-	push @options, $_;
+        push @options, $arg;
     }
 }
 
 my $dir;
 if (defined($options{opmode}) &&
-    $options{opmode} =~ /^(-b|--print-format|--(before|after)-build|--commit)$/) {
+    $options{opmode} =~ /^(build|print-format|(before|after)-build|commit)$/) {
     if (not scalar(@ARGV)) {
-	usageerr(_g('%s needs a directory'), $options{opmode})
-	    unless $1 eq '--commit';
+	usageerr(_g('--%s needs a directory'), $options{opmode})
+	    unless $1 eq 'commit';
 	$dir = '.';
     } else {
 	$dir = File::Spec->catdir(shift(@ARGV));
@@ -132,7 +135,7 @@ if (defined($options{opmode}) &&
 	$conf->filter(remove => sub { $_[0] =~ $forbidden_opts_re->{$filename} });
 	if (@$conf) {
 	    info(_g('using options from %s: %s'), $optfile, join(' ', @$conf))
-		unless $options{opmode} eq '--print-format';
+		unless $options{opmode} eq 'print-format';
 	    unshift @options, @$conf;
 	}
     }
@@ -210,10 +213,10 @@ while (@options) {
 }
 
 unless (defined($options{opmode})) {
-    usageerr(_g('need a command (-x, -b, --before-build, --after-build, --print-format, --commit)'));
+    usageerr(_g('need an action option'));
 }
 
-if ($options{opmode} =~ /^(-b|--print-format|--(before|after)-build|--commit)$/) {
+if ($options{opmode} =~ /^(build|print-format|(before|after)-build|commit)$/) {
 
     $options{ARGV} = \@ARGV;
 
@@ -369,7 +372,7 @@ if ($options{opmode} =~ /^(-b|--print-format|--(before|after)-build|--commit)$/)
 	    $fields->{$_} = $v;
 	} elsif (m/^Binary-Only$/) {
 	    error(_g('building source for a binary-only release'))
-	        if $v eq 'yes' and $options{opmode} eq '-b';
+	        if $v eq 'yes' and $options{opmode} eq 'build';
 	} elsif (m/^Maintainer$/i) {
             # Do not replace the field coming from the source entry
 	} else {
@@ -396,7 +399,7 @@ if ($options{opmode} =~ /^(-b|--print-format|--(before|after)-build|--commit)$/)
 	} else {
 	    warning(_g('no source format specified in %s, ' .
 	               'see dpkg-source(1)'), 'debian/source/format')
-		if $options{opmode} eq '-b';
+		if $options{opmode} eq 'build';
 	    $build_format = '1.0';
 	}
     }
@@ -406,16 +409,16 @@ if ($options{opmode} =~ /^(-b|--print-format|--(before|after)-build|--commit)$/)
     $srcpkg->init_options();
     $srcpkg->parse_cmdline_options(@cmdline_options);
 
-    if ($options{opmode} eq '--print-format') {
+    if ($options{opmode} eq 'print-format') {
 	print $fields->{'Format'} . "\n";
 	exit(0);
-    } elsif ($options{opmode} eq '--before-build') {
+    } elsif ($options{opmode} eq 'before-build') {
 	$srcpkg->before_build($dir);
 	exit(0);
-    } elsif ($options{opmode} eq '--after-build') {
+    } elsif ($options{opmode} eq 'after-build') {
 	$srcpkg->after_build($dir);
 	exit(0);
-    } elsif ($options{opmode} eq '--commit') {
+    } elsif ($options{opmode} eq 'commit') {
 	$srcpkg->commit($dir);
 	exit(0);
     }
@@ -439,18 +442,20 @@ if ($options{opmode} =~ /^(-b|--print-format|--(before|after)-build|--commit)$/)
 		       substvars => $substvars);
     exit(0);
 
-} elsif ($options{opmode} eq '-x') {
+} elsif ($options{opmode} eq 'extract') {
 
     # Check command line
     unless (scalar(@ARGV)) {
-	usageerr(_g('-x needs at least one argument, the .dsc'));
+        usageerr(_g('--%s needs at least one argument, the .dsc'),
+                 $options{opmode});
     }
     if (scalar(@ARGV) > 2) {
-	usageerr(_g('-x takes no more than two arguments'));
+        usageerr(_g('--%s takes no more than two arguments'), $options{opmode});
     }
     my $dsc = shift(@ARGV);
     if (-d $dsc) {
-	usageerr(_g('-x needs the .dsc file as first argument, not a directory'));
+        usageerr(_g('--%s needs the .dsc file as first argument, not a directory'),
+                 $options{opmode});
     }
 
     # Create the object that does everything
@@ -511,7 +516,8 @@ sub setopmode {
     my $opmode = shift;
 
     if (defined($options{opmode})) {
-	usageerr(_g('only one of -x, -b or --print-format allowed, and only once'));
+        usageerr(_g('two commands specified: --%s and --%s'),
+                 $options{opmode}, $opmode);
     }
     $options{opmode} = $opmode;
 }
@@ -530,12 +536,11 @@ sub usage {
 'Usage: %s [<option>...] <command>')
     . "\n\n" . _g(
 'Commands:
-  -x <filename>.dsc [<output-dir>]
+  -x, --extract <filename>.dsc [<output-dir>]
                            extract source package.
-  -b <dir>                 build source package.
-  --print-format <dir>     print the source format that would be
-                           used to build the source package.
-  --commit [<dir> [<patch-name>]]
+  -b, --build <dir>        build source package.
+      --print-format <dir> print the format to be used for the source package.
+      --commit [<dir> [<patch-name>]]
                            store upstream changes in a new patch.')
     . "\n\n" . _g(
 "Build options: