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

[PATCH] New dpkg-source build option: --no-generate-diff



Hello dpkg peoples,

Attached is a patch against dpkg Git implementing a new option for
the "build" operation of dpkg-source: --no-generate-diff. I describe
it as follows:

    --no-generate-diff
        Do not generate a diff against the upstream sources. This skips
        the process of extracting the original tarballs, and thus allows
        for a faster build. Not only is the source package directory not
        checked for any extraneous modifications, anything outside the
        debian subdirectory is ignored altogether. Use with caution.

The use case is as follows:

I am republishing Debian's chromium and firefox packages for another
distro. There are some modifications required to the debian/
subdirectory, but the original sources and tarball(s) remain untouched.
Thus the whole activity of unpacking the source tarball(s) and then
checking for modified source files is unnecessary, and just wastes time
and disk space. (The source trees for these packages each weigh in at
over 5 GB, so the overhead is not insubstantial.)

With this new option, I don't need to unpack the original source at all---
in fact, the source package directory can remain empty save for the
debian/ subdirectory---and I can get the same .debian.tar.xz and .dsc
files as produced by the existing process.

Since several options to dpkg-source relate to the generation of the
diff, and thus don't make sense when that step is skipped, I added a catch-
all incompatibility check. There might still be some option combinations
that lead to things breaking in a build, but hopefully the common cases
are covered here.


--Daniel


-- 
Daniel Richard G. || skunk@iSKUNK.ORG
My ASCII-art .sig got a bad case of Times New Roman.
diff --git a/man/dpkg-source.pod b/man/dpkg-source.pod
index 0ec1e97cb..0ff7458a8 100644
--- a/man/dpkg-source.pod
+++ b/man/dpkg-source.pod
@@ -608,7 +608,8 @@ patches have been applied during the extraction.
 
 B<Building>
 
-All original tarballs found in the current directory are extracted in a
+If B<--no-generate-diff> is not given, then
+all original tarballs found in the current directory are extracted in a
 temporary directory by following the same logic as for the unpack, the
 debian directory is copied over in the temporary directory, and all
 patches except the automatic patch (B<debian-changes->I<version>
@@ -739,6 +740,14 @@ or enable the patch unapplication process. Those options are only allowed
 in B<debian/source/local-options> so that all generated source
 packages have the same behavior by default.
 
+=item B<--no-generate-diff>
+
+Do not generate a diff against the upstream sources. This skips the process
+of extracting the original tarballs, and thus allows for a faster build.
+Not only is the source package directory not checked for any extraneous
+modifications, anything outside the debian subdirectory is ignored
+altogether. Use with caution.
+
 =item B<--abort-on-upstream-changes>
 
 The process fails if an automatic patch has been generated
diff --git a/scripts/Dpkg/Source/Package/V2.pm b/scripts/Dpkg/Source/Package/V2.pm
index 1f0946128..0eb9ba529 100644
--- a/scripts/Dpkg/Source/Package/V2.pm
+++ b/scripts/Dpkg/Source/Package/V2.pm
@@ -71,6 +71,7 @@ sub init_options {
     $self->{options}{unapply_patches} //= 'auto';
     $self->{options}{skip_debianization} //= 0;
     $self->{options}{create_empty_orig} //= 0;
+    $self->{options}{generate_diff} //= 1;
     $self->{options}{auto_commit} //= 0;
     $self->{options}{ignore_bad_version} //= 0;
 }
@@ -104,6 +105,10 @@ my @module_cmdline = (
         name => '--create-empty-orig',
         help => N_('create an empty original tarball if missing'),
         when => 'build',
+    }, {
+        name => '--no-generate-diff',
+        help => N_('do not generate diff against upstream sources'),
+        when => 'build',
     }, {
         name => '--abort-on-upstream-changes',
         help => N_('abort if generated diff has upstream files changes'),
@@ -156,6 +161,9 @@ sub parse_cmdline_option {
     } elsif ($opt eq '--create-empty-orig') {
         $self->{options}{create_empty_orig} = 1;
         return 1;
+    } elsif ($opt eq '--no-generate-diff') {
+        $self->{options}{generate_diff} = 0;
+        return 1;
     } elsif ($opt eq '--abort-on-upstream-changes') {
         $self->{options}{auto_commit} = 0;
         return 1;
@@ -460,6 +468,8 @@ sub _generate_patch {
         }
     }
 
+    return if !$opts{do_diff};
+
     # Unpack a second copy for comparison
     my $tmp = tempdir("$dirname.orig.XXXXXX", DIR => $updir);
     push_exit_handler(sub { erasedir($tmp) });
@@ -530,6 +540,21 @@ sub do_build {
         usageerr(g_("-b takes only one parameter with format '%s'"),
                  $self->{fields}{'Format'});
     }
+    if (!$self->{options}{generate_diff} &&
+        ($self->{options}{include_removal}   ||
+         $self->{options}{include_timestamp} ||
+         $self->{options}{include_binaries}  ||
+         $self->{options}{create_empty_orig} ||
+         $self->{options}{auto_commit})) {
+        my @incompat = (
+            "--include-removal",
+            "--include-timestamp",
+            "--include-binaries",
+            "--create-empty-orig",
+            "--auto-commit"
+        );
+        usageerr(g_("--no-generate-diff is incompatible with the following options: %s"), join(", ", @incompat));
+    }
     $self->prepare_build($dir);
 
     my $include_binaries = $self->{options}{include_binaries};
@@ -569,8 +594,9 @@ sub do_build {
                                         header_from => $autopatch,
                                         handle_binary => $handle_binary,
                                         skip_auto => $self->{options}{auto_commit},
+                                        do_diff => $self->{options}{generate_diff},
                                         usage => 'build');
-    unless (-z $tmpdiff or $self->{options}{auto_commit}) {
+    unless (!$tmpdiff or -z $tmpdiff or $self->{options}{auto_commit}) {
         info(g_('Hint: make sure the version in debian/changelog matches ' .
                 'the unpacked source tree'));
         info(g_('you can integrate the local changes with %s'),
@@ -578,7 +604,7 @@ sub do_build {
         error(g_('aborting due to unexpected upstream changes, see %s'),
               $tmpdiff);
     }
-    push_exit_handler(sub { unlink($tmpdiff) });
+    push_exit_handler(sub { !$tmpdiff or unlink($tmpdiff) });
     $binaryfiles->update_debian_source_include_binaries() if $include_binaries;
 
     # Install the diff as the new autopatch
@@ -590,7 +616,7 @@ sub do_build {
              $autopatch) if -e $autopatch;
         rmdir(File::Spec->catdir($dir, 'debian', 'patches')); # No check on purpose
     }
-    unlink($tmpdiff) or syserr(g_('cannot remove %s'), $tmpdiff);
+    !$tmpdiff or unlink($tmpdiff) or syserr(g_('cannot remove %s'), $tmpdiff);
     pop_exit_handler();
 
     # Create the debian.tar

Reply to: