Browse Source

dpkg-source: --after-build unapplies patches applied during --before-build

Implement this logic for the "2.0" and "3.0 (quilt)" source formats.
Raphaël Hertzog 15 years ago
parent
commit
e60718be56
4 changed files with 44 additions and 20 deletions
  1. 2 0
      debian/changelog
  2. 12 19
      man/dpkg-source.1
  3. 12 1
      scripts/Dpkg/Source/Package/V2.pm
  4. 18 0
      scripts/Dpkg/Source/Package/V3/quilt.pm

+ 2 - 0
debian/changelog

@@ -36,6 +36,8 @@ dpkg (1.16.1) UNRELEASED; urgency=low
   * dpkg-source can now also use debian/source/local-patch-header (that is not
     included in the generated source package) instead of
     debian/source/patch-header. Closes: #629582
+  * Changed dpkg-source --after-build to automatically unapply patches that it
+    has applied during --before-build.
 
   [ Guillem Jover ]
   * Install deb-src-control(5) man pages in dpkg-dev. Closes: #620520

+ 12 - 19
man/dpkg-source.1

@@ -458,19 +458,14 @@ files as well as many temporary files (see default value associated to
 \fB.pc\fP directory used by quilt is ignored during generation of the
 automatic patch.
 
-Note: \fBdpkg\-source\fP expects the source tree to have all patches
-listed in the series file applied when you generate the source package.
-This is not the case when the source tree has been obtained by unpacking a
-source package using the Format: 1.0 for instance. To mitigate the
-problem, \fBdpkg\-source\fP will apply the patches by itself if it
-believes that they have not yet been applied. To detect this situation, it
-uses the following heuristic: it finds the list of supposedly unapplied
-patches (they are listed in the \fBseries\fP file but not in
+Note: \fBdpkg\-source\fP \fB\-\-before\-build\fP (and \fB\-b\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
 \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. This operation is usually done as part of the
-\fB\-\-prepare\-build\fP command.
+applied without errors, it will apply them all. The option
+\fB\-\-no\-preparation\fP can be used to disable this
+behavior.
 .PP
 .B Build options
 .TP
@@ -516,13 +511,11 @@ be used when the source package is just a bundle of multiple upstream
 software and where there's no "main" software.
 .TP
 .B \-\-unapply\-patches
-Unapply the patches in the \fB\-\-after\-build\fP hook. This is mainly
-useful when you build your package directly in a VCS that contains
-unpatched upstream source and where you want to keep the tree unpatched
-even after a package build. This option is usually put in
-\fBdebian/source/local\-options\fP (it's not allowed in
-\fBdebian/source/options\fP so that all generated source packages have the
-same behaviour by default).
+Unapply the patches in the \fB\-\-after\-build\fP hook. You usually don't
+need this option as dpkg\-source will automatically unapply the patches
+if it did apply them during \fB\-\-before\-build\fP. This
+option is only allowed in \fBdebian/source/local\-options\fP so that all
+generated source packages have the same behavior by default.
 .TP
 .B \-\-abort\-on\-upstream\-changes
 The process fails if an automatic patch has been generated. This option

+ 12 - 1
scripts/Dpkg/Source/Package/V2.pm

@@ -208,6 +208,7 @@ sub apply_patches {
     return unless scalar(@patches);
     my $applied = File::Spec->catfile($dir, "debian", "patches", ".dpkg-source-applied");
     open(APPLIED, '>', $applied) || syserr(_g("cannot write %s"), $applied);
+    print APPLIED "# During $opts{'usage'}\n";
     my $timestamp = fs_time($applied);
     foreach my $patch ($self->get_patches($dir, %opts)) {
         my $path = File::Spec->catfile($dir, "debian", "patches", $patch);
@@ -253,7 +254,17 @@ sub before_build {
 
 sub after_build {
     my ($self, $dir) = @_;
-    $self->unapply_patches($dir) if $self->{'options'}{'unapply_patches'};
+    my $applied = File::Spec->catfile($dir, "debian", "patches", ".dpkg-source-applied");
+    my $reason = "";
+    if (-e $applied) {
+        open(APPLIED, "<", $applied) || syserr(_g("cannot read %s"), $applied);
+        $reason = <APPLIED>;
+        close(APPLIED);
+    }
+    if ($reason =~ /^# During preparation/ or
+        $self->{'options'}{'unapply_patches'}) {
+        $self->unapply_patches($dir);
+    }
 }
 
 sub prepare_build {

+ 18 - 0
scripts/Dpkg/Source/Package/V3/quilt.pm

@@ -217,6 +217,15 @@ sub apply_patches {
     }
     return unless scalar(@$patches);
 
+    if ($opts{'usage'} eq "preparation") {
+        # We're applying the patches in --before-build, remember to unapply
+        # them afterwards in --after-build
+        my $pc_unapply = File::Spec->catfile($dir, ".pc", ".dpkg-source-unapply");
+        open(UNAPPLY, ">", $pc_unapply) ||
+            syserr(_g("cannot write %s"), $pc_unapply);
+        close(UNAPPLY);
+    }
+
     # Apply patches
     my $pc_applied = File::Spec->catfile($dir, ".pc", "applied-patches");
     my @applied = $self->read_patch_list($pc_applied);
@@ -292,6 +301,15 @@ sub do_build {
     $self->SUPER::do_build($dir);
 }
 
+sub after_build {
+    my ($self, $dir) = @_;
+    my $pc_unapply = File::Spec->catfile($dir, ".pc", ".dpkg-source-unapply");
+    if (-e $pc_unapply or $self->{'options'}{'unapply_patches'}) {
+        unlink($pc_unapply);
+        $self->unapply_patches($dir);
+    }
+}
+
 sub check_patches_applied {
     my ($self, $dir) = @_;
     my $pc_applied = File::Spec->catfile($dir, ".pc", "applied-patches");