minor fixes for clang++
[senf.git] / site_scons / SparseTestHack.py
index 8ae888d..56cbada 100644 (file)
@@ -1,4 +1,4 @@
-import SCons.Node, SCons.Node.FS, SCons.Util
+import SCons.Node, SCons.Node.FS, SCons.Util, SCons.Errors, os
 
 #####################################################################
 # This IS a hack .. but a very useful one: The hack will remove the
@@ -6,7 +6,7 @@ import SCons.Node, SCons.Node.FS, SCons.Util
 # files needed explicitly.
 #
 # This works by building a list of all children (recursively) of the
-# test sources. For each child we check, wether a file with the same
+# test sources. For each child we check, whether a file with the same
 # name but an $OBJSUFFIX extension exists as a build target. In that
 # case, we add it to the list of needed objects (AND recursively scan
 # that objects children).
@@ -80,17 +80,24 @@ def setup(env):
     env['BUILDERS']['RealBoostUnitTest'] = env['BUILDERS']['BoostUnitTest']
     env['BUILDERS']['BoostUnitTest'] = AutoObjectBoostUnitTest
     env['_UNIT_TEST_LIST'] = []
+    env.Append(EXTRA_LIBS = [ '$BOOSTREGEXLIB', '$BOOSTSIGNALSLIB',
+                       '$BOOSTFSLIB', '$BOOSTSYSTEMLIB', '$BOOSTDATETIMELIB' ])
 
 # This needs to be called after all build targets have been set
 # up. This is important since the list of object targets needs to be
 # complete.
-def build(env):
+def build(env, accept_unknown_tests=False, verbose=False):
     env = env.Clone(LIBS = [ '$EXTRA_LIBS' ])
     if env.has_key("only_tests"):
-        only_tests = [ env.Dir(env.GetLaunchDir()).File(test)
-                       for test in env.Split(env['only_tests']) ]
+        only_tests = {}
+        dir = env.Dir(env.GetLaunchDir())
+        for test in env.Split(env['only_tests']):
+            test = dir.File(test)
+            if not test.name.endswith(".test.cc"):
+                test = test.target_from_source(prefix="", suffix=".test.cc")
+            only_tests[test] = False
     else:
-        only_tests = []
+        only_tests = {}
     for target, tests, kw in env['_UNIT_TEST_LIST']:
         objects = []
         build = False
@@ -98,7 +105,8 @@ def build(env):
             if test.suffix == env['OBJSUFFIX']:
                 objects.append(test)
             else:
-                if not only_tests or test in only_tests:
+                if not only_tests or only_tests.has_key(test):
+                    if only_tests : only_tests[test] = True
                     objects.extend(env.Object(test))
                     build = True
                 elif test.name == 'main.test.cc':
@@ -117,3 +125,32 @@ def build(env):
         objects = [ ob for ob in objects if not sources.get(ob) ]
 
         env.RealBoostUnitTest(target, objects, **kw)
+
+    if verbose and only_tests and not env.GetOption('no_progress'):
+        SCons.Util.display("scons: building tests: " + ", ".join("`%s'" % str(k)
+                                                                 for k,v in only_tests.iteritems()
+                                                                 if v))
+    if not accept_unknown_tests:
+        only_tests = [ k for k,v in only_tests.iteritems() if not v ]
+        if only_tests:
+            raise SCons.Errors.StopError("Unknown unit tests (only_tests): %s." 
+                                         % ", ".join("`%s'" % x for x in only_tests))
+
+def findSCMChanges(env):
+
+    def scmchanges(dir):
+        if os.popen("cd %s; svnversion" % dir.abspath).read().strip() in ("","exported"):
+            return [ dir.Entry(x)
+                     for x in os.popen("cd %s; git ls-files --modified" 
+                                       % dir.abspath).read().strip().split("\n") ]
+        else:
+            return [ dir.Entry(l[7:])
+                     for l in os.popen("cd %s; svn status" 
+                                       % dir.abspath).read().rstrip().split("\n")
+                     if l[0] == 'M' ]
+
+    changes=scmchanges(env.Dir('#'))
+    for dir in env.Dir('senf/Ext').glob("*"):
+        if isinstance(dir,SCons.Node.FS.Dir):
+            changes.extend(scmchanges(dir))
+    return [ x for x in changes if not isinstance(x,SCons.Node.FS.Dir) ]