From 47be469317aea6cded4e2879e371f5736a59dde3 Mon Sep 17 00:00:00 2001 From: stevenknight Date: Sun, 23 May 2004 12:11:42 +0000 Subject: [PATCH] Add support for fetching command-line arguments by position number. (Gary Oberbrunner) git-svn-id: http://scons.tigris.org/svn/scons/trunk@982 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- doc/man/scons.1 | 42 +++++++++++++++++++++++ src/CHANGES.txt | 9 +++++ src/engine/SCons/Script/SConscript.py | 3 ++ test/ARGLIST.py | 48 +++++++++++++++++++++++++++ 4 files changed, 102 insertions(+) create mode 100644 test/ARGLIST.py diff --git a/doc/man/scons.1 b/doc/man/scons.1 index ea0cf811..51c9e4c4 100644 --- a/doc/man/scons.1 +++ b/doc/man/scons.1 @@ -314,6 +314,17 @@ else: env = Environment() .EE +The command-line variable arguments are also available +in the ARGLIST list, +indexed by their order on the command line. +This allows you to process them in order rather than by name, +if necessary. +ARGLIST[0] returns a tuple +containing (argname, argvalue). +A Python exception is thrown if you +try to access a list member that +does not exist. + .B scons requires Python version 1.5.2 or later. There should be no other dependencies or requirements to run @@ -3749,6 +3760,37 @@ supports a number of Python variables that can be used in SConscript files to affect how you want the build to be performed. +'\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +.TP +ARGLIST +A list +.IR keyword = value +arguments specified on the command line. +Each element in the list is a tuple +containing the +.RI ( keyword , value ) +of the argument. +The separate +.I keyword +and +.I value +elements of the tuple +can be accessed by +subscripting for element +.B [0] +and +.B [1] +of the tuple, respectively. + +.ES +print "first keyword, value =", ARGLIST[0][0], ARGLIST[0][1] +print "second keyword, value =", ARGLIST[1][0], ARGLIST[1][1] +third_tuple = ARGLIST[2] +print "third keyword, value =", third_tuple[0], third_tuple[1] +for key, value in ARGLIST: + # process key and value +.EE + '\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" .TP ARGUMENTS diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 7aaabf5d..57166dff 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -25,6 +25,9 @@ RELEASE 0.96 - XXX - Suppress null values in construction variables like $LIBS that use the internal _concat() function. + - Remove .dll files from the construction variables searched for + libraries that can be fed to Win32 compilers. + From Chad Austin and Christoph Wiedemann: - Add support for a $RPATH variable to supply a list of directories @@ -139,6 +142,9 @@ RELEASE 0.96 - XXX - Try to find the ICL license file path name in the external environment and the registry before resorting to the hard-coded path name. + - Add support for fetching command-line keyword=value arguments in + order from an ARGLIST list. + From Simon Perkins: - Fix a bug introduced in building shared libraries under MinGW. @@ -150,6 +156,9 @@ RELEASE 0.96 - XXX - If Visual Studio is installed, assume the C/C++ compiler, the linker and the MIDL compiler that comes with it are available, too. + - Better error messages when evaluating a construction variable + expansion yields a Python syntax error. + From sam th: - Allow SConf.CheckLib() to search a list of libraries, like the diff --git a/src/engine/SCons/Script/SConscript.py b/src/engine/SCons/Script/SConscript.py index 6a414b75..405ce717 100644 --- a/src/engine/SCons/Script/SConscript.py +++ b/src/engine/SCons/Script/SConscript.py @@ -61,6 +61,7 @@ def do_nothing(text): pass HelpFunction = do_nothing Arguments = {} +ArgList = [] CommandLineTargets = [] DefaultCalled = None DefaultTargets = [] @@ -88,6 +89,7 @@ def _scons_add_args(alist): for arg in alist: a, b = string.split(arg, '=', 1) Arguments[a] = b + ArgList.append((a, b)) def _scons_add_targets(tlist): if tlist: @@ -684,6 +686,7 @@ def BuildDefaultGlobals(): # Other variables we provide. 'ARGUMENTS' : Arguments, + 'ARGLIST' : ArgList, 'BUILD_TARGETS' : BuildTargets, 'COMMAND_LINE_TARGETS' : CommandLineTargets, 'DEFAULT_TARGETS' : DefaultTargets, diff --git a/test/ARGLIST.py b/test/ARGLIST.py new file mode 100644 index 00000000..c70ed8ea --- /dev/null +++ b/test/ARGLIST.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import TestSCons + +test = TestSCons.TestSCons() + +test.write('SConstruct', """ +i = 0 +for key, value in ARGLIST: + print "%d: %s = %s" % (i, key, value) + i = i + 1 +""") + +expect = test.wrap_stdout(read_str="""\ +0: a = 1 +1: bz = 3 +2: xx = sd +3: zzz = foo=bar +""", + build_str="scons: `.' is up to date.\n") + +test.run(arguments='a=1 bz=3 xx=sd zzz=foo=bar .', stdout = expect) + +test.pass_test() -- 2.26.2