From: g0dil Date: Thu, 20 Aug 2009 08:27:45 +0000 (+0000) Subject: Restructure SENFSCons.Object helper X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=06367434e38b54b3fd4cea32bd4b67121b4349cd;hp=b1f9349b1f3521d58cbef52ead0f2e5303a58c9e;p=senf.git Restructure SENFSCons.Object helper git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1310 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/Packets/80211Bundle/SConscript b/Packets/80211Bundle/SConscript index 8aa9f69..66f97a4 100644 --- a/Packets/80211Bundle/SConscript +++ b/Packets/80211Bundle/SConscript @@ -5,10 +5,11 @@ import SENFSCons, glob ########################################################################### -sources, includes = SENFSCons.Glob(env) +(sources, tests), includes = SENFSCons.Glob(env) -SENFSCons.Object(env, target='80211Bundle', sources=sources) -SENFSCons.Lib(env, sources=sources[0]) +SENFSCons.Object(env, target='80211Bundle', sources=sources, + testSources = tests + [ '80211Bundle.o' ]) +SENFSCons.Lib(env, sources=sources) env.InstallSubdir(target = '$INCLUDEINSTALLDIR', source = includes) diff --git a/Packets/80221Bundle/SConscript b/Packets/80221Bundle/SConscript index c065a7b..0cbf20a 100644 --- a/Packets/80221Bundle/SConscript +++ b/Packets/80221Bundle/SConscript @@ -5,9 +5,10 @@ import SENFSCons, glob ########################################################################### -sources, includes = SENFSCons.Glob(env) +(sources, tests), includes = SENFSCons.Glob(env) -SENFSCons.Object(env, target = '80221Bundle', sources=sources) -SENFSCons.Lib(env, sources[0]) +SENFSCons.Object(env, target = '80221Bundle', sources=sources, + testSources = tests + [ '80221Bundle.o' ]) +SENFSCons.Lib(env, sources) SConscript(glob.glob("*/SConscript")) diff --git a/Packets/DefaultBundle/SConscript b/Packets/DefaultBundle/SConscript index c91e6e8..bfafdac 100644 --- a/Packets/DefaultBundle/SConscript +++ b/Packets/DefaultBundle/SConscript @@ -5,10 +5,11 @@ import SENFSCons, glob ########################################################################### -sources, includes = SENFSCons.Glob(env) +(sources, tests), includes = SENFSCons.Glob(env) -SENFSCons.Object(env, target='DefaultBundle', sources=sources) -SENFSCons.Lib(env, sources[0]) +SENFSCons.Object(env, target='DefaultBundle', sources=sources, + testSources=tests + [ 'DefaultBundle.o' ]) +SENFSCons.Lib(env, sources) env.InstallSubdir(target = '$INCLUDEINSTALLDIR', source = includes) diff --git a/Packets/MPEGDVBBundle/SConscript b/Packets/MPEGDVBBundle/SConscript index b661eca..dafcda7 100644 --- a/Packets/MPEGDVBBundle/SConscript +++ b/Packets/MPEGDVBBundle/SConscript @@ -5,9 +5,10 @@ import SENFSCons, glob ########################################################################### -sources, includes = SENFSCons.Glob(env) +(sources, tests), includes = SENFSCons.Glob(env) -SENFSCons.Object(env, target='MPEGDVBBundle', sources=sources) -SENFSCons.Lib(env, sources[0]) +SENFSCons.Object(env, target='MPEGDVBBundle', sources=sources, + testSources = tests + [ 'MPEGDVBBundle.o' ]) +SENFSCons.Lib(env, sources) env.InstallSubdir(target = '$INCLUDEINSTALLDIR', source = includes) diff --git a/senfscons/BoostUnitTests.py b/senfscons/BoostUnitTests.py index 1e28824..427dacf 100644 --- a/senfscons/BoostUnitTests.py +++ b/senfscons/BoostUnitTests.py @@ -26,37 +26,28 @@ import SCons.Defaults import os.path import os -def BoostUnitTests(env, target, objects, test_sources=None, LIBS = [], OBJECTS = [], DEPENDS = [], **kw): - path, name = os.path.split(target) - if test_sources: - if type(test_sources) is not type([]): - test_sources = [ test_sources ] - else: - test_sources = [] - testEnv = env.Clone(**kw) - testEnv.Prepend(_LIBFLAGS = ' -Wl,-Bstatic -l$BOOSTTESTLIB -Wl,-Bdynamic ') - testEnv.Prepend(LIBS = LIBS) - testEnv.Append(LIBS = env['TEST_EXTRA_LIBS']) - all_objects = [] - if not objects: - objects = [] - all_objects = objects + env.Object(test_sources) + OBJECTS - binName = os.path.join(path,'.' + name +'.bin') - testRunner = testEnv.Program(binName, all_objects) - stamp = os.path.join(path,'.' + os.path.splitext(name)[0]+'.stamp') - if DEPENDS: - env.Depends(testRunner, DEPENDS) - return env.Command([ stamp ], testRunner, - [ '$SOURCE $BOOSTTESTARGS', - 'touch $TARGET' ]) - -def dispatcher(*arg,**kw): - return BoostUnitTests(*arg,**kw) +def BoostUnitTests(env, target=None, source=None, **kw): + target = env.arg2nodes(target)[0] + + binnode = target.dir.File('.' + target.name + '.bin') + stampnode = target.dir.File('.' + target.name + '.stamp') + + bin = env.Program(binnode, source, + LIBS = env['LIBS'] + [ '$TEST_EXTRA_LIBS' ], + _LIBFLAGS = ' -Wl,-Bstatic -l$BOOSTTESTLIB -Wl,-Bdynamic ' + env['_LIBFLAGS'], + **kw) + + stamp = env.Command(stampnode, bin, + [ '$SOURCE $BOOSTTESTARGS', + 'touch $TARGET' ], + **kw) + + return env.Command(env.File(target), stamp, [ 'true' ]) def generate(env): env['BOOSTTESTLIB'] = 'boost_unit_test_framework' env['BOOSTTESTARGS'] = [ '--build_info=yes', '--log_level=test_suite' ] - env.__class__.BoostUnitTests = dispatcher + env['BUILDERS']['BoostUnitTests'] = BoostUnitTests def exists(env): return 1 diff --git a/senfscons/SENFSCons.py b/senfscons/SENFSCons.py index 1f302d8..97d5c35 100644 --- a/senfscons/SENFSCons.py +++ b/senfscons/SENFSCons.py @@ -30,64 +30,36 @@ def Glob(env, exclude=[], subdirs=[]): def LibPath(lib): return '${LOCALLIBDIR}/${LIBPREFIX}%s${LIBADDSUFFIX}${LIBSUFFIX}' % lib -def Test(env, sources, LIBS = [], OBJECTS = []): - test = [ env.BoostUnitTests( - target = 'test', - objects = [], - test_sources = sources, - LIBS = [ '$LIBSENF$LIBADDSUFFIX' ], - OBJECTS = OBJECTS, - DEPENDS = [ env.File(LibPath(env['LIBSENF'])) ]) ] +def Test(env, sources): + test = env.BoostUnitTests( target = 'test', + source = sources, + TEST_EXTRA_LIBS = [ '$LIBSENF$LIBADDSUFFIX' + ] + env['TEST_EXTRA_LIBS']) + compileTestSources = [ src for src in sources if 'COMPILE_CHECK' in file(src).read() ] if compileTestSources: - test.extend(env.CompileCheck(source = compileTestSources)) + env.Depends(test, env.CompileCheck(source = compileTestSources)) + env.Alias('all_tests', test) - env.Command(env.File('test'), test, [ 'true' ]) + + return test -def Objects(env, sources, testSources = None, OBJECTS = []): +def Objects(env, sources, testSources = None): if type(sources) == type(()): testSources = sources[1] sources = sources[0] if type(sources) is not type([]): sources = [ sources ] - objects = None - if sources: - obsources = [ source - for source in sources - if type(source) is type('') and not source.endswith('.o') ] - objects = [ source - for source in sources - if type(source) is not type('') or source.endswith('.o') ] - if obsources: - objects += env.Object(obsources) + objects = env.Object(sources) if testSources: - test = [ env.BoostUnitTests( - target = 'test', - objects = objects, - test_sources = testSources, - LIBS = [ '$LIBSENF$LIBADDSUFFIX' ], - OBJECTS = OBJECTS, - DEPENDS = [ env.File(LibPath(env['LIBSENF'])) ]) ] - compileTestSources = [ src for src in testSources - if 'COMPILE_CHECK' in file(src).read() ] - if compileTestSources: - test.extend(env.CompileCheck(source = compileTestSources)) - env.Alias('all_tests', test) - # Hmm ... here I'd like to use an Alias instead of a file - # however the alias does not seem to live in the subdirectory - # which breaks 'scons -u test' - env.Command(env.File('test'), test, [ 'true' ]) - #env.Alias(env.File('test'), test) + Test(env, testSources) return objects -## \brief Build documentation with doxygen -# -# \ingroup target def Doxygen(env, doxyfile = "Doxyfile", extra_sources = []): # There is one small problem we need to solve with this builder: The Doxygen builder reads # the Doxyfile and thus depends on the environment variables set by doclib/doxygen.sh. We @@ -151,20 +123,21 @@ def Doxygen(env, doxyfile = "Doxyfile", extra_sources = []): return doc def Lib(env, sources, testSources = None, OBJECTS = []): - objects = Objects(env,sources,testSources,OBJECTS=OBJECTS) + objects = Objects(env,sources,testSources) env.Append(ALLOBJECTS = objects) return objects def Object(env, target, sources, testSources = None, OBJECTS = []): - objects = Objects(env,sources,testSources,OBJECTS=OBJECTS) - ob = env.Command(target+"${OBJADDSUFFIX}${OBJSUFFIX}", objects, "ld -r -o $TARGET $SOURCES") + objects = Objects(env,sources,testSources) + ob = env.Command(target+"${OBJADDSUFFIX}${OBJSUFFIX}", objects+OBJECTS, + [ "ld -r -o $TARGET $SOURCES" ]) env.Default(ob) env.Alias('default', ob) env.Alias('install_all', env.Install("$OBJINSTALLDIR", ob)) return ob def Binary(env, binary, sources, testSources = None, OBJECTS = []): - objects = Objects(env, sources, testSources, OBJECTS=OBJECTS) + objects = Objects(env, sources, testSources) program = env.Program(target = binary, source = objects+OBJECTS, LIBS = [ '$LIBSENF$LIBADDSUFFIX' ] + env['LIBS'])