当我有自定义构建器时,什么会触发 scons 构建文件?

发布于 2024-09-26 21:30:36 字数 1285 浏览 4 评论 0原文

当我试图控制文件何时在 scons 中构建时,我简直要发疯了。我有一个非常简单的示例构建树(见下文),其中有一个 Poem 构建器,它只需要一个 .txt 文件并将其转换为相应 中的小写字母.eectxt 文件。

在我的 SConstruct 和 SConscript 文件中,我声明了 3 个 .txt 文件的依赖关系。

但我不知道是什么将这些放入默认构建中!

sconstest/
    SConstruct
    tiger.txt
    src/
        SConscript
        hope.txt
        jabberwocky.txt

其中 *.txt 文件是诗歌,我的 SConstruct 和 SConscript 如下所示:

SConstruct:

env = Environment();

def eecummings(target, source, env):
  if (len(target) == 1 and len(source) == 1):
    with open(str(source[0]), 'r') as fin:
        with open(str(target[0]), 'w') as fout:
            for line in fin:
                fout.write(line.lower());
  return None

env['BUILDERS']['Poem'] = Builder(action=eecummings, suffix='.eectxt', src_suffix='.txt');

Export('env');
poems = SConscript('src/SConscript');
tigerPoem = env.Poem('tiger.txt');

src/SConscript:

Import('env');

input = ['jabberwocky.txt', 'hope.txt'];
output = [env.Poem(x) for x in input];
Return('output');

我想要做的是声明来自相应 .eectxt 文件的依赖关系>.txt 文件,但不会导致它们被构建,除非我明确地将它们放入 SConstruct 文件中的 Default() 构建中,或者我请求它们明确地在命令行中。

我该怎么做?

I'm going nuts trying to control when files are built in scons. I have a very simple example build tree (see below), with a Poem builder that just takes a .txt file and converts it to lower case in a corresponding .eectxt file.

In my SConstruct and SConscript files, I declare dependencies of 3 .txt files.

But I can't figure out what's putting these into the default build!

sconstest/
    SConstruct
    tiger.txt
    src/
        SConscript
        hope.txt
        jabberwocky.txt

where the *.txt files are poems and my SConstruct and SConscript look like this:

SConstruct:

env = Environment();

def eecummings(target, source, env):
  if (len(target) == 1 and len(source) == 1):
    with open(str(source[0]), 'r') as fin:
        with open(str(target[0]), 'w') as fout:
            for line in fin:
                fout.write(line.lower());
  return None

env['BUILDERS']['Poem'] = Builder(action=eecummings, suffix='.eectxt', src_suffix='.txt');

Export('env');
poems = SConscript('src/SConscript');
tigerPoem = env.Poem('tiger.txt');

src/SConscript:

Import('env');

input = ['jabberwocky.txt', 'hope.txt'];
output = [env.Poem(x) for x in input];
Return('output');

What I want to do is to declare the dependency of the .eectxt files from the corresponding .txt files, but not cause them to be built unless I explicitly put them into the Default() build in the SConstruct file, or I request them explicitly at the command line.

How can I do this?

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

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

发布评论

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

评论(2

毅然前行 2024-10-03 21:30:36

默认情况下,目录取决于驻留在其中的所有文件和/或目标。
所以运行:

scons

然后将构建当前目录下的所有目标。

By default, a directory depends on all files and/or targets which reside in it.
So running:

scons

Will then build all targets under the current directory.

蓝梦月影 2024-10-03 21:30:36

我想出了如何做我想做的事,但我仍然不明白为什么我需要这样做。接受第一个解释它的体面答案。

如果我将以下内容添加到根 SConstruct 文件中,效果如下:

env.Ignore('.', tigerPoem);
env.Ignore('src', poems);
env.Alias('poems', [tigerPoem]+poems);

这会忽略默认目标中的 3 首诗,然后将它们添加为别名为“poems”的目标,因此如果我运行 scons不构建任何内容,但如果我运行 scons Poems 它会构建文件。

为什么这有效?为什么调用 env.Poem(...) 会向默认目标添加一些内容?

I figured out how to do what I want, but I still don't understand why I need to do it this way. Acceptance to the first decent answer that explains it.

Here's what works, if I add the following to the root SConstruct file:

env.Ignore('.', tigerPoem);
env.Ignore('src', poems);
env.Alias('poems', [tigerPoem]+poems);

This ignores the 3 poems from the default target, and then adds them as targets aliased to "poems", so if I run scons it builds nothing, but if I run scons poems it builds the files.

Why does this work? Why does calling env.Poem(...) add something to the default targets?

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