我写了一个python函数,比如替换字符串,并在scons脚本中调用.
def Replace(env, filename, old, new):
with open(filename,"r+") as f:
d = f.read()
d = d.replace(old, new)
f.truncate(0)
f.seek(0)
f.write(d)
f.close()
env.AddMethod(Replace,'Replace')
Run Code Online (Sandbox Code Playgroud)
在SConscript中
lib = env.SharedLibrary('lib', object, extra_libs)
tmp = env.Command([],[],[env.Replace(somefile, 'A', 'b')] )
env.Depends(tmp,lib )
Run Code Online (Sandbox Code Playgroud)
我期望在lib构建之后运行Replace()方法.但是scons总是在第一轮脚本解析短语中运行Replace().似乎我错过了一些依赖.