diff options
author | Daniel Moody <dmoody256@gmail.com> | 2022-05-10 16:46:55 (GMT) |
---|---|---|
committer | Daniel Moody <dmoody256@gmail.com> | 2022-05-10 16:46:55 (GMT) |
commit | 50fd3e098ec2271acab5a9622cb3b0191bce4455 (patch) | |
tree | e83fac8abf4bf0a41a76f97341a36a9da26681e7 | |
parent | cc811439cbb2a8b57d8626b1dec360ea37eb0ace (diff) | |
download | SCons-50fd3e098ec2271acab5a9622cb3b0191bce4455.zip SCons-50fd3e098ec2271acab5a9622cb3b0191bce4455.tar.gz SCons-50fd3e098ec2271acab5a9622cb3b0191bce4455.tar.bz2 |
added test for EXPANDED_SHELL_VAR
-rw-r--r-- | SCons/Action.py | 4 | ||||
-rw-r--r-- | test/Actions/subst_shell_env-fixture/SConstruct | 24 | ||||
-rw-r--r-- | test/Actions/subst_shell_env.py | 50 |
3 files changed, 76 insertions, 2 deletions
diff --git a/SCons/Action.py b/SCons/Action.py index 0110299..9f72efe 100644 --- a/SCons/Action.py +++ b/SCons/Action.py @@ -732,7 +732,7 @@ def _string_from_cmd_list(cmd_list): default_ENV = None -def get_default_ENV(env): +def get_default_ENV(env, target=None, source=None): """ A fiddlin' little function that has an 'import SCons.Environment' which can't be moved to the top level without creating an import loop. Since @@ -924,7 +924,7 @@ class CommandAction(_ActionAction): escape = env.get('ESCAPE', lambda x: x) - ENV = env.get('SHELL_ENV_EXPANDER', get_default_ENV)(env) + ENV = env.get('SHELL_ENV_EXPANDER', get_default_ENV)(env, target, source) # Ensure that the ENV values are all strings: for key, value in ENV.items(): diff --git a/test/Actions/subst_shell_env-fixture/SConstruct b/test/Actions/subst_shell_env-fixture/SConstruct new file mode 100644 index 0000000..1d6d2ef --- /dev/null +++ b/test/Actions/subst_shell_env-fixture/SConstruct @@ -0,0 +1,24 @@ +import sys + +def custom_environment_expansion(env, target, source): + ENV = env['ENV'] + ENV['EXPANDED_SHELL_VAR'] = env.subst(env['ENV']['EXPANDED_SHELL_VAR'], target=target, source=source) + return ENV + +def expand_this_generator(env, target, source, for_signature): + return "I_got_expanded_to_" + str(target[0]) + +env = Environment(tools=['textfile']) + +env['SHELL_ENV_EXPANDER'] = custom_environment_expansion + +env['EXPAND_THIS'] = expand_this_generator +env['ENV']['EXPANDED_SHELL_VAR'] = "$EXPAND_THIS" +env['ENV']['NON_EXPANDED_SHELL_VAR'] = "$EXPAND_THIS" + +env.Textfile('expand_script.py', [ + 'import os', + 'print(os.environ["EXPANDED_SHELL_VAR"])', + 'print(os.environ["NON_EXPANDED_SHELL_VAR"])', +]) +env.Command('out.txt', 'expand_script.py', f'{sys.executable} $SOURCE > $TARGET') diff --git a/test/Actions/subst_shell_env.py b/test/Actions/subst_shell_env.py new file mode 100644 index 0000000..fda3e00 --- /dev/null +++ b/test/Actions/subst_shell_env.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +""" +Verify that an Action list with a string command containing a Unicode file +name, and a Python function action, works corectly. This verifies that +the signatures of the two actions can be concatenated without encoding +Unicode problems. +""" +import os + +import TestSCons + +test = TestSCons.TestSCons() + +test.dir_fixture('subst_shell_env-fixture') + +test.run(arguments = ['-Q']) +test.must_match('out.txt', f"I_got_expanded_to_out.txt{os.linesep}$EXPAND_THIS{os.linesep}") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: |