Reputation: 189886
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?
Upvotes: 6
Views: 1277
Reputation: 3509
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.
Upvotes: 1
Reputation: 189886
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?
Upvotes: 0