diff --git a/playground/descriptions/wscript b/playground/descriptions/wscript new file mode 100644 index 00000000..9e0b80dc --- /dev/null +++ b/playground/descriptions/wscript @@ -0,0 +1,34 @@ +#! /usr/bin/env python +# encoding: utf-8 +# Justin Israel, 2017 + +""" +Allow the "waf list" command to display descriptions for each target +""" + +top = '.' +out = 'build' + +def configure(ctx): + pass + +def build(bld): + bld( + rule="touch ${TGT}", + target='file.in', + description='Create the input file', + ) + + bld( + rule='cp ${SRC} ${TGT}', + source='file.in', + target='file.out', + description='Generate output file', + ) + + bld.install_files( + 'dist', + ['file.out'], + name='install', + description='Deploy files', + ) diff --git a/waflib/Build.py b/waflib/Build.py index 62554f92..19d9d6f8 100644 --- a/waflib/Build.py +++ b/waflib/Build.py @@ -1295,6 +1295,10 @@ class ListContext(BuildContext): def execute(self): """ + In addition to printing the name of each build target, + a description column will include text for each task + generator which has a "description" field set. + See :py:func:`waflib.Build.BuildContext.execute`. """ self.restore() @@ -1321,9 +1325,23 @@ class ListContext(BuildContext): self.get_tgen_by_name('') except Errors.WafError: pass + + targets = sorted(self.task_gen_cache_names) - for k in sorted(self.task_gen_cache_names.keys()): - Logs.pprint('GREEN', k) + # figure out how much to left-justify, for largest target name + line_just = max(len(t) for t in targets) if targets else 0 + + for target in targets: + tgen = self.task_gen_cache_names[target] + + # Support displaying the description for the target + # if it was set on the tgen + descript = getattr(tgen, 'description', None) or '' + if descript: + target = target.ljust(line_just) + descript = ': {}'.format(descript) + + Logs.pprint('GREEN', target, label=descript) class StepContext(BuildContext): '''executes tasks in a step-by-step fashion, for debugging''' diff --git a/waflib/TaskGen.py b/waflib/TaskGen.py index 5c7b29c9..73bc404e 100644 --- a/waflib/TaskGen.py +++ b/waflib/TaskGen.py @@ -51,6 +51,11 @@ class task_gen(object): self.source = [] self.target = '' + self.description = '' + """ + String describing the target, used for display purposes + """ + self.meths = [] """ List of method names to execute (internal)