From 52361409ba4dc0a3eb9700bc8ef7151292d5f450 Mon Sep 17 00:00:00 2001 From: Raphael Hertzog Date: Fri, 14 Mar 2008 19:32:04 +0100 Subject: [PATCH] Dpkg::Source::Package::V3_0::quilt: Add fallback when quilt is not available * scripts/Dpkg/Source/Package/V3_0/quilt.pm: Check for quilt availability before using it to apply patches. Otherwise resort to using Dpkg::Source::Patch to apply patches. --- scripts/Dpkg/Source/Package/V3_0/quilt.pm | 47 ++++++++++++++--------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/scripts/Dpkg/Source/Package/V3_0/quilt.pm b/scripts/Dpkg/Source/Package/V3_0/quilt.pm index 1264767e..c9db0727 100644 --- a/scripts/Dpkg/Source/Package/V3_0/quilt.pm +++ b/scripts/Dpkg/Source/Package/V3_0/quilt.pm @@ -70,6 +70,9 @@ sub get_patches { sub apply_patches { my ($self, $dir, $skip_auto) = @_; + # Check if quilt is available + my $have_quilt = (-x "/usr/bin/quilt") ? 1 : 0; + # Update debian/patches/series symlink if needed to allow quilt usage my $series = $self->get_series_file($dir); return unless $series; # No series, no patches @@ -87,25 +90,31 @@ sub apply_patches { my $now = time(); foreach my $patch ($self->get_patches($dir, $skip_auto)) { my $path = File::Spec->catfile($dir, "debian", "patches", $patch); - info(_g("applying %s"), $patch) unless $skip_auto; my $patch_obj = Dpkg::Source::Patch->new(filename => $path); - my $analysis = $patch_obj->analyze($dir); - foreach my $dir (keys %{$analysis->{'dirtocreate'}}) { - eval { mkpath($dir); }; - syserr(_g("cannot create directory %s"), $dir) if $@; - } - my %opts = ( - env => { QUILT_PATCHES => 'debian/patches' }, - delete_env => [ 'QUILT_PATCH_OPTS' ], - 'chdir' => $dir, - 'exec' => [ 'quilt', '--quiltrc', '/dev/null', 'push', $patch ], - wait_child => 1, - to_file => '/dev/null', - ); - fork_and_exec(%opts); - foreach my $fn (keys %{$analysis->{'filepatched'}}) { - utime($now, $now, $fn) || - syserr(_g("cannot change timestamp for %s"), $fn); + if ($have_quilt) { + info(_g("applying %s with quilt"), $patch) unless $skip_auto; + my $analysis = $patch_obj->analyze($dir); + foreach my $dir (keys %{$analysis->{'dirtocreate'}}) { + eval { mkpath($dir); }; + syserr(_g("cannot create directory %s"), $dir) if $@; + } + my %opts = ( + env => { QUILT_PATCHES => 'debian/patches' }, + delete_env => [ 'QUILT_PATCH_OPTS' ], + 'chdir' => $dir, + 'exec' => [ 'quilt', '--quiltrc', '/dev/null', 'push', $patch ], + wait_child => 1, + to_file => '/dev/null', + ); + fork_and_exec(%opts); + foreach my $fn (keys %{$analysis->{'filepatched'}}) { + utime($now, $now, $fn) || + syserr(_g("cannot change timestamp for %s"), $fn); + } + } else { + info(_g("applying %s"), $patch) unless $skip_auto; + $patch_obj->apply($dir, timestamp => $now, + force_timestamp => 1, create_dirs => 1); } } } @@ -128,7 +137,7 @@ sub prepare_build { sub register_autopatch { my ($self, $dir) = @_; my $auto_patch = $self->get_autopatch_name(); - my $has_patch = grep(/\/\Q$auto_patch\E$/, $self->get_patches($dir)) ? 1 : 0; + my $has_patch = (grep { $_ eq $auto_patch } $self->get_patches($dir)) ? 1 : 0; my $series = $self->get_series_file($dir); $series ||= File::Spec->catfile($dir, "debian", "patches", "series"); if (-e "$dir/debian/patches/$auto_patch") { -- 2.39.5