From: Raphael Hertzog Date: Fri, 29 Feb 2008 20:24:14 +0000 (+0100) Subject: dpkg-source: use a list of possible format for building a source package X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3b5dc12a4835d7d97542ebf5a5a346a96e0f567c;p=dpkg dpkg-source: use a list of possible format for building a source package * scripts/dpkg-source.pl: Define a list of formats that can be used to build a source package and use the first one that is able to build a source package. Let the user add formats to try at the beginning of that list with the --format= command-line option. * scripts/Dpkg/Source/Package/V1_0.pm (can_build): Only accept to build a source package is the compression option is gzip. * scripts/Dpkg/Source/Package.pm (can_build): Return a proper error message. * scripts/dpkg-source.pl: Use the info() function to report progress. --- diff --git a/scripts/Dpkg/Source/Package.pm b/scripts/Dpkg/Source/Package.pm index 7219e757..5d8699b5 100644 --- a/scripts/Dpkg/Source/Package.pm +++ b/scripts/Dpkg/Source/Package.pm @@ -246,7 +246,7 @@ sub do_build { sub can_build { my ($self, $dir) = @_; - return 0; + return (0, "can_build() has not been overriden"); } sub add_file { diff --git a/scripts/Dpkg/Source/Package/V1_0.pm b/scripts/Dpkg/Source/Package/V1_0.pm index 4d63b3f0..7a0da845 100644 --- a/scripts/Dpkg/Source/Package/V1_0.pm +++ b/scripts/Dpkg/Source/Package/V1_0.pm @@ -152,6 +152,14 @@ sub do_extract { } } +sub can_build { + my ($self, $dir) = @_; + # As long as we can use gzip, we can do it as we have + # native packages as fallback + return ($self->{'options'}{'compression'} eq "gzip", + _g("only supports gzip compression")); +} + sub do_build { my ($self, $dir) = @_; my $sourcestyle = $self->{'options'}{'sourcestyle'}; diff --git a/scripts/dpkg-source.pl b/scripts/dpkg-source.pl index 397ca855..b16aa0b7 100755 --- a/scripts/dpkg-source.pl +++ b/scripts/dpkg-source.pl @@ -7,7 +7,7 @@ use warnings; use Dpkg; use Dpkg::Gettext; use Dpkg::ErrorHandling qw(warning warnerror error failure unknown - internerr syserr subprocerr usageerr + internerr syserr subprocerr usageerr info $warnable_error $quiet_warnings); use Dpkg::Arch qw(debarch_eq); use Dpkg::Deps qw(@src_dep_fields %dep_field_type); @@ -82,7 +82,7 @@ _darcs {arch} ); -my $def_dscformat = "1.0"; # default format for -b +my @build_formats = ("1.0"); my %options = ( # Compression related compression => 'gzip', @@ -100,7 +100,6 @@ my %remove; my %override; my $substvars = Dpkg::Substvars->new(); - my $opmode; my $tar_ignore_default_pattern_done; @@ -110,6 +109,8 @@ while (@ARGV && $ARGV[0] =~ m/^-/) { setopmode('build'); } elsif (m/^-x$/) { setopmode('extract'); + } elsif (m/^--format=(.*)$/) { + unshift @build_formats, $1; } elsif (m/^-Z/) { my $compression = $POSTMATCH; $options{'compression'} = $compression; @@ -198,9 +199,6 @@ if ($opmode eq 'build') { my $srcpkg = Dpkg::Source::Package->new(options => \%options); my $fields = $srcpkg->{'fields'}; - # TODO: find another way to switch default building format - $fields->{"Format"} = $options{'compression'} eq 'gzip' ? $def_dscformat : '2.0'; - my @sourcearch; my %archadded; my @binarypackages; @@ -299,16 +297,23 @@ if ($opmode eq 'build') { $fields->{'Binary'} = join(', ', @binarypackages); - # Format is supposedly defined, switch to corresponding object type - $srcpkg->upgrade_object_type(); # Fails if format is unsupported + unshift @build_formats, $fields->{'Format'} if exists $fields->{'Format'}; + # Try all suggested formats until one is acceptable + foreach my $format (@build_formats) { + $fields->{'Format'} = $format; + $srcpkg->upgrade_object_type(); # Fails if format is unsupported + my ($res, $msg) = $srcpkg->can_build($dir); + last if $res; + info(_g("source format `%s' discarded: %s"), $format, $msg); + } + info(_g("using source format `%s'"), $fields->{'Format'}); # Build the files (.tar.gz, .diff.gz, etc) $srcpkg->build($dir); # Write the .dsc my $dscname = $srcpkg->get_basename(1) . ".dsc"; - printf(_g("%s: building %s in %s")."\n", - $progname, $sourcepackage, $dscname); + info(_g("building %s in %s"), $sourcepackage, $dscname); $substvars->parse($varlistfile) if $varlistfile && -e $varlistfile; $srcpkg->write_dsc(filename => $dscname, remove => \%remove, @@ -353,8 +358,7 @@ if ($opmode eq 'build') { $srcpkg->check_checksums(); # Unpack the source package (delegated to Dpkg::Source::Package::*) - printf(_g("%s: extracting %s in %s")."\n", - $progname, $srcpkg->{'fields'}{'Source'}, $newdirectory); + info(_g("extracting %s in %s"), $srcpkg->{'fields'}{'Source'}, $newdirectory); $srcpkg->extract($newdirectory); # Make sure debian/rules is executable