Move SCons.Util.scons_str2nodes() to SCons.Node/__init__.py and shorten its name.
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sun, 24 Mar 2002 00:51:23 +0000 (00:51 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sun, 24 Mar 2002 00:51:23 +0000 (00:51 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@304 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/engine/SCons/Builder.py
src/engine/SCons/Environment.py
src/engine/SCons/Node/NodeTests.py
src/engine/SCons/Node/__init__.py
src/engine/SCons/Scanner/C.py
src/engine/SCons/Scanner/Prog.py
src/engine/SCons/Script/SConscript.py
src/engine/SCons/Util.py
src/engine/SCons/UtilTests.py

index a62d91d62ee7739c47c68dddeee471dc9b802d10..46fe9cb0e6d32ba79d5f26bfdd4ad5ca5e5dad34 100644 (file)
@@ -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 = {}
index 65af179e5632faf37a158ff68568c12e3c4c07b2..04bf26da628b229a06b850d9bd4ba268cd34009d 100644 (file)
@@ -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))
index 8a166f22b1a27148cae9a8f4c24742723cb4432f..1c9247655bd89acba6e97541a51aa7d0715d834e 100644 (file)
@@ -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():
index c66a1a4ca61fcbf22f912a174809a80d18c89fac..a7c8521a4d0e6c760b34cd2340d3ad9dff5faa80 100644 (file)
@@ -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
index 7a9a4bad1b516d207674419e81773f679029dae7..8d4497c70a5cfd7e0be3307fa52045466d775566 100644 (file)
@@ -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):
index 87b0ce8c72c95db1764b46ef0550612b51e02b45..9ecc37b0612165bf5ec904b60decf4b8ba63f008 100644 (file)
@@ -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 = ()
 
index d50f521a238c35bc2101e392d769d332271eebe9..2cfc64bd5902523dfff9dbb19f27e6cea7bc0e8f 100644 (file)
@@ -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]
index 5175ac5774e91e3e78d5125ed360c348b6b519ee..f60e9815647387482b04a6c68ea735551f3ef0a9 100644 (file)
@@ -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):
index 0b0003a7986ce54ca2498ac719fcd27c64ced4d8..67bdbb42090bfa1895755ed780bc1722a3cee6cd 100644 (file)
@@ -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 = {}