Browse Source

dpkg-source: new option --create-empty-orig in formats "2.0" and "3.0 (quilt)"

With this option, dpkg-source will auto-create the main original tarball
when it's missing and when there are supplementary tarballs. This makes it
easier to bundle multiple software together.

dpkg-source needs to be modified since the options have to be parsed
before can_build() is called.
Raphaël Hertzog 16 years ago
parent
commit
61ab00f675
5 changed files with 41 additions and 12 deletions
  1. 4 0
      debian/changelog
  2. 6 0
      man/dpkg-source.1
  3. 10 5
      scripts/Dpkg/Source/Package.pm
  4. 18 3
      scripts/Dpkg/Source/Package/V2.pm
  5. 3 4
      scripts/dpkg-source.pl

+ 4 - 0
debian/changelog

@@ -49,6 +49,10 @@ dpkg (1.15.6) UNRELEASED; urgency=low
   * The -T option of dpkg-{source,gencontrol,genchanges} can now be used
     multiple times to read substitution variables from multiple files.
     Closes: #363323
+  * dpkg-source now supports an option --create-empty-orig in formats
+    "2.0" and "3.0 (quilt)" to auto-create the main original tarball when
+    there are supplementary tarballs. This makes it easier to bundle
+    multiple software together. Closes: #554488
 
   [ Guillem Jover ]
   * Handle argument parsing in dpkg-checkbuilddeps and dpkg-scanpackages

+ 6 - 0
man/dpkg-source.1

@@ -476,6 +476,12 @@ be generated. Instead the current diff with upstream should be stored in a
 single patch. When using this option, it is recommended to create
 a debian/source/patch-header file explaining how the Debian changes can be
 best reviewed, for example in the VCS that is used.
+.TP
+.B \-\-create\-empty\-orig
+Automatically create the main original tarball as empty if it's missing
+and if there are supplementary original tarballs. This option is meant to
+be used when the source package is just a bundle of multiple upstream
+software and where there's no "main" software.
 
 .PP
 .B Extract options

+ 10 - 5
scripts/Dpkg/Source/Package.pm

@@ -241,16 +241,21 @@ sub get_basename {
 }
 
 sub find_original_tarballs {
-    my ($self, $ext) = @_;
-    $ext ||= $compression_re_file_ext;
+    my ($self, %opts) = @_;
+    $opts{extension} = $compression_re_file_ext unless exists $opts{extension};
+    $opts{include_main} = 1 unless exists $opts{include_main};
+    $opts{include_supplementary} = 1 unless exists $opts{include_supplementary};
     my $basename = $self->get_basename();
     my @tar;
     foreach my $dir (".", $self->{'basedir'}, $self->{'options'}{'origtardir'}) {
         next unless defined($dir) and -d $dir;
         opendir(DIR, $dir) || syserr(_g("cannot opendir %s"), $dir);
-        push @tar, map { "$dir/$_" }
-                  grep { /^\Q$basename\E\.orig(-[\w-]+)?\.tar\.$ext$/ }
-                  readdir(DIR);
+        push @tar, map { "$dir/$_" } grep {
+		($opts{include_main} and
+		 /^\Q$basename\E\.orig\.tar\.$opts{extension}$/) or
+		($opts{include_supplementary} and
+		 /^\Q$basename\E\.orig-[\w-]+\.tar\.$opts{extension}$/)
+	    } readdir(DIR);
         closedir(DIR);
     }
     return @tar;

+ 18 - 3
scripts/Dpkg/Source/Package/V2.pm

@@ -55,6 +55,8 @@ sub init_options {
         unless exists $self->{'options'}{'skip_patches'};
     $self->{'options'}{'skip_debianization'} = 0
         unless exists $self->{'options'}{'skip_debianization'};
+    $self->{'options'}{'create_empty_orig'} = 0
+        unless exists $self->{'options'}{'create_empty_orig'};
 }
 
 sub parse_cmdline_option {
@@ -77,6 +79,9 @@ sub parse_cmdline_option {
     } elsif ($opt =~ /^--skip-debianization$/) {
         $self->{'options'}{'skip_debianization'} = 1;
         return 1;
+    } elsif ($opt =~ /^--create-empty-orig$/) {
+        $self->{'options'}{'create_empty_orig'} = 1;
+        return 1;
     }
     return 0;
 }
@@ -203,9 +208,9 @@ sub apply_patches {
 
 sub can_build {
     my ($self, $dir) = @_;
-    foreach ($self->find_original_tarballs()) {
-        return 1 if /\.orig\.tar\.$compression_re_file_ext$/;
-    }
+    return 1 if $self->find_original_tarballs(include_supplementary => 0);
+    return 1 if $self->{'options'}{'create_empty_orig'} and
+                $self->find_original_tarballs(include_main => 0);
     return (0, _g("no orig.tar file found"));
 }
 
@@ -219,6 +224,16 @@ sub prepare_build {
     };
     push @{$self->{'options'}{'tar_ignore'}}, "debian/patches/.dpkg-source-applied";
     $self->check_patches_applied($dir) if $self->{'options'}{'preparation'};
+    if ($self->{'options'}{'create_empty_orig'} and
+        not $self->find_original_tarballs(include_supplementary => 0))
+    {
+        # No main orig.tar, create a dummy one
+        my $filename = $self->get_basename() . ".orig.tar." .
+                       $self->{'options'}{'comp_ext'};
+        my $tar = Dpkg::Source::Archive->new(filename => $filename);
+        $tar->create();
+        $tar->finish();
+    }
 }
 
 sub check_patches_applied {

+ 3 - 4
scripts/dpkg-source.pl

@@ -303,6 +303,9 @@ if ($options{'opmode'} =~ /^(-b|--print-format)$/) {
     foreach my $format (@try_formats) {
         $fields->{'Format'} = $format;
         $srcpkg->upgrade_object_type(); # Fails if format is unsupported
+	# Parse command line options
+	$srcpkg->init_options();
+	$srcpkg->parse_cmdline_options(@cmdline_options);
         my ($res, $msg) = $srcpkg->can_build($dir);
         last if $res;
         info(_g("source format `%s' discarded: %s"), $format, $msg);
@@ -313,10 +316,6 @@ if ($options{'opmode'} =~ /^(-b|--print-format)$/) {
     }
     info(_g("using source format `%s'"), $fields->{'Format'});
 
-    # Parse command line options
-    $srcpkg->init_options();
-    $srcpkg->parse_cmdline_options(@cmdline_options);
-
     run_vendor_hook("before-source-build", $srcpkg);
     # Build the files (.tar.gz, .diff.gz, etc)
     $srcpkg->build($dir);