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

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.
Raphaël Hertzog лет назад: 16
Родитель
Сommit
8c1fc347f7
4 измененных файлов с 49 добавлено и 6 удалено
  1. 19 1
      man/dpkg-source.1
  2. 8 0
      scripts/Dpkg/Source/Package.pm
  3. 5 0
      scripts/Dpkg/Source/Package/V2.pm
  4. 17 5
      scripts/dpkg-source.pl

+ 19 - 1
man/dpkg-source.1

@@ -70,6 +70,23 @@ 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).
 
+.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.
@@ -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

+ 8 - 0
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.");

+ 5 - 0
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'} = {

+ 17 - 5
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);