Skip to content

Commit 428e225

Browse files
committed
Make Value.get_text_contents() use child csigs instead of contents
Current implementation of Value.get_text_contents() returns a concatenation of all child contents. Instead, make the contents of a Value similar to an Alias, except prepend the stringified 'value' attribute as well. Since Value.get_text_contents() will no longer fail (as long as child nodes implement a working get_csig() which they should), make get_contents() return get_text_contents() but utf-8 encoded. Also make get_csig() just return get_text_contents() Add new tests for testing get_contents() and get_text_contents() only rely on child node csigs, and not directly on child content.
1 parent 8530029 commit 428e225

File tree

2 files changed

+36
-25
lines changed

2 files changed

+36
-25
lines changed

SCons/Node/Python.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -138,24 +138,20 @@ def read(self):
138138
def get_text_contents(self):
139139
"""By the assumption that the node.built_value is a
140140
deterministic product of the sources, the contents of a Value
141-
are the concatenation of all the contents of its sources. As
142-
the value need not be built when get_contents() is called, we
141+
are the concatenation of all the content signatures of its sources.
142+
As the value need not be built when get_contents() is called, we
143143
cannot use the actual node.built_value."""
144-
###TODO: something reasonable about universal newlines
145144
contents = str(self.value)
146-
for kid in self.children(None):
147-
contents = contents + kid.get_contents().decode()
145+
contents += ''.join(n.get_csig() for n in self.children())
148146
return contents
149147

150148
def get_contents(self):
151149
"""
152-
Get contents for signature calculations.
150+
Same as get_text_contents() but encode as utf-8 in case other
151+
functions rely on get_contents() existing.
153152
:return: bytes
154153
"""
155-
contents = str(self.value).encode('utf-8')
156-
for kid in self.children(None):
157-
contents = contents + kid.get_contents()
158-
return contents
154+
return self.get_text_contents().encode('utf-8')
159155

160156
def changed_since_last_build(self, target, prev_ni):
161157
cur_csig = self.get_csig()
@@ -176,10 +172,8 @@ def get_csig(self, calc=None):
176172
except AttributeError:
177173
pass
178174

179-
csig = str(self.value)
180-
csig += ''.join(child.get_csig() for child in self.children(None))
175+
csig = self.get_text_contents()
181176

182-
self.get_ninfo().csig = csig
183177
return csig
184178

185179

SCons/Node/PythonTests.py

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,22 +122,39 @@ def get_csig(self, calc=None):
122122
csig = v.get_csig(None)
123123
assert csig == 'aaacsig1csig2', csig
124124

125-
def test_get_content_with_child_binary_content(self):
125+
def test_get_text_contents_with_children(self):
126+
"""Test calculating text contents with child nodes
127+
"""
126128
class DummyNode:
127-
def __init__(self, contents):
128-
self.contents = contents
129-
def get_contents(self):
130-
return self.contents
129+
def __init__(self, csig):
130+
self.csig = csig
131+
def get_csig(self):
132+
return self.csig
131133

132-
# Node with binary content that is not valid utf-8.
133-
node_with_binary = DummyNode(b'\xff')
134+
v = SCons.Node.Python.Value('aaa')
135+
c1 = DummyNode(csig='csig1')
136+
c2 = DummyNode(csig='csig2')
134137

135-
v = SCons.Node.Python.Value('v')
136-
v.add_dependency([node_with_binary])
138+
v.add_dependency([c1, c2])
139+
text_contents = v.get_text_contents()
140+
assert text_contents == 'aaacsig1csig2', text_contents
137141

138-
# Just make sure this call doesn't fail. Not sure what to check the
139-
# return value against.
140-
v.get_contents()
142+
def test_get_content_with_children(self):
143+
"""Test calculating contents with child nodes
144+
"""
145+
class DummyNode:
146+
def __init__(self, csig):
147+
self.csig = csig
148+
def get_csig(self):
149+
return self.csig
150+
151+
v = SCons.Node.Python.Value('aaa')
152+
c1 = DummyNode(csig='csig1')
153+
c2 = DummyNode(csig='csig2')
154+
155+
v.add_dependency([c1, c2])
156+
contents = v.get_contents()
157+
assert contents == v.get_text_contents().encode('utf-8'), contents
141158

142159

143160
class ValueNodeInfoTestCase(unittest.TestCase):

0 commit comments

Comments
 (0)