From e2c4829658334fa26a86298bcdbd06e2244500b0 Mon Sep 17 00:00:00 2001 From: Michael Pyne Date: Thu, 9 Apr 2009 02:33:21 +0000 Subject: [PATCH] Give up on saving the values of the program environment in Perl and simply only change the environment in child processes. This should help with run-tests and a couple of other reports of environment variables disappearing. (Doesn't help that I was using "local %ENV" wrong but it seemed to happen to work here) I'll work further on testing on Friday probably as I will be away Thursday. CCMAIL:dfaure@kde.org svn path=/trunk/KDE/kdesdk/scripts/kdesvn-build; revision=951359 --- kdesvn-build | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/kdesvn-build b/kdesvn-build index d191a2f..25559e7 100755 --- a/kdesvn-build +++ b/kdesvn-build @@ -371,6 +371,19 @@ our %package_opts = ( } ); +# This hash is used to store environment variables to be used on the next +# execution of log_command(). This is done so that we don't have to fork new +# processes just to change values in the environment. +# +# Previously we simply saved %ENV in a temp hash, but that broke on some systems. +# Then we used 'local %ENV' to push/pop the environment from a stack but it only +# really worked on the developer's system. :( +# +# Now we save environment variables to set right after forking... +# +# Don't use this except via setenv(), resetenv(), and log_command(). +my %ENV_VARS; + # Base class for IPC interaction. Should have most of the functionality, with # the actual bits of reading and writing left to subclasses. { @@ -2261,6 +2274,11 @@ sub log_command else { # Child + + # Apply altered environment variables. + whisper "Environment altered for child"; + $ENV{$_} = $ENV_VARS{$_} foreach keys %ENV_VARS; + if (not defined $logdir or not -e $logdir) { # Error creating directory for some reason. @@ -2759,7 +2777,14 @@ sub setenv whisper "\tWould have set g[$var]=y[$val]." if pretending; - $ENV{$var} = $val; + $ENV_VARS{$var} = $val; +} + +# Clears out the list of environment variables to apply to created +# subprocesses. +sub resetenv +{ + %ENV_VARS = (); } # Display a message to the user regarding their relative lack of @@ -5897,7 +5922,7 @@ EOF while (my $module = shift @modules) { note "Building g[$module] ($i/$num_modules)"; - local %ENV; # Saves environment to keep module changes from conflicting + resetenv(); # Resets the list of env vars to change my $start_time = time; # If using IPC, read in the contents of the message buffer, and wait @@ -6882,7 +6907,7 @@ eval { # Installation mode for my $module (get_install_list()) { - local %ENV; # Don't keep overwriting environment + resetenv(); # Don't keep overwriting environment update_module_environment ($module); $result = handle_install ($module) || $result; }