Reputation: 2753
I have a project set up with several individual Sconstruct files and one toplevel SConstruct file.
project/SConstruct -- toplevel SConstruct file
project/binary1/SConstruct -- lower level SConstructs
project/binary2/SConstruct
project/binary3/src/SConstruct
I want to be able to call the individual SConstruct files with options. So each SConstruct can be called like this:
scons install --prefix=/usr/local/bin
and they have a section for that option in the SConstruct file:
AddOption('--prefix',
dest='prefix',
type='string',
nargs=1,
action='store',
metavar='DIR',
default=prefix,
help='installation prefix')
Also, in the toplevel SConstruct file, I would like to be able to call all of the lower level SConstruct files, so I added this to the toplevel SConstruct:
SConscript(binary1/SConstruct)
SConscript(binary2/SConstruct)
SConscript(binary3/src/SConstruct)
However, if I try to do this, I will get an OptionConflictError
on binary2/SConstruct
because the --prefix
option is already defined (in binary1/SConstruct
):
OptionConflictError: option --prefix: conflicting option string(s): --prefix:
Is there a way to get around this OptionConflictError
?
I know I can surround the call to AddOption()
with a try
block, but are there better ways? Can I add a conflict_handler
? Can I check if the --prefix
option already exists?
Can I organize things better? I need the individual SConstruct files unfortunately, so I can't reorganize too much.
Upvotes: 1
Views: 1079
Reputation: 10357
I think it would be better to do this by defining SConscript files in the sub-directories: binary1, binary2, and binary3.
I answered a similar question recently and proposed how to organize the SConsctruct and SConscript files, I think that answer would help you:
Real Hierarchical Builds with SCons?
This way you could define the --prefix
option in the SConstruct files, and from the root SConstruct file, call the subdirectory SConscript files, thus avoiding the afore-mentioned error.
Upvotes: 1