SCONS 运行目标 [英] SCONS run target

查看:40
本文介绍了SCONS 运行目标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找,一直在寻找,但找不到我问题的答案.我今晚刚开始学习 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.

为了便于开发,我经常喜欢让我的 make 文件构建我的目标,然后运行它,以便我可以一键测试更改.这在 make 文件中非常简单:

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])

但是这个解决方案有问题.就我的实验而言,scons 不会等到您的程序完成构建后再开始子进程调用,因此您最终会运行旧的可执行文件,或者如果它是清理后的构建,则会出现错误.

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.

推荐答案

我对你来说可能有点晚了,但我有这个使用 Alias 的解决方案.通过使用以下命令,它将构建并运行程序:

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:

$ scons run

# Define the different target output
program = env.Program('build/output', Glob('build/test/*.cpp'))

env.Default(program)
env.Alias('run', program, program[0].abspath)

注意我们使用的是abspath,所以它可以是跨平台的win/linux(对于linux,如果你的PATH设置不正确,你需要在程序名前加上./".

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.

这篇关于SCONS 运行目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆