获取 scons 根目录

发布于 2024-08-05 09:08:22 字数 811 浏览 3 评论 0原文

我需要作为自定义构建器的一部分按顺序运行两个程序。

其中之一是我无法处理绝对/相对路径的程序,因此我必须使用生成器的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

萌无敌 2024-08-12 09:08:22

您应该使用“#”来指示源目录的顶部。

print Dir('#').abspath

如果您也使用变体目录,此版本也适用。例如在 SConstruct 中:

SConscript('main.scons', variant_dir="build")

然后在 ma​​in.scons 中:

print Dir('.').abspath
print Dir('#').abspath

第一个将打印 /path/to/project/build,而第二个将显示正确的/path/to/project

You should use "#" to indicate the top of the source directory.

print Dir('#').abspath

This version works if you use a variant directory too. For example in SConstruct:

SConscript('main.scons', variant_dir="build")

Then in main.scons:

print Dir('.').abspath
print Dir('#').abspath

The first will print /path/to/project/build, whereas the second will show the correct /path/to/project.

追我者格杀勿论 2024-08-12 09:08:22

咕噜。很简单;这似乎有效。

env['BUILD_ROOT'] = Dir('.');
Builder(action = ['somecmd ${BUILD_ROOT.abspath}/tools/myscript.bar ...']);

Grrr. It is simple; this seems to work.

env['BUILD_ROOT'] = Dir('.');
Builder(action = ['somecmd ${BUILD_ROOT.abspath}/tools/myscript.bar ...']);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文