[debhelper-devel] [debhelper] 01/01: dh_gencontrol: Add substvars without using fork+exec

Niels Thykier nthykier at moszumanska.debian.org
Sun Jul 23 11:15:14 UTC 2017


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

nthykier pushed a commit to branch master
in repository debhelper.

commit f6fe609f336c0771654fc79bd1047c10efdca5b5
Author: Niels Thykier <niels at thykier.net>
Date:   Sun Jul 23 11:08:34 2017 +0000

    dh_gencontrol: Add substvars without using fork+exec
    
    Signed-off-by: Niels Thykier <niels at thykier.net>
---
 debian/changelog |  3 +++
 dh_gencontrol    | 38 ++++++++++++++++++++++++++++++--------
 2 files changed, 33 insertions(+), 8 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index d43e5c7..3c43061 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -51,6 +51,9 @@ debhelper (10.7) UNRELEASED; urgency=medium
   * dh_installexamples: Ditto.
   * dh_installinfo: Ditto.
   * dh_installman: Ditto.
+  * dh_gencontrol: Rewrite code that ensures that misc:Depends and
+    misc:Pre-Depends are present to avoid relying external processes
+    for this.
 
  -- Niels Thykier <niels at thykier.net>  Sat, 15 Jul 2017 09:42:32 +0000
 
diff --git a/dh_gencontrol b/dh_gencontrol
index 790f733..18deda9 100755
--- a/dh_gencontrol
+++ b/dh_gencontrol
@@ -8,6 +8,7 @@ dh_gencontrol - generate and install control file
 
 use strict;
 use warnings;
+use Errno qw(ENOENT);
 use Debian::Debhelper::Dh_Lib;
 
 our $VERSION = DH_BUILTIN_VERSION;
@@ -55,6 +56,33 @@ init(options => {
 	"dpkg-gencontrol-params=s", => \$dh{U_PARAMS},
 });
 
+sub ensure_substvars_are_present {
+	my ($file, @substvars) = @_;
+	my (%vars, $fd);
+	return 1 if $dh{NO_ACT};
+	if (open($fd, '+<', $file)) {
+		while (my $line = <$fd>) {
+			my $k;
+			($k, undef) = split(m/=/, $line, 2);
+			$vars{$k} = 1 if $k;
+		}
+		# Fall-through and append the missing vars if any.
+	} else {
+		error("open(${file}) failed: $!") if $! != ENOENT;
+		open($fd, '>', $file) or error("open(${file}) failed: $!");
+	}
+
+	for my $var (@substvars) {
+		if (not exists($vars{$var})) {
+			verbose_print("echo ${var}= >> ${file}");
+			print ${fd} "${var}=\n";
+			$vars{$var} = 1;
+		}
+	}
+	close($fd) or error("close(${file}) failed: $!");
+	return 1;
+}
+
 on_pkgs_in_parallel {
 	foreach my $package (@_) {
 		my $tmp=tmpdir($package);
@@ -71,14 +99,8 @@ on_pkgs_in_parallel {
 
 		install_dir("$tmp/DEBIAN");
 
-		# avoid gratuitous warning
-		if (! -e $substvars || system("grep -q '^misc:Depends=' $substvars") != 0) {
-			complex_doit("echo misc:Depends= >> $substvars");
-		}
-		# avoid (another) gratuitous warning
-		if (! -e $substvars || system("grep -q '^misc:Pre-Depends=' $substvars") != 0) {
-			complex_doit("echo misc:Pre-Depends= >> $substvars");
-		}
+		# avoid gratuitous warnings
+		ensure_substvars_are_present($substvars, 'misc:Depends', 'misc:Pre-Depends');
 
 		my (@debug_info_params, $build_ids, @multiarch_params);
 		if ( -d $dbgsym_info_dir ) {

-- 
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