summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaphaël Hertzog <hertzog@debian.org>2010-04-28 22:27:08 +0200
committerRaphaël Hertzog <hertzog@debian.org>2010-05-02 21:08:05 +0200
commit8c1fc347f7d50b64f3693ba1d7e064bf9ccbae8c (patch)
treeb2df449436900af90e5c0de07a1b02016974615a
parent6a606c37571a2aa25dd7d4d46d4ed45206e4dbeb (diff)
downloaddpkg-8c1fc347f7d50b64f3693ba1d7e064bf9ccbae8c.tar.gz
dpkg-source: implement --before-build and --after-build command
Those commands are really hooks that source formats can use and that will be called by dpkg-buildpackage before and after the actual build. Source formats "2.0" and "3.0 (quilt)" use this hook to ensure patches are applied before the build.
-rw-r--r--man/dpkg-source.120
-rw-r--r--scripts/Dpkg/Source/Package.pm8
-rw-r--r--scripts/Dpkg/Source/Package/V2.pm5
-rwxr-xr-xscripts/dpkg-source.pl22
4 files changed, 49 insertions, 6 deletions
diff --git a/man/dpkg-source.1 b/man/dpkg-source.1
index a7913c297..5e4d30b7c 100644
--- a/man/dpkg-source.1
+++ b/man/dpkg-source.1
@@ -71,6 +71,23 @@ Print the source format that would be used to build the source package if
with the same parameters).
.TP
+.RI "\fB\-\-before\-build\fP " directory
+This command should be called before any build of the package
+(\fBdpkg\-buildpackage\fP calls it very early even before \fBdebian/rules
+clean\fP). This command should be idempotent and can be called multiple
+times. Not all source formats implement something in this hook, and those
+that do usually prepare the source tree for the build for example by
+ensuring that the Debian patches are applied.
+
+.TP
+.RI "\fB\-\-after\-build\fP " directory
+This command should be called after any build of the package
+(\fBdpkg\-buildpackage\fP calls it last). This command should be idempotent
+and can be called multiple times. Not all source formats implement
+something in this hook, and those that do usually use it to undo what
+\fB\-\-before\-build\fP has done.
+
+.TP
.BR \-h ", " \-\-help
Show the usage message and exit.
.TP
@@ -445,7 +462,8 @@ patches (they are listed in the \fBseries\fP file but not in
\fB.pc/applied-patches\fP), and if the first patch in that set can be
applied without errors, it will apply them all.
The option \fB\-\-no\-preparation\fP can be used to disable this
-behaviour.
+behaviour. This operation is usually done as part of the
+\fB\-\-prepare\-build\fP command.
.PP
.B Build options
.TP
diff --git a/scripts/Dpkg/Source/Package.pm b/scripts/Dpkg/Source/Package.pm
index 6c9cba2ca..c9d1a07e2 100644
--- a/scripts/Dpkg/Source/Package.pm
+++ b/scripts/Dpkg/Source/Package.pm
@@ -374,6 +374,10 @@ sub do_extract {
# Function used specifically during creation of a source package
+sub before_build {
+ my ($self, $dir) = @_;
+}
+
sub build {
my $self = shift;
eval { $self->do_build(@_) };
@@ -383,6 +387,10 @@ sub build {
}
}
+sub after_build {
+ my ($self, $dir) = @_;
+}
+
sub do_build {
internerr("Dpkg::Source::Package doesn't know how to build a " .
"source package. Use one of the subclasses.");
diff --git a/scripts/Dpkg/Source/Package/V2.pm b/scripts/Dpkg/Source/Package/V2.pm
index 1fc1e0abe..787d6acd6 100644
--- a/scripts/Dpkg/Source/Package/V2.pm
+++ b/scripts/Dpkg/Source/Package/V2.pm
@@ -214,6 +214,11 @@ sub can_build {
return (0, _g("no orig.tar file found"));
}
+sub before_build {
+ my ($self, $dir) = @_;
+ $self->check_patches_applied($dir) if $self->{'options'}{'preparation'};
+}
+
sub prepare_build {
my ($self, $dir) = @_;
$self->{'diff_options'} = {
diff --git a/scripts/dpkg-source.pl b/scripts/dpkg-source.pl
index d8cfda2ef..a5e29af0d 100755
--- a/scripts/dpkg-source.pl
+++ b/scripts/dpkg-source.pl
@@ -83,6 +83,8 @@ while (@ARGV && $ARGV[0] =~ m/^-/) {
setopmode('-b');
} elsif (m/^-x$/) {
setopmode('-x');
+ } elsif (m/^--(before|after)-build$/) {
+ setopmode($_);
} elsif (m/^--print-format$/) {
setopmode('--print-format');
report_options(info_fh => \*STDERR); # Avoid clutter on STDOUT
@@ -93,7 +95,7 @@ while (@ARGV && $ARGV[0] =~ m/^-/) {
my $dir;
if (defined($options{'opmode'}) &&
- $options{'opmode'} =~ /^(-b|--print-format)$/) {
+ $options{'opmode'} =~ /^(-b|--print-format|--before-build|--after-build)$/) {
if (not scalar(@ARGV)) {
usageerr(_g("%s needs a directory"), $options{'opmode'});
}
@@ -188,10 +190,10 @@ while (@options) {
}
unless (defined($options{'opmode'})) {
- usageerr(_g("need -x or -b"));
+ usageerr(_g("need a command (-x, -b, --before-build, --after-build, --print-format)"));
}
-if ($options{'opmode'} =~ /^(-b|--print-format)$/) {
+if ($options{'opmode'} =~ /^(-b|--print-format|--(before|after)-build)$/) {
$options{'ARGV'} = \@ARGV;
@@ -304,7 +306,8 @@ if ($options{'opmode'} =~ /^(-b|--print-format)$/) {
close(FORMAT);
} else {
warning(_g("no source format specified in %s, " .
- "see dpkg-source(1)"), "debian/source/format");
+ "see dpkg-source(1)"), "debian/source/format")
+ if $options{'opmode'} eq "-b";
$build_format = "1.0";
}
}
@@ -322,8 +325,17 @@ if ($options{'opmode'} =~ /^(-b|--print-format)$/) {
# Verify pre-requesites are met
my ($res, $msg) = $srcpkg->can_build($dir);
error(_g("can't build with source format '%s': %s"), $build_format, $msg) unless $res;
- info(_g("using source format `%s'"), $fields->{'Format'});
+ if ($options{'opmode'} eq "--before-build") {
+ $srcpkg->before_build($dir);
+ exit(0);
+ } elsif ($options{'opmode'} eq "--after-build") {
+ $srcpkg->after_build($dir);
+ exit(0);
+ }
+
+ # Only -b left
+ info(_g("using source format `%s'"), $fields->{'Format'});
run_vendor_hook("before-source-build", $srcpkg);
# Build the files (.tar.gz, .diff.gz, etc)
$srcpkg->build($dir);