根据scons documentation,subst
方法将递归插值构造变量。然而,这似乎并没有递归:递归变量替换env.subst
e = Environment(CPPDEFINES = ["FOOBAR=${foobar}"])
e["foo"] = 1
e["bar"] = "${foo + 1}"
e["foobar"] = "$${foo + ${bar}}"
# I want this to print "foobar: 3"
print "foobar:", e.subst("${foobar}")
e.Program("test.c")
打印:
scons: Reading SConscript files ...
foobar: ${foo + 2}
scons: done reading SConscript files.
scons: Building targets ...
gcc -o test.o -c -DFOOBAR=3 test.c
gcc -o test test.o
scons: done building targets.
foobar
编译为CPPDEFINES的一部分时被正确评估,而不是在print语句。我怎样才能让subst
完全评估foobar?
我目前无法对其进行测试,并且我无法在文档中找到它,因此我无法发布完整答案,但我认为$$已被转移到非易失性存储器中,评估$。尝试使用相同的代码,但使用e [“foobar”] =“$ {foo + $ {bar}}” –