Here's the minimal repro steps for the problem I am experimenting.
Let's say I have the following SConscripts and SConsctruct:
#/SConstruct:
SConscript( "SConscript", variant_dir="build" )
#/SConscript:
SConscript( "lib1/SConscript" )
SConscript( "lib2/SConscript" )
#/lib1/SConscript:
Alias( "lib", SharedLibrary( "lib1", "codeLib1.cpp" ) )
#/lib2/SConscript:
Alias( "lib", SharedLibrary( "lib2", "codeLib2.cpp" ) )
The scons manual states that calling "scons -u" will only build specified targets found at and under the current directory.
This means that calling
scons -u lib
inside the directory #/lib1 would build the "lib" target (my alias in this scenario) under lib1 and all it's dependencies.
From what I understand, "scons -u lib" will only build the "lib" target if there is one target named lib (the alias in our case) under the current folder, which there is. If I'd ask for the target "tests", which would have existed elsewhere (let's say at the root of the project), it wouldn't have been compiled.
It seems the algorithm scons uses is:
- Read all SConscript and build the dependency tree
- See if the requested target of the command line ("lib") exists at or under the current directory( "-u" )
- If it doesn't exist, don't do anything
- If it does, compile all the dependencies of that target.
Unfortunately, "lib" has a dependency on lib1 AND lib2 and scons proceeds into compiling them both. I has hoping that since lib2 wasn't under lib1 that it wouldn't have been added to the build.
One solution would be to have libraries each have their own aliases suffixed by lib, but then the system would be trickier to use. Another one would be to inspect where an alias is being created from (by replacing the Alias method on the environment by my own that uses the Scons' call_stack global to know which SConscript I'm calling Alias from and create or not depending on the location of the SConscript) and return the newly created alias or the object as is.
I'd rather not mess around with that, so I was wondering if I was missing something or not.
Thank