Checkpoint minor refactorings en route to signature refactoring.
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Fri, 16 Dec 2005 12:11:01 +0000 (12:11 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Fri, 16 Dec 2005 12:11:01 +0000 (12:11 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@1402 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/engine/SCons/Node/Alias.py
src/engine/SCons/Node/AliasTests.py
src/engine/SCons/Node/FS.py
src/engine/SCons/Node/FSTests.py
src/engine/SCons/Node/NodeTests.py
src/engine/SCons/Node/__init__.py

index 2730abfeb4df798835a4182cc5f202874c332e31..bc7e53b415c4c8c65740e401c4319e8e39ef9d6c 100644 (file)
@@ -32,6 +32,7 @@ This creates a hash of global Aliases (dummy targets).
 
 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
 
+import string
 import UserDict
 
 import SCons.Errors
@@ -75,10 +76,8 @@ class Alias(SCons.Node.Node):
     def get_contents(self):
         """The contents of an alias is the concatenation
         of all the contents of its sources"""
-        contents = ""
-        for kid in self.children(None):
-            contents = contents + kid.get_contents()
-        return contents
+        contents = map(lambda n: n.get_contents(), self.children(None))
+        return string.join(contents, '')
 
     def sconsign(self):
         """An Alias is not recorded in .sconsign files"""
index 417cc2b38d5c0b8d7e1cce454b3c767ee6e0a02d..9a12766e0ac6a93c8327b3b3c5f3e40fb1d7579a 100644 (file)
@@ -48,6 +48,25 @@ class AliasTestCase(unittest.TestCase):
         a2 = ans.Alias('a1')
         assert a1 is a2, (a1, a2)
 
+    def test_get_contents(self):
+        """Test the get_contents() method
+        """
+        class DummyNode:
+            def __init__(self, contents):
+                self.contents = contents
+            def get_contents(self):
+                return self.contents
+
+        ans = SCons.Node.Alias.AliasNameSpace()
+
+        ans.Alias('a1')
+        a = ans.lookup('a1')
+
+        a.sources = [ DummyNode('one'), DummyNode('two'), DummyNode('three') ]
+
+        c = a.get_contents()
+        assert c == 'onetwothree', c
+
     def test_lookup(self):
         """Test the lookup() method
         """
index 7f45751e591b8ead7763a2d21c95e5333a0dfb75..59ad70755e91419c19b57c385d86f3790bac4154 100644 (file)
@@ -727,6 +727,18 @@ class Entry(Base):
         directory."""
         return self.disambiguate().exists()
 
+    def missing(self):
+        """Return if the Entry is missing.  Check the file system to
+        see what we should turn into first.  Assume a file if there's
+        no directory."""
+        return self.disambiguate().missing()
+
+    def get_csig(self):
+        """Return the entry's content signature.  Check the file system
+        to see what we should turn into first.  Assume a file if there's
+        no directory."""
+        return self.disambiguate().get_csig()
+
     def calc_signature(self, calc=None):
         """Return the Entry's calculated signature.  Check the file
         system to see what we should turn into first.  Assume a file if
@@ -1360,10 +1372,8 @@ class Dir(Base):
 
     def get_contents(self):
         """Return aggregate contents of all our children."""
-        contents = cStringIO.StringIO()
-        for kid in self.children():
-            contents.write(kid.get_contents())
-        return contents.getvalue()
+        contents = map(lambda n: n.get_contents(), self.children())
+        return  string.join(contents, '')
 
     def prepare(self):
         pass
@@ -1627,6 +1637,14 @@ class BuildInfo(SCons.Node.BuildInfo):
                 pass
             else:
                 setattr(self, attr, map(Entry_func, val))
+    def format(self):
+        result = [ self.ninfo.format() ]
+        bkids = self.bsources + self.bdepends + self.bimplicit
+        bkidsigs = self.bsourcesigs + self.bdependsigs + self.bimplicitsigs
+        for i in xrange(len(bkids)):
+            result.append(str(bkids[i]) + ': ' + bkidsigs[i].format())
+        return string.join(result, '\n')
+
 
 class File(Base):
     """A class for files in a file system.
index 65143759d67d570b10d9e565ffa0971cddd0659a..ba6cea834df79e9d1ba17a031e99b604b0f9c19d 100644 (file)
@@ -757,6 +757,28 @@ class BuildInfoTestCase(_tempdirTestCase):
     def test_convert_from_sconsign(self):
         """Test converting from .sconsign file format"""
 
+    def test_format(self):
+        """Test the format() method"""
+        f1 = self.fs.File('f1')
+        bi1 = SCons.Node.FS.BuildInfo(f1)
+
+        s1sig = SCons.Node.FS.NodeInfo()
+        s1sig.a = 1
+        d1sig = SCons.Node.FS.NodeInfo()
+        d1sig.a = 2
+        i1sig = SCons.Node.FS.NodeInfo()
+        i1sig.a = 3
+
+        bi1.bsources = [self.fs.File('s1')]
+        bi1.bdepends = [self.fs.File('d1')]
+        bi1.bimplicit = [self.fs.File('i1')]
+        bi1.bsourcesigs = [s1sig]
+        bi1.bdependsigs = [d1sig]
+        bi1.bimplicitsigs = [i1sig]
+
+        format = bi1.format()
+        assert format == 'None 0\ns1: 1\nd1: 2\ni1: 3', repr(format)
+
 class FSTestCase(_tempdirTestCase):
     def test_runTest(self):
         """Test FS (file system) Node operations
@@ -1843,6 +1865,55 @@ class EntryTestCase(_tempdirTestCase):
         self.fs.Entry('#topdir')
         self.fs.Entry('#topdir/a/b/c')
 
+    def test_missing(self):
+        """Test that the Entry.missing() method disambiguates node types"""
+        test = TestCmd(workdir='')
+        # FS doesn't like the cwd to be something other than its root.
+        os.chdir(test.workpath(""))
+
+        fs = SCons.Node.FS.FS()
+
+        test.subdir('emd')
+        test.write('emf', "emf\n")
+
+        emd = fs.Entry('emd')
+        missing = emd.missing()
+        assert emd.__class__ is SCons.Node.FS.Dir, emd.__class__
+        assert not missing
+
+        emf = fs.Entry('emf')
+        missing = emf.missing()
+        assert emf.__class__ is SCons.Node.FS.File, emf.__class__
+        assert not missing
+
+        emn = fs.Entry('emn')
+        missing = emn.missing()
+        assert emn.__class__ is SCons.Node.FS.File, emn.__class__
+        assert missing
+
+    def test_get_csig(self):
+        """Test that the Entry.get_csig() method disambiguates node types"""
+        test = TestCmd(workdir='')
+        # FS doesn't like the cwd to be something other than its root.
+        os.chdir(test.workpath(""))
+
+        fs = SCons.Node.FS.FS()
+
+        test.subdir('egcd')
+        test.write('egcf', "egcf\n")
+
+        egcd = fs.Entry('egcd')
+        egcd.get_csig()
+        assert egcd.__class__ is SCons.Node.FS.Dir, egcd.__class__
+
+        egcf = fs.Entry('egcf')
+        egcf.get_csig()
+        assert egcf.__class__ is SCons.Node.FS.File, egcf.__class__
+
+        egcn = fs.Entry('egcn')
+        egcn.get_csig()
+        assert egcn.__class__ is SCons.Node.FS.File, egcn.__class__
+
 
 
 class FileTestCase(_tempdirTestCase):
index 11c57a9573a381cd08167decb975f48ed2082af0..3e2fd5c22b07ea0141786df38c147d56cb6d6390 100644 (file)
@@ -251,6 +251,21 @@ class NodeInfoTestCase(unittest.TestCase):
         ni = SCons.Node.NodeInfo()
         ni.update(SCons.Node.Node())
 
+    def test_format(self):
+        """Test the NodeInfo.format() method"""
+        ni1 = SCons.Node.NodeInfo()
+        ni1.xxx = 'x'
+        ni1.yyy = 'y'
+        ni1.zzz = 'z'
+
+        f = ni1.format()
+        assert f == 'x y z', f
+
+        ni1.field_list = ['xxx', 'zzz', 'aaa']
+
+        f = ni1.format()
+        assert f == 'x z None', f
+
 
 
 class BuildInfoTestCase(unittest.TestCase):
@@ -311,7 +326,6 @@ class BuildInfoTestCase(unittest.TestCase):
 
 
 
-
 class NodeTestCase(unittest.TestCase):
 
     def test_build(self):
index a77b09ba3603e2f53b3815cc68b1bb52187c2cc0..7a29f95cbc85ec001bb7e46890367d9a145bb34c 100644 (file)
@@ -117,6 +117,20 @@ class NodeInfo:
     def merge(self, other):
         for key, val in other.__dict__.items():
             self.__dict__[key] = val
+    def format(self):
+        try:
+            field_list = self.field_list
+        except AttributeError:
+            field_list = self.__dict__.keys()
+            field_list.sort()
+        fields = []
+        for field in field_list:
+            try:
+                f = getattr(self, field)
+            except AttributeError:
+                f = None
+            fields.append(str(f))
+        return string.join(fields, " ")
 
 class BuildInfo:
     """