in an Environment's BUILDERS dictionary, making for easier creation
and use of wrappers (pseudo-Builders) that call other Builders.
+ - On Python 2.x, wrap lists of Nodes returned by Builders in a UserList
+ object that adds a method that makes str() object return a string
+ with all of the Nodes expanded to their path names. (Builders under
+ Python 1.5.2 still return lists to avoid TypeErrors when trying
+ to extend() list, so Python 1.5.2 doesn't get pretty-printing of Node
+ lists, but everything should still function.)
+
From Wayne Lee:
- Avoid "maximum recursion limit" errors when removing $(-$) pairs
from SCons.Debug import logInstanceCreation
from SCons.Errors import InternalError, UserError
import SCons.Executor
+import SCons.Node
import SCons.Node.FS
import SCons.Util
import SCons.Warnings
builder = ListBuilder(self, env, tlist)
_init_nodes(builder, env, overwarn.data, executor_kw, tlist, slist)
- return tlist
+ return SCons.Node.NodeList(tlist)
def __call__(self, env, target=None, source=None, chdir=_null, **kw):
# We now assume that target and source are lists or None.
import sys
import types
import unittest
+import UserList
import TestCmd
target_factory=MyNode,
source_factory=MyNode)
- n1 = MyNode("n1");
- n2 = MyNode("n2");
+ n1 = MyNode("n1")
+ n2 = MyNode("n2")
builder(env, target = n1, source = n2)
assert env_arg2nodes_called
assert n1.env == env, n1.env
assert n1.executor, "no executor found"
assert not hasattr(n2, 'env')
- target = builder(env, target = 'n3', source = 'n4')[0]
+ l = [1]
+ ul = UserList.UserList([2])
+ try:
+ l.extend(ul)
+ except TypeError:
+ def mystr(l):
+ return str(map(str, l))
+ else:
+ mystr = str
+
+ nnn1 = MyNode("nnn1")
+ nnn2 = MyNode("nnn2")
+ tlist = builder(env, target = [nnn1, nnn2], source = [])
+ s = mystr(tlist)
+ assert s == "['nnn1', 'nnn2']", s
+ l = map(str, tlist)
+ assert l == ['nnn1', 'nnn2'], l
+
+ tlist = builder(env, target = 'n3', source = 'n4')
+ s = mystr(tlist)
+ assert s == "['n3']", s
+ target = tlist[0]
+ l = map(str, tlist)
+ assert l == ['n3'], l
assert target.name == 'n3'
assert target.sources[0].name == 'n4'
- target = builder(env, target = 'n4 n5', source = ['n6 n7'])[0]
+ tlist = builder(env, target = 'n4 n5', source = ['n6 n7'])
+ s = mystr(tlist)
+ assert s == "['n4 n5']", s
+ l = map(str, tlist)
+ assert l == ['n4 n5'], l
+ target = tlist[0]
assert target.name == 'n4 n5'
assert target.sources[0].name == 'n6 n7'
- target = builder(env, target = ['n8 n9'], source = 'n10 n11')[0]
+ tlist = builder(env, target = ['n8 n9'], source = 'n10 n11')
+ s = mystr(tlist)
+ assert s == "['n8 n9']", s
+ l = map(str, tlist)
+ assert l == ['n8 n9'], l
+ target = tlist[0]
assert target.name == 'n8 n9'
assert target.sources[0].name == 'n10 n11'
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
import os
+import re
+import string
import sys
import types
import unittest
+import UserList
import SCons.Errors
import SCons.Node
n1.call_for_all_waiting_parents(func)
assert result == [n1, n2], result
+class NodeListTestCase(unittest.TestCase):
+ def test___str__(self):
+ """Test"""
+ n1 = MyNode("n1")
+ n2 = MyNode("n2")
+ n3 = MyNode("n3")
+ nl = SCons.Node.NodeList([n3, n2, n1])
+
+ l = [1]
+ ul = UserList.UserList([2])
+ try:
+ l.extend(ul)
+ except TypeError:
+ # An older version of Python (*cough* 1.5.2 *cough*)
+ # that doesn't allow UserList objects to extend lists.
+ pass
+ else:
+ s = str(nl)
+ assert s == "['n3', 'n2', 'n1']", s
+
+ r = repr(nl)
+ r = re.sub('at (0x)?[0-9a-z]+', 'at 0x', repr(nl))
+ l = string.join(["<__main__.MyNode instance at 0x>"]*3, ", ")
+ assert r == '[%s]' % l, r
+
if __name__ == "__main__":
- suite = unittest.makeSuite(NodeTestCase, 'test_')
+ suite = unittest.TestSuite()
+ tclasses = [ NodeTestCase,
+ NodeListTestCase ]
+ for tclass in tclasses:
+ names = unittest.getTestCaseNames(tclass, 'test_')
+ suite.addTests(map(tclass, names))
if not unittest.TextTestRunner().run(suite).wasSuccessful():
sys.exit(1)
import copy
import string
+import UserList
from SCons.Debug import logInstanceCreation
import SCons.SConsign
lines = ["%s:\n" % preamble] + lines
return string.join(lines, ' '*11)
+l = [1]
+ul = UserList.UserList([2])
+try:
+ l.extend(ul)
+except TypeError:
+ def NodeList(l):
+ return l
+else:
+ class NodeList(UserList.UserList):
+ def __str__(self):
+ return str(map(str, self.data))
+del l
+del ul
+
def get_children(node, parent): return node.children()
def ignore_cycle(node, stack): pass
def do_nothing(node, parent): pass