[debhelper-devel] [debhelper] 03/04: Dh_Lib: doit - support update_env to change child %ENV
Niels Thykier
nthykier at moszumanska.debian.org
Sat Dec 30 20:59:54 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 23c75208ae487223fbf7de7900d6149a4feed614
Author: Niels Thykier <niels at thykier.net>
Date: Sat Dec 30 20:44:32 2017 +0000
Dh_Lib: doit - support update_env to change child %ENV
Signed-off-by: Niels Thykier <niels at thykier.net>
---
doc/PROGRAMMING | 7 ++++++-
lib/Debian/Debhelper/Dh_Lib.pm | 9 +++++++++
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/doc/PROGRAMMING b/doc/PROGRAMMING
index b76bc9e..bb8a35b 100644
--- a/doc/PROGRAMMING
+++ b/doc/PROGRAMMING
@@ -168,9 +168,14 @@ doit([$options, ]@command)
to that file. [debhelper (>= 10.7)]
* chdir => A directory. The child process will do a chdir into that
directory before executing the command. [debhelper (>= 10.9)]
+ * update_env => A hashref. Each key in it represents an environment variable
+ that should be set in the child (possibly replacing the existing value)
+ prior to the exec. If the value is undef, the environment variable will
+ be unset. Environment variables in %ENV but not listed in the update_env
+ hashref will be preserved as-is. [debhelper (>= 11.1)]
This will *not* invoke a shell, so meta characters will not have any special
- meaning. Use complex_doit for that.
+ meaning. Use complex_doit for that (or emulate via "bash -c").
NB: In compat 11 and below, there was a bug that would make doit fork a shell
in one special case. This is deprecated and will be removed in compat 12.
The detection code for this can be disabled by passing an empty hashref for
diff --git a/lib/Debian/Debhelper/Dh_Lib.pm b/lib/Debian/Debhelper/Dh_Lib.pm
index b44ca7e..17bbe1b 100644
--- a/lib/Debian/Debhelper/Dh_Lib.pm
+++ b/lib/Debian/Debhelper/Dh_Lib.pm
@@ -343,6 +343,15 @@ sub _doit {
if (defined(my $output = $options->{stdout})) {
open(STDOUT, '>', $output) or error("redirect STDOUT failed: $!");
}
+ if (defined(my $update_env = $options->{update_env})) {
+ while (my ($k, $v) = each(%{$update_env})) {
+ if (defined($v)) {
+ $ENV{$k} = $v;
+ } else {
+ delete($ENV{$k});
+ }
+ }
+ }
}
# Force execvp call to avoid shell. Apparently, even exec can
# involve a shell if you don't do this.
--
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