diff options
author | Iosif Daniel Kurazs <iosif.kurazs@intel.com> | 2020-02-18 13:17:33 (GMT) |
---|---|---|
committer | Mats Wichmann <mats@linux.com> | 2020-03-24 16:07:12 (GMT) |
commit | 86b44676da95a1291cfb16144378ec59687c55e5 (patch) | |
tree | 883323a03d328e03fe22d328003c5a362ee88901 | |
parent | e27bfff2a44ad006c2f9d895fc4ca96b9201daf1 (diff) | |
download | SCons-86b44676da95a1291cfb16144378ec59687c55e5.zip SCons-86b44676da95a1291cfb16144378ec59687c55e5.tar.gz SCons-86b44676da95a1291cfb16144378ec59687c55e5.tar.bz2 |
Adding posibility to use single line drawing when displaying the dependency tree
-rw-r--r-- | src/engine/SCons/Script/Main.py | 5 | ||||
-rw-r--r-- | src/engine/SCons/Script/SConsOptions.py | 4 | ||||
-rw-r--r-- | src/engine/SCons/Util.py | 44 |
3 files changed, 40 insertions, 13 deletions
diff --git a/src/engine/SCons/Script/Main.py b/src/engine/SCons/Script/Main.py index ce948a0..62cd908 100644 --- a/src/engine/SCons/Script/Main.py +++ b/src/engine/SCons/Script/Main.py @@ -430,10 +430,11 @@ class QuestionTask(SCons.Taskmaster.AlwaysTask): class TreePrinter(object): - def __init__(self, derived=False, prune=False, status=False): + def __init__(self, derived=False, prune=False, status=False, sLineDraw=False): self.derived = derived self.prune = prune self.status = status + self.sLineDraw = sLineDraw def get_all_children(self, node): return node.all_children() def get_derived_children(self, node): @@ -445,7 +446,7 @@ class TreePrinter(object): else: func = self.get_all_children s = self.status and 2 or 0 - SCons.Util.print_tree(t, func, prune=self.prune, showtags=s) + SCons.Util.print_tree(t, func, prune=self.prune, showtags=s, lastChild=True, singleLineDraw=self.sLineDraw) def python_version_string(): diff --git a/src/engine/SCons/Script/SConsOptions.py b/src/engine/SCons/Script/SConsOptions.py index 8ec8ccf..0c82faf 100644 --- a/src/engine/SCons/Script/SConsOptions.py +++ b/src/engine/SCons/Script/SConsOptions.py @@ -834,7 +834,7 @@ def Parser(version): help="Trace Node evaluation to FILE.", metavar="FILE") - tree_options = ["all", "derived", "prune", "status"] + tree_options = ["all", "derived", "prune", "status", "linedraw"] def opt_tree(option, opt, value, parser, tree_options=tree_options): from . import Main @@ -848,6 +848,8 @@ def Parser(version): tp.prune = True elif o == 'status': tp.status = True + elif o == 'linedraw': + tp.sLineDraw = True else: raise OptionValueError(opt_invalid('--tree', o, tree_options)) parser.values.tree_printers.append(tp) diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py index 22df6fa..e55ccb4 100644 --- a/src/engine/SCons/Util.py +++ b/src/engine/SCons/Util.py @@ -254,7 +254,7 @@ def render_tree(root, child_func, prune=0, margin=[0], visited=None): IDX = lambda N: N and 1 or 0 -def print_tree(root, child_func, prune=0, showtags=0, margin=[0], visited=None): +def print_tree(root, child_func, prune=0, showtags=0, margin=[0], visited=None, lastChild=False, singleLineDraw=False): """ Print a tree of nodes. This is like render_tree, except it prints lines directly instead of creating a string representation in memory, @@ -300,7 +300,8 @@ def print_tree(root, child_func, prune=0, showtags=0, margin=[0], visited=None): [0, 1][IDX(root.has_explicit_builder())] + [0, 2][IDX(root.has_builder())] ], - ' S'[IDX(root.side_effect)], ' P'[IDX(root.precious)], + ' S'[IDX(root.side_effect)], + ' P'[IDX(root.precious)], ' A'[IDX(root.always_build)], ' C'[IDX(root.is_up_to_date())], ' N'[IDX(root.noclean)], @@ -312,27 +313,50 @@ def print_tree(root, child_func, prune=0, showtags=0, margin=[0], visited=None): tags = [] def MMM(m): - return [" ","| "][m] + if singleLineDraw: + return [" ","│ "][m] + else: + return [" ","| "][m] + margins = list(map(MMM, margin[:-1])) children = child_func(root) + cross = "+-" + if singleLineDraw: + cross = "├─" # sign used to point to the leaf. + # check if this is the last leaf of the branch + if lastChild: + #if this if the last leaf, then terminate: + cross = "└─" # sign for the last leaf + + # if this branch has children then split it + if len(children)>0: + # if it's a leaf: + if prune and rname in visited and children: + cross += "─" + else: + cross += "┬" + if prune and rname in visited and children: - sys.stdout.write(''.join(tags + margins + ['+-[', rname, ']']) + '\n') + sys.stdout.write(''.join(tags + margins + [cross,'[', rname, ']']) + '\n') return - sys.stdout.write(''.join(tags + margins + ['+-', rname]) + '\n') + sys.stdout.write(''.join(tags + margins + [cross, rname]) + '\n') visited[rname] = 1 + # if this item has children: if children: - margin.append(1) + margin.append(1) # Initialize margin with 1 for vertical bar. idx = IDX(showtags) + _child = 0 # Initialize this for the first child. for C in children[:-1]: - print_tree(C, child_func, prune, idx, margin, visited) - margin[-1] = 0 - print_tree(children[-1], child_func, prune, idx, margin, visited) - margin.pop() + _child = _child + 1 # number the children + print_tree(C, child_func, prune, idx, margin, visited, (len(children) - _child) <= 0 ,singleLineDraw) + margin[-1] = 0 # margins are with space (index 0) because we arrived to the last child. + print_tree(children[-1], child_func, prune, idx, margin, visited, True ,singleLineDraw) # for this call child and nr of children needs to be set 0, to signal the second phase. + margin.pop() # destroy the last margin added # Functions for deciding if things are like various types, mainly to |