SCons不会清除所有文件 [英] SCons does not clean all files

查看:155
本文介绍了SCons不会清除所有文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件系统,其中包含"builds"目录,每个目录都包含一个名为"build-info.xml"的文件.但是,有些构建是在构建脚本生成"build-info.xml"之前发生的,因此在这种情况下,我有一个不太平凡的SCons SConstruct,用于生成框架build-info.xml,以便将其用作依赖其他规则.

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.

即:对于每个目录:

  • 如果build-info.xml已经存在,则不执行任何操作.更重要的是,请勿在"conscons --clean"上将其删除.
  • 如果build-info.xml不存在,请生成一个框架-build-info.xml不依赖于任何其他文件-框架本质上是最小的默认值.
  • 在--clean期间,如果build-info.xml是生成的,则将其删除,否则将其保留.
  • 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.

我的SConstruct看起来像这样:

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)

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

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

我在'if'中玩过env.Clean(t,build_info_xml),但是我无法使它正常工作-主要是因为我无法确定分配给't'的内容-我想要一个生成的版本-info.xml可以无条件清理,而不是基于另一个目标的清理,而我无法使其正常工作.

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"之后但在"if"之外尝试了一个简单的env.Clean(无,"build_info_xml"),我发现SCons将清除每个单独的build-info.xml文件,包括未生成的文件.也不好.

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.

我想知道SCons如何确定应该清除哪些文件,而不应该清除哪些文件.我使用生成器功能阻止SCons将此目标记录为Clean候选对象的方式是否有些有趣?

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?

推荐答案

好吧,我想我已经解决了发生的事情-我错误地假设SCons会记录它创建的文件(作为目标),然后使用它在随后的清理"过程中记录的列表.这当然没有道理.

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.

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

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.

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

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.

解决此问题的方法是在生成的文件旁边创建一个哨兵文件.但是就目前而言,我对SCons的清洁"行为的新理解就足够了.

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.

这篇关于SCons不会清除所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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