summaryrefslogtreecommitdiffstats
path: root/src/engine
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2002-03-24 00:51:23 (GMT)
committerSteven Knight <knight@baldmt.com>2002-03-24 00:51:23 (GMT)
commit94d7ac89ad998937fbbc3c896dffc88cece8e925 (patch)
tree9120c2c8716c1ff5c824a644fb3a967ada0e8fd0 /src/engine
parent2fa424ece5fd4df18a3aeff1f6e59e2ecb41a28e (diff)
downloadSCons-94d7ac89ad998937fbbc3c896dffc88cece8e925.zip
SCons-94d7ac89ad998937fbbc3c896dffc88cece8e925.tar.gz
SCons-94d7ac89ad998937fbbc3c896dffc88cece8e925.tar.bz2
Move SCons.Util.scons_str2nodes() to SCons.Node/__init__.py and shorten its name.
Diffstat (limited to 'src/engine')
-rw-r--r--src/engine/SCons/Builder.py19
-rw-r--r--src/engine/SCons/Environment.py27
-rw-r--r--src/engine/SCons/Node/NodeTests.py59
-rw-r--r--src/engine/SCons/Node/__init__.py37
-rw-r--r--src/engine/SCons/Scanner/C.py7
-rw-r--r--src/engine/SCons/Scanner/Prog.py5
-rw-r--r--src/engine/SCons/Script/SConscript.py5
-rw-r--r--src/engine/SCons/Util.py36
-rw-r--r--src/engine/SCons/UtilTests.py51
9 files changed, 129 insertions, 117 deletions
diff --git a/src/engine/SCons/Builder.py b/src/engine/SCons/Builder.py
index a62d91d..46fe9cb 100644
--- a/src/engine/SCons/Builder.py
+++ b/src/engine/SCons/Builder.py
@@ -36,6 +36,7 @@ import string
from Errors import UserError
import SCons.Action
+import SCons.Node
import SCons.Node.FS
import SCons.Util
@@ -132,15 +133,15 @@ class BuilderBase:
ret.append(f)
return ret
- tlist = SCons.Util.scons_str2nodes(adjustixes(target,
- env.subst(self.prefix),
- env.subst(self.suffix)),
- self.node_factory)
+ tlist = SCons.Node.arg2nodes(adjustixes(target,
+ env.subst(self.prefix),
+ env.subst(self.suffix)),
+ self.node_factory)
- slist = SCons.Util.scons_str2nodes(adjustixes(source,
- None,
- env.subst(self.src_suffix)),
- self.node_factory)
+ slist = SCons.Node.arg2nodes(adjustixes(source,
+ None,
+ env.subst(self.src_suffix)),
+ self.node_factory)
return tlist, slist
def __call__(self, env, target = None, source = None):
@@ -248,7 +249,7 @@ class MultiStepBuilder(BuilderBase):
self.src_builder = src_builder
def __call__(self, env, target = None, source = None):
- slist = SCons.Util.scons_str2nodes(source, self.node_factory)
+ slist = SCons.Node.arg2nodes(source, self.node_factory)
final_sources = []
src_suffix = env.subst(self.src_suffix)
sdict = {}
diff --git a/src/engine/SCons/Environment.py b/src/engine/SCons/Environment.py
index 65af179..04bf26d 100644
--- a/src/engine/SCons/Environment.py
+++ b/src/engine/SCons/Environment.py
@@ -30,10 +30,11 @@ XXX
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-import os
import copy
+import os
import os.path
import re
+import shutil
import string
import sys
import types
@@ -41,6 +42,7 @@ import types
import SCons.Builder
import SCons.Defaults
from SCons.Errors import UserError
+import SCons.Node
import SCons.Node.FS
import SCons.Util
@@ -91,8 +93,8 @@ class Environment:
"""
def __init__(self, **kw):
- import SCons.Defaults
- self._dict = our_deepcopy(SCons.Defaults.ConstructionEnvironment)
+ self.fs = SCons.Node.FS.default_fs
+ self._dict = our_deepcopy(SCons.Defaults.ConstructionEnvironment)
apply(self.Update, (), kw)
#
@@ -187,8 +189,8 @@ class Environment:
def Depends(self, target, dependency):
"""Explicity specify that 'target's depend on 'dependency'."""
- tlist = SCons.Util.scons_str2nodes(target)
- dlist = SCons.Util.scons_str2nodes(dependency)
+ tlist = SCons.Node.arg2nodes(target, self.fs.File)
+ dlist = SCons.Node.arg2nodes(dependency, self.fs.File)
for t in tlist:
t.add_dependency(dlist)
@@ -198,8 +200,8 @@ class Environment:
def Ignore(self, target, dependency):
"""Ignore a dependency."""
- tlist = SCons.Util.scons_str2nodes(target)
- dlist = SCons.Util.scons_str2nodes(dependency)
+ tlist = SCons.Node.arg2nodes(target, self.fs.File)
+ dlist = SCons.Node.arg2nodes(dependency, self.fs.File)
for t in tlist:
t.add_ignore(dlist)
@@ -210,7 +212,7 @@ class Environment:
def Precious(self, *targets):
tlist = []
for t in targets:
- tlist.extend(SCons.Util.scons_str2nodes(t))
+ tlist.extend(SCons.Node.arg2nodes(t, self.fs.File))
for t in tlist:
t.set_precious()
@@ -246,9 +248,8 @@ class Environment:
def Install(self, dir, source):
"""Install specified files in the given directory."""
- sources = SCons.Util.scons_str2nodes(source)
- dnodes = SCons.Util.scons_str2nodes(dir,
- SCons.Node.FS.default_fs.Dir)
+ sources = SCons.Node.arg2nodes(source, self.fs.File)
+ dnodes = SCons.Node.arg2nodes(dir, self.fs.Dir)
tgt = []
for dnode in dnodes:
for src in sources:
@@ -260,8 +261,8 @@ class Environment:
def InstallAs(self, target, source):
"""Install sources as targets."""
- sources = SCons.Util.scons_str2nodes(source)
- targets = SCons.Util.scons_str2nodes(target)
+ sources = SCons.Node.arg2nodes(source, self.fs.File)
+ targets = SCons.Node.arg2nodes(target, self.fs.File)
ret = []
for src, tgt in map(lambda x, y: (x, y), sources, targets):
ret.append(InstallBuilder(self, tgt, src))
diff --git a/src/engine/SCons/Node/NodeTests.py b/src/engine/SCons/Node/NodeTests.py
index 8a166f2..1c92476 100644
--- a/src/engine/SCons/Node/NodeTests.py
+++ b/src/engine/SCons/Node/NodeTests.py
@@ -25,6 +25,7 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
import os
import sys
+import types
import unittest
import SCons.Errors
@@ -683,6 +684,64 @@ class NodeTestCase(unittest.TestCase):
assert tn.scanned[ds]
assert len(tn.implicit[ds]) == 2, tn.implicit
+ def test_arg2nodes(self):
+ """Test the arg2nodes function."""
+ dict = {}
+ class X(SCons.Node.Node):
+ pass
+ def Factory(name, directory = None, create = 1, dict=dict, X=X):
+ if not dict.has_key(name):
+ dict[name] = X()
+ dict[name].name = name
+ return dict[name]
+
+ nodes = SCons.Node.arg2nodes("Util.py UtilTests.py", Factory)
+ assert len(nodes) == 2, nodes
+ assert isinstance(nodes[0], X)
+ assert isinstance(nodes[1], X)
+ assert nodes[0].name == "Util.py"
+ assert nodes[1].name == "UtilTests.py"
+
+ if hasattr(types, 'UnicodeType'):
+ code = """if 1:
+ nodes = SCons.Node.arg2nodes(u"Util.py UtilTests.py", Factory)
+ assert len(nodes) == 2, nodes
+ assert isinstance(nodes[0], X)
+ assert isinstance(nodes[1], X)
+ assert nodes[0].name == u"Util.py"
+ assert nodes[1].name == u"UtilTests.py"
+ \n"""
+ exec code
+
+ nodes = SCons.Node.arg2nodes(["Util.py", "UtilTests.py"], Factory)
+ assert len(nodes) == 2, nodes
+ assert isinstance(nodes[0], X)
+ assert isinstance(nodes[1], X)
+ assert nodes[0].name == "Util.py"
+ assert nodes[1].name == "UtilTests.py"
+
+ n1 = Factory("Util.py")
+ nodes = SCons.Node.arg2nodes([n1, "UtilTests.py"], Factory)
+ assert len(nodes) == 2, nodes
+ assert isinstance(nodes[0], X)
+ assert isinstance(nodes[1], X)
+ assert nodes[0].name == "Util.py"
+ assert nodes[1].name == "UtilTests.py"
+
+ class SConsNode(SCons.Node.Node):
+ pass
+ nodes = SCons.Node.arg2nodes(SConsNode())
+ assert len(nodes) == 1, nodes
+ assert isinstance(nodes[0], SConsNode), node
+
+ class OtherNode:
+ pass
+ nodes = SCons.Node.arg2nodes(OtherNode())
+ assert len(nodes) == 1, nodes
+ assert isinstance(nodes[0], OtherNode), node
+
+
+
if __name__ == "__main__":
suite = unittest.makeSuite(NodeTestCase, 'test_')
if not unittest.TextTestRunner().run(suite).wasSuccessful():
diff --git a/src/engine/SCons/Node/__init__.py b/src/engine/SCons/Node/__init__.py
index c66a1a4..a7c8521 100644
--- a/src/engine/SCons/Node/__init__.py
+++ b/src/engine/SCons/Node/__init__.py
@@ -31,12 +31,14 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-from SCons.Errors import BuildError
import string
import types
import copy
import sys
+from SCons.Errors import BuildError
+import SCons.Util
+
# Node states
#
# These are in "priority" order, so that the maximum value for any
@@ -318,3 +320,36 @@ class Walker:
def is_done(self):
return not self.stack
+
+
+def arg2nodes(arg, node_factory=None):
+ """This function converts a string or list into a list of Node instances.
+ It follows the rules outlined in the SCons design document by accepting
+ any of the following inputs:
+ - A single string containing names separated by spaces. These will be
+ split apart at the spaces.
+ - A single Node instance,
+ - A list containingg either strings or Node instances. Any strings
+ in the list are not split at spaces.
+ In all cases, the function returns a list of Node instances."""
+
+ narg = arg
+ if SCons.Util.is_String(arg):
+ narg = string.split(arg)
+ elif not SCons.Util.is_List(arg):
+ narg = [arg]
+
+ nodes = []
+ for v in narg:
+ if SCons.Util.is_String(v):
+ if node_factory:
+ nodes.append(node_factory(v))
+ # Do we enforce the following restriction? Maybe, but it
+ # would also restrict what we can do to allow people to
+ # use the engine with alternate Node implementations...
+ #elif not issubclass(v.__class__, Node):
+ # raise TypeError
+ else:
+ nodes.append(v)
+
+ return nodes
diff --git a/src/engine/SCons/Scanner/C.py b/src/engine/SCons/Scanner/C.py
index 7a9a4ba..8d4497c 100644
--- a/src/engine/SCons/Scanner/C.py
+++ b/src/engine/SCons/Scanner/C.py
@@ -33,6 +33,9 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
import copy
import os.path
import re
+
+import SCons.Node
+import SCons.Node.FS
import SCons.Scanner
import SCons.Util
@@ -60,8 +63,8 @@ class CScanner(SCons.Scanner.Recursive):
given environment.
"""
try:
- dirs = tuple(SCons.Util.scons_str2nodes(env.Dictionary('CPPPATH'),
- self.fs.Dir))
+ dirs = tuple(SCons.Node.arg2nodes(env.Dictionary('CPPPATH'),
+ self.fs.Dir))
except:
dirs = ()
if not self.pathscanners.has_key(dirs):
diff --git a/src/engine/SCons/Scanner/Prog.py b/src/engine/SCons/Scanner/Prog.py
index 87b0ce8..9ecc37b 100644
--- a/src/engine/SCons/Scanner/Prog.py
+++ b/src/engine/SCons/Scanner/Prog.py
@@ -26,6 +26,7 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
import copy
import string
+import SCons.Node
import SCons.Node.FS
import SCons.Scanner
import SCons.Util
@@ -65,8 +66,8 @@ class ProgScanner(SCons.Scanner.Base):
libs = string.split(libs)
try:
- dirs = tuple(SCons.Util.scons_str2nodes(env.Dictionary('LIBPATH'),
- self.fs.Dir))
+ dirs = tuple(SCons.Node.arg2nodes(env.Dictionary('LIBPATH'),
+ self.fs.Dir))
except:
dirs = ()
diff --git a/src/engine/SCons/Script/SConscript.py b/src/engine/SCons/Script/SConscript.py
index d50f521..2cfc64b 100644
--- a/src/engine/SCons/Script/SConscript.py
+++ b/src/engine/SCons/Script/SConscript.py
@@ -123,7 +123,7 @@ def Default(*targets):
if isinstance(t, SCons.Node.Node):
default_targets.append(t)
else:
- default_targets.extend(SCons.Util.scons_str2nodes(t,
+ default_targets.extend(SCons.Node.arg2nodes(t,
SCons.Node.FS.default_fs.Entry))
def Help(text):
@@ -136,8 +136,7 @@ def BuildDir(build_dir, src_dir, duplicate=1):
SCons.Node.FS.default_fs.BuildDir(build_dir, src_dir, duplicate)
def GetBuildPath(files):
- nodes = SCons.Util.scons_str2nodes(files,
- SCons.Node.FS.default_fs.Entry)
+ nodes = SCons.Node.arg2nodes(files, SCons.Node.FS.default_fs.Entry)
ret = map(str, nodes)
if len(ret) == 1:
return ret[0]
diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py
index 5175ac5..f60e981 100644
--- a/src/engine/SCons/Util.py
+++ b/src/engine/SCons/Util.py
@@ -44,42 +44,6 @@ except ImportError:
class UserString:
pass
-import SCons.Node
-import SCons.Node.FS
-
-def scons_str2nodes(arg, node_factory=SCons.Node.FS.default_fs.File):
- """This function converts a string or list into a list of Node instances.
- It follows the rules outlined in the SCons design document by accepting
- any of the following inputs:
- - A single string containing names separated by spaces. These will be
- split apart at the spaces.
- - A single Node instance,
- - A list containingg either strings or Node instances. Any strings
- in the list are not split at spaces.
- In all cases, the function returns a list of Node instances."""
-
- narg = arg
- if is_String(arg):
- narg = string.split(arg)
- elif not is_List(arg):
- narg = [arg]
-
- nodes = []
- for v in narg:
- if is_String(v):
- nodes.append(node_factory(v))
- # Do we enforce the following restriction? Maybe, but it
- # also restricts what we can do for allowing people to
- # use the engine with alternate Node implementations...
- # Perhaps this should be split in two, with the SCons.Node
- # logic in a wrapper somewhere under SCons.Node, and the
- # string-parsing logic here...?
- #elif not issubclass(v.__class__, SCons.Node.Node):
- # raise TypeError
- else:
- nodes.append(v)
-
- return nodes
class PathList(UserList.UserList):
diff --git a/src/engine/SCons/UtilTests.py b/src/engine/SCons/UtilTests.py
index 0b0003a..67bdbb4 100644
--- a/src/engine/SCons/UtilTests.py
+++ b/src/engine/SCons/UtilTests.py
@@ -36,57 +36,6 @@ from SCons.Util import *
import TestCmd
class UtilTestCase(unittest.TestCase):
- def test_str2nodes(self):
- """Test the str2nodes function."""
- nodes = scons_str2nodes("Util.py UtilTests.py")
- assert len(nodes) == 2, nodes
- assert isinstance(nodes[0], SCons.Node.FS.File)
- assert isinstance(nodes[1], SCons.Node.FS.File)
- assert nodes[0].path == "Util.py"
- assert nodes[1].path == "UtilTests.py"
-
- if hasattr(types, 'UnicodeType'):
- code = """if 1:
- nodes = scons_str2nodes(u"Util.py UtilTests.py")
- assert len(nodes) == 2, nodes
- assert isinstance(nodes[0], SCons.Node.FS.File)
- assert isinstance(nodes[1], SCons.Node.FS.File)
- assert nodes[0].path == u"Util.py"
- assert nodes[1].path == u"UtilTests.py"
- \n"""
- exec code
-
- nodes = scons_str2nodes("Util.py UtilTests.py", SCons.Node.FS.FS().File)
- assert len(nodes) == 2, nodes
- assert isinstance(nodes[0], SCons.Node.FS.File)
- assert isinstance(nodes[1], SCons.Node.FS.File)
- assert nodes[0].path == "Util.py"
- assert nodes[1].path == "UtilTests.py"
-
- nodes = scons_str2nodes(["Util.py", "UtilTests.py"])
- assert len(nodes) == 2, nodes
- assert isinstance(nodes[0], SCons.Node.FS.File)
- assert isinstance(nodes[1], SCons.Node.FS.File)
- assert nodes[0].path == "Util.py"
- assert nodes[1].path == "UtilTests.py"
-
- n1 = SCons.Node.FS.default_fs.File("Util.py")
- nodes = scons_str2nodes([n1, "UtilTests.py"])
- assert len(nodes) == 2, nodes
- assert isinstance(nodes[0], SCons.Node.FS.File)
- assert isinstance(nodes[1], SCons.Node.FS.File)
- assert nodes[0].path == "Util.py"
- assert nodes[1].path == "UtilTests.py"
-
- class SConsNode(SCons.Node.Node):
- pass
- node = scons_str2nodes(SConsNode())
-
- class OtherNode:
- pass
- node = scons_str2nodes(OtherNode())
-
-
def test_subst(self):
"""Test the subst function."""
loc = {}