Parcourir la source

dpkg-buildpackage: new option to call arbitrary debian/rules targets

* scripts/dpkg-buildpackage.pl: Add new option --target/-T to
allow a specific debian/rules target to be run. The new --as-root
option forces the target to be run with root rights.
Add support for the two common syntaxes for long
options ("--admindir=…" and "--admindir …").
* man/dpkg-buildpackage.1: Update documentation accordingly.
Raphael Hertzog il y a 17 ans
Parent
commit
66264bb266
4 fichiers modifiés avec 62 ajouts et 2 suppressions
  1. 9 0
      ChangeLog
  2. 3 0
      debian/changelog
  3. 25 2
      man/dpkg-buildpackage.1
  4. 25 0
      scripts/dpkg-buildpackage.pl

+ 9 - 0
ChangeLog

@@ -1,3 +1,12 @@
+2009-02-11  Raphael Hertzog  <hertzog@debian.org>
+
+	* scripts/dpkg-buildpackage.pl: Add new option --target/-T to
+	allow a specific debian/rules target to be run. The new --as-root
+	option forces the target to be run with root rights.
+	Add support for the two common syntaxes for long
+	options	("--admindir=…" and "--admindir …").
+	* man/dpkg-buildpackage.1: Update documentation accordingly.
+
 2009-02-11  Raphael Hertzog  <hertzog@debian.org>
 
 	* man/dpkg-buildpackage.1: Fix name of binary target in default

+ 3 - 0
debian/changelog

@@ -138,6 +138,9 @@ dpkg (1.15.0) UNRELEASED; urgency=low
     installed is the one currently selected. Closes: #100135
   * Let update-alternatives deal with empty files in its administrative
     directory by ignoring them. Closes: #457863
+  * Add new --target and --as-root options to dpkg-buildpackage to call
+    any debian/rules target with the proper build environment.
+    Closes: #477916
 
   [ Pierre Habouzit ]
   * Add a --query option to update-alternatives. Closes: #336091, #441904

+ 25 - 2
man/dpkg-buildpackage.1

@@ -17,7 +17,9 @@ variables (see \fBENVIRONMENT VARIABLES\fP).
 It checks that the build-dependencies and build-conflicts
 are satisfied (unless \fB\-d\fP is specified).
 .IP \fB3.\fP 3
-It calls \fBfakeroot debian/rules clean\fP to clean the build-tree (unless
+If a specific target has been selected with the \fB-T\fP or \fB--target\fP
+option, it calls that target and stops here. Otherwise it calls
+\fBfakeroot debian/rules clean\fP to clean the build-tree (unless
 \fB\-nc\fP is specified).
 .IP \fB4.\fP 3
 It calls \fBdpkg-source\fP to generate the source package (unless
@@ -62,6 +64,23 @@ packages. Passed to \fBdpkg-genchanges\fP.
 Specifies a source-only build, no binary packages need to be made.
 Passed to \fBdpkg-genchanges\fP.
 .P
+.BI \-\-target= target
+.br
+.BI "\-\-target " target
+.br
+.BI \-T target
+.RS
+Calls \fBdebian/rules\fP \fItarget\fP after having setup the build
+environment and stops the package build process here. If
+\fB\-\-as\-root\fP is also given, then the command is executed
+as root (see \fB\-r\fP). Note that official targets that are required to
+be run as root by the Debian policy do not need this option.
+.RE
+.TP
+.B \-\-as\-root
+Only meaningful together with \fB\-\-target\fP. Requires that the target be
+run with root rights.
+.P
 .B \-si
 .br
 .B \-sa
@@ -186,10 +205,14 @@ Do not sign the \fB.changes\fP file.
 .RS
 Passed unchanged to \fBdpkg\-source\fP. See its manual page.
 .RE
-.TP
+.P
 .BI \-\-admindir= dir
+.br
+.BI "\-\-admindir " dir
+.RS
 Change the location of the \fBdpkg\fR database. The default location is
 \fI/var/lib/dpkg\fP.
+.RE
 .TP
 .BR \-h ", " \-\-help
 Show the usage message and exit.

+ 25 - 0
scripts/dpkg-buildpackage.pl

@@ -43,6 +43,8 @@ Options:
   -p<sign-command>
   -d             do not check build dependencies and conflicts.
   -D             check build dependencies and conflicts.
+  -T<target>     call debian/rules <target> with the proper environment
+  --as-root      ensure -T calls the target with root rights
   -j[<number>]   specify jobs to run simultaneously } passed to debian/rules
   -k<keyid>      the key to use for signing.
   -sgpg          the sign-command is called like GPG.
@@ -102,6 +104,8 @@ my $signchanges = 1;
 my $diffignore = '';
 my $binarytarget = 'binary';
 my $targetarch = my $targetgnusystem = '';
+my $call_target = '';
+my $call_target_as_root = 0;
 
 while (@ARGV) {
     $_ = shift @ARGV;
@@ -112,6 +116,8 @@ while (@ARGV) {
     } elsif (/^--version$/) {
 	showversion;
 	exit 0;
+    } elsif (/^--admindir$/) {
+        $admindir = shift @ARGV;
     } elsif (/^--admindir=(.*)$/) {
 	$admindir = $1;
     } elsif (/^-j(\d*)$/) {
@@ -149,6 +155,12 @@ while (@ARGV) {
 	$cleansource = 1;
     } elsif (/^-t(.*)$/) {
 	$targetgnusystem = $1; # Order DOES matter!
+    } elsif (/^(--target|-T)$/) {
+        $call_target = shift @ARGV;
+    } elsif (/^(--target=|-T)(.+)$/) {
+        $call_target = $2;
+    } elsif (/^--as-root$/) {
+        $call_target_as_root = 1;
     } elsif (/^-nc$/) {
 	$noclean = 1;
 	if ($sourceonly) {
@@ -333,6 +345,8 @@ unless ($sourceonly) {
     $arch = 'source';
 }
 
+# Preparation of environment stops here
+
 (my $sversion = $version) =~ s/^\d+://;
 
 my $pv = "${pkg}_$sversion";
@@ -356,6 +370,17 @@ if ($checkbuilddep) {
     }
 }
 
+if ($call_target) {
+    if ($call_target_as_root or
+        $call_target =~ /^(clean|binary(|-arch|-indep))$/)
+    {
+        withecho(@rootcommand, @debian_rules, $call_target);
+    } else {
+        withecho(@debian_rules, $call_target);
+    }
+    exit 0;
+}
+
 unless ($noclean) {
     withecho(@rootcommand, @debian_rules, 'clean');
 }