Add -u support to scons target@host support
[senf.git] / SConstruct
index 60683ef..d8c0510 100644 (file)
@@ -12,16 +12,7 @@ env.Decider('MD5-timestamp')
 env.EnsureSConsVersion(1,2)
 
 # Load all the local SCons tools
-env.Tool('Doxygen')
-env.Tool('Dia2Png')
-env.Tool('PkgDraw')
-env.Tool('InstallSubdir')
-env.Tool('CopyToDir')
-env.Tool('Boost')
-env.Tool('CombinedObject')
-env.Tool('PhonyTarget')
-env.Tool('InstallDir')
-env.Tool('CreateFile')
+senfutil.loadTools(env)
 
 env.Help("""
 Additional top-level build targets:
@@ -40,13 +31,21 @@ 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               = '#',
+   BUILDDIR               = '${FLAVOR and "#/build/$FLAVOR" or "#"}',
    CPPPATH                = [ '$BUILDDIR', '#' ],
    LOCALLIBDIR            = '$BUILDDIR',
    LIBPATH                = [ '$LOCALLIBDIR' ],
@@ -101,9 +100,13 @@ 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 ""}',
+    OBJADDSUFFIX      = '${LIBADDSUFFIX}',
+    FLAVOR            = '',
 )
 
 # Set variables from command line
@@ -131,10 +134,10 @@ SConscriptChdir(0)
 SConscript("debian/SConscript")
 SConscriptChdir(1)
 if os.path.exists('SConscript.local') : SConscript('SConscript.local')
-if env['BUILDDIR'] == '#':
+if env.subst('$BUILDDIR') == '#':
     SConscript("SConscript")
 else:
-    SConscript("SConscript", variant_dir=env['BUILDDIR'], src_dir='#', duplicate=False)
+    SConscript("SConscript", variant_dir=env.subst('$BUILDDIR'), src_dir='#', duplicate=False)
 SConscript("Examples/SConscript")
 SConscript("HowTos/SConscript")
 SConscript("doclib/SConscript")
@@ -174,8 +177,8 @@ for test in env.FindAllBoostUnitTests():
 
 ### lcov
 env.PhonyTarget('lcov', [], [
-        '$SCONS debug=1 BUILDDIR="#/lcov-build" CCFLAGS+="-fprofile-arcs -ftest-coverage" LIBS+="gcov" all_tests',
-        '$LCOV --follow --directory $TOPDIR/lcov-build/senf --capture --output-file /tmp/senf_lcov.info --base-directory $TOPDIR',
+        '$SCONS debug=1 BUILDDIR="#/build/lcov" CCFLAGS+="-fprofile-arcs -ftest-coverage" LIBS+="gcov" all_tests',
+        '$LCOV --follow --directory $TOPDIR/build/lcov/senf --capture --output-file /tmp/senf_lcov.info --base-directory $TOPDIR',
         '$LCOV --output-file lcov.info --remove /tmp/senf_lcov.info "*/include/*" "*/boost/*" "*.test.*" ',
         '$GENHTML --output-directory doc/lcov --title all_tests lcov.info',
         'rm /tmp/senf_lcov.info' ])
@@ -184,13 +187,13 @@ if env.GetOption('clean'):
                         for path, subdirs, files in os.walk('.')
                         for pattern in ('*.gcno', '*.gcda', '*.gcov')
                         for f in fnmatch.filter(files,pattern) ] + 
-                      [ 'lcov.info', env.Dir('doc/lcov'), env.Dir('lcov-build') ])
+                      [ 'lcov.info', env.Dir('doc/lcov'), env.Dir('build/lcov') ])
     
 #### clean
-env.Clean('all', ('.prepare-stamp', env.Dir('dist')))
+env.Clean('all', ('.prepare-stamp', env.Dir('dist'), env.Dir('build')))
 if env.GetOption('clean') : env.Depends('all', ('lcov', 'all_valgrinds'))
 
-if env.GetOption('clean') and     'all' in BUILD_TARGETS:
+if env.GetOption('clean') and 'all' in BUILD_TARGETS:
     env.Clean('all', [ os.path.join(path,f)
                        for path, subdirs, files in os.walk('.')
                        for pattern in env['CLEAN_PATTERNS']
@@ -201,3 +204,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)