我一直在寻找、寻找,但找不到我的问题的答案。
我今晚刚刚开始学习 scons,看起来棒极了!不过我遇到了一点困惑。
为了便于开发,我经常喜欢让我的 make 文件构建我的目标,然后运行它,以便我可以通过一次按键来测试更改。这在 make 文件中非常简单:
run: $(exe)
chmod a+x $(exe)
$(exe)
我发现我可以使用子进程来做到这一点,如下所示:
import subprocess import os.path
env = Environment();
result = env.Program(target = "FOO", source = "BAR");
location = os.path.abspath(result[0].name)
subprocess.call([location])
但这个解决方案有一个问题。据我试验, scons 不会等到你的程序完成构建才开始子进程调用,所以你最终会运行旧的可执行文件,或者如果它是清理后的构建,则会出现错误。
您在 scons 文件中所做的操作是 scons 中典型的初学者错误。您假设您正在编写用于构建项目的脚本。
Scons 不是这样工作的。 scons 文件是一个脚本,添加targets到项目。这是通过 python 完成的,各种对象允许您创建和操作目标,直到脚本完成。首先,该项目将开始建设。
您在代码中所做的就是描述环境使用时,将Program创建,然后调用运行某个程序的子进程。此后,项目将开始构建 - 难怪旧的可执行文件已运行,新的可执行文件尚未开始构建。
您应该做的是使用自定义构建器来执行程序。
env = Environment() #construct your environment
files = "test.cpp" #env.Glob or list some files
#now we create some targets
program = env.Program("test",files) #create the target *program*
execution = env.Command(None,None,"./test") #create the execution target (No input & output
Depends(execution,program) #tell scons that execution depends on program
#there might be a way to get SCons to figure out this dependency itself
#now the script is completed, so the targets are built
这里依赖关系很清楚,程序必须在执行完成之前构建,并且它会
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)