[debhelper-devel] [debhelper] 01/01: Dh_Lib: Promote error_exitcode to an API sub

Niels Thykier nthykier at moszumanska.debian.org
Wed May 20 20:14:36 UTC 2015


This is an automated email from the git hooks/post-receive script.

nthykier pushed a commit to branch master
in repository debhelper.

commit bdb3a1f1e12b272dcff0f8d5fff3e2b499f19ec0
Author: Niels Thykier <niels at thykier.net>
Date:   Wed May 20 22:14:14 2015 +0200

    Dh_Lib: Promote error_exitcode to an API sub
    
    Signed-off-by: Niels Thykier <niels at thykier.net>
---
 Debian/Debhelper/Dh_Lib.pm | 26 +++++++++++++++++++-------
 debian/changelog           |  4 ++++
 doc/PROGRAMMING            |  6 ++++++
 3 files changed, 29 insertions(+), 7 deletions(-)

diff --git a/Debian/Debhelper/Dh_Lib.pm b/Debian/Debhelper/Dh_Lib.pm
index e26fb64..2285c2d 100644
--- a/Debian/Debhelper/Dh_Lib.pm
+++ b/Debian/Debhelper/Dh_Lib.pm
@@ -21,7 +21,7 @@ use vars qw(@ISA @EXPORT %dh);
 	    &dpkg_architecture_value &sourcepackage &make_symlink
 	    &is_make_jobserver_unavailable &clean_jobserver_makeflags
 	    &cross_command &set_buildflags &get_buildoption
-	    &install_dh_config_file
+	    &install_dh_config_file &error_exitcode
 	    &install_file &install_prog &install_lib &install_dir
 );
 
@@ -221,7 +221,7 @@ sub escape_shell {
 # Note that this cannot handle complex commands, especially anything
 # involving redirection. Use complex_doit instead.
 sub doit {
-	doit_noerror(@_) || _error_exitcode(join(" ", @_));
+	doit_noerror(@_) || error_exitcode(join(" ", @_));
 }
 
 sub doit_noerror {
@@ -236,7 +236,7 @@ sub doit_noerror {
 }
 
 sub print_and_doit {
-	print_and_doit_noerror(@_) || _error_exitcode(join(" ", @_));
+	print_and_doit_noerror(@_) || error_exitcode(join(" ", @_));
 }
 
 sub print_and_doit_noerror {
@@ -259,21 +259,33 @@ sub complex_doit {
 	
 	if (! $dh{NO_ACT}) {
 		# The join makes system get a scalar so it forks off a shell.
-		system(join(" ", @_)) == 0 || _error_exitcode(join(" ", @_))
+		system(join(" ", @_)) == 0 || error_exitcode(join(" ", @_))
 	}			
 }
 
 sub _error_exitcode {
+	# A little "reminder" warning to a dh-like tool that have abused
+	# this internal subroutine...
+	warning('[Deprecation] The internal sub _error_exitcode will be removed - please stop using it');
+	error_exitcode(@_);
+}
+
+sub error_exitcode {
 	my $command=shift;
 	if ($? == -1) {
 		error("$command failed to to execute: $!");
 	}
 	elsif ($? & 127) {
 		error("$command died with signal ".($? & 127));
-        }
-	else {
+	}
+	elsif ($?) {
 		error("$command returned exit code ".($? >> 8));
 	}
+	else {
+		warning("This tool claimed that $command have failed, but it");
+		warning("appears to have returned 0.");
+		error("Probably a bug in this tool is hiding the actual problem.");
+	}
 }
 
 # Some shortcut functions for installing files and dirs to always
@@ -1174,7 +1186,7 @@ sub install_dh_config_file {
 		}
 		if (!close($sfd)) {
 			error("cannot close handle from $source: $!") if $!;
-			_error_exitcode($source);
+			error_exitcode($source);
 		}
 		close($tfd) || error("cannot close $target: $!");
 		# Set the mtime (and atime) to ensure reproducibility.
diff --git a/debian/changelog b/debian/changelog
index a3f2775..6b066a4 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -3,6 +3,10 @@ debhelper (9.20150508) UNRELEASED; urgency=medium
   * Buildsystem.pm: Apply patch from Emmanuel Bourg to
     provide doit_in_{build,source}dir_noerror methods.
     (Closes: #785811)
+  * Dh_Lib.pm: Promote error_exitcode to a regular exported
+    subroutine (from an internal one).  For backwards
+    compatibility the old _error_exitcode will be provided
+    until a known external is updated.
 
  -- Niels Thykier <niels at thykier.net>  Wed, 20 May 2015 21:53:08 +0200
 
diff --git a/doc/PROGRAMMING b/doc/PROGRAMMING
index bca2312..36eb88e 100644
--- a/doc/PROGRAMMING
+++ b/doc/PROGRAMMING
@@ -173,6 +173,12 @@ nonquiet_print($message)
 error($errormsg)
 	Pass this command a string, it will output it to standard error and
 	exit.
+error_exitcode($cmd)
+	Pass this subroutine a string (representing a command line), it will
+	output a message describing that the command failed to standard error
+	and exit.  Note that this relies on the value of $? to produce a
+	meaningful error message.  Even if $? is 0, this /will/ still terminate
+	the program (although with a rather unhelpful message).
 warning($message)
 	Pass this command a string, and it will output it to standard error
 	as a warning message.

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debhelper/debhelper.git




More information about the debhelper-devel mailing list