Add sub-project (senf/Ext) support to test_changes target
[senf.git] / SConstruct
index 6cde4f7..435bfb4 100644 (file)
@@ -31,18 +31,27 @@ linklint       Check links of doxygen documentation with 'linklint'
 fixlinks       Fix broken links in doxygen documentation
 all_valgrinds  Run all tests under valgrind/memcheck
 lcov           Generate test coverage output in doc/lcov and lcov.info
+
+You may execute targets on a remote host (if the directory layout is the same)
+by calling
+
+    scons <target>@[<user>@]<host>
 """)
 
 env.Append(
-   ENV                    = { 'PATH' : os.environ.get('PATH'), 'HOME' : os.environ.get('HOME') },
+   ENV                    = { 'PATH' : os.environ.get('PATH'), 
+                              'HOME' : os.environ.get('HOME'),
+                              'SSH_AGENT_PID': os.environ.get('SSH_AGENT_PID'),
+                              'SSH_AUTH_SOCK': os.environ.get('SSH_AUTH_SOCK') },
    CLEAN_PATTERNS         = [ '*~', '#*#', '*.pyc', 'semantic.cache', '.sconsign*' ],
 
    BUILDDIR               = '${FLAVOR and "#/build/$FLAVOR" or "#"}',
    CPPPATH                = [ '$BUILDDIR', '#' ],
    LOCALLIBDIR            = '$BUILDDIR',
    LIBPATH                = [ '$LOCALLIBDIR' ],
-   LIBS                   = [ '$LIBSENF$LIBADDSUFFIX', 'rt', '$BOOSTREGEXLIB', 
-                              '$BOOSTIOSTREAMSLIB', '$BOOSTSIGNALSLIB', '$BOOSTFSLIB' ], 
+   LIBS                   = [ '$LIBSENF$LIBADDSUFFIX', '$EXTRA_LIBS' ],
+   EXTRA_LIBS             = [ 'rt', '$BOOSTREGEXLIB', '$BOOSTIOSTREAMSLIB', '$BOOSTSIGNALSLIB', 
+                              '$BOOSTFSLIB' ], 
    TEST_EXTRA_LIBS        = [  ],
    VALGRINDARGS           = [ '--num-callers=50' ],
 
@@ -92,7 +101,8 @@ env.SetDefault(
     LCOV              = "lcov",
     GENHTML           = "genhtml",
     SCONSBIN          = env.File("#/tools/scons"),
-    SCONS             = "@$SCONSBIN -Q -j$CONCURRENCY_LEVEL",
+    SCONSARGS          = [ '-Q', '-j$CONCURRENCY_LEVEL', 'debug=$debug', 'final=$final' ],
+    SCONS             = "@$SCONSBIN $SCONSARGS",
     CONCURRENCY_LEVEL = env.GetOption('num_jobs') or 1,
     TOPDIR            = env.Dir('#').abspath,
     LIBADDSUFFIX      = '${FLAVOR and "_$FLAVOR" or ""}',
@@ -106,8 +116,13 @@ senfutil.parseArguments(
     BoolVariable('final', 'Build final (optimized) build', False),
     BoolVariable('debug', 'Link in debug symbols', False),
     BoolVariable('syslayout', 'Install in to system layout directories (lib/, include/ etc)', False),
+    BoolVariable('sparse_tests', 'Link tests against object files and not the senf lib', False)
 )
 
+if 'test_changes' in COMMAND_LINE_TARGETS and not env.has_key('only_tests'):
+    env['only_tests'] = " ".join(x.abspath for x in SparseTestHack.findSCMChanges())
+
+if env.has_key('only_tests') : env['sparse_tests'] = True
 Export('env')
 
 # Create Doxyfile.local otherwise doxygen will barf on this non-existent file
@@ -125,6 +140,9 @@ SConscriptChdir(0)
 SConscript("debian/SConscript")
 SConscriptChdir(1)
 if os.path.exists('SConscript.local') : SConscript('SConscript.local')
+if env['sparse_tests']:
+    import SparseTestHack
+    SparseTestHack.setup(env)
 if env.subst('$BUILDDIR') == '#':
     SConscript("SConscript")
 else:
@@ -132,6 +150,8 @@ else:
 SConscript("Examples/SConscript")
 SConscript("HowTos/SConscript")
 SConscript("doclib/SConscript")
+if env['sparse_tests']:
+    SparseTestHack.build(env, 'test_changes' in COMMAND_LINE_TARGETS)
 
 ###########################################################################
 # Define build targets
@@ -147,6 +167,7 @@ env.Install('${INCLUDEINSTALLDIR}', 'boost')
 env.Alias('install_all', env.FindInstalledFiles())
 env.Alias('default', DEFAULT_TARGETS)
 env.Alias('all_tests', env.FindAllBoostUnitTests())
+env.Alias('test_changes', 'all_tests')
 env.Alias('all', [ 'default', 'all_tests', 'examples', 'all_docs' ])
 
 #### prepare
@@ -195,3 +216,16 @@ if env.GetOption('clean') and 'all' in BUILD_TARGETS:
 
 if not env.GetOption('clean') and not os.path.exists(".prepare-stamp"):
     Execute(Touch(".prepare-stamp"))
+
+### execute targets on remote hosts
+for target in COMMAND_LINE_TARGETS:
+    if '@' in target:
+        realtarget, host = target.split('@',1)
+        cwd=env.GetLaunchDir()
+        home=os.environ['HOME']+'/'
+        if cwd.startswith(home) : cwd = cwd[len(home):]
+        args = [ '$SCONSARGS' ]
+        if env.GetLaunchDir() != os.getcwd():
+            args.append('-u')
+        env.PhonyTarget(target, [], [ "ssh $HOST scons $SCONSARGS -C $DIR $RTARGET" ],
+                        HOST=host, RTARGET=realtarget, DIR=cwd, SCONSARGS=args)