SCons - 如何为跨脚本的目标提供显式依赖关系

发布于 2025-01-06 00:52:38 字数 696 浏览 2 评论 0原文

这是我的主要 SConstruct 文件

env = Environment()

gen_source = env.SConscript(
        'generate_sources.scons',
        variant_dir='derived_src', src_dir='src',
        duplicate=0)
compile_source = env.SConscript('compile.scons',
        variant_dir='build', src_dir='derived_src',
        duplicate=0)
env.Depends('build/', 'derived_src/')

gen_source 是一个具有一个源生成器目标的脚本,该目标从我的源目录输出 衍生_src/ 中的文件,以及 compile_source是一个具有多个目标的脚本。

如果命令行中没有提供目标,即运行scons,它将生成源代码然后编译,但如果提供了目标,例如scons pg_test,那么scons将失败并抱怨 衍生_src/some_file 不存在。

对这种目标关系进行建模的最佳方法是什么?最好我希望改变它的行为,以便它只生成要编译的源代码。

This is my main SConstruct file

env = Environment()

gen_source = env.SConscript(
        'generate_sources.scons',
        variant_dir='derived_src', src_dir='src',
        duplicate=0)
compile_source = env.SConscript('compile.scons',
        variant_dir='build', src_dir='derived_src',
        duplicate=0)
env.Depends('build/', 'derived_src/')

The gen_source is a script with one source generator target which outputs files in derived_src/ from my source directory, and compile_source is a script with multiple targets.

If no target is provided in command line, i.e. run scons, it will generate sources then compile, but if a target is provided, such as scons pg_test then scons will fail and complain about derived_src/some_file does not exist.

What is the best way to model such a relationship of targets? Preferably I hope to change its behaviour such that it only generates the sources that are going to be compiled.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

二手情话 2025-01-13 00:52:38

根据您从 gen_source 和compile_source SConscript 执行返回的内容,如果它是一个目标列表,那么我认为像这样设置依赖关系会更有意义:

env.Depends(compile_source, gen_source)

或者如果您没有返回目标列表,那么在至少,将目录放在相对于根 SConstruct 的位置,如下所示:

env.Depends('#build', '#derived_src')

进一步的一步是指定这些目录中的文件,可能使用 Glob()

希望有帮助。

Depending on what you are returning from the gen_source and compile_source SConscript executions, if its a list of targets then I think it would make more sense to setup the dependencies like this:

env.Depends(compile_source, gen_source)

Or if you're not returning a list of targets, then at the very least, put the directories relative to the root SConstruct, like this:

env.Depends('#build', '#derived_src')

And one step further would be to specify the files in those directories, possibly with Glob()

Hope that helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文