1

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.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Kevin S
  • 2,713
  • 24
  • 31

1 Answers1

1

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.

Community
  • 1
  • 1
Brady
  • 10,207
  • 2
  • 20
  • 59
  • I am not really having a problem with hierarchical builds, I can get things to build when I remove the `AddOption()` calls. I think the problem is that `AddOption()` isn't restricted to a specific environment, so each SConscript file is trying to add the same options causing the `OptionConflictError`. However, the post you linked definitely had some good information. Thank you! – Kevin S Apr 13 '12 at 03:35
  • Ya, I think if you organize your SConstruct and SConscript scripts like the post I referenced, then that should fix your problems. You're right about AddOption(), its a global call, not one that can be called on a specific env. Many SCons funcions can either be called globally, or on a specific env, and it makes sense that AddOption() should be global. – Brady Apr 13 '12 at 08:07