From f5f4218cdab046b6f55fdb56043752fbe479d614 Mon Sep 17 00:00:00 2001 From: Thomas Nagy Date: Sun, 10 Dec 2017 21:26:17 +0100 Subject: [PATCH] Set task.stdout=task.stderr for long-running tasks --- demos/c/wscript | 4 +++- docs/sphinx/conf.py | 4 ++-- waflib/Task.py | 12 ++++++++++++ waflib/TaskGen.py | 25 ++++++++++++++++++++++++- 4 files changed, 41 insertions(+), 4 deletions(-) diff --git a/demos/c/wscript b/demos/c/wscript index af5d98e6..b9c8b8a8 100644 --- a/demos/c/wscript +++ b/demos/c/wscript @@ -95,7 +95,9 @@ def build(bld): always=True, source='wscript', shell=1, name='Shell') if not Utils.is_win32: bld(rule='echo ${ST:FOO} ${ST:SRC} ${A}${B} ${ST:SRCA} ${ST:SRC[0].abspath()}', - always=True, source='wscript', shell=0, cls_keyword=lambda x:'Trying again', name='NoShell') + always=True, source='wscript', shell=0, + stdout=None, stderr=None, # disable synchronized outputs on this rule + cls_keyword=lambda x:'Trying again', name='NoShell') # illustrate how to add a command 'foo' and to execute things in it if bld.cmd == 'foo': diff --git a/docs/sphinx/conf.py b/docs/sphinx/conf.py index 51c50e68..2d04da5b 100644 --- a/docs/sphinx/conf.py +++ b/docs/sphinx/conf.py @@ -331,7 +331,7 @@ f.close() # Add any Sphinx extension module names here, as strings. They can be extensions # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. -extensions = ['sphinx.ext.autodoc', 'sphinx.ext.todo', 'sphinx.ext.pngmath', 'sphinx.ext.inheritance_diagram', 'sphinx.ext.graphviz', 'sphinx.ext.viewcode'] +extensions = ['sphinx.ext.autodoc', 'sphinx.ext.todo', 'sphinx.ext.imgmath', 'sphinx.ext.inheritance_diagram', 'sphinx.ext.graphviz', 'sphinx.ext.viewcode'] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] @@ -488,7 +488,7 @@ htmlhelp_basename = 'wafdoc' # -- Options for LaTeX output -------------------------------------------------- # The paper size ('letter' or 'a4'). -latex_paper_size = 'a4' +#latex_paper_size = 'a4' # The font size ('10pt', '11pt' or '12pt'). #latex_font_size = '10pt' diff --git a/waflib/Task.py b/waflib/Task.py index b2e96129..411caf75 100644 --- a/waflib/Task.py +++ b/waflib/Task.py @@ -259,6 +259,13 @@ class Task(evil): :type cmd: list of string (best) or string (process will use a shell) :return: the return code :rtype: int + + Optional parameters: + + #. cwd: current working directory (Node or string) + #. stdout: set to None to prevent waf from capturing the process standard output + #. stderr: set to None to prevent waf from capturing the process standard error + #. timeout: timeout value (Python 3) """ if not 'cwd' in kw: kw['cwd'] = self.get_cwd() @@ -270,6 +277,11 @@ class Task(evil): env = kw['env'] = dict(kw.get('env') or self.env.env or os.environ) env['PATH'] = self.env.PATH if isinstance(self.env.PATH, str) else os.pathsep.join(self.env.PATH) + if hasattr(self, 'stdout'): + kw['stdout'] = self.stdout + if hasattr(self, 'stderr'): + kw['stderr'] = self.stderr + # workaround for command line length limit: # http://support.microsoft.com/kb/830473 if not isinstance(cmd, str) and (len(repr(cmd)) >= 8192 if Utils.is_win32 else len(cmd) > 200000): diff --git a/waflib/TaskGen.py b/waflib/TaskGen.py index 2e67784b..eb3624fd 100644 --- a/waflib/TaskGen.py +++ b/waflib/TaskGen.py @@ -553,6 +553,24 @@ def process_rule(self): def build(bld): bld(rule='cp ${SRC} ${TGT}', source='wscript', target='bar.txt') + + Main attributes processed: + + * rule: command to execute, it can be a tuple of strings for multiple commands + * chmod: permissions for the resulting files (integer value such as Utils.O755) + * shell: set to False to execute the command directly (default is True to use a shell) + * scan: scanner function + * vars: list of variables to trigger rebuilts, such as CFLAGS + * cls_str: string to display when executing the task + * cls_keyword: label to display when executing the task + * cache_rule: by default, try to re-use similar classes, set to False to disable + * source: list of Node or string objects representing the source files required by this task + * target: list of Node or string objects representing the files that this task creates + * cwd: current working directory (Node or string) + * stdout: standard output, set to None to prevent waf from capturing the text + * stderr: standard error, set to None to prevent waf from capturing the text + * timeout: timeout for command execution (Python 3) + * always: whether to always run the command (False by default) """ if not getattr(self, 'rule', None): return @@ -630,6 +648,12 @@ def process_rule(self): for x in ('after', 'before', 'ext_in', 'ext_out'): setattr(tsk, x, getattr(self, x, [])) + if hasattr(self, 'stdout'): + tsk.stdout = self.stdout + + if hasattr(self, 'stderr'): + tsk.stderr = self.stderr + if getattr(self, 'timeout', None): tsk.timeout = self.timeout @@ -665,7 +689,6 @@ def process_rule(self): # methods during instance attribute look-up." tsk.run = functools.partial(tsk.run, tsk) - @feature('seq') def sequence_order(self): """