Multiple developers work on a project and each developer has different paths to dependencies, compiler etc. At the moment, all developers share a SConstruct file. When a new developer joins, a new Environment needs to be created, e.g.:

## environment: macbook
macbook = Environment()
### include
macbook.Append(CPPPATH = ["/usr/local/Cellar/gcc48/4.8.1/gcc/include/c++/4.8.", \
                          "/Users/cls/workspace/gtest/include", \
                          "/usr/local/Cellar/log4cxx/0.10.0/include"])

The environments are later selected via a command line parameter.

This works, but it is not very elegant, because the SConstruct file becomes longer with every developer. Is it possible to source the environment settings out to a settings file which needs to be modified per developer?

有帮助吗?

解决方案

There are a few ways that you can solve this issue:

  • You can have each developer specify environment variables and those environment variables could be ready in by your SConscript using pythons os.environ method
  • you can use scons Variables
  • you can create a config file that is read in by the scons script.

For example since I see you are using gtest. If you want to specify the path to gtest you could write a script similar to this.

# build variables
vars = Variables()

vars.Add(EnumVariable('VARIANT', 'Build variant', 'debug', allowed_values('debug', 'release'))
vars.Add(PathVariable('GTEST_DIR', 'path to gtest', os.environ.get('GTEST_PATH'), PathVariable.PathIsDir))

## environment: macbook
macbook = Environment(variables = vars)

Help(vars.GenerateHelpText(macbook))

### include
macbook.Append(CPPPATH = ["/usr/local/Cellar/gcc48/4.8.1/gcc/include/c++/4.8.", \
                      "$GTEST_PATH/include", \
                      "/usr/local/Cellar/log4cxx/0.10.0/include"])

Now when you run SCons you add the build variable

scons GTEST_PATH=/Users/cls/workspace/gtest VARIANT=release

if you don't want to type that in every time you run you can specify the environment variable GTEST_PATH or you can specify the SCONSFLAGS environment variable.

using the scons variables helps because when you type scons -h you will get a list of the current value of the variable and the help text.

If you would like you could create a config file that gets read in. I would checkout this post:

Scons (Build System) Variables : load config file with custom/unknown values

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top