From: stevenknight Date: Fri, 16 Dec 2005 12:11:01 +0000 (+0000) Subject: Checkpoint minor refactorings en route to signature refactoring. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=7a6c9d3ff8601774e9564d96a6a358821095cf45;p=scons.git Checkpoint minor refactorings en route to signature refactoring. git-svn-id: http://scons.tigris.org/svn/scons/trunk@1402 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- diff --git a/src/engine/SCons/Node/Alias.py b/src/engine/SCons/Node/Alias.py index 2730abfe..bc7e53b4 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 417cc2b3..9a12766e 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 7f45751e..59ad7075 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 65143759..ba6cea83 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 11c57a95..3e2fd5c2 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 a77b09ba..7a29f95c 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: """