SCons 不会清除所有文件

发布于 2024-08-25 07:23:18 字数 1490 浏览 6 评论 0原文

我有一个包含“builds”目录的文件系统,每个目录都包含一个名为“build-info.xml”的文件。然而,一些构建发生在构建脚本生成“build-info.xml”之前,因此在这种情况下,我有一个有点不平凡的 SCons SConstruct,用于生成骨架 build-info.xml,以便它可以用作对进一步规则的依赖。

即:对于每个目录:

  • 如果 build-info.xml 已经存在,则不执行任何操作。更重要的是,不要在“scons --clean”上删除它。
  • 如果 build-info.xml 不存在,则生成一个框架 - build-info.xml 不依赖于任何其他文件 - 该框架本质上是最小的默认值。
  • 在 --clean 期间,如果生成了 build-info.xml,则删除它,否则保留它。

我的 SConstruct 看起来像这样:

def generate_actions_BuildInfoXML(source, target, env, for_signature):
    cmd = "python '%s/bin/create-build-info-xml.py' --version $VERSION --path . --output ${TARGET.file}" % (Dir('#').abspath,)
    return cmd

bld = Builder(generator = generate_actions_BuildInfoXML, chdir = 1)
env.Append(BUILDERS = { "BuildInfoXML" : bld })

...

# VERSION = some arbitrary string, not important here
# path = filesystem path, set elsewhere
build_info_xml = "%s/build-info.xml" % (path,)
if not os.path.exists(build_info_xml):
    env.BuildInfoXML(build_info_xml, None, VERSION = build)

我的问题是“scons --clean”不会删除生成的 build-info.xml 文件。

我在“if”中尝试了 env.Clean(t, build_info_xml) 但我无法让它工作 - 主要是因为我无法弄清楚要分配给“t”的内容 - 我想要一个生成的构建信息。 xml 被无条件地清理,而不是基于另一个目标的清理,但我无法让它工作。

如果我在“if”之外尝试一个简单的 env.Clean(None, "build_info_xml") ,我发现 SCons 会清理每个 build-info.xml 文件,包括那些未生成的文件。也不好。

我想知道的是 SCons 如何确定哪些文件应该被清理,哪些不应该被清理。我使用生成器函数阻止 SCons 将此目标记录为 Clean 候选者的方式有什么有趣的吗?

I have a file system containing directories of "builds", each of which contains a file called "build-info.xml". However some of the builds happened before the build script generated "build-info.xml" so in that case I have a somewhat non-trivial SCons SConstruct that is used to generate a skeleton build-info.xml so that it can be used as a dependency for further rules.

I.e.: for each directory:

  • if build-info.xml already exists, do nothing. More importantly, do not remove it on a 'scons --clean'.
  • if build-info.xml does not exist, generate a skeleton one instead - build-info.xml has no dependencies on any other files - the skeleton is essentially minimal defaults.
  • during a --clean, remove build-info.xml if it was generated, otherwise leave it be.

My SConstruct looks something like this:

def generate_actions_BuildInfoXML(source, target, env, for_signature):
    cmd = "python '%s/bin/create-build-info-xml.py' --version $VERSION --path . --output ${TARGET.file}" % (Dir('#').abspath,)
    return cmd

bld = Builder(generator = generate_actions_BuildInfoXML, chdir = 1)
env.Append(BUILDERS = { "BuildInfoXML" : bld })

...

# VERSION = some arbitrary string, not important here
# path = filesystem path, set elsewhere
build_info_xml = "%s/build-info.xml" % (path,)
if not os.path.exists(build_info_xml):
    env.BuildInfoXML(build_info_xml, None, VERSION = build)

My problem is that 'scons --clean' does not remove the generated build-info.xml files.

I played around with env.Clean(t, build_info_xml) within the 'if' but I was unable to get this to work - mainly because I could not work out what to assign to 't' - I want a generated build-info.xml to be cleaned unconditionally, rather than based on the cleaning of another target, and I wasn't able to get this to work.

If I tried a simple env.Clean(None, "build_info_xml") after but outside the 'if' I found that SCons would clean every single build-info.xml file including those that weren't generated. Not good either.

What I'd like to know is how SCons goes about determining which files should be cleaned and which should not. Is there something funny about the way I've used a generator function that prevents SCons from recording this target as a Clean candidate?

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

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

发布评论

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

评论(1

幽蝶幻影 2024-09-01 07:23:20

好吧,我想我已经弄清楚发生了什么 - 我做了一个错误的假设,SCons 记录它创建的那些文件(作为目标),然后在后续的“清理”过程中使用这个记录的列表。这当然没有意义。

SCons 实际上所做的是重新运行所有依赖关系规则并创建一个新的依赖关系树。它用它来确定要清理哪些文件。因为我有 os.path.exists() 条件,这意味着 build-info.xml 从未添加到 Clean 列表中,因为它在运行 --clean 时始终存在。

事实证明 env.Clean() 工作正常,因为它会删除所有此类文件,仅仅是因为第二次运行时 SCons 无法(使用 --clean)知道特定的 build-info.xml 文件是生成的而不是已经存在的。

解决这个问题的方法是在这些生成的文件旁边创建一个哨兵文件。但现在,我对 SCons 的 Clean 行为的新理解就足够了。

Ok, I think I've worked out what's going on - I made an incorrect assumption that SCons records those files it creates (as targets) and then uses this recorded list during a subsequent 'clean'. This of course makes no sense.

What SCons actually does is re-run through all the dependency rules and create a fresh dependency tree. It uses this to determine which files to clean. Because I had that os.path.exists() condition, it means that build-info.xml was never added to the Clean list because it would always exist at the time --clean is run.

It turns out that the env.Clean() was working properly, in that it would remove all such files, simply because there is no way for SCons when running the second time (with --clean) to know that a particular build-info.xml file was generated rather than already present.

The way to work around this would be to create a sentinel file alongside those generated files. But for now, my new understanding of SCons' Clean behaviour will suffice.

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