Reputation: 177
The problem is as follows: I have an environment with some variables defined like this:
env = Environment(CPPPATH=['#/include'])
In some cases I need to invoke a builder with some extra values which should not be added permanently to the environment to not unnecessarily pollute it.
One way is to append the extra value to the builder call by merging it with the environment's value.
env.Object('test.c', CPPPATH=['#/some_other_include_path']+env['CPPPATH'])
Is there a more elegant way to do it?
Upvotes: 2
Views: 2447
Reputation: 10357
I do this by cloning the env and appending on to it, like this:
clonedEnv = env.Clone()
clonedEnv.Append(CPPPATH=['#anotherPath'])
clonedEnv.Object('test.c')
A more pythonic (and efficient) way to do what you are doing would be to use the python list.extend() function:
cpppath = ['path1', 'path2']
cpppath.extend(env['CPPPATH'])
env.Object('test.c', CPPPATH = cpppath)
Upvotes: 3