Reputation: 1337
I am trying to use to scons for my build environment, and the directory structure resembles something like :
main_dir
main_dir/dir_A
main_dir/dir_B
main_dir/dir_C
main_dir/dirB/dir_b1
main_dir/dirB/dir_b2
main_dir/dirB/dir_b3
I have SConstruct file in the main_dir and corresponding SConscript in the subsequent directories. Inside dir_b1, dir_b2 and dir_b3 much of the build env setting is common, so i am trying to import a common python module do all that stuff and here lies the dilemma. Lets say dir_b1, currently i do :
Import('my_env')
env = my_env.Clone()
env['ENV']['LIB_NAME'] = xxx #unique to each dir
env['ENV']['CXX_COMPILER'] = 'yyy' #common to all
I want to move all such common stuff into my python module and leave anything specific in the dir to SConscript file.
How should i manage the environment variable here ?
If i clone the env variable in python module as well and set values in both the module and SConscript, will changes in both will taken by scons when doing the build ?
Upvotes: 0
Views: 324
Reputation: 4052
The build descriptions of SCons in the SConstructs/SConscripts are read in a first "parse" phase. In this phase, SCons collects all the informations about which Nodes to build and which Environments to use for this.
An Environment behaves pretty much like a dictionary (=map), in the sense that it supports the setting of certain values via a key each. For a single Environment like "my_env
" in your example above, it doesn't matter where exactly this happens. Regarding the Actions in the final "build" phase, assignments to the Environment are independent of whether they happen in your top-level SConstruct or some SConscript in a deeply buried subdirectory. If you assign to the same key, the last assignment wins.
Only when the "parse" phase is complete, the actual "build" starts.
Finally, and most important, the "build" doesn't follow the order of your definitions as you gave them in the SConstructs/SConscripts, it follows the dependencies between target and source files that you defined.
So you should be able to setup your common variables in the top-level SConstruct and then pass this Environment on to the SConscripts where you can Clone
them, and add/change other values for this clone
d Environments if required.
Upvotes: 1