tags:

views:

12

answers:

1

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?

A: 

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?

Jason S