]> git.donarmstrong.com Git - debhelper.git/commitdiff
Improve handling of logging in override targets
authorJoey Hess <joey@kitenet.net>
Thu, 10 Feb 2011 23:56:44 +0000 (19:56 -0400)
committerJoey Hess <joey@kitenet.net>
Thu, 10 Feb 2011 23:56:51 +0000 (19:56 -0400)
Changes in 76ef1cbd64829ee4a5156a5fc4b887bcba6b974f broke
--remaining-packages in override target.

Now all debhelper commands run in the override target are marked as running
as part of the override, and when the whole target is run, the log is
updated to indicate that commands run during the override have finished.

So, inside the override target, --remaining-packages will see the commands
run as part of the target as having been run. Outside, if the target
fails, dh won't see the commands run it it as having been run.

Closes: #612828
Debian/Debhelper/Dh_Lib.pm
debian/changelog
dh

index 9b6118e90c44b871582cb5fbfb6c2792b4236729..01777210fde6bcbe53685348464c00232fa9ffa4 100644 (file)
@@ -15,8 +15,8 @@ use vars qw(@ISA @EXPORT %dh);
            &filedoublearray &getpackages &basename &dirname &xargs %dh
            &compat &addsubstvar &delsubstvar &excludefile &package_arch
            &is_udeb &udeb_filename &debhelper_script_subst &escape_shell
-           &inhibit_log &load_log &write_log &dpkg_architecture_value
-           &sourcepackage
+           &inhibit_log &load_log &write_log &commit_override_log
+           &dpkg_architecture_value &sourcepackage
            &is_make_jobserver_unavailable &clean_jobserver_makeflags
            &cross_command);
 
@@ -107,16 +107,36 @@ sub END {
        }
 }
 
+sub logfile {
+       my $package=shift;
+       my $ext=pkgext($package);
+       return "debian/${ext}debhelper.log"
+}
+
+sub add_override {
+       my $line=shift;
+       $line="override_$ENV{DH_INTERNAL_OVERRIDE} $line"
+               if defined $ENV{DH_INTERNAL_OVERRIDE};
+       return $line;
+}
+
+sub remove_override {
+       my $line=shift;
+       $line=~s/^\Qoverride_$ENV{DH_INTERNAL_OVERRIDE}\E\s+//
+               if defined $ENV{DH_INTERNAL_OVERRIDE};
+       return $line;
+}
+
 sub load_log {
        my ($package, $db)=@_;
-       my $ext=pkgext($package);
 
        my @log;
-       open(LOG, "<", "debian/${ext}debhelper.log") || return;
+       open(LOG, "<", logfile($package)) || return;
        while (<LOG>) {
                chomp;
-               push @log, $_;
-               $db->{$package}{$_}=1 if defined $db;
+               my $command=remove_override($_);
+               push @log, $command;
+               $db->{$package}{$command}=1 if defined $db;
        }
        close LOG;
        return @log;
@@ -126,13 +146,22 @@ sub write_log {
        my $cmd=shift;
        my @packages=@_;
 
-       return if defined $ENV{DH_INHIBIT_LOG} && $cmd eq $ENV{DH_INHIBIT_LOG};
-
        foreach my $package (@packages) {
-               my $ext=pkgext($package);
-               my $log="debian/${ext}debhelper.log";
+               my $log=logfile($package);
                open(LOG, ">>", $log) || error("failed to write to ${log}: $!");
-               print LOG $cmd."\n";
+               print LOG add_override($cmd)."\n";
+               close LOG;
+       }
+}
+
+sub commit_override_log {
+       my @packages=@_;
+
+       foreach my $package (@packages) {
+               my @log=map { remove_override($_) } load_log($package);
+               my $log=logfile($package);
+               open(LOG, ">", $log) || error("failed to write to ${log}: $!");
+               print LOG $_."\n" foreach @log;
                close LOG;
        }
 }
index 02eb58231d8a8f8a2533bf7a04256cb62b5799fc..6858f0f2a83dd1cfdc7f26961d2a504405b698d8 100644 (file)
@@ -1,8 +1,13 @@
 debhelper (8.1.1) UNRELEASED; urgency=low
 
   * dh_strip, dh_makeshlibs: use triplet-objdump, triplet-objcopy and
-    triplet-strip from cross-binutils when cross-compiling; closes: #412118.
+    triplet-strip from cross-binutils when cross-compiling; Closes: #412118.
     (Thanks, Loïc Minier)
+  * Improve handling of logging in override targets, so that
+    --remaining-packages can be used again. Now all debhelper commands run
+    in the override target are marked as running as part of the override,
+    and when the whole target is run, the log is updated to indicate that
+    commands run during the override have finished. Closes: #612828
 
  -- Joey Hess <joeyh@debian.org>  Tue, 08 Feb 2011 15:32:35 -0400
 
diff --git a/dh b/dh
index 301ce5d2a7850de14c27c3c1ab02b895f30b728a..9e6fa04e65d8d1e3dde932690d6f0c232576a94b 100755 (executable)
--- a/dh
+++ b/dh
@@ -647,9 +647,7 @@ sub run {
                        # This passes the options through to commands called
                        # inside the target.
                        $ENV{DH_INTERNAL_OPTIONS}=join("\x1e", @options);
-                       # Prevent commands called inside the target from
-                       # logging.
-                       $ENV{DH_INHIBIT_LOG}=$command;
+                       $ENV{DH_INTERNAL_OVERRIDE}=$command;
                        $command="debian/rules";
                        @options="override_".$override_command;
                }
@@ -670,10 +668,11 @@ sub run {
        else {
                print "   ", "# Skipping ", $override_command, " - empty override", "\n";
        }
-
+                               
        if (! $dh{NO_ACT}) {
                if (defined $command) {
                        my $ret=system($command, @options);
+                       
                        if ($ret >> 8 != 0) {
                                exit $ret >> 8;
                        }
@@ -683,8 +682,6 @@ sub run {
                }
 
                if (defined $override_command) {
-                       delete $ENV{DH_INTERNAL_OPTIONS};
-                       delete $ENV{DH_INHIBIT_LOG};
                        # Update log for overridden command now that it has
                        # finished successfully.
                        # (But avoid logging for dh_clean since it removes
@@ -692,8 +689,12 @@ sub run {
                        if ($override_command ne 'dh_clean') {
                                my %packages=map { $_ => 1 } @packages;
                                map { delete $packages{$_} } @exclude;
+                               commit_override_log(keys %packages);
                                write_log($override_command, keys %packages);
                        }
+
+                       delete $ENV{DH_INTERNAL_OPTIONS};
+                       delete $ENV{DH_INTERNAL_OVERRIDE};
                }
        }
 }