Fix boost-unit-test exit status reporting in SCons
[senf.git] / satscons / BoostUnitTests.py
1 import SCons.Script.SConscript
2 import SCons.Defaults
3 import os.path
4 import os
5
6 def BoostUnitTests(env, target, source, test_source=None, LIBS = [], DEPENDS = [], **kw):
7     path, name = os.path.split(target)
8     if test_source:
9         if type(test_source) is not type([]):
10             test_source = [ test_source ]
11     else:
12         test_source = []
13     testEnv = env.Copy(**kw)
14     testEnv.Prepend(LIBS = '$BOOSTTESTLIB')
15     testEnv.Prepend(LIBS = LIBS)
16     sources = []
17     if source:
18         sources = sources + env.Object(source)
19     sources = sources + test_source
20     binName = os.path.join(path,'.' + os.path.splitext(name)[0]+'.bin')
21     testRunner = testEnv.Program(binName, sources)
22     stamp = os.path.join(path,'.' + os.path.splitext(name)[0]+'.stamp')
23     if DEPENDS:
24         env.Depends(testRunner, DEPENDS)
25     return env.Command([ target, stamp ], testRunner,
26                        [ '( $SOURCE $BOOSTTESTARGS 2>&1 && touch ${TARGETS[1]} ) | tee ${TARGETS[0]}; exit $$PIPESTATUS[0]' ])
27
28 def dispatcher(*arg,**kw):
29     return BoostUnitTests(*arg,**kw)
30     
31 def generate(env):
32     env['BOOSTTESTLIB'] = 'boost_unit_test_framework'
33     env['BOOSTTESTARGS'] = [ '--build_info=yes', '--log_level=test_suite' ]
34     env.__class__.BoostUnitTests = dispatcher
35
36 def exists(env):
37     return 1