X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=site_scons%2Fsite_tools%2FBoost.py;h=7e20e2bbc1ce7a31d1763af0848d3ccaee91ddc5;hb=566fb4271b2aff5aa07943707f770b2a84c2738b;hp=4e07ac3ac7f6bdb85f925e4e25bf5b326ffd418d;hpb=d33cd468d4ece7c0c98270b4d1a9858e5a94510d;p=senf.git diff --git a/site_scons/site_tools/Boost.py b/site_scons/site_tools/Boost.py index 4e07ac3..7e20e2b 100644 --- a/site_scons/site_tools/Boost.py +++ b/site_scons/site_tools/Boost.py @@ -6,6 +6,7 @@ import os import sys import tempfile import SCons.Scanner.C +import CustomTests # ARGH ... Why do they put a '+' in the module name ???????? SCons.Tool.cplusplus=getattr(__import__('SCons.Tool.c++', globals(), locals(), []).Tool, 'c++') @@ -36,7 +37,8 @@ def CompileCheck(target, source, env): passedTests = {} delay_name = None out.seek(0) - for error in out.read().splitlines(): + result = out.read(); + for error in result.splitlines(): elts = error.split(':',2) if len(elts) != 3 : continue filename, line, message = elts @@ -49,7 +51,7 @@ def CompileCheck(target, source, env): print "Passed test '%s': %s" % (delay_name, message) delay_name = None continue - + filename = os.path.abspath(filename) if filename != source[0].abspath : continue @@ -71,31 +73,32 @@ def CompileCheck(target, source, env): if os.path.exists(target[0].abspath): os.unlink(target[0].abspath) return 1 - file(target[0].abspath,"w").close() + file(target[0].abspath,"w").write(result) return 0 CompileCheck = SCons.Script.Action(CompileCheck) def BoostUnitTest(env, target=None, source=None, **kw): + global _ALL_TESTS + target = env.arg2nodes(target)[0] source = env.arg2nodes(source) binnode = target.dir.File('.' + target.name + '.bin') stampnode = target.dir.File('.' + target.name + '.stamp') - bin = env.Program(binnode, source, + 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' ], + [ './$SOURCE $BOOSTTESTARGS', SCons.Script.Touch('$TARGET')], **kw) - alias = env.Command(env.File(target), stamp, []) + alias = env.Command(env.File(target), stamp, [ env.NopAction() ] ) - compileTests = [ src for src in source + compileTests = [ src for src in source if src.suffix in SCons.Tool.cplusplus.CXXSuffixes \ and src.exists() \ and 'COMPILE_CHECK' in file(str(src)).read() ] @@ -103,24 +106,116 @@ def BoostUnitTest(env, target=None, source=None, **kw): env.Depends(alias, env.CompileCheck(source = compileTests)) _ALL_TESTS.append(alias) - + return alias def FindAllBoostUnitTests(env, target, source): + global _ALL_TESTS return _ALL_TESTS +def NopAction(env, target, source): + def nop(target, source, env) : return None + def nopstr(target, source, env) : return '' + return env.Action(nop, nopstr) + +ConfTest = CustomTests.ConfTest() + +@ConfTest +def CheckBoostVersion(context,fail=False,min=None,max=None): + """Check for boost includes. + +Will place the boost version number (BOOST_LIB_VERSION) into the +BOOST_VERSION environment variable. + +Options: + + min/max compare boost version against given range. + + fail if fail is set to True, the build will be terminated, + when no valid boost includes are found.""" + if min and max: + msg = ' in range %s to %s' % (min,max) + elif min: + msg = ' at least %s' % min + elif max: + msg = ' at most %s' % max + else: + msg = '' + context.Message( "Checking boost version%s... " % msg ) + if context.env.has_key('BOOST_VERSION'): + ret = context.env['BOOST_VERSION'] + else: + ret = context.TryRun("#include \n" + "#include \n" + "int main(int, char **)\n" + "{ std::cout << BOOST_LIB_VERSION << std::endl; }", + ".cc")[-1].strip() + + if not ret: + msg = "no boost includes found" + context.env.Replace( BOOST_VERSION = None ) + else: + context.env.Replace( BOOST_VERSION = ret ) + msg = ret + if min or max: + try: version = map(int,ret.split('_')) + except ValueError: + msg = "[%s] invalid version syntax" % ret + ret = None + else: + if min : ret = ret and (version>=map(int,min.split('_'))) + if max : ret = ret and (version<=map(int,max.split('_'))) + msg = '[%s] %s' % (msg, ret and "yes" or "no") + context.Result(msg) + if fail and not ret : context.env.Fail('No valid boost includes found') + return ret + +@ConfTest +def CheckBoostVariants(context, *variants): + if not variants : variants = ('','mt') + useVariant = None + if context.env['BOOST_VARIANT'] is not None: + useVariant = context.env['BOOST_VARIANT'] + try: + _env = context.env.Clone() + for variant in variants: + if variant : variantStr = "'%s'" % variant + else : variantStr = "default" + context.Message( "Checking boost %s variant... " % variantStr ) + context.env.Replace( BOOST_VARIANT=variant ) + context.env.Append( _LIBFLAGS = ' -Wl,-Bstatic -l$BOOSTTESTLIB -Wl,-Bdynamic' ) + ret = context.TryLink("#define BOOST_AUTO_TEST_MAIN\n" + "#include \n" + "#include \n" + "BOOST_AUTO_TEST_CASE(test) { BOOST_CHECK(true); }\n", + ".cc") + context.Result( ret ) + if ret and useVariant is None: + useVariant = variant + finally: + context.env.Replace(**_env.Dictionary()) + if useVariant is not None and not context.env.GetOption('no_progress'): + print "Using %s boost variant." % ( + useVariant and "'%s'" % useVariant or "default") + context.env.Replace( BOOST_VARIANT = useVariant ) + return useVariant + def generate(env): env.SetDefault( - BOOST_VARIANT = '', + BOOST_VARIANT = None, + _BOOST_VARIANT = '${BOOST_VARIANT and "-" or None}$BOOST_VARIANT', - BOOSTTESTLIB = 'boost_unit_test_framework$BOOST_VARIANT', - BOOSTREGEXLIB = 'boost_regex$BOOST_VARIANT', - BOOSTFSLIB = 'boost_filesystem$BOOST_VARIANT', - BOOSTIOSTREAMSLIB = 'boost_iostreams$BOOST_VARIANT', - BOOSTSIGNALSLIB = 'boost_signals$BOOST_VARIANT', + BOOSTTESTLIB = 'boost_unit_test_framework$_BOOST_VARIANT', + BOOSTREGEXLIB = 'boost_regex$_BOOST_VARIANT', + BOOSTFSLIB = 'boost_filesystem$_BOOST_VARIANT', + BOOSTIOSTREAMSLIB = 'boost_iostreams$_BOOST_VARIANT', + BOOSTSIGNALSLIB = 'boost_signals$_BOOST_VARIANT', BOOSTTESTARGS = [ '--build_info=yes', '--log_level=test_suite' ], - ) + ) + env.Append( + CUSTOM_TESTS = ConfTest.tests, + ) env['BUILDERS']['BoostUnitTest'] = BoostUnitTest env['BUILDERS']['FindAllBoostUnitTests'] = FindAllBoostUnitTests @@ -131,6 +226,7 @@ def generate(env): source_scanner = SCons.Scanner.C.CScanner(), single_source=1 ) + env['BUILDERS']['NopAction'] = NopAction def exists(env): return True