SCons and VariantDir code generation

I would like SCons to create some source files for me in my src/ directory, and then create them like any other source file in my build/variantX .

This is my SCons file:

 import SCons def my_builder(env, target, source): # do stuff pass env = Environment() env.VariantDir('build/variant1/', 'src', duplicate=0) env.Command('src/foobar.cc', 'src/foobar.input', action=my_builder) env.Program('bin/test', [ 'build/variant1/foobar.cc', 'build/variant1/test.cc', ]) 

These are errors with the following message:

Source src/foobar.cc not found, target build/variant1/foobar.o

which, in my opinion, is not true, given that I really provide a command to build src/foobar.cc .

Now I have tried some workarounds:

  • if I replace build/variant1/foobar.cc in the program with src/foobar.cc , it works, but obviously foobar.o is created in src/ and not build/variant1

  • if I replaced src/foobar.cc in Command with build/variant1/foobar.cc , it works, but I would like the code to be generated in src/ ; (also because things like relative paths in include directories won't work if duplicate=1 )

  • if duplicate=1 , I get a similar error message, but this time mentioned the options directory:

    Source build/variant1/foobar.cc not found, target build/variant1/foobar.o

Is there any way around this? Is this a limitation / error in SCons, or is there a fundamental misunderstanding on my side?

+7
source share
2 answers

I would suggest creating an explicit dependency between Command () and Program () calls as follows:

 target1 = env.Command('src/foobar.cc', 'src/foobar.input', action=my_builder) target2 = env.Program('bin/test', [ 'build/variant1/foobar.cc', 'build/variant1/test.cc', ]) Depends(target2, target1) # This should work too # Depends(target2, "src/foobar.cc") 

Or you can specify the target from Command () as part of the source for Program () as follows:

 target1 = env.Command('src/foobar.cc', 'src/foobar.input', action=my_builder) env.Program('bin/test', [ target1, 'build/variant1/test.cc', ]) 

I have not tested this, so I'm not sure how it will work in conjunction with calling VariantDir ()

Here's more information about generating source code using SCons.

+2
source

I know that some time has passed, but I hit the same wall. With minor modifications to the β€œtest case” and solution (see below), the code:

 import SCons env = Environment() env.VariantDir('build/variant1/', 'src', duplicate=0) env.Command('src/foobar.cc', 'src/foobar.input', action="cp src/foobar.input src/foobar.cc", shell=True ) env.Depends("build/variant1/foobar.cc", "src/foobar.cc") env.Program('bin/test', [ 'build/variant1/foobar.cc', ]) 

Added 'env.Depends' in 'variantdir-source' to 'generated source' is the key. I don’t know why this is necessary. I would call it a mistake, but I think its featured (based on the feedback you received).

Greetings

0
source

All Articles