scons

Copying files to a project subdirectory in a SCons hierarchical build


Consider this SCons project:

myproject/
  resource/
  objects/
     SConscript
     foo
     bar
  src/
     SConscript
     ...
  SConstruct

In objects/SConscript, I have some rules to make intermediate files. To simplify the example, though, let's reduce it to a raw copy. I'd like copies of foo and bar to wind up in myproject/resource after the build.

objects/SConscript looks like:

Import('env')
data_out = '#/resource'
# ...
env.Install(data_out, 'foo')
env.Install(data_out, 'bar')

However, when I run scons objects from the project root, some of the intermediate rules are run, but myproject/resource/ does not contain the copied files.

(I don't know if this is relevant, but the objects sub-build uses a variant_dir).

Why is this? What is the idiomatic way to get those files into the resource directory?


Solution

  • Because by running SCons as: scons objects

    You are only asking SCons to build targets under that directory. You're install/copied files are in #/resource, so they are not processed.

    You can resolve this by running SCons as: scons objects resource

    Or if you always want to do the copy into #/resource you can add the following to your SConscript

    Import('env')
    data_out = '#/resource'
    # ...
    env.Install(data_out, 'foo')
    env.Install(data_out, 'bar')
    Default('#/resource') # This line added
    

    Or you can add an Alias() in your SConstruct

    Alias('object_and_resource',['#/object','#/resource'])
    

    Or you can gather only the items installed from objects into resources into an Alias() as well.

    Or you could specify the targets for however you build foo to be in the #/resource dir and then just scons resource would do it too.

    Really depends exactly what you want to happen.

    Note that this is mostly covered in the FAQ