It can be a hassle to handle multi-flavor projects. In the multi-flavor project post, I suggested a solution to simplify the multi-flavor build process. Using that solution, you just run
scons flavor_name to build a specific flavor. But there’s still room for improvement! If you want to run a program you just built, you still need to specify the path to the flavored executable.
For example, say you built a project with a program named
say_hi in the module
hello. You built it by running
scons debug. To run it you execute
./build/debug/hello/say_hi. It can be a hassle to write
./build/debug over and over. Even worse, it’s the first time you need to know about the layout of the build directory. Up until now, such details were nicely hidden in the config file.
In addition, you may often want to work with just one flavor. You may be developing a new feature, and you want to only build and run the debug flavor. If you run
scons without the
debug argument, all flavors will be built. This can be annoying and time consuming.
In this post, I suggest a helper script to make things simpler. The purpose of the script is to allow you to activate a flavor in a terminal session. While a flavor is active, magical things happen:
sconswith no arguments builds only the active flavor.
- The executable programs of the active flavor can be executed more conveniently.
- The active flavor is indicated in the terminal prompt.
The final result is available on my GitHub scons-series repository. In the rest of this post I go into the details of the helper script and related changes.