diff options
author | William Deegan <bill@baddogconsulting.com> | 2022-05-12 18:44:31 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-12 18:44:31 (GMT) |
commit | fdae889759be56c6299bcedc577aecf2225f0190 (patch) | |
tree | 13a3135601bfb57a1ca16c0e92c24b264a4e0049 /test | |
parent | 49207b9527118ddb6f40e351e6b2436c7e934cb8 (diff) | |
parent | 88eea7f204de3dd2ba524d33093f6970b996191a (diff) | |
download | SCons-fdae889759be56c6299bcedc577aecf2225f0190.zip SCons-fdae889759be56c6299bcedc577aecf2225f0190.tar.gz SCons-fdae889759be56c6299bcedc577aecf2225f0190.tar.bz2 |
Merge pull request #4144 from dmoody256/shell_subst_env_vars
Added SHELL_ENV_EXPANDER to configure/alter/generate shell environment before commands are spawned.
Diffstat (limited to 'test')
-rw-r--r-- | test/Actions/subst_shell_env-fixture/SConstruct | 26 | ||||
-rw-r--r-- | test/Actions/subst_shell_env.py | 48 |
2 files changed, 74 insertions, 0 deletions
diff --git a/test/Actions/subst_shell_env-fixture/SConstruct b/test/Actions/subst_shell_env-fixture/SConstruct new file mode 100644 index 0000000..6e48add --- /dev/null +++ b/test/Actions/subst_shell_env-fixture/SConstruct @@ -0,0 +1,26 @@ +import sys + +def custom_environment_expansion(env, target, source): + ENV = env['ENV'].copy() + 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_GENERATOR'] = 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', fr'{sys.executable} $SOURCE > $TARGET') + +env.Depends('out.txt', env.Command('out2.txt', 'expand_script.py', fr'{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..9f5c5db --- /dev/null +++ b/test/Actions/subst_shell_env.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python +# +# Copyright The SCons Foundation +# +# 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. +# + + +""" +Verify that shell environment variables can be expanded per target/source +when exectuting actions on the command line. +""" +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.must_match('out2.txt', f"I_got_expanded_to_out2.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: |