SCons 有一个功能称为“变量 http://www.scons.org/doc/production/HTML/scons-user/x2429.html#AEN2488“。您可以对其进行设置,以便它很容易地从命令行参数变量中读取。因此,在您的情况下,您可以从命令行执行类似的操作:
scons LIBFOO=C:\custom_path\libfoo
...并且该变量将在运行之间被记住。所以下次你跑步的时候scons
它使用 LIBFOO 的先前值。
在代码中你可以像这样使用它:
# read variables from the cache, a user's custom.py file or command line
# arguments
var = Variables(['variables.cache', 'custom.py'], ARGUMENTS)
# add a path variable
var.AddVariables(PathVariable('LIBFOO',
'where the foo library is installed',
r'C:\default\libfoo', PathVariable.PathIsDir))
env = Environment(variables=var)
env.Program('test', 'main.c', LIBPATH='$LIBFOO')
# save variables to a file
var.Save('variables.cache', env)
如果您确实想使用“--”样式选项,那么您可以将上述内容与AddOption
功能,但比较复杂。
这个问题 https://stackoverflow.com/questions/456100/scons-problem-dont-understand-variables-class讨论从变量对象中获取值而不通过环境传递它们所涉及的问题。