Restructure SENFSCons.Object helper
[senf.git] / senfscons / BoostUnitTests.py
index 2dce3ba..427dacf 100644 (file)
@@ -26,36 +26,28 @@ import SCons.Defaults
 import os.path
 import os
 
-def BoostUnitTests(env, target, source, test_source=None, LIBS = [], OBJECTS = [], DEPENDS = [], **kw):
-    path, name = os.path.split(target)
-    if test_source:
-        if type(test_source) is not type([]):
-            test_source = [ test_source ]
-    else:
-        test_source = []
-    testEnv = env.Copy(**kw)
-    testEnv.Prepend(LIBS = '$BOOSTTESTLIB')
-    testEnv.Prepend(LIBS = LIBS)
-    sources = []
-    if source:
-        sources = sources + env.Object(source) + OBJECTS
-    sources = sources + test_source
-    binName = os.path.join(path,'.' + name +'.bin')
-    testRunner = testEnv.Program(binName, sources)
-    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