1
|
|
|
""" Monkey patch waf code to pipe command output direct to stdout |
2
|
|
|
|
3
|
|
|
As far as I know there is no way to do this using standard waf build commands |
4
|
|
|
options. |
5
|
|
|
""" |
6
|
|
|
|
7
|
|
|
import sys |
8
|
|
|
from waflib import Utils, Errors, Logs, Context |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
def my_exec_command(self,cmd,**kw): |
12
|
|
|
""" Copy of Context.exec_command that doesn't capture stdout / stderr |
13
|
|
|
|
14
|
|
|
This is necessary to prevent travis-ci timing out while waiting for |
15
|
|
|
feedback from the scipy build process, in particular |
16
|
|
|
""" |
17
|
|
|
subprocess=Utils.subprocess |
18
|
|
|
kw['shell']=isinstance(cmd,str) |
19
|
|
|
Logs.debug('runner: %r'%cmd) |
20
|
|
|
Logs.debug('runner_env: kw=%s'%kw) |
21
|
|
|
if self.logger: |
22
|
|
|
self.logger.info(cmd) |
23
|
|
|
if'stdout'not in kw: |
24
|
|
|
kw['stdout']=sys.stdout |
25
|
|
|
if'stderr'not in kw: |
26
|
|
|
kw['stderr']=sys.stderr |
27
|
|
|
try: |
28
|
|
|
if kw['stdout']or kw['stderr']: |
29
|
|
|
p=subprocess.Popen(cmd,**kw) |
30
|
|
|
(out,err)=p.communicate() |
31
|
|
|
ret=p.returncode |
32
|
|
|
else: |
33
|
|
|
out,err=(None,None) |
34
|
|
|
ret=subprocess.Popen(cmd,**kw).wait() |
35
|
|
|
except Exception as e: |
36
|
|
|
raise Errors.WafError('Execution failure: %s'%str(e),ex=e) |
37
|
|
|
if out: |
38
|
|
|
if not isinstance(out,str): |
39
|
|
|
out=out.decode(sys.stdout.encoding or'iso8859-1') |
40
|
|
|
if self.logger: |
41
|
|
|
self.logger.debug('out: %s'%out) |
42
|
|
|
else: |
43
|
|
|
sys.stdout.write(out) |
44
|
|
|
if err: |
45
|
|
|
if not isinstance(err,str): |
46
|
|
|
err=err.decode(sys.stdout.encoding or'iso8859-1') |
47
|
|
|
if self.logger: |
48
|
|
|
self.logger.error('err: %s'%err) |
49
|
|
|
else: |
50
|
|
|
sys.stderr.write(err) |
51
|
|
|
return ret |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
def monkey_patch(): |
55
|
|
|
""" Apply monkey patch to exec_command """ |
56
|
|
|
Context.Context.exec_command = my_exec_command |
57
|
|
|
|