English 中文(简体)
scons hierarchcal builds: propagating builders
原标题:
  • 时间:2009-12-23 08:00:57
  •  标签:
  • scons

I need to be able to tune a construction environment so that I can either build a static or a shared objects in lower levels. Currently, I came up with the following approach:

top-level SConstruct:

if build_shared:
    env.Replace(ObjectBuilder = env.SharedObject)
    env.Replace(LibraryBuilder = env.SharedLibrary)
else:
    env.Replace(ObjectBuilder = env.StaticObject)
    env.Replace(LibraryBuilder = env.StaticLibrary)

and in lower-level SConstructs I invoke them by name:

env[ ObjectBuilder ]( foo.c )
env[ LibraryBuilder ]( lib , objects)

However, I m not sure how sound this solution is. Is there a more straightforward/proper way to achieve the same functionality?

Thanks in advance.

最佳回答

The easiest way is to declare your own wrapper for env.Library() that simply passes its parameters to either env.StaticLibrary() or env.SharedLibrary().

Depending on whatever construction variable/scons option, you can have that wrapper alternate between the two.

def MyLibraryWrapper(self, *args, **kwargs):
  if self[ BUILD_SHARED ]:
    return self.SharedLibrary(*args, **kwargs)
  else:
    return self.StaticLibrary(*args, **kwargs)

env.SetDefault(BUILD_SHARED = False)
env.AddMethod(MyLibraryWrapper)

Make sure that snippet is your SConstruct, before any SConscript is parsed. To make it extra clean, create a tool in site_scons/site_tools and load it using env.Tool().

问题回答

If this is a user controllable option, you may want to use the AddOption, GetOption interfaces to control whether static or dynamic libraries are built. IMHO, that methodology doesn t seem too bad, but I ve not seen many SCons scripts aside from my own.





相关问题
scons hierarchcal builds: propagating builders

I need to be able to tune a construction environment so that I can either build a static or a shared objects in lower levels. Currently, I came up with the following approach: top-level SConstruct: ...

Determining Build Directory from SConscript

I have an SConscript which is being copied to a build directory (variant_dir = ...) for construction. As a workaround for not being able to express dependencies, I m trying to copy some additional ...

Expressing an SConscript s Own Dependencies

I have an SCons project set up as follows: Project/ SConstruct # "SConscript( stuff/SConscript , variant_dir = build ) stuff/ SConscript # "import configuration" ...

How to set ":make" to use scons?

I know there is a way to make vim run scons instead of make when I press :make. I had an option that did this in my ~/.vimrc but I removed it a while ago and forgot what it was.

How to make scons work properly

I m trying to compile the SndObj library from the source. Supposedly it s as easy as just running scons from the top of the SndObj directory. I get this: nhnifong@ubuntu-nate:~/SndObj-2.6.6$ scons ...

热门标签