From f6b40110c10a164902360b1139ed6da00021b58a Mon Sep 17 00:00:00 2001 From: Michael Pyne Date: Fri, 28 Dec 2012 21:51:55 -0500 Subject: [PATCH] Move set-env handling to Module. --- kdesrc-build | 21 +-------------------- kdesrc-build-test.pl | 2 +- modules/ksb/Module.pm | 39 ++++++++++++++++++++++++++++++++++++--- 3 files changed, 38 insertions(+), 24 deletions(-) diff --git a/kdesrc-build b/kdesrc-build index 3b7980d..21424d8 100755 --- a/kdesrc-build +++ b/kdesrc-build @@ -716,7 +716,7 @@ sub parse_moduleset } } elsif ($option eq 'set-env') { - handle_set_env(\%optionSet, $option, $value); + Module::processSetEnvOption(\%optionSet, $option, $value); } else { $optionSet{$option} = $value; @@ -1238,25 +1238,6 @@ sub extract_option_value_required($\@) return $returnValue; } -# Utility subroutine to handle setting the environment variable type of value. -# Returns true (non-zero) if this subroutine handled everything, 0 otherwise. -# The first parameter should by the reference to the hash with the 'set-env' -# hash ref, second parameter is the exact option to check, and the third -# option is the value to set that option to. -sub handle_set_env -{ - my ($href, $option, $value) = @_; - - return 0 if $option !~ /^#?set-env$/; - - my ($var, @values) = split(' ', $value); - - ${$href}{$option} //= { }; - ${$href}{$option}->{$var} = join(' ', @values); - - return 1; -} - # Function: process_arguments # # Processes the command line arguments, which are used to modify the given diff --git a/kdesrc-build-test.pl b/kdesrc-build-test.pl index c3e3d8c..edc39bd 100755 --- a/kdesrc-build-test.pl +++ b/kdesrc-build-test.pl @@ -95,7 +95,7 @@ eval { ksb::Util->import(); -# If using set-env, it is handled by the handle_set_env routine, so the +# If using set-env, it is handled by the Module::processSetEnvOption, so the # value should be the space separated VAR and VALUE. $ctx->setOption('set-env', 'TESTY_MCTEST yes'); $ctx->setOption('cxxflags', '-g -O0'); diff --git a/modules/ksb/Module.pm b/modules/ksb/Module.pm index 1253c55..9618fb3 100644 --- a/modules/ksb/Module.pm +++ b/modules/ksb/Module.pm @@ -821,6 +821,39 @@ sub hasOption return exists $self->{options}{$key}; } +# Function: processSetEnvOption +# +# Handles setting set-env options in a format appropriate for a Module option +# hash (a reference to which should be given as the first argument). +# +# Though part of the Module package, this is a simple sub, not a "method", so +# call with Module::processSetEnvOption, not ->. +# +# Parameters: +# +# optionHash - hashref to the option hash where the set-env option(s) will be +# stored. The environment variable settings will be stored under the 'set-env' +# key, which will hold a hashref to the variables/values. +# variable - Name of the environment variable to later set. +# value - Value to give to the environment (can be empty). +# +# Returns: +# +# Boolean true if variable was processed, false otherwise. +sub processSetEnvOption +{ + my ($href, $variable, $value) = @_; + + return if $variable !~ /^#?set-env$/; + + my ($var, @values) = split(' ', $value); + + ${$href}{$variable} //= { }; + ${$href}{$variable}->{$var} = join(' ', @values); + + return 1; +} + # Sets the option refered to by the first parameter (a string) to the # scalar (e.g. references are OK too) value given as the second paramter. sub setOption @@ -828,9 +861,9 @@ sub setOption my ($self, %options) = @_; while (my ($key, $value) = each %options) { # ref($value) checks if value is already a reference (i.e. a hashref) - # which means we should just copy it over, as all handle_set_env does - # is convert the string to the right hashref. - if (!ref($value) && main::handle_set_env($self->{options}, $key, $value)) + # which means we should just copy it over, as all processSetEnvOption + # does is convert the string to the right hashref. + if (!ref($value) && processSetEnvOption($self->{options}, $key, $value)) { return }