This is the ninth post in my SCons series. The topic of this post is automating module discovery.
Up until now, the module directories were hardcoded in site_scons/site_config.py. This was a natural choice, because you needed to specify the modules in the correct order. In the previous episode, I implemented a solution that supports arbitrary modules order. Now it’s much more natural to automate the process of module discovery, over manual specification.
As a developer in the project, you know that when you create a new module you need to create a SConscript to describe how to build it. It makes sense that the build system will be able to locate all modules to build, by looking for the SConscript files recursively from the project base directory.
In this episode, I describe how I implemented module auto-discovery by walking the project directory tree.
My implementation also correctly handles common caveats:
- Avoid walking the build directory.
- Skip “hidden” directories (like
.git
, and .whatever
from your favorite IDE metadata).
In addition, my implementation provides several useful features:
- Ability to limit recursion depth.
- Support for “stop marker files”. If a stop marker file (e.g.
.noscons
) exists in a project directory, the directory (and all sub-directories) will be skipped.
The episode builds on top of the previous episode. The final result is available on my GitHub scons-series repository.
Continue Reading…