1 import SCons.Util, SCons.Defaults
4 class BuildTypeOptions:
5 def __init__(self, var):
8 def __call__(self, target, source, env, for_signature):
9 type = env['final'] and "final" or env['debug'] and "debug" or "normal"
10 return env[self._var + "_" + type]
12 _DOLLAR_RE = re.compile(r'\$([a-zA-Z_][\.\w]*)|\${([^}]*)}')
14 def _expandDefines(defs, target, source, env, for_signature):
16 if SCons.Util.is_Dict(defs):
19 defs = [ (k,defs[k]) for k in keys ]
20 elif not SCons.Util.is_List(defs):
23 if SCons.Util.is_String(elt):
24 m = _DOLLAR_RE.match(elt)
26 match = m.group(1) or m.group(2)
27 try: rv.extend(_expandDefines(eval(match, env.gvars(), env.lvars()),
28 target, source, env, for_signature))
29 except NameError: pass
30 except IndexError: pass
32 rv.append(env.subst(elt))
34 rv.extend(_expandDefines(elt(target, source, env, for_signature),
35 target, source, env, for_signature))
36 elif SCons.Util.is_Sequence(elt):
37 if len(elt)<2 or elt[1] is None:
38 rv.append(env.subst(elt[0]))
40 rv.append(env.subst(elt[0]) + "=" + env.subst(elt[1]))
45 def expandDefines(prefix, defs, suffix, env):
46 """Expand defines in <defs> using <env>. Calls SCons.Defaults._concat_ixes
47 to append prefix/suffix before/after each define.
50 Call the callable and replace it with the call result. If the result
51 is a list, the list is processed recursively. It the result is a
52 dictionary it is converted into a list of typles and processed
54 '$<variable>' or '${<variable>}'
55 Replace the element with the variable expansion. If the result is a
56 list, the list is processed recursively. It the result is a
57 dictionary it is converted into a list of typles and processed
60 Define a symbol with that (expanded!) name
62 The iteratble must have two elments. The first element defines the
63 symbol name, the second the symbol value."""
65 defs = _expandDefines(defs, None, None, env, False)
66 return SCons.Defaults._concat_ixes(prefix, defs, suffix, env)
68 def _BuildTypeOptions(env, var) : return BuildTypeOptions(var)
72 _defines = expandDefines,
75 env.AddMethod(_BuildTypeOptions, 'BuildTypeOptions')