3 # WARNING! Do not edit! https://waf.io/book/index.html#_obtaining_the_waf_file
8 Illustrate how to override a class method to do something
10 In this case, print the commands being executed as strings
11 (the commands are usually lists, so this can be misleading)
15 from waflib import Context, Utils, Errors, Logs
17 def exec_command(self, cmd, **kw):
18 subprocess = Utils.subprocess
19 kw['shell'] = isinstance(cmd, str)
21 if isinstance(cmd, str):
25 txt = ' '.join(repr(x) if ' ' in x else x for x in cmd)
27 Logs.debug('runner: %s', txt)
28 Logs.debug('runner_env: kw=%s', kw)
33 if 'stdout' not in kw:
34 kw['stdout'] = subprocess.PIPE
35 if 'stderr' not in kw:
36 kw['stderr'] = subprocess.PIPE
38 if Logs.verbose and not kw['shell'] and not Utils.check_exe(cmd[0]):
39 raise Errors.WafError("Program %s not found!" % cmd[0])
43 if kw['timeout'] is not None:
44 wargs['timeout'] = kw['timeout']
48 wargs['input'] = kw['input']
49 kw['stdin'] = Utils.subprocess.PIPE
53 if not isinstance(kw['cwd'], str):
54 kw['cwd'] = kw['cwd'].abspath()
57 if kw['stdout'] or kw['stderr']:
58 p = subprocess.Popen(cmd, **kw)
59 (out, err) = p.communicate(**wargs)
62 out, err = (None, None)
63 ret = subprocess.Popen(cmd, **kw).wait(**wargs)
65 raise Errors.WafError('Execution failure: %s' % str(e), ex=e)
68 if not isinstance(out, str):
69 out = out.decode(sys.stdout.encoding or 'iso8859-1')
71 self.logger.debug('out: %s' % out)
73 Logs.info(out, extra={'stream':sys.stdout, 'c1': ''})
75 if not isinstance(err, str):
76 err = err.decode(sys.stdout.encoding or 'iso8859-1')
78 self.logger.error('err: %s' % err)
80 Logs.info(err, extra={'stream':sys.stderr, 'c1': ''})
84 Context.Context.exec_command = exec_command