SCONS 中所有构建目标的隐式列表?

发布于 2024-09-16 00:07:36 字数 742 浏览 2 评论 0原文

我有一个 scons 项目,强制包含多个头文件作为编译器标志。

# Forced include files passed directly to the compiler
env.Append(CCFLAGS = ['/FIinclude.h'])

这些文件不包含在项目中的任何文件中。我需要为它们添加显式依赖项。

forced_include_headers = ['include.h']

# Trying to add an explicit dependency for each build target
for object in BUILD_TARGETS:
  env.Depends(object, forced_include_headers)

我遇到的问题是 BUILD_TARGETS 列表为空。它似乎只包含从 COMMAND_LINE_TARGETSDEFAULT_TARGETS 传递的内容。我们项目中的所有目标都是隐式构建的。我们不使用 env.Default 等。有没有办法获取隐式目标列表,或者我必须手动构建它?我注意到 TARGETS 是保留的,似乎也不包含我想要的内容。

我可以为所有目标在各自的 SConscript 文件中添加一个 env.Depends(target,forced_include_headers) ,但该项目相当大。

I have an scons project that force includes several header files as a compiler flag.

# Forced include files passed directly to the compiler
env.Append(CCFLAGS = ['/FIinclude.h'])

These files are not included by any files in the project. I need to add an explicit dependency for them.

forced_include_headers = ['include.h']

# Trying to add an explicit dependency for each build target
for object in BUILD_TARGETS:
  env.Depends(object, forced_include_headers)

The problem I'm running into is that BUILD_TARGETS list is empty. It seems to only contain things passed from COMMAND_LINE_TARGETS or DEFAULT_TARGETS. All of the targets in our project are built implicitly. We do not make use of env.Default, etc. Is there a way to get the implicit target list, or do I have to manually build it? I noticed that TARGETS is reserved and does not seem to contain what I want either.

I can add an env.Depends(target, forced_include_headers) for all of the targets in their respective SConscript files, but the project is quite large.

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

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

发布评论

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

评论(1

不交电费瞎发啥光 2024-09-23 00:07:36

我不确定这是解决问题的最佳方法(事实上,我认为创建伪构建器的想法效果更好),但此代码将返回 Object 目标列表:

# Typical SConstruct / SConscript
env = Environment()
env.Program('foo.c')
lib = env.SharedLibrary('bar.c')
env.Program('foo2.c', LIBS=[lib])
SConscript('subdir/SConscript', exports={'env':env})

# Get a list of all Object targets
def get_all_targets(env, node='.'):
    def get_all_targets_iter(env, node):
        if node.has_builder() and node.get_builder().get_name(env) in ('Object', 'SharedObject'):
            yield node
        for kid in node.all_children():
            for kid in get_all_targets(env, kid):
                yield kid
    node = env.arg2nodes(node, env.fs.Entry)[0]
    return list(get_all_targets_iter(env, node))

# Force them all to depend upon some header
env.Depends(get_all_targets(env), 'site_wide.h')

I'm not sure that this is the best way to solve the problem (in fact, I think the idea of creating a pseudo-builder works better), but this code will return a list of Object targets:

# Typical SConstruct / SConscript
env = Environment()
env.Program('foo.c')
lib = env.SharedLibrary('bar.c')
env.Program('foo2.c', LIBS=[lib])
SConscript('subdir/SConscript', exports={'env':env})

# Get a list of all Object targets
def get_all_targets(env, node='.'):
    def get_all_targets_iter(env, node):
        if node.has_builder() and node.get_builder().get_name(env) in ('Object', 'SharedObject'):
            yield node
        for kid in node.all_children():
            for kid in get_all_targets(env, kid):
                yield kid
    node = env.arg2nodes(node, env.fs.Entry)[0]
    return list(get_all_targets_iter(env, node))

# Force them all to depend upon some header
env.Depends(get_all_targets(env), 'site_wide.h')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文