问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/35056538/scons-create-late-targets