[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[PATCH/RFC] dpkg-source: add option to provide arbitrary commands for --before-build



The --before-build-command option specifies commands to be executed at
the beginning of the ‘dpkg-source --before-build’ run.  This option
can be used with any source format and is expected to be mostly used
from debian/source/local-options for such tasks as generating a
changelog from the revision control log.

Do not add a corresponding --after-build-command option; that can
always be added later if it turns out to be useful.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
Hi Raphaël,

As a bit of a purist and a lazy person, I don’t like keeping generated
files in version control.  When upstream does not ship a changelog,
the solution is to write a debian/autogen.sh that automatically
generates a commit log and puts it in the debian/ directory, and ask
people to run it before each build.

When the debian/source/local-options feature appeared, at the back of
my mind I thought, “Could this be used to automatically run
debian/autogen.sh?”  It looks like it could.

This patch might also be useful for those misguided souls that require
autoreconf to be run on developer machines instead of buildds. :)

What do you think?
Jonathan

 debian/changelog       |    7 +++++++
 man/dpkg-source.1      |    9 +++++++++
 scripts/dpkg-source.pl |   26 ++++++++++++++++++++++++--
 3 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 16ddb25..022244c 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -34,6 +34,13 @@ dpkg (1.15.8) UNRELEASED; urgency=low
     - Add versioned Build-Depends.
   * Fix variable usage after delete in dselect.
 
+  [ Jonathan Nieder ]
+  * dpkg-source supports a --before-build-command option specifying an
+    arbitrary command to be run before the standard --before-build
+    hook.  This can be used from debian/source/local-options to specify a
+    command to generate missing source files from a version controlled
+    checkout.
+
   [ Updated programs translations ]
   * Russian (Yuri Kozlov). Closes: #579149
   * Swedish (Peter Krefting).
diff --git a/man/dpkg-source.1 b/man/dpkg-source.1
index 5e4d30b..bac8fa6 100644
--- a/man/dpkg-source.1
+++ b/man/dpkg-source.1
@@ -206,6 +206,15 @@ documentation.
 
 The default regexp and patterns for both options can be seen
 in the output of the \fB\-\-help\fP command.
+.TP
+.BI \-\-before\-build\-command= command
+Set a hook \fIcommand\fP to be run via \*(lqsh -c\*(rq before the
+package format's standard hook for \fB\-\-before\-build\fP
+(called by \fBdpkg\-buildpackage\fP before \fBdebian/rules clean\fP).
+The \fIcommand\fP should be idempotent and may be called multiple
+times. The intent is for this option to be used in
+\fBdebian/source/local-options\fP to specify commands to generate
+source files from a version control repository.
 .SH GENERIC EXTRACT OPTIONS
 .TP
 .BI \-\-no\-copy
diff --git a/scripts/dpkg-source.pl b/scripts/dpkg-source.pl
index 403f0fc..288c156 100755
--- a/scripts/dpkg-source.pl
+++ b/scripts/dpkg-source.pl
@@ -36,6 +36,7 @@ use Dpkg::Arch qw(debarch_eq);
 use Dpkg::Deps;
 use Dpkg::Compression;
 use Dpkg::Conf;
+use Dpkg::IPC qw(spawn);
 use Dpkg::Control::Info;
 use Dpkg::Control::Fields;
 use Dpkg::Substvars;
@@ -63,6 +64,7 @@ my %options = (
     tar_ignore => [],
     diff_ignore_regexp => '',
     # Misc options
+    before_build_command => [],
     copy_orig_tarballs => 1,
     no_check => 0,
     require_valid_signature => 0,
@@ -93,6 +95,24 @@ while (@ARGV && $ARGV[0] =~ m/^-/) {
     }
 }
 
+sub before_build {
+    my ($srcpkg, $dir) = @_;
+    foreach my $cmd (@{$options{'before_build_command'}}) {
+	my @exec = ('sh', '-c', $cmd);
+	spawn(
+	    'chdir' => $dir,
+	    'exec' => \@exec,
+	    'wait_child' => 1,
+	);
+    }
+    $srcpkg->before_build($dir);
+}
+
+sub after_build {
+    my ($srcpkg, $dir) = @_;
+    $srcpkg->after_build($dir);
+}
+
 my $dir;
 if (defined($options{'opmode'}) &&
     $options{'opmode'} =~ /^(-b|--print-format|--before-build|--after-build)$/) {
@@ -160,6 +180,8 @@ while (@options) {
             # Prevent adding multiple times
             $tar_ignore_default_pattern_done = 1;
         }
+    } elsif (m/^--before-build-command=(.+)$/) {
+        push @{$options{'before_build_command'}}, $1;
     } elsif (m/^--no-copy$/) {
         $options{'copy_orig_tarballs'} = 0;
     } elsif (m/^--no-check$/) {
@@ -321,10 +343,10 @@ if ($options{'opmode'} =~ /^(-b|--print-format|--(before|after)-build)$/) {
 	print $fields->{'Format'} . "\n";
 	exit(0);
     } elsif ($options{'opmode'} eq "--before-build") {
-	$srcpkg->before_build($dir);
+	before_build($srcpkg, $dir);
 	exit(0);
     } elsif ($options{'opmode'} eq "--after-build") {
-	$srcpkg->after_build($dir);
+	after_build($srcpkg, $dir);
 	exit(0);
     }
 
-- 
1.7.1


Reply to: