From e5f2858ca5ff86bd28490f0de1dbf803767b8bdc Mon Sep 17 00:00:00 2001 From: stevenknight Date: Thu, 24 Mar 2005 04:17:25 +0000 Subject: [PATCH] Allow toolpath to be stored in the environment and re-used for Copy() and Tool() calls. (Chad Austin) git-svn-id: http://scons.tigris.org/svn/scons/trunk@1264 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- doc/man/scons.1 | 15 ++++++++- src/CHANGES.txt | 3 ++ src/engine/SCons/Environment.py | 16 +++++++--- src/engine/SCons/EnvironmentTests.py | 46 ++++++++++++++++++++++++++++ test/toolpath.py | 5 +++ 5 files changed, 79 insertions(+), 6 deletions(-) diff --git a/doc/man/scons.1 b/doc/man/scons.1 index 3aac25c7..26fcc66c 100644 --- a/doc/man/scons.1 +++ b/doc/man/scons.1 @@ -1023,6 +1023,19 @@ value if the tool is available. Tools in the toolpath are used before any of the built-in ones. For example, adding gcc.py to the toolpath would override the built-in gcc tool. +Also note that the toolpath is +stored in the environment for use +by later calls to +.BR Copy () +and +.BR Tool () +methods: + +.ES +base = Environment(toolpath=['custom_path']) +derived = base.Copy(tools=['custom_tool']) +derived.CustomBuilder() +.EE The elements of the tools list may also be functions or callable objects, @@ -7382,7 +7395,7 @@ and selects the compiler to be used for the check; the default is "C". .TP -.RI Configure.CheckLib( self ", [" library ", " symbol ", " header ", " language ", " autoadd ]) +.RI Configure.CheckLib( self ", [" library ", " symbol ", " header ", " language ", " autoadd=1 ]) Checks if .I library provides diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 2e265450..6f0691ff 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -25,6 +25,9 @@ RELEASE 0.97 - XXX - Allow Tools found on a toolpath to import Python modules from their local directory. + - Have the environment store the toolpath and re-use it to find Tools + modules during later Copy() or Tool() calls (unless overridden). + From Stanislav Baranov: - Make it possible to support with custom Alias (sub-)classes. diff --git a/src/engine/SCons/Environment.py b/src/engine/SCons/Environment.py index 9b93e12d..77ce3c29 100644 --- a/src/engine/SCons/Environment.py +++ b/src/engine/SCons/Environment.py @@ -117,6 +117,10 @@ def our_deepcopy(x): return copy def apply_tools(env, tools, toolpath): + # Store the toolpath in the Environment. + if toolpath is not None: + env['toolpath'] = toolpath + if not tools: return # Filter out null tools from the list. @@ -124,9 +128,9 @@ def apply_tools(env, tools, toolpath): if SCons.Util.is_List(tool) or type(tool)==type(()): toolname = tool[0] toolargs = tool[1] # should be a dict of kw args - tool = apply(env.Tool, (toolname, toolpath), toolargs) + tool = apply(env.Tool, [toolname], toolargs) else: - env.Tool(tool, toolpath) + env.Tool(tool) # These names are controlled by SCons; users should never set or override # them. This warning can optionally be turned off, but scons will still @@ -465,7 +469,7 @@ class Base(SubstitutionEnvironment): def __init__(self, platform=None, tools=None, - toolpath=[], + toolpath=None, options=None, **kw): """ @@ -704,7 +708,7 @@ class Base(SubstitutionEnvironment): self._dict[key] = self._dict[key] + val self.scanner_map_delete(kw) - def Copy(self, tools=[], toolpath=[], **kw): + def Copy(self, tools=[], toolpath=None, **kw): """Return a copy of a construction Environment. The copy is like a Python "deep copy"--that is, independent copies are made recursively of each objects--except that @@ -1045,9 +1049,11 @@ class Base(SubstitutionEnvironment): del kw[k] apply(self.Replace, (), kw) - def Tool(self, tool, toolpath=[], **kw): + def Tool(self, tool, toolpath=None, **kw): if SCons.Util.is_String(tool): tool = self.subst(tool) + if toolpath is None: + toolpath = self.get('toolpath', []) toolpath = map(self.subst, toolpath) tool = apply(SCons.Tool.Tool, (tool, toolpath), kw) tool(self) diff --git a/src/engine/SCons/EnvironmentTests.py b/src/engine/SCons/EnvironmentTests.py index 0e8fd56b..a508529a 100644 --- a/src/engine/SCons/EnvironmentTests.py +++ b/src/engine/SCons/EnvironmentTests.py @@ -1354,6 +1354,29 @@ def exists(env): x = env2.get('FLAGS') assert x == ['flag1', 'flag2', 'flag3', 'flag4'], x + # Test that the environment stores the toolpath and + # re-uses it for copies. + test = TestCmd.TestCmd(workdir = '') + + test.write('xxx.py', """\ +def exists(env): + 1 +def generate(env): + env['XXX'] = 'one' +""") + + test.write('yyy.py', """\ +def exists(env): + 1 +def generate(env): + env['YYY'] = 'two' +""") + + env = Environment(tools=['xxx'], toolpath=[test.workpath('')]) + assert env['XXX'] == 'one', env['XXX'] + env = env.Copy(tools=['yyy']) + assert env['YYY'] == 'two', env['YYY'] + def test_Detect(self): """Test Detect()ing tools""" test = TestCmd.TestCmd(workdir = '') @@ -1843,6 +1866,29 @@ f5: \ env.Tool('$LINK') assert env['LINK'] == '$SMARTLINK', env['LINK'] + # Test that the environment stores the toolpath and + # re-uses it for later calls. + test = TestCmd.TestCmd(workdir = '') + + test.write('xxx.py', """\ +def exists(env): + 1 +def generate(env): + env['XXX'] = 'one' +""") + + test.write('yyy.py', """\ +def exists(env): + 1 +def generate(env): + env['YYY'] = 'two' +""") + + env = Environment(tools=['xxx'], toolpath=[test.workpath('')]) + assert env['XXX'] == 'one', env['XXX'] + env.Tool('yyy') + assert env['YYY'] == 'two', env['YYY'] + def test_WhereIs(self): """Test the WhereIs() method""" test = TestCmd.TestCmd(workdir = '') diff --git a/test/toolpath.py b/test/toolpath.py index 797f3452..55b70fdf 100644 --- a/test/toolpath.py +++ b/test/toolpath.py @@ -87,6 +87,10 @@ env0.Tool('SCCS', toolpath=['$TOOLPATH']) print "env0['SCCS'] =", env0.get('SCCS') print "env0['TOOL_SCCS1'] =", env0.get('TOOL_SCCS1') print "env0['TOOL_SCCS2'] =", env0.get('TOOL_SCCS2') + +base = Environment(tools=[], toolpath=['tools']) +derived = base.Copy(tools=['bar']) +print "derived['TOOL_BAR'] =", derived.get('TOOL_BAR') """) test.write('SCCS.py', r"""\ @@ -148,6 +152,7 @@ env9['TOOL_SCCS2'] = 1 env0['SCCS'] = None env0['TOOL_SCCS1'] = None env0['TOOL_SCCS2'] = 1 +derived['TOOL_BAR'] = 1 scons: done reading SConscript files. scons: Building targets ... scons: `.' is up to date. -- 2.26.2