append value to environment variable on builder call

僤鯓⒐⒋嵵緔 提交于 2019-12-11 03:15:23

问题


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?


回答1:


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)


来源:https://stackoverflow.com/questions/10365776/append-value-to-environment-variable-on-builder-call

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!