koo
koo

Reputation: 2918

SCons - how to provide explicit dependency for targets across scripts

This is my main SConstruct file

env = Environment()

gen_source = env.SConscript(
        'generate_sources.scons',
        variant_dir='derived_src', src_dir='src',
        duplicate=0)
compile_source = env.SConscript('compile.scons',
        variant_dir='build', src_dir='derived_src',
        duplicate=0)
env.Depends('build/', 'derived_src/')

The gen_source is a script with one source generator target which outputs files in derived_src/ from my source directory, and compile_source is a script with multiple targets.

If no target is provided in command line, i.e. run scons, it will generate sources then compile, but if a target is provided, such as scons pg_test then scons will fail and complain about derived_src/some_file does not exist.

What is the best way to model such a relationship of targets? Preferably I hope to change its behaviour such that it only generates the sources that are going to be compiled.

Upvotes: 3

Views: 4208

Answers (1)

Brady
Brady

Reputation: 10357

Depending on what you are returning from the gen_source and compile_source SConscript executions, if its a list of targets then I think it would make more sense to setup the dependencies like this:

env.Depends(compile_source, gen_source)

Or if you're not returning a list of targets, then at the very least, put the directories relative to the root SConstruct, like this:

env.Depends('#build', '#derived_src')

And one step further would be to specify the files in those directories, possibly with Glob()

Hope that helps.

Upvotes: 3

Related Questions