The build phase uses configuration environments created during the configuration phase. The configuration environments are Python Dictionaries which map keys to values. The configuration environment files created take the following form:
$ cat build/c4che/default.cache.py CXXFLAGS = ['-O2', '-Wall']
By default, the conf object comes with a default built-in configuration environment:
def configure(conf): conf.env.append_value('CXXFLAGS', '-O2')
To replace the default configuration environment, a new one must be created and assigned:
def configure(conf): conf.env.append_value('CXXFLAGS', '-O2') env2 = conf.env.copy()conf.set_env_name('debug', env2)
conf.setenv('debug')
conf.env.append_value('CXXFLAGS', '-g')
![]()
Duplicates the default configuration environment (shallow copy) | |
Binds the configuration environment to the name 'debug' | |
Replaces the default configuration environment by the 'debug' one | |
Changes the CXXFLAGS entry in the 'debug' configuration environment. Since we are using a shallow copy, we have to use the methods append_value, prepend_value or append_unique instead of '+=' or '[].append' |
In the previous example, the file contents will be:
$ tree build `-- build |-- c4che | |-- default.cache.py | |-- debug.cache.py $ cat build/c4che/default.cache.py CXXFLAGS = ['-O2'] $ cat build/c4che/debug.cache.py CXXFLAGS = ['-g']
In the build section, the values are retrieved using bld.env_of_name, for example
def build(bld): print(bld.env_of_name('default')['CXXFLAGS']) print(bld.env_of_name('debug')['CXXFLAGS'])