diff options
author | Mats Wichmann <mats@linux.com> | 2020-03-24 19:07:46 (GMT) |
---|---|---|
committer | Mats Wichmann <mats@linux.com> | 2020-03-24 19:07:46 (GMT) |
commit | 7143fba43006c5dbccb4d1d9f43aa8fa0c05c271 (patch) | |
tree | 28fdb87a515eaec8755b1ed36185ade958f20a8d | |
parent | 89d03e37128aa839ed72ec72739b2ed431b7f4da (diff) | |
download | SCons-7143fba43006c5dbccb4d1d9f43aa8fa0c05c271.zip SCons-7143fba43006c5dbccb4d1d9f43aa8fa0c05c271.tar.gz SCons-7143fba43006c5dbccb4d1d9f43aa8fa0c05c271.tar.bz2 |
Add option to use box-draw chars with --tree
This picks up and hopefully completes PR #3560.
Add documentation for new --tree "linedraw" option.
There is a new example output in userguide, which renumbers
several of the existing troubleshoot_tree example outputs.
Test is cleaned up a bit (not just the added part).
The actual function in Util is made a little more genral -
it uses unicode chr() values instead of literally pasting
in the line drawing characters.
Signed-off-by: Mats Wichmann <mats@linux.com>
-rw-r--r-- | doc/generated/examples/troubleshoot_tree1_2.xml | 34 | ||||
-rw-r--r-- | doc/generated/examples/troubleshoot_tree1_3.xml | 13 | ||||
-rw-r--r-- | doc/generated/examples/troubleshoot_tree1_4.xml | 47 | ||||
-rw-r--r-- | doc/generated/examples/troubleshoot_tree1_5.xml | 47 | ||||
-rw-r--r-- | doc/generated/examples/troubleshoot_tree1_6.xml | 30 | ||||
-rw-r--r-- | doc/man/scons.xml | 15 | ||||
-rw-r--r-- | doc/user/troubleshoot.xml | 23 | ||||
-rw-r--r-- | src/engine/SCons/Util.py | 24 | ||||
-rw-r--r-- | test/option--tree.py | 48 |
9 files changed, 151 insertions, 130 deletions
diff --git a/doc/generated/examples/troubleshoot_tree1_2.xml b/doc/generated/examples/troubleshoot_tree1_2.xml index 0bd4874..d99435d 100644 --- a/doc/generated/examples/troubleshoot_tree1_2.xml +++ b/doc/generated/examples/troubleshoot_tree1_2.xml @@ -1,7 +1,31 @@ -<?xml version="1.0" encoding="UTF-8"?> -<screen xmlns="http://www.scons.org/dbxsd/v1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.scons.org/dbxsd/v1.0 http://www.scons.org/dbxsd/v1.0/scons.xsd">% <userinput>scons -Q --tree=all f2.o</userinput> +<screen xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.scons.org/dbxsd/v1.0" xsi:schemaLocation="http://www.scons.org/dbxsd/v1.0 http://www.scons.org/dbxsd/v1.0/scons.xsd">% <userinput>scons -Q --tree=all,linedraw</userinput> +cc -o f1.o -c -I. f1.c cc -o f2.o -c -I. f2.c -+-f2.o - +-f2.c - +-inc.h +cc -o f3.o -c -I. f3.c +cc -o prog f1.o f2.o f3.o +└─┬. + ├─SConstruct + ├─f1.c + ├─┬f1.o + │ ├─f1.c + │ └─inc.h + ├─f2.c + ├─┬f2.o + │ ├─f2.c + │ └─inc.h + ├─f3.c + ├─┬f3.o + │ ├─f3.c + │ └─inc.h + ├─inc.h + └─┬prog + ├─┬f1.o + │ ├─f1.c + │ └─inc.h + ├─┬f2.o + │ ├─f2.c + │ └─inc.h + └─┬f3.o + ├─f3.c + └─inc.h </screen> diff --git a/doc/generated/examples/troubleshoot_tree1_3.xml b/doc/generated/examples/troubleshoot_tree1_3.xml index 75fa841..7f3789f 100644 --- a/doc/generated/examples/troubleshoot_tree1_3.xml +++ b/doc/generated/examples/troubleshoot_tree1_3.xml @@ -1,11 +1,6 @@ -<?xml version="1.0" encoding="UTF-8"?> -<screen xmlns="http://www.scons.org/dbxsd/v1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.scons.org/dbxsd/v1.0 http://www.scons.org/dbxsd/v1.0/scons.xsd">% <userinput>scons -Q --tree=all f1.o f3.o</userinput> -cc -o f1.o -c -I. f1.c -+-f1.o - +-f1.c - +-inc.h -cc -o f3.o -c -I. f3.c -+-f3.o - +-f3.c +<screen xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.scons.org/dbxsd/v1.0" xsi:schemaLocation="http://www.scons.org/dbxsd/v1.0 http://www.scons.org/dbxsd/v1.0/scons.xsd">% <userinput>scons -Q --tree=all f2.o</userinput> +cc -o f2.o -c -I. f2.c ++-f2.o + +-f2.c +-inc.h </screen> diff --git a/doc/generated/examples/troubleshoot_tree1_4.xml b/doc/generated/examples/troubleshoot_tree1_4.xml index 409bce9..bc0dbac 100644 --- a/doc/generated/examples/troubleshoot_tree1_4.xml +++ b/doc/generated/examples/troubleshoot_tree1_4.xml @@ -1,43 +1,10 @@ -<?xml version="1.0" encoding="UTF-8"?> -<screen xmlns="http://www.scons.org/dbxsd/v1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.scons.org/dbxsd/v1.0 http://www.scons.org/dbxsd/v1.0/scons.xsd">% <userinput>scons -Q --tree=status</userinput> +<screen xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.scons.org/dbxsd/v1.0" xsi:schemaLocation="http://www.scons.org/dbxsd/v1.0 http://www.scons.org/dbxsd/v1.0/scons.xsd">% <userinput>scons -Q --tree=all f1.o f3.o</userinput> cc -o f1.o -c -I. f1.c -cc -o f2.o -c -I. f2.c ++-f1.o + +-f1.c + +-inc.h cc -o f3.o -c -I. f3.c -cc -o prog f1.o f2.o f3.o - E = exists - R = exists in repository only - b = implicit builder - B = explicit builder - S = side effect - P = precious - A = always build - C = current - N = no clean - H = no cache - -[E b ]+-. -[E C ] +-SConstruct -[E C ] +-f1.c -[E B C ] +-f1.o -[E C ] | +-f1.c -[E C ] | +-inc.h -[E C ] +-f2.c -[E B C ] +-f2.o -[E C ] | +-f2.c -[E C ] | +-inc.h -[E C ] +-f3.c -[E B C ] +-f3.o -[E C ] | +-f3.c -[E C ] | +-inc.h -[E C ] +-inc.h -[E B C ] +-prog -[E B C ] +-f1.o -[E C ] | +-f1.c -[E C ] | +-inc.h -[E B C ] +-f2.o -[E C ] | +-f2.c -[E C ] | +-inc.h -[E B C ] +-f3.o -[E C ] +-f3.c -[E C ] +-inc.h ++-f3.o + +-f3.c + +-inc.h </screen> diff --git a/doc/generated/examples/troubleshoot_tree1_5.xml b/doc/generated/examples/troubleshoot_tree1_5.xml index b852ab0..687b1ba 100644 --- a/doc/generated/examples/troubleshoot_tree1_5.xml +++ b/doc/generated/examples/troubleshoot_tree1_5.xml @@ -1,15 +1,42 @@ -<?xml version="1.0" encoding="UTF-8"?> -<screen xmlns="http://www.scons.org/dbxsd/v1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.scons.org/dbxsd/v1.0 http://www.scons.org/dbxsd/v1.0/scons.xsd">% <userinput>scons -Q --tree=derived</userinput> +<screen xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.scons.org/dbxsd/v1.0" xsi:schemaLocation="http://www.scons.org/dbxsd/v1.0 http://www.scons.org/dbxsd/v1.0/scons.xsd">% <userinput>scons -Q --tree=status</userinput> cc -o f1.o -c -I. f1.c cc -o f2.o -c -I. f2.c cc -o f3.o -c -I. f3.c cc -o prog f1.o f2.o f3.o -+-. - +-f1.o - +-f2.o - +-f3.o - +-prog - +-f1.o - +-f2.o - +-f3.o + E = exists + R = exists in repository only + b = implicit builder + B = explicit builder + S = side effect + P = precious + A = always build + C = current + N = no clean + H = no cache + +[E b ]+-. +[E C ] +-SConstruct +[E C ] +-f1.c +[E B C ] +-f1.o +[E C ] | +-f1.c +[E C ] | +-inc.h +[E C ] +-f2.c +[E B C ] +-f2.o +[E C ] | +-f2.c +[E C ] | +-inc.h +[E C ] +-f3.c +[E B C ] +-f3.o +[E C ] | +-f3.c +[E C ] | +-inc.h +[E C ] +-inc.h +[E B C ] +-prog +[E B C ] +-f1.o +[E C ] | +-f1.c +[E C ] | +-inc.h +[E B C ] +-f2.o +[E C ] | +-f2.c +[E C ] | +-inc.h +[E B C ] +-f3.o +[E C ] +-f3.c +[E C ] +-inc.h </screen> diff --git a/doc/generated/examples/troubleshoot_tree1_6.xml b/doc/generated/examples/troubleshoot_tree1_6.xml index a0d42d7..00b05ac 100644 --- a/doc/generated/examples/troubleshoot_tree1_6.xml +++ b/doc/generated/examples/troubleshoot_tree1_6.xml @@ -1,26 +1,14 @@ -<?xml version="1.0" encoding="UTF-8"?> -<screen xmlns="http://www.scons.org/dbxsd/v1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.scons.org/dbxsd/v1.0 http://www.scons.org/dbxsd/v1.0/scons.xsd">% <userinput>scons -Q --tree=derived,status</userinput> +<screen xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.scons.org/dbxsd/v1.0" xsi:schemaLocation="http://www.scons.org/dbxsd/v1.0 http://www.scons.org/dbxsd/v1.0/scons.xsd">% <userinput>scons -Q --tree=derived</userinput> cc -o f1.o -c -I. f1.c cc -o f2.o -c -I. f2.c cc -o f3.o -c -I. f3.c cc -o prog f1.o f2.o f3.o - E = exists - R = exists in repository only - b = implicit builder - B = explicit builder - S = side effect - P = precious - A = always build - C = current - N = no clean - H = no cache - -[E b ]+-. -[E B C ] +-f1.o -[E B C ] +-f2.o -[E B C ] +-f3.o -[E B C ] +-prog -[E B C ] +-f1.o -[E B C ] +-f2.o -[E B C ] +-f3.o ++-. + +-f1.o + +-f2.o + +-f3.o + +-prog + +-f1.o + +-f2.o + +-f3.o </screen> diff --git a/doc/man/scons.xml b/doc/man/scons.xml index bfc4fd7..3d2abdf 100644 --- a/doc/man/scons.xml +++ b/doc/man/scons.xml @@ -1709,6 +1709,19 @@ not source files.</para> </varlistentry> <varlistentry> + <term><emphasis role="bold">linedraw</emphasis></term> + <listitem> +<para>Draw the tree output using Unicode line-drawing characters +instead of plain ASCII text. This option acts as a modifier +to the selected <replaceable>type</replaceable>(s). If +specified alone, without any <replaceable>type</replaceable>, +it behaves as if <emphasis role="bold">all</emphasis> +had been specified. +</para> + </listitem> + </varlistentry> + + <varlistentry> <term><emphasis role="bold">status</emphasis></term> <listitem> <para>Prints status information for each displayed node.</para> @@ -6844,7 +6857,7 @@ env.PDFBuilder(target = 'bar', source = 'bar') <para>Note also that the above initialization overwrites the default Builder objects, so the Environment created above -can not be used call Builders like +can not be used call Builders like <methodname>env.Program</methodname>, <methodname>env.Object</methodname>, <methodname>env.StaticLibrary</methodname> etc.</para> diff --git a/doc/user/troubleshoot.xml b/doc/user/troubleshoot.xml index beea8c9..7049deb 100644 --- a/doc/user/troubleshoot.xml +++ b/doc/user/troubleshoot.xml @@ -442,6 +442,19 @@ inc.h <para> + By default &SCons; uses "ASCII art" to draw the tree. It is + possible to use line-drawing characters (Unicode calls these + Box Drawing) to make a nicer display. To do this, add the + <option>linedraw</option> qualifier: + + </para> + + <scons_output example="troubleshoot_tree1" suffix="2"> + <scons_output_command>scons -Q --tree=all,linedraw</scons_output_command> + </scons_output> + + <para> + The <option>--tree</option> option only prints the dependency graph for the specified targets (or the default target(s) if none are specified on the command line). @@ -452,7 +465,7 @@ inc.h </para> - <scons_output example="troubleshoot_tree1" suffix="2"> + <scons_output example="troubleshoot_tree1" suffix="3"> <scons_output_command>scons -Q --tree=all f2.o</scons_output_command> </scons_output> @@ -468,7 +481,7 @@ inc.h </para> - <scons_output example="troubleshoot_tree1" suffix="3"> + <scons_output example="troubleshoot_tree1" suffix="4"> <scons_output_command>scons -Q --tree=all f1.o f3.o</scons_output_command> </scons_output> @@ -480,7 +493,7 @@ inc.h </para> - <scons_output example="troubleshoot_tree1" suffix="4"> + <scons_output example="troubleshoot_tree1" suffix="5"> <scons_output_command>scons -Q --tree=status</scons_output_command> </scons_output> @@ -498,7 +511,7 @@ inc.h </para> - <scons_output example="troubleshoot_tree1" suffix="5"> + <scons_output example="troubleshoot_tree1" suffix="6"> <scons_output_command>scons -Q --tree=derived</scons_output_command> </scons_output> @@ -509,7 +522,7 @@ inc.h </para> - <scons_output example="troubleshoot_tree1" suffix="6"> + <scons_output example="troubleshoot_tree1" suffix="7"> <scons_output_command>scons -Q --tree=derived,status</scons_output_command> </scons_output> diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py index e55ccb4..767b3f9 100644 --- a/src/engine/SCons/Util.py +++ b/src/engine/SCons/Util.py @@ -267,6 +267,7 @@ def print_tree(root, child_func, prune=0, showtags=0, margin=[0], visited=None, - `showtags` - print status information to the left of each node line - `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 dictionary of visited nodes in the current branch if not prune, or in the whole tree if prune. + - `singleLineDraw` - use line-drawing characters rather than ASCII. """ rname = str(root) @@ -301,7 +302,7 @@ def print_tree(root, child_func, prune=0, showtags=0, margin=[0], visited=None, [0, 2][IDX(root.has_builder())] ], ' S'[IDX(root.side_effect)], - ' P'[IDX(root.precious)], + ' P'[IDX(root.precious)], ' A'[IDX(root.always_build)], ' C'[IDX(root.is_up_to_date())], ' N'[IDX(root.noclean)], @@ -322,21 +323,32 @@ def print_tree(root, child_func, prune=0, showtags=0, margin=[0], visited=None, children = child_func(root) + cross = "+-" if singleLineDraw: - cross = "├─" # sign used to point to the leaf. + # unicode line drawing chars: + box_horiz = chr(0x2500) # '─' + box_vert = chr(0x2510) # '│' + box_up_right = chr(0x2514) # '└' + box_down_right = chr(0x250c) # '┌' + box_down_left = chr(0x2510) # '┐' + box_up_left = chr(0x2518) # '┘' + box_vert_right = chr(0x251c) # '├' + box_horiz_down = chr(0x252c) # '┬' + + cross = box_vert_right + box_horiz # 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 + cross = box_up_right + box_horiz # sign for the last leaf # if this branch has children then split it - if len(children)>0: + if children: # if it's a leaf: if prune and rname in visited and children: - cross += "─" + cross += box_horiz else: - cross += "┬" + cross += box_horiz_down if prune and rname in visited and children: sys.stdout.write(''.join(tags + margins + [cross,'[', rname, ']']) + '\n') diff --git a/test/option--tree.py b/test/option--tree.py index 0beec7f..290f1d4 100644 --- a/test/option--tree.py +++ b/test/option--tree.py @@ -47,60 +47,42 @@ SCons Error: `foofoo' is not a valid --tree option type, try: # Test that unicode characters can be printed (escaped) with the --tree option -test.write('SConstruct', - """ +test.write('SConstruct', """\ env = Environment() env.Tool("textfile") -try: - # Python 2 - write = unichr(0xe7).encode('utf-8') -except NameError: - # Python 3 - # str is utf-8 by default - write = chr(0xe7) -env.Textfile("Foo", write) +name = "français" +env.Textfile("Foo", name) """) -if sys.version_info.major < 3: - py23_char = unichr(0xe7).encode('utf-8') -else: - py23_char = chr(0xe7) +uchar = chr(0xe7) expected = """Creating 'Foo.txt' +-. +-Foo.txt - | +-""" + py23_char + """ + | +-fran%sais +-SConstruct -""" +""" % uchar -test.run(arguments='-Q --tree=all', - stdout=expected, - status=0) +test.run(arguments='-Q --tree=all', stdout=expected, status=0) -#Tests the new command line option "linedraw" -test.write('SConstruct', - """ +# Test the "linedraw" option: same basic test as previous. +# With "--tree=linedraw" must default to "all", and use line-drawing chars. +test.write('SConstruct', """\ env = Environment() env.Tool("textfile") -# Python 3 -# str is utf-8 by default -write = chr(0xe7) -env.Textfile("LineDraw", write) +name = "français" +env.Textfile("LineDraw", name) """) -py23_char = chr(0xe7) - expected = """Creating 'LineDraw.txt' └─┬. ├─┬LineDraw.txt - │ └─""" + py23_char + """ + │ └─fran%sais └─SConstruct -""" +""" % uchar -test.run(arguments='-Q --tree=linedraw', - stdout=expected, - status=0) +test.run(arguments='-Q --tree=linedraw', stdout=expected, status=0) test.pass_test() |