summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2005-12-16 12:11:01 (GMT)
committerSteven Knight <knight@baldmt.com>2005-12-16 12:11:01 (GMT)
commit5282b161bd006fff6f2942d21e4924769bd9cf7a (patch)
treeb0c2cac4f046d9461ef9e1910e22acb84fa3d99e /src
parente6c6b149292506a1b625beee0e69d6c35bb1d048 (diff)
downloadSCons-5282b161bd006fff6f2942d21e4924769bd9cf7a.zip
SCons-5282b161bd006fff6f2942d21e4924769bd9cf7a.tar.gz
SCons-5282b161bd006fff6f2942d21e4924769bd9cf7a.tar.bz2
Checkpoint minor refactorings en route to signature refactoring.
Diffstat (limited to 'src')
-rw-r--r--src/engine/SCons/Node/Alias.py7
-rw-r--r--src/engine/SCons/Node/AliasTests.py19
-rw-r--r--src/engine/SCons/Node/FS.py26
-rw-r--r--src/engine/SCons/Node/FSTests.py71
-rw-r--r--src/engine/SCons/Node/NodeTests.py16
-rw-r--r--src/engine/SCons/Node/__init__.py14
6 files changed, 144 insertions, 9 deletions
diff --git a/src/engine/SCons/Node/Alias.py b/src/engine/SCons/Node/Alias.py
index 2730abf..bc7e53b 100644
--- a/src/engine/SCons/Node/Alias.py
+++ b/src/engine/SCons/Node/Alias.py
@@ -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"""
diff --git a/src/engine/SCons/Node/AliasTests.py b/src/engine/SCons/Node/AliasTests.py
index 417cc2b..9a12766 100644
--- a/src/engine/SCons/Node/AliasTests.py
+++ b/src/engine/SCons/Node/AliasTests.py
@@ -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
"""
diff --git a/src/engine/SCons/Node/FS.py b/src/engine/SCons/Node/FS.py
index 7f45751..59ad707 100644
--- a/src/engine/SCons/Node/FS.py
+++ b/src/engine/SCons/Node/FS.py
@@ -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.
diff --git a/src/engine/SCons/Node/FSTests.py b/src/engine/SCons/Node/FSTests.py
index 6514375..ba6cea8 100644
--- a/src/engine/SCons/Node/FSTests.py
+++ b/src/engine/SCons/Node/FSTests.py
@@ -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):
diff --git a/src/engine/SCons/Node/NodeTests.py b/src/engine/SCons/Node/NodeTests.py
index 11c57a9..3e2fd5c 100644
--- a/src/engine/SCons/Node/NodeTests.py
+++ b/src/engine/SCons/Node/NodeTests.py
@@ -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):
diff --git a/src/engine/SCons/Node/__init__.py b/src/engine/SCons/Node/__init__.py
index a77b09b..7a29f95 100644
--- a/src/engine/SCons/Node/__init__.py
+++ b/src/engine/SCons/Node/__init__.py
@@ -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:
"""