3 # Copyright The SCons Foundation
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 _is_valid_var
= re
.compile(r
'[_a-zA-Z]\w*$')
28 _rm
= re
.compile(r
'\$[()]')
29 _remove
= re
.compile(r
'\$\([^$]*(\$[^)][^$]*)*\$\)')
31 # Regular expressions for splitting strings and handling substitutions,
32 # for use by the scons_subst() and scons_subst_list() functions:
34 # The first expression compiled matches all of the $-introduced tokens
35 # that we need to process in some way, and is used for substitutions.
36 # The expressions it matches are:
41 # "$variable" [must begin with alphabetic or underscore]
44 # The second expression compiled is used for splitting strings into tokens
45 # to be processed, and it matches all of the tokens listed above, plus
46 # the following that affect how arguments do or don't get joined together:
49 # "non-white-space" [without any dollar signs]
50 # "$" [single dollar sign]
52 _dollar_exps_str
= r
'\$[\$\(\)]|\$[_a-zA-Z][\.\w]*|\${[^}]*}'
53 _dollar_exps
= re
.compile(r
'(%s)' % _dollar_exps_str
)
54 _separate_args
= re
.compile(r
'(%s|\s+|[^\s$]+|\$)' % _dollar_exps_str
)
56 # This regular expression is used to replace strings of multiple white
57 # space characters in the string result from the scons_subst() function.
58 _space_sep
= re
.compile(r
'[\t ]+(?![^{]*})')
62 Enum to store what type of value the variable holds.
70 class EnvironmentValue
:
72 Hold a single value. We're going to cache parsed version of the file
73 We're going to keep track of variables which feed into this values evaluation
75 def __init__(self
, value
) -> None:
77 self
.var_type
= ValueTypes
.UNKNOWN
79 if callable(self
.value
):
80 self
.var_type
= ValueTypes
.CALLABLE
85 def parse_value(self
) -> None:
87 Scan the string and break into component values
91 if '$' not in self
.value
:
92 self
._parsed
= self
.value
93 self
.var_type
= ValueTypes
.STRING
95 # Now we need to parse the specified string
96 result
= _dollar_exps
.sub(sub_match
, args
)
99 # likely callable? either way we don't parse
100 self
._parsed
= self
.value
102 def parse_trial(self
) -> None:
104 Try alternate parsing methods.
112 class EnvironmentValues
:
114 A class to hold all the environment variables
116 def __init__(self
, **kw
) -> None:
119 self
._dict
[k
] = EnvironmentValue(kw
[k
])