From 552f1297158198338c29f2d853c50d678a4a3617 Mon Sep 17 00:00:00 2001 From: stevenknight Date: Thu, 14 Mar 2002 02:57:20 +0000 Subject: [PATCH] Swap the global and local arguments in scons_subst*() to match the Python convention for exec(). git-svn-id: http://scons.tigris.org/svn/scons/trunk@294 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- src/engine/SCons/Util.py | 10 +++++----- src/engine/SCons/UtilTests.py | 11 +++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py index 6806c318..04e7e7d9 100644 --- a/src/engine/SCons/Util.py +++ b/src/engine/SCons/Util.py @@ -170,7 +170,7 @@ class PathList(UserList.UserList): _cv = re.compile(r'\$([_a-zA-Z]\w*|{[^}]*})') _space_sep = re.compile(r'[\t ]+(?![^{]*})') -def scons_subst_list(strSubst, locals, globals, remove=None): +def scons_subst_list(strSubst, globals, locals, remove=None): """ This function is similar to scons_subst(), but with one important difference. Instead of returning a single @@ -189,12 +189,12 @@ def scons_subst_list(strSubst, locals, globals, remove=None): This is the only way to know where the 'split' between arguments is for executing a command line.""" - def repl(m, locals=locals, globals=globals): + def repl(m, globals=globals, locals=locals): key = m.group(1) if key[:1] == '{' and key[-1:] == '}': key = key[1:-1] try: - e = eval(key, locals, globals) + e = eval(key, globals, locals) if not e: s = '' elif is_List(e): @@ -219,7 +219,7 @@ def scons_subst_list(strSubst, locals, globals, remove=None): return map(lambda x: filter(lambda y: y, string.split(x, '\0')), listLines) -def scons_subst(strSubst, locals, globals, remove=None): +def scons_subst(strSubst, globals, locals, remove=None): """Recursively interpolates dictionary variables into the specified string, returning the expanded result. Variables are specified by a $ prefix in the string and @@ -229,7 +229,7 @@ def scons_subst(strSubst, locals, globals, remove=None): surrounded by curly braces to separate the name from trailing characters. """ - cmd_list = scons_subst_list(strSubst, locals, globals, remove) + cmd_list = scons_subst_list(strSubst, globals, locals, remove) return string.join(map(string.join, cmd_list), '\n') class VarInterpolator: diff --git a/src/engine/SCons/UtilTests.py b/src/engine/SCons/UtilTests.py index aa58c8ea..f3569f05 100644 --- a/src/engine/SCons/UtilTests.py +++ b/src/engine/SCons/UtilTests.py @@ -155,6 +155,11 @@ class UtilTestCase(unittest.TestCase): newcom = scons_subst("test aXbXcXd", loc, {}, re.compile('X')) assert newcom == cvt("test abcd"), newcom + glob = { 'a' : 1, 'b' : 2 } + loc = {'a' : 3, 'c' : 4 } + newcom = scons_subst("test $a $b $c $d test", glob, loc) + assert newcom == "test 3 2 4 test", newcom + def test_subst_list(self): """Testing the scons_subst_list() method...""" loc = {} @@ -188,6 +193,12 @@ class UtilTestCase(unittest.TestCase): assert cmd_list[1][0] == 'after', cmd_list[1][0] assert cmd_list[0][2] == cvt('../foo/ack.cbefore'), cmd_list[0][2] + glob = { 'a' : 1, 'b' : 2 } + loc = {'a' : 3, 'c' : 4 } + cmd_list = scons_subst_list("test $a $b $c $d test", glob, loc) + assert len(cmd_list) == 1, cmd_list + assert cmd_list[0] == ['test', '3', '2', '4', 'test'], cmd_list + def test_autogenerate(dict): """Test autogenerating variables in a dictionary.""" dict = {'LIBS' : [ 'foo', 'bar', 'baz' ], -- 2.26.2