From 47c0cc5e016e63f7fc925091229bae111a7ffb6c Mon Sep 17 00:00:00 2001 From: stevenknight Date: Sat, 29 Dec 2001 08:43:48 +0000 Subject: [PATCH] Add --debug=tree (print depenency tree) support git-svn-id: http://scons.tigris.org/svn/scons/trunk@179 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- doc/man/scons.1 | 20 ++++--- src/CHANGES.txt | 2 + src/engine/SCons/Script/__init__.py | 23 +++++++- src/engine/SCons/Util.py | 32 ++++++++++ src/engine/SCons/UtilTests.py | 36 ++++++++++- test/option--debug.py | 92 +++++++++++++++++++++++++++++ 6 files changed, 194 insertions(+), 11 deletions(-) create mode 100644 test/option--debug.py diff --git a/doc/man/scons.1 b/doc/man/scons.1 index 38b196d0..ad8a8349 100644 --- a/doc/man/scons.1 +++ b/doc/man/scons.1 @@ -264,14 +264,20 @@ or .I sconstruct in the specified directory.) -.IP -d -Display dependencies while building target files. Useful for -figuring out why a specific file is being rebuilt, as well as -general debugging of the build process. +.\" .IP -d +.\" Display dependencies while building target files. Useful for +.\" figuring out why a specific file is being rebuilt, as well as +.\" general debugging of the build process. -.\" .TP -.\" .RI --debug= flags -.\"Print debugging information. ??? +.TP +.RI --debug= type +Print debugging information durring the build process. +.I type +specifies what type of of debugging information to print. Currently the +only supported type is +.I tree +which causes the dependency tree to be printed after each top-level +target is built. .IP "-e, --environment-overrides" Variables from the execution environment override construction diff --git a/src/CHANGES.txt b/src/CHANGES.txt index c84d0cb4..54dc2ad8 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -20,6 +20,8 @@ RELEASE 0.03 - - Add a "duplicate" keyword argument to BuildDir() that can be set to prevent linking/copying source files into build directories. + - Add a "--debug=tree" option to print an ASCII dependency tree. + RELEASE 0.02 - Sun, 23 Dec 2001 19:05:09 -0600 diff --git a/src/engine/SCons/Script/__init__.py b/src/engine/SCons/Script/__init__.py index bb679918..3b5a79d1 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 262762e2..76872502 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