0

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

fronsacqc
  • 320
  • 2
  • 12

1 Answers1

0

If you want lib1 and lib2 to be treated differently using the Alias() function, then you need to assign a different alias name to each of them, something like this:

/lib1/SConscript:

Alias( "lib1", SharedLibrary( "lib1", "codeLib1.cpp" ) )

/lib2/SConscript:

Alias( "lib2", SharedLibrary( "lib2", "codeLib2.cpp" ) )

If you assign the same alias name to both targets, then you are adding both targets to the same alias name, and they will both be compiled/evaluated (considered for compilation) when compiling that alias target.

If you only want to compile what's in a certain directory, you should be able to do the following:

# cd lib1
# scons .

Or you can specify the path to be compiled, assuming you're in the project root dir:

# scons ./lib1
Brady
  • 10,207
  • 2
  • 20
  • 59
  • I'm familiar with scons . Unfortunately, doing scons . in the real world (not in this example) would mean that only my library would be compiled (cool), but so would the unit tests, and then run them, and then create the distribution package for that library, since those targets are all defined under . – fronsacqc May 04 '12 at 13:49
  • I wonder if using the Default() function would help, but that specifies what targets to compile when you dont specify a target.. Or maybe consider reorganizing the project so there arent so many things defined in the same place. – Brady May 04 '12 at 13:55