问题描述
我有一些需要构建的目标,以确定我的其他一些目标是什么.我如何告诉 SCons?
I have some targets that need to be built in order to determine what some of my other targets are. How do I tell SCons?
示例:
脚本,generate
在一些配置文件上运行.此脚本根据配置文件中的信息生成包含路径和构建标志.为了构建 SCons Object
,我需要读取生成的文件.
A script, generate
is run on some configuration files. This script generates include path and build flags based on information in the configuration files. In order to build a SCons Object
, I need to read the generated files.
我只是在 generate
上运行 Execute()
但它现在有很多文件要生成并且需要很长时间,所以我只想运行当它或配置文件更改时.一旦这个 Command
完成了它需要做的任何事情,我如何告诉 SCons 在构建时向我询问更多目标?
I was just running Execute()
on generate
but it's now got lots of files to generate and it takes a good amount of time, so I only want to run it when it or a configuration file changes. How do I tell SCons to ask me at build time for some more targets once this Command
has done anything it needs to do?
推荐答案
好的,先澄清一些 SCons.在构建过程中,Scons 有两个阶段.首先,在分析阶段所有Scons 脚本被执行,结果是一个静态依赖树,描述脚本中定义的所有构建器的源文件和目标文件.接下来,根据该树、上次构建的构建数据库和光盘上文件的签名,所有具有过期目标的构建器都将被重建.
ok, some SCons clarifications first. Scons have two phases in doing a build. First, in the analysis phase all Scons scripts are executed and the result is a static dependency tree describing source and target files for all the builders defined in the scripts. Next, based on that tree, the build database from last build and the signatures of the files on disc, all builders with out of date targets are rebuild.
现在回答你的问题.如果您只想在必要时运行 generate
(当 generate
或配置文件更改时),那么运行 generate
作为分析阶段的一部分是谈不上.所以不要使用Execute()
.相反 generate
必须是它自己的构建器.到目前为止一切顺利.
Now to your question. If you want to only run generate
when necessary (when generate
or configuration files changes), then running generate
as a part of the analysis phase is out of the question. So don't use Execute()
. Instead generate
must be a builder of its own. So far so good.
现在您有两个构建器,第一个构建器 generate
和第二个构建器,我称之为 buildObject
.buildObject
依赖于 generate
的目标,但正如您所说,generate
目标在分析时是未知的(因为 generate
code> 未运行,它仅设置为构建器).在分析时具有未知目标是 SCons 的一个经典挑战,并且没有简单的方法来解决它.
Now you have two builders, the first builder generate
and the second builder, I call it buildObject
. buildObject
depend in the targets of generate
, but as you state, the generate
targets are unknown at analysis time (because generate
is not run, it is only set up as a builder). Having unknown targets at analysis time is a classic challenge with SCons, and there are no easy way to solve it.
我通常使用我称之为 SCons.pleaser
的文件来解决它.在您的情况下,它将是 generate
生成的包含高分辨率时间戳的已知目标.buildObject
构建器然后将此文件作为源.现在,如果你的配置文件没有改变,generate
不会运行,SCons.pleaser 不会改变,buildObject
不会运行.如果您更改配置文件,generate 将运行,SCons.pleaser 将更改,buildObject
也将运行.
I normally solve it by using what I call a SCons.pleaser
file.In your case it would be a known target that generate
generates containing a high res timestamp. The buildObject
builder then take this file as a source.Now, if your configuration files has not changed, generate
will not run, the SCons.pleaser will not change, and the buildObject
will not run. If you change you configuration files, generate will run, the SCons.pleaser will change, and the buildObject
will run as well.
问候
这篇关于SCons 目标的构建时间确定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!