Scons building inheritance

I have a problem refactoring a scons based build system. We have a C / C ++ source tree with several different output objects (DLLs, executables, test executables) and a somewhat heterogeneous layout for our source files (although most of them are located in the c module directories src/and inc/directories).

One of my biggest problems with the current setup is that we really want all of these build products to be built using the default default compiler options. Our current layout has a SConstruct master file that calls many sub-SConscript files in subdirectories, which then build chunks of larger build products (for example, .a). By default, a function SConscript()in scons does not pass or inherit the current object of the build environment to the SConstruct file being called. This means that currently all of these sub-SConstript files all use their own development environment.

The new layout I'm trying to assemble has the main building environment, combined at the root of the source tree, with all the necessary CFLAGS and the assembly we need. I would like to build this medium was transferred to sub-SConscript files, so I know that every single file .cand .cppin our build tree is built with the same command line.

I am not sure how to do this in scons. There are functions Import()and Export(), but these are basically ugly global variables - the calling SConstruct file does not have much control over what the sub-SConstruct file does with the global variable Export()'ed, is there any clean way that essentially passes the sub-SConscript file to the current the construction environment as a parameter, not allowing it to necessarily modify it? Something may be similar:

master_env = Environment()
master_env.Append( CXXFLAGS=['-Wall', '-Werror', '-g', '-fPIC', ... ] )

### add other stuff that we want everything to use

SConscript( 'somelibrary/SConstruct', inherited_environment=master_env.Clone() )

### master_env has now been used to build a 
### .dll in somelibrary/, but any variations
### made to somelibrary/SConstruct inherited 
### env haven't contaminated master_env

I know that I could do something awkward and kind of rude:

clobber_env = Environment()
master_env = Environment()
master_env.Append( CXXFLAGS=['-Wall', '-Werror', '-g', '-fPIC', ... ] )

call_somelibrary_sconstruct( master_env )

def call_somelibrary_sconstruct(env):
    param_env = env.Clone()
    Export( 'param_env' )
    SConstript( 'somelibrary/SConstruct' )

    # because we don't want any contamination of our global variable 
    # between SConscript calls. I'm not even sure if this is necessary
    # or does what I think it does because I'm not sure how this ugly
    # Export()'d global variable environment works with locals like 
    # param_env here.
    param_env = clobber_env
    Export( 'param_env' ) 

Is there an elegant way to do this?

Update:

So, I played with this a little more, and it seems that while I am doing this in the main SConstruct file:

def build_somelib( env ):
    Export( env=env.Clone() )
    somelib = SConscript( 'somelib/SConscript' )
    return somelib

master_env = Environment()
master_env.Append( CXXFLAGS=['-Wall', '-Werror', '-g', '-fPIC', ... ] )

build_somelib( master_env )

and then in somelib/SConscript

Import( 'env' )
env.Append( CXXFLAGS=['-weirdoption1', ... ] )
lib = env.StaticLibrary( 'somelib', source=['source1.cpp', 'source2.cpp', ...] )
Return( "lib" )

master_env SConstruct . , Export( env=env.Clone() ) , - -Clone() 'ing - SConscript/SConstruct.

, env .

+5
3

, , SConstruct, :

env = Environment()

env.SConscript('src/SConscript', 'env')

src/SConscript:

Import('env')

env, SConstruct. SConstruct env src/SConscript, :

env = env.Clone()

, , .

+7

I grep (Scons 2.1.0 Ubuntu 12.04) , Export global_exports .

, , , :

Export( param_env=env.Clone() )
SConscript( 'somelibrary/SConstruct' )
Export( param_env=clobber_env ) 

, .

Export SConstript , , python, .

+1

, OP , ( scons-2.3.3 scons-2.3.4):

def build_somelib( env ):
    Export( env=env.Clone() )
    somelib = SConscript( 'somelib/SConscript' )
    return somelib

master_env = Environment()
master_env.Append( CXXFLAGS=['-Wall', '-Werror', '-g', '-fPIC', ... ] )

build_somelib( master_env )

CacheDir(some_dir) ( VariantDir, ). dir1 , scons --cache-debug=log. dir2 , scons --cache-debug=log. , , . , , MD5 . "dir1" , "dir2", . MD5.

At this point, execute scons -cand then delete the .sconsign.dblite files in both directories (and delete the build cache for a good score). Rebuild first at dir1, and when it ends, rebuild to 'dir2'. You will get the correct behavior: MD5 signatures will match and files will be copied from the build cache.

As a result, I abandoned the OP solution and switched responsibility for maintaining the parent environment to all subdirectories in accordance with Tom's decision. Not quite what I wanted to do, but at least the build cache now works as expected.

+1
source

All Articles