From 6944852b169d3ab40a7a5adcba37d4bcf41a2293 Mon Sep 17 00:00:00 2001 From: Raphael Hertzog Date: Sat, 15 Mar 2008 23:20:54 +0100 Subject: [PATCH] Each source package format can have its own command line options * scripts/Dpkg/Source/Package.pm (init_options): Provide default values to various options in a format-specific way. * scripts/Dpkg/Source/Package.pm (parse_cmdline_options, parse_cmdline_option): New functions to handle command line options. * scripts/dpkg-source.pl: Forward unknown options to the source package object. Remove handling of all -s? options and move it... * scripts/Dpkg/Source/Package/V1_0.pm: ...here. * scripts/Dpkg/Source/Package/V2_0.pm: Add support of options --include-removal and --include-timestamp. * scripts/Dpkg/Source/Package/V3_0/quilt.pm: Add support of option --without-quilt. --- scripts/Dpkg/Source/Package.pm | 18 +++++++++++ scripts/Dpkg/Source/Package/V1_0.pm | 17 ++++++++++ scripts/Dpkg/Source/Package/V2_0.pm | 24 +++++++++++++- scripts/Dpkg/Source/Package/V3_0/quilt.pm | 27 +++++++++++++--- scripts/dpkg-source.pl | 39 ++++++++++------------- 5 files changed, 96 insertions(+), 29 deletions(-) diff --git a/scripts/Dpkg/Source/Package.pm b/scripts/Dpkg/Source/Package.pm index 5d8699b5..f228d13b 100644 --- a/scripts/Dpkg/Source/Package.pm +++ b/scripts/Dpkg/Source/Package.pm @@ -53,9 +53,14 @@ sub new { if (exists $args{"options"}) { $self->{'options'} = $args{'options'}; } + $self->init_options(); return $self; } +sub init_options { + my ($self) = @_; +} + sub initialize { my ($self, $filename) = @_; my ($fn, $dir) = fileparse($filename); @@ -216,6 +221,19 @@ sub check_signature { } } +sub parse_cmdline_options { + my ($self, @opts) = @_; + foreach (@opts) { + if (not $self->parse_cmdline_option($_)) { + warning(_g("%s is not a valid option for %s"), $_, ref($self)); + } + } +} + +sub parse_cmdline_option { + return 0; +} + sub extract { my $self = shift; eval { $self->do_extract(@_) }; diff --git a/scripts/Dpkg/Source/Package/V1_0.pm b/scripts/Dpkg/Source/Package/V1_0.pm index e61d7c87..14e48d51 100644 --- a/scripts/Dpkg/Source/Package/V1_0.pm +++ b/scripts/Dpkg/Source/Package/V1_0.pm @@ -38,6 +38,23 @@ use File::Basename; use File::Temp qw(tempfile); use File::Spec; +sub init_options { + my ($self) = @_; + $self->{'options'}{'sourcestyle'} ||= 'X'; +} + +sub parse_cmdline_option { + my ($self, $opt) = @_; + my $o = $self->{'options'}; + if ($opt =~ m/^-s([akpursnAKPUR])$/) { + warning(_g("-s%s option overrides earlier -s%s option"), $1, + $o->{'sourcestyle'}) if $o->{'sourcestyle'} ne 'X'; + $o->{'sourcestyle'} = $1; + return 1; + } + return 0; +} + sub do_extract { my ($self, $newdirectory) = @_; my $sourcestyle = $self->{'options'}{'sourcestyle'}; diff --git a/scripts/Dpkg/Source/Package/V2_0.pm b/scripts/Dpkg/Source/Package/V2_0.pm index 4a8136ad..cc4ced56 100644 --- a/scripts/Dpkg/Source/Package/V2_0.pm +++ b/scripts/Dpkg/Source/Package/V2_0.pm @@ -37,6 +37,26 @@ use File::Temp qw(tempfile tempdir); use File::Path; use File::Spec; +sub init_options { + my ($self) = @_; + $self->{'options'}{'include_removal'} = 0 + unless exists $self->{'options'}{'include_removal'}; + $self->{'options'}{'include_timestamp'} = 0 + unless exists $self->{'options'}{'include_timestamp'}; +} + +sub parse_cmdline_option { + my ($self, $opt) = @_; + if ($opt =~ /^--include-removal$/) { + $self->{'options'}{'include_removal'} = 1; + return 1; + } elsif ($opt =~ /^--include-timestamp$/) { + $self->{'options'}{'include_timestamp'} = 1; + return 1; + } + return 0; +} + sub do_extract { my ($self, $newdirectory) = @_; my $fields = $self->{'fields'}; @@ -144,7 +164,9 @@ sub can_build { sub prepare_build { my ($self, $dir) = @_; $self->{'diff_options'} = { - diff_ignore_regexp => $self->{'options'}{'diff_ignore_regexp'} + diff_ignore_regexp => $self->{'options'}{'diff_ignore_regexp'}, + include_removal => $self->{'options'}{'include_removal'}, + include_timestamp => $self->{'options'}{'include_timestamp'}, }; } diff --git a/scripts/Dpkg/Source/Package/V3_0/quilt.pm b/scripts/Dpkg/Source/Package/V3_0/quilt.pm index 432174ab..1229feda 100644 --- a/scripts/Dpkg/Source/Package/V3_0/quilt.pm +++ b/scripts/Dpkg/Source/Package/V3_0/quilt.pm @@ -28,9 +28,27 @@ use Dpkg::ErrorHandling qw(error syserr warning usageerr subprocerr info); use Dpkg::Source::Patch; use Dpkg::IPC; +use POSIX; use File::Basename; use File::Spec; +sub init_options { + my ($self) = @_; + $self->SUPER::init_options(); + $self->{'options'}{'without_quilt'} = 0 + unless exists $self->{'options'}{'without_quilt'}; +} + +sub parse_cmdline_option { + my ($self, $opt) = @_; + return 1 if $self->SUPER::parse_cmdline_option($opt); + if ($opt =~ /^--without-quilt$/) { + $self->{'options'}{'without_quilt'} = 1; + return 1; + } + return 0; +} + sub get_autopatch_name { my ($self) = @_; return "debian-changes-" . $self->{'fields'}{'Version'} . ".diff"; @@ -91,7 +109,7 @@ sub apply_patches { foreach my $patch ($self->get_patches($dir, $skip_auto)) { my $path = File::Spec->catfile($dir, "debian", "patches", $patch); my $patch_obj = Dpkg::Source::Patch->new(filename => $path); - if ($have_quilt) { + if ($have_quilt and not $self->{'options'}{'without_quilt'}) { info(_g("applying %s with quilt"), $patch) unless $skip_auto; my $analysis = $patch_obj->analyze($dir); foreach my $dir (keys %{$analysis->{'dirtocreate'}}) { @@ -108,7 +126,7 @@ sub apply_patches { ); fork_and_exec(%opts); foreach my $fn (keys %{$analysis->{'filepatched'}}) { - utime($now, $now, $fn) || + utime($now, $now, $fn) || $! == ENOENT || syserr(_g("cannot change timestamp for %s"), $fn); } } else { @@ -122,6 +140,7 @@ sub apply_patches { sub prepare_build { my ($self, $dir) = @_; + $self->SUPER::prepare_build($dir); # Skip .pc directories of quilt by default and ignore difference # on debian/patches/series symlinks my $func = sub { @@ -130,9 +149,7 @@ sub prepare_build { return 1 if $_[0] =~ /$self->{'options'}{'diff_ignore_regexp'}/; return 0; }; - $self->{'diff_options'} = { - diff_ignore_func => $func - }; + $self->{'diff_options'}{'diff_ignore_func'} = $func; } sub register_autopatch { diff --git a/scripts/dpkg-source.pl b/scripts/dpkg-source.pl index 6539b37e..c10128c6 100755 --- a/scripts/dpkg-source.pl +++ b/scripts/dpkg-source.pl @@ -91,8 +91,6 @@ my %options = ( # Ignore files tar_ignore => [], diff_ignore_regexp => '', - # Sourcestyle - sourcestyle => 'X', ); # Fields to remove/override @@ -103,6 +101,7 @@ my $substvars = Dpkg::Substvars->new(); my $opmode; my $tar_ignore_default_pattern_done; +my @cmdline_options; while (@ARGV && $ARGV[0] =~ m/^-/) { $_ = shift(@ARGV); if (m/^-b$/) { @@ -124,10 +123,6 @@ while (@ARGV && $ARGV[0] =~ m/^-/) { usageerr(_g("%s is not a compression level"), $comp_level) unless $comp_level =~ /^([1-9]|fast|best)$/; Dpkg::Source::Compressor->set_default_compression_level($comp_level); - } elsif (m/^-s([akpursnAKPUR])$/) { - warning(_g("-s%s option overrides earlier -s%s option"), $1, - $options{'sourcestyle'}) if $options{'sourcestyle'} ne 'X'; - $options{'sourcestyle'} = $1; } elsif (m/^-c/) { $controlfile = $POSTMATCH; } elsif (m/^-l/) { @@ -150,9 +145,10 @@ while (@ARGV && $ARGV[0] =~ m/^-/) { } } elsif (m/^-V(\w[-:0-9A-Za-z]*)[=:]/) { $substvars->set($1, $POSTMATCH); + warning(_g("substvars support is deprecated (see README.feature-removal-schedule)")); } elsif (m/^-T/) { - $varlistfile = $POSTMATCH; - warning(_g("substvars support is deprecated (see README.feature-removal-schedule)")); + $varlistfile = $POSTMATCH; + warning(_g("substvars support is deprecated (see README.feature-removal-schedule)")); } elsif (m/^-(h|-help)$/) { usage(); exit(0); @@ -168,7 +164,7 @@ while (@ARGV && $ARGV[0] =~ m/^-/) { } elsif (m/^--$/) { last; } else { - usageerr(_g("unknown option \`%s'"), $_); + push @cmdline_options, $_; } } @@ -308,6 +304,10 @@ if ($opmode eq 'build') { } info(_g("using source format `%s'"), $fields->{'Format'}); + # Parse command line options + $srcpkg->init_options(); + $srcpkg->parse_cmdline_options(@cmdline_options); + # Build the files (.tar.gz, .diff.gz, etc) $srcpkg->build($dir); @@ -339,6 +339,9 @@ if ($opmode eq 'build') { my $srcpkg = Dpkg::Source::Package->new(filename => $dsc, options => \%options); + # Parse command line options + $srcpkg->parse_cmdline_options(@cmdline_options); + # Decide where to unpack my $newdirectory = $srcpkg->get_basename(); $newdirectory =~ s/_/-/g; @@ -405,7 +408,7 @@ sub usage { Commands: -x .dsc [] extract source package. - -b [||\'\'] + -b build source package. Build options: @@ -423,27 +426,17 @@ Build options: (defaults to: '%s'). -I[] filter out files when building tarballs (defaults to: %s). - -sa auto select orig source (-sA is default). - -sk use packed orig source (unpack & keep). - -sp use packed orig source (unpack & remove). - -su use unpacked orig source (pack & keep). - -sr use unpacked orig source (pack & remove). - -ss trust packed & unpacked orig src are same. - -sn there is no diff, do main tarfile only. - -sA,-sK,-sP,-sU,-sR like -sa,-sk,-sp,-su,-sr but may overwrite. -Z select compression to use (defaults to 'gzip', supported are: %s). -z compression level to use (defaults to '9', supported are: '1'-'9', 'best', 'fast') -Extract options: - -sp (default) leave orig source packed in current dir. - -sn do not copy original source to current dir. - -su unpack original source tree too. - General options: -h, --help show this help message. --version show the version. + +More options are available but they depend on the source package format. +See dpkg-source(1) for more info. "), $progname, $diff_ignore_default_regexp, join('', map { " -I$_" } @tar_ignore_default_pattern), -- 2.39.5