Add program and sconscript tools
This commit is contained in:
parent
bd7a79c9e1
commit
e1c4e0c4b7
4 changed files with 87 additions and 8 deletions
|
@ -149,6 +149,8 @@ class Environment(SCons.Environment.Environment):
|
|||
out_dir = self.build_root.Dir('src')
|
||||
# TODO: Do the thing.
|
||||
# do_sconscript(env, env.source_root, src_out_dir)
|
||||
self.SConscript(self.src_root.File('SConscript'),
|
||||
variant_dir=out_dir)
|
||||
self.Append(CPPPATH=[self.src_root])
|
||||
|
||||
#
|
||||
|
@ -194,7 +196,7 @@ class Environment(SCons.Environment.Environment):
|
|||
def _append_custom_tools(self, kwargs):
|
||||
'''Add custom tools to the `kwargs`.'''
|
||||
tools = kwargs.setdefault('tools', ['default'])
|
||||
for tool in ['lib', 'test']:
|
||||
for tool in ['lib', 'test', 'program', 'sconscript']:
|
||||
if tool in tools:
|
||||
continue
|
||||
tools.append(tool)
|
||||
|
|
|
@ -48,14 +48,9 @@ def _process_lib_dir(env, lib, src_dir=None, out_dir=None, inc_dir=None):
|
|||
if include_dir.isdir():
|
||||
inc_dir = [include_dir]
|
||||
env.Append(CPPPATH=inc_dir)
|
||||
exports = {'Library': env.Library,
|
||||
'StaticLibrary': env.StaticLibrary,
|
||||
'SharedLibrary': env.SharedLibrary}
|
||||
SCons.Script._SConscript.GlobalDict.update(exports)
|
||||
out = env.SConscript(src_dir.File('SConscript'),
|
||||
{'env': env.Clone()},
|
||||
variant_dir=out_dir,
|
||||
exports=exports)
|
||||
clone=True,
|
||||
variant_dir=out_dir)
|
||||
return out
|
||||
|
||||
|
||||
|
|
46
site_scons/site_tools/program.py
Normal file
46
site_scons/site_tools/program.py
Normal file
|
@ -0,0 +1,46 @@
|
|||
# program.py
|
||||
# Eryn Wells <eryn@erynwells.me>
|
||||
|
||||
'''
|
||||
SCons tool for working with Programs.
|
||||
'''
|
||||
|
||||
def _program(env, name):
|
||||
return env['PROGRAMS'].get(name)
|
||||
|
||||
|
||||
def _register_program(env, name, program):
|
||||
env['PROGRAMS'][name] = program
|
||||
|
||||
|
||||
def _build_program(env):
|
||||
original_builder = env.Program
|
||||
|
||||
def builder(env, program, sources, local_libs=None, *args, **kwargs):
|
||||
# local_libs is an array of names of libs built in the local project.
|
||||
# These will be looked up in the environment and added to the LIBS
|
||||
# array, if present.
|
||||
# if local_libs:
|
||||
# local_libs = map(lambda lib: env.lib(lib), local_libs)
|
||||
# try:
|
||||
# kwargs['LIBS'].extend(local_libs)
|
||||
# except KeyError:
|
||||
# kwargs['LIBS'] = local_libs
|
||||
prog = original_builder(program, sources, *args, **kwargs)
|
||||
register_program(prog)
|
||||
return prog
|
||||
|
||||
return builder
|
||||
|
||||
#
|
||||
# SCons tool interface
|
||||
#
|
||||
|
||||
def generate(env):
|
||||
env.SetDefault(PROGRAMS={})
|
||||
env.AddMethod(_build_program(env), 'Program')
|
||||
env.AddMethod(_program, 'program')
|
||||
|
||||
|
||||
def exists(env):
|
||||
return True
|
36
site_scons/site_tools/sconscript.py
Normal file
36
site_scons/site_tools/sconscript.py
Normal file
|
@ -0,0 +1,36 @@
|
|||
# sconscript.py
|
||||
# Eryn Wells <eryn@erynwells.me>
|
||||
|
||||
'''
|
||||
SCons tool for working with SConscripts.
|
||||
'''
|
||||
|
||||
import SCons.Script
|
||||
|
||||
def _do_sconscript(env):
|
||||
original_sconscript = env.SConscript
|
||||
|
||||
def sconscript(env, sconscript, clone=False, *args, **kwargs):
|
||||
exports = {'Library': env.Library,
|
||||
'StaticLibrary': env.StaticLibrary,
|
||||
'SharedLibrary': env.SharedLibrary,
|
||||
'Program': env.Program}
|
||||
SCons.Script._SConscript.GlobalDict.update(exports)
|
||||
env.log('Reading {}'.format(sconscript))
|
||||
return original_sconscript(sconscript,
|
||||
{'env': env.Clone() if clone else env},
|
||||
*args,
|
||||
**kwargs)
|
||||
|
||||
return sconscript
|
||||
|
||||
#
|
||||
# SCons tool interface
|
||||
#
|
||||
|
||||
def generate(env):
|
||||
env.AddMethod(_do_sconscript(env), 'SConscript')
|
||||
|
||||
|
||||
def exists(env):
|
||||
return True
|
Loading…
Add table
Add a link
Reference in a new issue