Debian Codegraph @

test/Actions/subst_shell_env-fixture/SConstruct

raw
1 # SPDX-License-Identifier: MIT
2 #
3 # Copyright The SCons Foundation
4
5 import sys
6
7 def custom_environment_expansion1(env, target, source, shell_env):
8 ENV = shell_env.copy()
9 ENV['EXPANDED_SHELL_VAR1'] = env.subst(env['ENV']['EXPANDED_SHELL_VAR1'], target=target, source=source)
10 return ENV
11
12 def custom_environment_expansion2(env, target, source, shell_env):
13 ENV = shell_env.copy()
14 ENV['EXPANDED_SHELL_VAR2'] = env.subst(env['ENV']['EXPANDED_SHELL_VAR2'], target=target, source=source)
15 return ENV
16
17 def expand_this_generator(env, target, source, for_signature):
18 return "I_got_expanded_to_" + str(target[0])
19
20 def expand_that_generator(env, target, source, for_signature):
21 return str(target[0]) + "_is_from_expansion"
22
23 DefaultEnvironment(tools=[])
24 env = Environment(tools=['textfile'])
25
26 env['SHELL_ENV_GENERATORS'] = [custom_environment_expansion1, custom_environment_expansion2]
27
28 env['EXPAND_THIS'] = expand_this_generator
29 env['EXPAND_THAT'] = expand_that_generator
30
31 env['ENV']['EXPANDED_SHELL_VAR1'] = "$EXPAND_THIS"
32 env['ENV']['EXPANDED_SHELL_VAR2'] = "$EXPAND_THAT"
33 env['ENV']['NON_EXPANDED_SHELL_VAR'] = "$EXPAND_THIS"
34
35 env.Textfile('expand_script.py', [
36 'import os',
37 'print(os.environ["EXPANDED_SHELL_VAR1"])',
38 'print(os.environ["EXPANDED_SHELL_VAR2"])',
39 'print(os.environ["NON_EXPANDED_SHELL_VAR"])',
40 ])
41 env.Command('out.txt', 'expand_script.py', fr'{sys.executable} $SOURCE > $TARGET')
42
43 env.Depends('out.txt', env.Command('out2.txt', 'expand_script.py', fr'{sys.executable} $SOURCE > $TARGET'))