diff options
author | Dirk Baechle <dl9obn@darc.de> | 2015-12-14 21:44:58 (GMT) |
---|---|---|
committer | Dirk Baechle <dl9obn@darc.de> | 2015-12-14 21:44:58 (GMT) |
commit | 42ac4c63bd25680c49ff9a7fa6f1e1139d589ced (patch) | |
tree | 4f345454ffa8d1de1f9a235fe23cce4b644e315f /src | |
parent | e7de9d22c9503cf29e5d8b5e7813f060d59a00e5 (diff) | |
download | SCons-42ac4c63bd25680c49ff9a7fa6f1e1139d589ced.zip SCons-42ac4c63bd25680c49ff9a7fa6f1e1139d589ced.tar.gz SCons-42ac4c63bd25680c49ff9a7fa6f1e1139d589ced.tar.bz2 |
- fixed render_tree default argument for "visited" as well
- added tests for the new "visited" default arguments of the render_tree and print_tree methods
- added simple test for the new "None" default arguments in Variables constructor
Diffstat (limited to 'src')
-rw-r--r-- | src/CHANGES.txt | 9 | ||||
-rw-r--r-- | src/engine/SCons/Node/__init__.py | 2 | ||||
-rw-r--r-- | src/engine/SCons/Util.py | 6 | ||||
-rw-r--r-- | src/engine/SCons/UtilTests.py | 52 | ||||
-rw-r--r-- | src/engine/SCons/Variables/VariablesTests.py | 16 |
5 files changed, 75 insertions, 10 deletions
diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 9e9ec42..9e335f9 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -11,7 +11,14 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER SCons now respects scanner keys for implicit dependencies. - Resolved missing cross-language dependencies for SWIG bindings (fixes #2264). - + + From Dirk Baechle: + - Removed a lot of compatibility methods and workarounds + for Python versions < 2.7, in order to prepare the work + towards a combined 2.7/3.x version. (PR #284) + Also fixed the default arguments for the print_tree and + render_tree methods. (PR #284, too) + RELEASE 2.4.1 - Mon, 07 Nov 2015 10:37:21 -0700 diff --git a/src/engine/SCons/Node/__init__.py b/src/engine/SCons/Node/__init__.py index 40ee8f0..86a5c1d 100644 --- a/src/engine/SCons/Node/__init__.py +++ b/src/engine/SCons/Node/__init__.py @@ -577,7 +577,7 @@ class Node(object): self.always_build = None self.includes = None self.attributes = self.Attrs() # Generic place to stick information about the Node. - self.side_effect = 0 # true if this node is a side effect + self.side_effect = 0 # true iff this node is a side effect self.side_effects = [] # the side effects of building this target self.linked = 0 # is this node linked to the variant directory? self.changed_since_last_build = 0 diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py index a834726..cd23e6e 100644 --- a/src/engine/SCons/Util.py +++ b/src/engine/SCons/Util.py @@ -167,7 +167,7 @@ class DisplayEngine(object): def set_mode(self, mode): self.print_it = mode -def render_tree(root, child_func, prune=0, margin=[0], visited={}): +def render_tree(root, child_func, prune=0, margin=[0], visited=None): """ Render a tree of nodes into an ASCII tree view. root - the root node of the tree @@ -181,6 +181,10 @@ def render_tree(root, child_func, prune=0, margin=[0], visited={}): rname = str(root) + # Initialize 'visited' dict, if required + if visited is None: + visited = {} + children = child_func(root) retval = "" for pipe in margin[:-1]: diff --git a/src/engine/SCons/UtilTests.py b/src/engine/SCons/UtilTests.py index d59d40c..9f80e86 100644 --- a/src/engine/SCons/UtilTests.py +++ b/src/engine/SCons/UtilTests.py @@ -124,7 +124,9 @@ class UtilTestCase(unittest.TestCase): def tree_case_2(self, prune=1): """Fixture for the render_tree() and print_tree() tests.""" - stdlib_h = self.Node("stdlib.h") + types_h = self.Node('types.h') + malloc_h = self.Node('malloc.h') + stdlib_h = self.Node('stdlib.h', [types_h, malloc_h]) bar_h = self.Node('bar.h', [stdlib_h]) blat_h = self.Node('blat.h', [stdlib_h]) blat_c = self.Node('blat.c', [blat_h, bar_h]) @@ -135,13 +137,18 @@ class UtilTestCase(unittest.TestCase): +-blat.c +-blat.h | +-stdlib.h + | +-types.h + | +-malloc.h +-bar.h - +-[stdlib.h] """ - - if not prune: - expect = expect.replace('[', '') - expect = expect.replace(']', '') + if prune: + expect += """ +-[stdlib.h] +""" + else: + expect += """ +-stdlib.h + +-types.h + +-malloc.h +""" lines = expect.split('\n')[:-1] lines = ['[E BSPACN ]'+l for l in lines] @@ -162,6 +169,13 @@ class UtilTestCase(unittest.TestCase): actual = render_tree(node, get_children, 1) assert expect == actual, (expect, actual) + # Ensure that we can call render_tree on the same Node + # again. This wasn't possible in version 2.4.1 and earlier + # due to a bug in render_tree (visited was set to {} as default + # parameter) + actual = render_tree(node, get_children, 1) + assert expect == actual, (expect, actual) + def test_print_tree(self): """Test the print_tree() function""" def get_children(node): @@ -181,9 +195,33 @@ class UtilTestCase(unittest.TestCase): print_tree(node, get_children, showtags=1) actual = sys.stdout.getvalue() assert withtags == actual, (withtags, actual) - + + # Test that explicitly setting prune to zero works + # the same as the default (see above) node, expect, withtags = self.tree_case_2(prune=0) + + sys.stdout = io.StringIO() + print_tree(node, get_children, 0) + actual = sys.stdout.getvalue() + assert expect == actual, (expect, actual) + + sys.stdout = io.StringIO() + print_tree(node, get_children, 0, showtags=1) + actual = sys.stdout.getvalue() + assert withtags == actual, (withtags, actual) + + # Test output with prune=1 + node, expect, withtags = self.tree_case_2(prune=1) + + sys.stdout = io.StringIO() + print_tree(node, get_children, 1) + actual = sys.stdout.getvalue() + assert expect == actual, (expect, actual) + # Ensure that we can call print_tree on the same Node + # again. This wasn't possible in version 2.4.1 and earlier + # due to a bug in print_tree (visited was set to {} as default + # parameter) sys.stdout = io.StringIO() print_tree(node, get_children, 1) actual = sys.stdout.getvalue() diff --git a/src/engine/SCons/Variables/VariablesTests.py b/src/engine/SCons/Variables/VariablesTests.py index d2110c1..50f7d13 100644 --- a/src/engine/SCons/Variables/VariablesTests.py +++ b/src/engine/SCons/Variables/VariablesTests.py @@ -273,6 +273,22 @@ class VariablesTestCase(unittest.TestCase): opts.Update(env, {}) assert 'ANSWER' not in env + def test_noaggregation(self): + """Test that the 'files' and 'args' attributes of the Variables class + don't aggregate entries from one instance to another. + This used to be a bug in SCons version 2.4.1 and earlier. + """ + + opts = SCons.Variables.Variables() + opts.files.append('custom.py') + opts.args['ANSWER'] = 54 + nopts = SCons.Variables.Variables() + + # Ensure that both attributes are initialized to + # an empty list and dict, respectively. + assert len(nopts.files) == 0 + assert len(nopts.args) == 0 + def test_args(self): """Test updating an Environment with arguments overridden""" |