SCONS 运行目标
我一直在寻找、寻找,但找不到我的问题的答案。 我今晚刚刚开始学习 scons,看起来棒极了!不过我遇到了一点困惑。
为了便于开发,我经常喜欢让我的 make 文件构建我的目标,然后运行它,以便我可以通过一次按键来测试更改。这在 make 文件中非常简单:
run: $(exe)
chmod a+x $(exe)
$(exe)
我发现我可以使用 subprocess 来完成它,如下所示:
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 不会等到程序构建完成才开始子进程调用,因此您最终会运行旧的可执行文件,或者如果它是清理后的构建,则会出现错误。
I've been looking, and looking, and I can't find an answer to my question.
I've just started learning scons tonight, and it looks awesome! I'm running into a little confusion though.
For ease of development, I often like to have my make file build my target, and then run it so that I can test a change with one keystroke. This is very simple in a make file:
run: $(exe)
chmod a+x $(exe)
$(exe)
I have figured out that I can do it using subprocess like so:
import subprocess import os.path
env = Environment();
result = env.Program(target = "FOO", source = "BAR");
location = os.path.abspath(result[0].name)
subprocess.call([location])
But there's a problem with this solution. As far as I have experimented, scons won't wait until your program is finished building before it starts the subprocess call, so you end up running the old executable, or having an error if it's a build after a clean.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您在 scons 文件中所做的操作是 scons 中典型的初学者错误。您假设您正在编写用于构建项目的脚本。
Scons 不是这样工作的。 scons 文件是一个将目标添加到项目的脚本。这是通过 python 完成的,各种对象允许您创建和操作目标,直到脚本完成。 首先项目将开始构建。
您在代码中所做的就是描述要使用的环境、要创建的程序以及之后的内容您调用运行某个程序的子进程。此后,项目将开始构建 - 难怪旧的可执行文件已运行,新的可执行文件尚未开始构建。
您应该做的是使用自定义构建器来执行程序。
这里依赖关系很清楚,程序必须在执行完成之前构建,并且它会
What you do in your scons file is a typical beginner error in scons. Your assume that you are writing a script for building your project.
Scons doesn't work like that. The scons files is a script that add targets to the project. This is done through python, and the various objects allows you to create and manipulate targets until the script is done. First then will the project start building.
What you do in your code is to describe the Environment to use, the Program to create, and after that you call a subprocess that runs some program. After this the project will start building - no wonder the old executable is run, the new one haven't started to be built yet.
What you should do is to use a custom builder for executing the program.
Here the dependencies are clear, the program must be built before the execution is done, and it will
我可能对你来说有点晚了,但我有使用 Alias 的解决方案。
通过使用以下命令,它将构建并运行程序:
注意,我们使用了abspath,因此它可以跨平台win/linux(对于linux,如果您的PATH是,则需要在程序名前添加“./”)设置不正确。
I may be a little bit late for you, but I have this solution using Alias.
By using the following command, it will build and run the program:
note that we use the abspath, so it can be cross platform win/linux (for linux you need to add the "./" before the program name if your PATH is not correctly set.
好吧,我有点紧张回答我自己的问题,但我找到了一个或多或少可以接受的解决方案。
我刚刚建立了一个简单的链。
我设置了一个 Makefile,其中包含类似的内容:
这会以静默模式调用 scons,然后自动运行您的程序。这不是一个仅限 scons 的解决方案,但它确实有效。我仍然有兴趣看看是否有人有其他答案。
谢谢!
墨菲
Ok, I'm a little nervous to answer my own question, but I found a more or less acceptable solution.
I have just set up a simple chain.
I set up a Makefile with something like this in it:
This calls scons in silent mode, and runs your program automatically afterwards. It's not a scons-only solution, but it works. I'd still be interested to see if anyone has another answer.
Thanks!
Murphy