From: g0dil Date: Fri, 28 Aug 2009 15:22:08 +0000 (+0000) Subject: Correctly parse boolen command line arguments X-Git-Url: http://g0dil.de/git?p=senf.git;a=commitdiff_plain;h=c96297689340465d5f1cb4c677eccea8abdbfc42 Correctly parse boolen command line arguments Add '+=' support to command line argument parsing git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1353 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/Mainpage.dox b/Mainpage.dox index 571a519..e535169 100644 --- a/Mainpage.dox +++ b/Mainpage.dox @@ -51,34 +51,14 @@ \section senfutil_overview Building Projects using SENF When building projects using senf, SENFSCons has a very simple helper module \ref senfutil to - make the building of libraries utilizing senf simpler: - \code - import sys - sys.path.extend(('senf/site_scons','/usr/lib/senf/site_scons')) - import glob, senfutil - - env = Environment() - senfutil.SetupForSENF(env) - senfutil.DefaultOptions(env) - - env.Append( LOGLEVELS_debug = [ 'senf::log::Debug||VERBOSE' ] ) - - env.Default( - env.Program( target = 'udpforward', source = glob.glob('*.cc') ) - ) - \endcode - - This example builds a simple binary from a number of source files (all '.cc' files). It links - against the SENF library and automatically sets all the correct compiler options using - senfutil.SetupForSENF( env ). - - This script automatically uses a SENF installation either symlinked or imported into the current - project in directory 'senf' or, if this directory does not exist, a globally installed SENF. + make the building of libraries utilizing senf simpler. \see \ref senf_senfutil */ -/** \page senf_senfutil SENF SCons build utility +/** \page senf_senfutil SENF SCons build utility (senfutil.py) + + \autotoc The \c senfutil utility for SCons helps setting up a project to compile against SENF: @@ -116,6 +96,13 @@ ) \endcode + This example builds a simple binary from a number of source files (all '.cc' files). It links + against the SENF library and automatically sets all the correct compiler options using + senfutil.SetupForSENF( env ). + + This script automatically uses a SENF installation either symlinked or imported into the current + project in directory 'senf' or, if this directory does not exist, a globally installed SENF. + \section senf_senfutil_options Build options \c senfutil supports the debug=1 or final=1 build options. These parameters @@ -160,6 +147,33 @@ LINKFLAGS_normal = [ '-Wl,-S' ], ) \endcode + + Thus above example can be simplified to + \code + import sys + sys.path.extend(('senf/site_scons','/usr/lib/senf/site_scons')) + import glob, senfutil + + env = Environment() + senfutil.SetupForSENF(env) + senfutil.DefaultOptions(env) + + env.Append( LOGLEVELS_debug = [ 'senf::log::Debug||VERBOSE' ] ) + + env.Default( + env.Program( target = 'udpforward', source = glob.glob('*.cc') ) + ) + \endcode + + \section senf_senfutil_arguments 'scons' Command line arguments + + \c senfutil automatically parses SCons command line arguments into the SCons build + environment. This allows specifying any parameter on the command line: +
+    $ scons CXXCOM=mygcc CXXFLAGS+=-mtune=geode
+    
+ You may either set variables unconditionally using '=' or append values to the end of a list + using '+='. */ /** \page senf_usage Using the SENF framework diff --git a/SConstruct b/SConstruct index f56ce4f..f9ce745 100644 --- a/SConstruct +++ b/SConstruct @@ -35,15 +35,6 @@ debbin Build debian binary package linklint Check links of doxygen documentation with 'linklint' fixlinks Fix broken links in doxygen documentation valgrind Run all tests under valgrind/memcheck - -Build parameters: - -final=1 Build optimized library without debug symbols -debug=1 Link all binaries with debug symbols (slow!) -syslayout=1 Install into system layout directories ($$PREFIX/lib, $$PREFIX/include etc) - -additionally, any construction environment variable may be set from the scons -command line (see SConstruct file and SCons documentation for a list of variables). """) env.Replace( @@ -99,18 +90,23 @@ env.Append( LINKFLAGS_ = senfutil.BuildTypeOptions('LINKFLAGS'), LINKFLAGS_final = [ ], LINKFLAGS_normal = [ '-Wl,-S' ], - LINKFLAGS_debug = [ ], + LINKFLAGS_debug = [ '-g' ], ) env.SetDefault( LIBSENF = "senf", - final = 0, - debug = 0, - syslayout = 0 + final = False, + debug = False, + syslayout = False ) # Set variables from command line -env.Replace(**ARGUMENTS) +senfutil.parseArguments( + env, + 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), +) Export('env') diff --git a/site_scons/senfutil.py b/site_scons/senfutil.py index 3fd7567..25e1249 100644 --- a/site_scons/senfutil.py +++ b/site_scons/senfutil.py @@ -22,6 +22,28 @@ class BuildTypeOptions: type = env['final'] and "final" or env['debug'] and "debug" or "normal" return env[self._var + "_" + type] +def parseArguments(env, *defs): + vars = Variables(args=ARGUMENTS) + vars.AddVariables(*defs) + vars.Update(env) + env.Help(""" +Any construction environment variable may be set from the scons +command line (see SConstruct file and SCons documentation for a list +of variables) using + + VARNAME=value Assign new value + VARNAME+=value Append value at end + +Special command line parameters: +""") + env.Help(vars.GenerateHelpText(env)) + for k,v in vars.UnknownVariables().iteritems(): + if k.endswith('+'): + env.Append(**{k[:-1]: v}) + else: + env.Replace(**{k: v}) + + ########################################################################### # This looks much more complicated than it is: We do three things here: # a) switch between final or debug options @@ -73,14 +95,11 @@ def SetupForSENF(env, senf_paths = []): ) # Interpret command line options - opts = Variables(args=ARGUMENTS) - opts.Add( 'LOGLEVELS', 'Special log levels. Syntax: |[]| ...', - '${"$LOGLEVELS_"+(final and "final" or "debug")}' ) - opts.Add( BoolVariable('final', 'Build final (optimized) build', False) ) - opts.Add( BoolVariable('debug', 'Link in debug symbols', False) ) - opts.Update(env) - env.Replace(**dict(opts.UnknownVariables())) - env.Help(opts.GenerateHelpText(env)) + parseArguments( + env, + BoolVariable('final', 'Build final (optimized) build', False), + BoolVariable('debug', 'Link in debug symbols', False), + ) # If we have a symbolic link (or directory) 'senf', we use it as our # senf repository @@ -115,4 +134,5 @@ def DefaultOptions(env): CXXFLAGS_debug = [ '$CXXFLAGS_normal' ], LINKFLAGS_normal = [ '-Wl,-S' ], + LINKFLAGS_debug = [ '-g' ], )