获取 scons 根目录
我需要作为自定义构建器的一部分按顺序运行两个程序。
其中之一是我无法处理绝对/相对路径的程序,因此我必须使用生成器的 chdir=1 选项,以便其操作在相同的路径中运行目录作为目标。
第二个是位于项目的 tools
子目录中的脚本; SConstruct 文件位于项目的根目录中。我需要创建一个操作来运行此脚本,但遇到了麻烦,因为我既没有项目的绝对路径,也没有从目标所在目录到工具的相对路径> 脚本所在的子目录。如果我能以某种方式获得项目根目录的绝对路径,我就准备好了,我可以连接“tools/myscript.bar”并完成它。
这或多或少是我所拥有的:
env['BUILDERS']['FooBar'] = Builder(action = [
'c:/bin/foo.exe ${SOURCE.filebase}',
'c:/bin/bar-interpreter.exe myscript.bar ${SOURCE.filebase}',
], chdir=1);
问题是我需要更改有问题的操作,以便可以找到“myscript.bar”,例如:
env['BUILDERS']['FooBar'] = Builder(action = [
'c:/bin/foo.exe ${SOURCE.filebase}',
'c:/bin/bar-interpreter.exe $PATHTOHERE/tools/myscript.bar ${SOURCE.filebase}',
], chdir=1);
这看起来很简单,但我不知道如何做。
I need to run two programs in sequence as part of a custom builder.
One of them is a program that I'm stuck with and can't deal with absolute/relative paths so I have to use the chdir=1
option of the Builder so that its actions run in the same directory as the target.
The second is a script that is located in the tools
subdirectory of the project; the SConstruct file is in the root of the project. I need to create an action to run this script, and am having trouble because I have neither the absolute path to the project, nor a relative path from the directory in which the target is located back up to the tools
subdirectory where the script is located. If I could somehow get the absolute path to the root directory of my project, I'd be all set, I could just concatenate `tools/myscript.bar' and be done with it.
Here's what I have, more or less:
env['BUILDERS']['FooBar'] = Builder(action = [
'c:/bin/foo.exe ${SOURCE.filebase}',
'c:/bin/bar-interpreter.exe myscript.bar ${SOURCE.filebase}',
], chdir=1);
The problem is that I need to change the action in question so that "myscript.bar" can be found, something like:
env['BUILDERS']['FooBar'] = Builder(action = [
'c:/bin/foo.exe ${SOURCE.filebase}',
'c:/bin/bar-interpreter.exe $PATHTOHERE/tools/myscript.bar ${SOURCE.filebase}',
], chdir=1);
This seems so simple but I can't figure out how.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该使用“#”来指示源目录的顶部。
如果您也使用变体目录,此版本也适用。例如在 SConstruct 中:
然后在 main.scons 中:
第一个将打印
/path/to/project/build
,而第二个将显示正确的/path/to/project
。You should use "#" to indicate the top of the source directory.
This version works if you use a variant directory too. For example in SConstruct:
Then in main.scons:
The first will print
/path/to/project/build
, whereas the second will show the correct/path/to/project
.咕噜。很简单;这似乎有效。
Grrr. It is simple; this seems to work.