L. Amber O'Hearn
L. Amber O'Hearn

Reputation: 308

How can I make SCons optionally ignore a dependency with custom builders?

Here is the dependency structure of my project:

There is a single file, F, from which files A, B, and C are derived. Everything else in the project ultimately depends on A, B, or C.

A, B, and C are built with a custom Builder like this:

ABCbuilder = Builder(action = build_abc)
env = Environment(BUILDERS = {'abc' : ABCbuilder,...}
env.abc([A,B,C],[F])

The problem is that F is unwieldy, and I'd like to have the option of not including it in the distribution, and only including A, B, and C.

How can I make it so that SCons will accept A, B, and C as the starting sources if they are present without F? Currently if I copy A, B, and C into a new directory that does not contain F, it tries to rebuild them.

I've looked at the manual section 6.7. Ignoring Dependencies: the Ignore Function, but I don't see how to apply it to my code.

Upvotes: 3

Views: 788

Answers (2)

Brady
Brady

Reputation: 10357

You can find more detailed information about the Ignore() function in the SCons man pages. Here is the signature according to the man pages:

Ignore(target, dependency)
env.Ignore(target, dependency)

You should be able to do the following:

# assuming aTarget, bTarget, cTarget, and F are set accordingly

Ignore(aTarget, F)
Ignore(bTarget, F)
Ignore(cTarget, F)

There are several different ways to handle Command Line options in SCons, here is an overview:

The simplest way is this, that would allow you to do the following:

useF = ARGUMENTS.get('includeF', 0)
if not int(useF):
    Ignore(aTarget, F)
    Ignore(bTarget, F)
    Ignore(cTarget, F)

And the command line would look something like this:

#scons includeF=1

Upvotes: 4

L. Amber O'Hearn
L. Amber O'Hearn

Reputation: 308

Well, I thought of a workaround. I made a commandline variable that I use to determine whether the build is rooted at F. It seems like there is probably a "SCons" way to do it that I'm missing, but I think this is fine.

do_abc = False
for key, value in ARGLIST:
    if key == "do_abc":
        do_abc = bool(value)

if do_abc:
    ABCbuilder = Builder(action = build_abc)
    env = Environment(BUILDERS = {'abc' : ABCbuilder,...}
    env.abc([A,B,C],[F])

else:
     env = Environment(BUILDERS = {...})

Upvotes: 0

Related Questions