diff options
author | Steven Knight <knight@baldmt.com> | 2001-12-29 08:43:48 (GMT) |
---|---|---|
committer | Steven Knight <knight@baldmt.com> | 2001-12-29 08:43:48 (GMT) |
commit | 19318e0471d8ae3f223b867010a437986382f4d2 (patch) | |
tree | b5227be8cda1b4f8cf58a316ca442b191cbfd2bd /src/engine | |
parent | 9198503d21ac99352629e8d8dfb7c14b11f34401 (diff) | |
download | SCons-19318e0471d8ae3f223b867010a437986382f4d2.zip SCons-19318e0471d8ae3f223b867010a437986382f4d2.tar.gz SCons-19318e0471d8ae3f223b867010a437986382f4d2.tar.bz2 |
Add --debug=tree (print depenency tree) support
Diffstat (limited to 'src/engine')
-rw-r--r-- | src/engine/SCons/Script/__init__.py | 23 | ||||
-rw-r--r-- | src/engine/SCons/Util.py | 32 | ||||
-rw-r--r-- | src/engine/SCons/UtilTests.py | 36 |
3 files changed, 87 insertions, 4 deletions
diff --git a/src/engine/SCons/Script/__init__.py b/src/engine/SCons/Script/__init__.py index bb67991..3b5a79d 100644 --- a/src/engine/SCons/Script/__init__.py +++ b/src/engine/SCons/Script/__init__.py @@ -71,9 +71,15 @@ class BuildTask(SCons.Taskmaster.Task): if self.target.get_state() == SCons.Node.up_to_date: if self.top: print 'scons: "%s" is up to date.' % str(self.target) + if print_tree: + print + print SCons.Util.render_tree(self.target, get_children) else: try: self.target.build() + if self.top and print_tree: + print + print SCons.Util.render_tree(self.target, get_children) except BuildError, e: sys.stderr.write("scons: *** [%s] Error %s\n" % (e.node, str(e.stat))) raise @@ -106,9 +112,12 @@ calc = None ignore_errors = 0 keep_going_on_error = 0 help_option = None +print_tree = 0 # utility functions +def get_children(node): return node.children() + def _scons_syntax_error(e): """Handle syntax errors. Print out a message and show where the error occurred. @@ -340,9 +349,17 @@ def options_init(): short = 'd', help = "Print file dependency information.") - Option(func = opt_not_yet, future = 1, - long = ['debug'], arg = 'FLAGS', - help = "Print various types of debugging information.") + def opt_debug(opt, arg): + global print_tree + if arg == "tree": + print_tree = 1 + else: + sys.stderr.write("Warning: %s is not a valid debug type\n" + % arg) + + Option(func = opt_debug, + long = ['debug'], arg='TYPE', + help = "Print various types of debugging information.") Option(func = opt_not_yet, future = 1, short = 'e', long = ['environment-overrides'], diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py index 262762e..7687250 100644 --- a/src/engine/SCons/Util.py +++ b/src/engine/SCons/Util.py @@ -360,3 +360,35 @@ def autogenerate(dict, fs = SCons.Node.FS.default_fs, dir = None): for interp in AUTO_GEN_VARS: interp.instance(dir, fs).generate(dict) +def render_tree(root, child_func, margin=[0], visited={}): + """ + Render a tree of nodes into an ASCII tree view. + root - the root node of the tree + child_func - the function called to get the children of a node + margin - the format of the left margin to use for children of root. + 1 results in a pipe, and 0 results in no pipe. + visited - a dictionart of visited nodes in the current branch + """ + + if visited.has_key(root): + return "" + + children = child_func(root) + retval = "" + for pipe in margin[:-1]: + if pipe: + retval = retval + "| " + else: + retval = retval + " " + + retval = retval + "+-" + str(root) + "\n" + visited = copy.copy(visited) + visited[root] = 1 + + for i in range(len(children)): + margin.append(i<len(children)-1) + retval = retval + render_tree(children[i], child_func, margin, visited +) + margin.pop() + + return retval diff --git a/src/engine/SCons/UtilTests.py b/src/engine/SCons/UtilTests.py index a7c9e70..168896f 100644 --- a/src/engine/SCons/UtilTests.py +++ b/src/engine/SCons/UtilTests.py @@ -207,7 +207,41 @@ class UtilTestCase(unittest.TestCase): assert dict['_INCFLAGS'][4] == os.path.normpath('fooblatbar'), \ dict['_INCFLAGS'][4] - + + def test_render_tree(self): + class Node: + def __init__(self, name, children=[]): + self.children = children + self.name = name + def __str__(self): + return self.name + + def get_children(node): + return node.children + + windows_h = Node("windows.h") + stdlib_h = Node("stdlib.h") + stdio_h = Node("stdio.h") + bar_c = Node("bar.c", [stdlib_h, windows_h]) + bar_o = Node("bar.o", [bar_c]) + foo_c = Node("foo.c", [stdio_h]) + foo_o = Node("foo.o", [foo_c]) + foo = Node("foo", [foo_o, bar_o]) + + expect = """\ ++-foo + +-foo.o + | +-foo.c + | +-stdio.h + +-bar.o + +-bar.c + +-stdlib.h + +-windows.h +""" + + actual = render_tree(foo, get_children) + assert expect == actual, (expect, actual) + if __name__ == "__main__": suite = unittest.makeSuite(UtilTestCase, 'test_') if not unittest.TextTestRunner().run(suite).wasSuccessful(): |