Scons:创建后期目标 [英] Scons: create late targets

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

问题描述

我们有两个工具:Tool1 和 Tool2.Tool1 基于 SourceFile 创建一些 TargetFile.Tool2 使用 Tool1 (TargetFile) 的输出作为源.结构类似于:

 env.Tool1(TargetFile, SourceFile)env.Tool2(NewTargetFile, TargetFile)

问题在于 Tool2 的发射器使用 TargetFile 创建新目标:

 def Tool2_emitter(target, source, env):target.append( CreateNewTargetFunc(source) )返回目标,源

但是当Scons创建一个依赖时,他找不到TargetFile,因为它还没有创建.

是否可以在创建依赖之前运行 Tool1 的生成器?

解决方案

发射器实际上并不是用来构建"东西的,例如您示例中的文件 TargetFile.它只是返回将在构建阶段稍后"创建或更新的目标.SCons 将通过将虚拟"文件(可能尚未物理存在)存储在内部数据结构中来记录此信息.稍后在实际构建期间解析依赖项时也会使用此树.请注意,通过发射器更新目标和源列表"与使用为当前构建器指定的单个操作构建目标"是完全不同的任务.它们甚至不必匹配,关于生成的文件的名称!

发射器在解析阶段"运行,但构建器及其操作在构建阶段"(在阅读所​​有 SConstructs 之后)执行.因此,如果您的 Tool2_emitter 确实需要 Tool1 的目标来解析/猜测其创建的目标列表,那么您将陷入困境并且无法在一次运行中成功构建.

正式版就这么多了.;) 但是你可以看看 https://bitbucket.org/scons/scons/wiki/DynamicSourceGenerator 可能会帮助您克服上述限制.

We have two tools: Tool1 and Tool2. Tool1 create some TargetFile, based on the SourceFile. Tool2 use the output of Tool1 (TargetFile) as a source. Structure is similar to this:

   env.Tool1(TargetFile, SourceFile)
   env.Tool2(NewTargetFile, TargetFile)

The problem is that emitter of Tool2 use TargetFile to create new targets:

   def Tool2_emitter(target, source, env):
       target.append( CreateNewTargetFunc(source) )
       return target, source

But when Scons is creating a dependency, then he can't find TargetFile, because it is not yet created.

Is it possible to run generator of Tool1 befor creating dependency?

解决方案

The Emitter is not actually there to "build" stuff, like the file TargetFile in your example. It simply returns which targets will be created or updated, "later on" during the build phase. SCons will take note of this information by storing the "virtual" File (might not physically exist yet) in an internal data structure. This tree is also used later on, when resolving dependencies during the actual build. Note, that "updating the list of targets and sources via an Emitter" is a completely different task than "building the targets with the single Actions as specified for the current Builder". They don't even have to match, regarding the names of the produced files!

The Emitter runs in the "Parsing phase", but the Builder and its Actions are executed in the "Build phase" (after reading in all SConstructs). So, if your Tool2_emitter really requires the target of Tool1 to parse/guess its list of created targets, you're pretty much stuck and won't be able to successfully build in one single run.

So much for the official version. ;) But you can have a look at https://bitbucket.org/scons/scons/wiki/DynamicSourceGenerator which might help you to overcome the restrictions above in your case.

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

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