def exec_command(self, cmd, **kw): subprocess = Utils.subprocess kw['shell'] = isinstance(cmd, str) # FIXME: hacky solution to fix PIC-PIE-conflict if '-shared' in cmd: Logs.debug('runner: old %r' % (cmd, )) cmd = [x for x in cmd if x != '-fPIE' and x != '-pie'] Logs.debug('runner: %r', cmd) Logs.debug('runner_env: kw=%s', kw) if self.logger: self.logger.info(cmd) if 'stdout' not in kw: kw['stdout'] = subprocess.PIPE if 'stderr' not in kw: kw['stderr'] = subprocess.PIPE if Logs.verbose and not kw['shell'] and not Utils.check_exe(cmd[0]): raise Errors.WafError('Program %s not found!' % cmd[0]) wargs = {} if 'timeout' in kw: if kw['timeout'] is not None: wargs['timeout'] = kw['timeout'] del kw['timeout'] if 'input' in kw: if kw['input']: wargs['input'] = kw['input'] kw['stdin'] = subprocess.PIPE del kw['input'] if 'cwd' in kw: if not isinstance(kw['cwd'], str): kw['cwd'] = kw['cwd'].abspath() try: ret, out, err = Utils.run_process(cmd, kw, wargs) except Exception, e: raise Errors.WafError('Execution failure: %s' % str(e), ex=e), None, sys.exc_info()[2]
def run(self): ctx = self.generator.bld success = True try: argv = [ ctx.env.CLANG_TIDY[0], '-quiet', '--checks=%s' % ','.join([ 'clang-diagnostic-*', 'clang-analyzer-*', # This check is triggered deep down in boost, # e.g. noisicaa/builtin_nodes/control_track/processor.cpp (a false-positive # afaict), and I don't know how to disable it more locally. '-clang-analyzer-core.DivideZero', ]), self.inputs[0].relpath(), '--', '-Wall', '-I.', '-Ibuild', ] argv += ['-I%s' % p for p in ctx.env.INCLUDES_LILV] argv += ['-I%s' % p for p in ctx.env.INCLUDES_SUIL] argv += ['-I%s' % p for p in ctx.env.INCLUDES_GTK2] argv += ['-I%s' % p for p in ctx.env.INCLUDES] env = dict(os.environ) kw = { 'cwd': ctx.top_dir, 'env': env, 'stdout': subprocess.PIPE, 'stderr': subprocess.PIPE, } ctx.log_command(argv, kw) _, out, _ = Utils.run_process(argv, kw) out = out.strip() if out: success = False out_path = os.path.join(ctx.TEST_RESULTS_PATH, self.mod_name, 'clang-tidy.log') os.makedirs(os.path.dirname(out_path), exist_ok=True) with open(out_path, 'wb') as fp: fp.write(out) if out and ctx.options.fail_fast: sys.stderr.write(out.decode('utf-8')) sys.stderr.write('\n') raise RuntimeError("clang-tidy for %s failed." % self.mod_name) except Exception: success = False raise finally: ctx.record_test_state(self.test_id, success)
def exec_command(self, cmd, **kw): subprocess = Utils.subprocess kw['shell'] = isinstance(cmd, str) self.log_command(cmd, kw) if self.logger: self.logger.info(cmd) if 'stdout' not in kw: kw['stdout'] = subprocess.PIPE if 'stderr' not in kw: kw['stderr'] = subprocess.PIPE if Logs.verbose and not kw['shell'] and not Utils.check_exe(cmd[0]): raise Errors.WafError('Program %s not found!' % cmd[0]) cargs = {} if 'timeout' in kw: if sys.hexversion >= 0x3030000: cargs['timeout'] = kw['timeout'] if not 'start_new_session' in kw: kw['start_new_session'] = True del kw['timeout'] if 'input' in kw: if kw['input']: cargs['input'] = kw['input'] kw['stdin'] = subprocess.PIPE del kw['input'] if 'cwd' in kw: if not isinstance(kw['cwd'], str): kw['cwd'] = kw['cwd'].abspath() try: ret, out, err = Utils.run_process(cmd, kw, cargs) except Exception, e: raise Errors.WafError('Execution failure: %s' % str(e), ex=e), None, sys.exc_info()[2]
def cmd_and_log(self,cmd,**kw): subprocess=Utils.subprocess kw['shell']=isinstance(cmd,str) self.log_command(cmd,kw) quiet=kw.pop('quiet',None) to_ret=kw.pop('output',STDOUT) if Logs.verbose and not kw['shell']and not Utils.check_exe(cmd[0]): raise Errors.WafError('Program %r not found!'%cmd[0]) kw['stdout']=kw['stderr']=subprocess.PIPE if quiet is None: self.to_log(cmd) cargs={} if'timeout'in kw: if sys.hexversion>=0x3030000: cargs['timeout']=kw['timeout'] if not'start_new_session'in kw: kw['start_new_session']=True del kw['timeout'] if'input'in kw: if kw['input']: cargs['input']=kw['input'] kw['stdin']=subprocess.PIPE del kw['input'] if'cwd'in kw: if not isinstance(kw['cwd'],str): kw['cwd']=kw['cwd'].abspath() encoding=kw.pop('decode_as',default_encoding) try: ret,out,err=Utils.run_process(cmd,kw,cargs) except Exception ,e: raise Errors.WafError('Execution failure: %s'%str(e),ex=e),None,sys.exc_info()[2]
def exec_command(self,cmd,**kw): subprocess=Utils.subprocess kw['shell']=isinstance(cmd,str) # FIXME: hacky solution to fix PIC-PIE-conflict if '-shared' in cmd: Logs.debug('runner: old %r'%(cmd,)) cmd = [x for x in cmd if x != '-fPIE' and x != '-pie'] Logs.debug('runner: %r',cmd) Logs.debug('runner_env: kw=%s',kw) if self.logger: self.logger.info(cmd) if'stdout'not in kw: kw['stdout']=subprocess.PIPE if'stderr'not in kw: kw['stderr']=subprocess.PIPE if Logs.verbose and not kw['shell']and not Utils.check_exe(cmd[0]): raise Errors.WafError('Program %s not found!'%cmd[0]) wargs={} if'timeout'in kw: if kw['timeout']is not None: wargs['timeout']=kw['timeout'] del kw['timeout'] if'input'in kw: if kw['input']: wargs['input']=kw['input'] kw['stdin']=subprocess.PIPE del kw['input'] if'cwd'in kw: if not isinstance(kw['cwd'],str): kw['cwd']=kw['cwd'].abspath() try: ret,out,err=Utils.run_process(cmd,kw,wargs) except Exception ,e: raise Errors.WafError('Execution failure: %s'%str(e),ex=e),None,sys.exc_info()[2]
def cmd_and_log(self, cmd, **kw): subprocess = Utils.subprocess kw["shell"] = isinstance(cmd, str) Logs.debug("runner: %r", cmd) if "quiet" in kw: quiet = kw["quiet"] del kw["quiet"] else: quiet = None if "output" in kw: to_ret = kw["output"] del kw["output"] else: to_ret = STDOUT if Logs.verbose and not kw["shell"] and not Utils.check_exe(cmd[0]): raise Errors.WafError("Program %r not found!" % cmd[0]) kw["stdout"] = kw["stderr"] = subprocess.PIPE if quiet is None: self.to_log(cmd) wargs = {} if "timeout" in kw: if kw["timeout"] is not None: wargs["timeout"] = kw["timeout"] del kw["timeout"] if "input" in kw: if kw["input"]: wargs["input"] = kw["input"] kw["stdin"] = subprocess.PIPE del kw["input"] if "cwd" in kw: if not isinstance(kw["cwd"], str): kw["cwd"] = kw["cwd"].abspath() try: ret, out, err = Utils.run_process(cmd, kw, wargs) except Exception as e: raise Errors.WafError("Execution failure: %s" % str(e), ex=e) if not isinstance(out, str): out = out.decode(sys.stdout.encoding or "iso8859-1") if not isinstance(err, str): err = err.decode(sys.stdout.encoding or "iso8859-1") if out and quiet != STDOUT and quiet != BOTH: self.to_log("out: %s" % out) if err and quiet != STDERR and quiet != BOTH: self.to_log("err: %s" % err) if ret: e = Errors.WafError("Command %r returned %r" % (cmd, ret)) e.returncode = ret e.stderr = err e.stdout = out raise e if to_ret == BOTH: return (out, err) elif to_ret == STDERR: return err return out
def cmd_and_log(self,cmd,**kw): subprocess=Utils.subprocess kw['shell']=isinstance(cmd,str) Logs.debug('runner: %r',cmd) if'quiet'in kw: quiet=kw['quiet'] del kw['quiet'] else: quiet=None if'output'in kw: to_ret=kw['output'] del kw['output'] else: to_ret=STDOUT if Logs.verbose and not kw['shell']and not Utils.check_exe(cmd[0]): raise Errors.WafError('Program %r not found!'%cmd[0]) kw['stdout']=kw['stderr']=subprocess.PIPE if quiet is None: self.to_log(cmd) wargs={} if'timeout'in kw: if kw['timeout']is not None: wargs['timeout']=kw['timeout'] del kw['timeout'] if'input'in kw: if kw['input']: wargs['input']=kw['input'] kw['stdin']=subprocess.PIPE del kw['input'] if'cwd'in kw: if not isinstance(kw['cwd'],str): kw['cwd']=kw['cwd'].abspath() try: ret,out,err=Utils.run_process(cmd,kw,wargs) except Exception as e: raise Errors.WafError('Execution failure: %s'%str(e),ex=e) if not isinstance(out,str): out=out.decode(sys.stdout.encoding or'iso8859-1') if not isinstance(err,str): err=err.decode(sys.stdout.encoding or'iso8859-1') if out and quiet!=STDOUT and quiet!=BOTH: self.to_log('out: %s'%out) if err and quiet!=STDERR and quiet!=BOTH: self.to_log('err: %s'%err) if ret: e=Errors.WafError('Command %r returned %r'%(cmd,ret)) e.returncode=ret e.stderr=err e.stdout=out raise e if to_ret==BOTH: return(out,err) elif to_ret==STDERR: return err return out
def cmd_and_log(self, cmd, **kw): subprocess = Utils.subprocess kw['shell'] = isinstance(cmd, str) self.log_command(cmd, kw) quiet = kw.pop('quiet', None) to_ret = kw.pop('output', STDOUT) if Logs.verbose and not kw['shell'] and not Utils.check_exe(cmd[0]): raise Errors.WafError('Program %r not found!' % cmd[0]) kw['stdout'] = kw['stderr'] = subprocess.PIPE if quiet is None: self.to_log(cmd) cargs = {} if 'timeout' in kw: if sys.hexversion >= 0x3030000: cargs['timeout'] = kw['timeout'] if not 'start_new_session' in kw: kw['start_new_session'] = True del kw['timeout'] if 'input' in kw: if kw['input']: cargs['input'] = kw['input'] kw['stdin'] = subprocess.PIPE del kw['input'] if 'cwd' in kw: if not isinstance(kw['cwd'], str): kw['cwd'] = kw['cwd'].abspath() encoding = kw.pop('decode_as', default_encoding) try: ret, out, err = Utils.run_process(cmd, kw, cargs) except Exception as e: raise Errors.WafError('Execution failure: %s' % str(e), ex=e) if not isinstance(out, str): out = out.decode(encoding, errors='replace') if not isinstance(err, str): err = err.decode(encoding, errors='replace') if out and quiet != STDOUT and quiet != BOTH: self.to_log('out: %s' % out) if err and quiet != STDERR and quiet != BOTH: self.to_log('err: %s' % err) if ret: e = Errors.WafError('Command %r returned %r' % (cmd, ret)) e.returncode = ret e.stderr = err e.stdout = out raise e if to_ret == BOTH: return (out, err) elif to_ret == STDERR: return err return out
def exec_command(self, cmd, **kw): subprocess = Utils.subprocess kw['shell'] = isinstance(cmd, str) self.log_command(cmd, kw) if self.logger: self.logger.info(cmd) if 'stdout' not in kw: kw['stdout'] = subprocess.PIPE if 'stderr' not in kw: kw['stderr'] = subprocess.PIPE if Logs.verbose and not kw['shell'] and not Utils.check_exe(cmd[0]): raise Errors.WafError('Program %s not found!' % cmd[0]) cargs = {} if 'timeout' in kw: if sys.hexversion >= 0x3030000: cargs['timeout'] = kw['timeout'] if not 'start_new_session' in kw: kw['start_new_session'] = True del kw['timeout'] if 'input' in kw: if kw['input']: cargs['input'] = kw['input'] kw['stdin'] = subprocess.PIPE del kw['input'] if 'cwd' in kw: if not isinstance(kw['cwd'], str): kw['cwd'] = kw['cwd'].abspath() encoding = kw.pop('decode_as', default_encoding) try: ret, out, err = Utils.run_process(cmd, kw, cargs) except Exception as e: raise Errors.WafError('Execution failure: %s' % str(e), ex=e) if out: if not isinstance(out, str): out = out.decode(encoding, errors='replace') if self.logger: self.logger.debug('out: %s', out) else: Logs.info(out, extra={'stream': sys.stdout, 'c1': ''}) if err: if not isinstance(err, str): err = err.decode(encoding, errors='replace') if self.logger: self.logger.error('err: %s' % err) else: Logs.info(err, extra={'stream': sys.stderr, 'c1': ''}) return ret
def run(self): ctx = self.generator.bld success = True try: argv = [ os.path.join(ctx.env.VIRTUAL_ENV, 'bin', 'pylint'), '--rcfile=%s' % os.path.join(ctx.top_dir, 'bin', 'pylintrc'), '--output-format=parseable', '--score=no', '--exit-zero', self.mod_name, ] kw = { 'cwd': ctx.out_dir, 'stdout': subprocess.PIPE, 'stderr': subprocess.PIPE, } ctx.log_command(argv, kw) rc, out, err = Utils.run_process(argv, kw) out = out.strip() if out: success = False if rc != 0: sys.stderr.write(err.decode('utf-8')) raise RuntimeError("pylint is unhappy") out_path = os.path.join(ctx.TEST_RESULTS_PATH, self.mod_name, 'pylint.log') os.makedirs(os.path.dirname(out_path), exist_ok=True) with open(out_path, 'wb') as fp: fp.write(out) if out and ctx.options.fail_fast: sys.stderr.write(out.decode('utf-8')) sys.stderr.write('\n') raise RuntimeError("pylint for %s failed." % self.mod_name) except Exception: success = False raise finally: ctx.record_test_state(self.test_id, success)
def exec_command(self,cmd,**kw): subprocess=Utils.subprocess kw['shell']=isinstance(cmd,str) Logs.debug('runner: %r',cmd) Logs.debug('runner_env: kw=%s',kw) if self.logger: self.logger.info(cmd) if'stdout'not in kw: kw['stdout']=subprocess.PIPE if'stderr'not in kw: kw['stderr']=subprocess.PIPE if Logs.verbose and not kw['shell']and not Utils.check_exe(cmd[0]): raise Errors.WafError('Program %s not found!'%cmd[0]) wargs={} if'timeout'in kw: if kw['timeout']is not None: wargs['timeout']=kw['timeout'] del kw['timeout'] if'input'in kw: if kw['input']: wargs['input']=kw['input'] kw['stdin']=subprocess.PIPE del kw['input'] if'cwd'in kw: if not isinstance(kw['cwd'],str): kw['cwd']=kw['cwd'].abspath() try: ret,out,err=Utils.run_process(cmd,kw,wargs) except Exception as e: raise Errors.WafError('Execution failure: %s'%str(e),ex=e) if out: if not isinstance(out,str): out=out.decode(sys.stdout.encoding or'iso8859-1') if self.logger: self.logger.debug('out: %s',out) else: Logs.info(out,extra={'stream':sys.stdout,'c1':''}) if err: if not isinstance(err,str): err=err.decode(sys.stdout.encoding or'iso8859-1') if self.logger: self.logger.error('err: %s'%err) else: Logs.info(err,extra={'stream':sys.stderr,'c1':''}) return ret
def exec_command(self, cmd, **kw): subprocess = Utils.subprocess kw["shell"] = isinstance(cmd, str) Logs.debug("runner: %r", cmd) Logs.debug("runner_env: kw=%s", kw) if self.logger: self.logger.info(cmd) if "stdout" not in kw: kw["stdout"] = subprocess.PIPE if "stderr" not in kw: kw["stderr"] = subprocess.PIPE if Logs.verbose and not kw["shell"] and not Utils.check_exe(cmd[0]): raise Errors.WafError("Program %s not found!" % cmd[0]) wargs = {} if "timeout" in kw: if kw["timeout"] is not None: wargs["timeout"] = kw["timeout"] del kw["timeout"] if "input" in kw: if kw["input"]: wargs["input"] = kw["input"] kw["stdin"] = subprocess.PIPE del kw["input"] if "cwd" in kw: if not isinstance(kw["cwd"], str): kw["cwd"] = kw["cwd"].abspath() try: ret, out, err = Utils.run_process(cmd, kw, wargs) except Exception as e: raise Errors.WafError("Execution failure: %s" % str(e), ex=e) if out: if not isinstance(out, str): out = out.decode(sys.stdout.encoding or "iso8859-1") if self.logger: self.logger.debug("out: %s", out) else: Logs.info(out, extra={"stream": sys.stdout, "c1": ""}) if err: if not isinstance(err, str): err = err.decode(sys.stdout.encoding or "iso8859-1") if self.logger: self.logger.error("err: %s" % err) else: Logs.info(err, extra={"stream": sys.stderr, "c1": ""}) return ret
def run(self): ctx = self.generator.bld cwd = ctx.srcnode cmd = [ ctx.env.CSOUND[0], '-o' + self.outputs[0].path_from(cwd), self.inputs[0].path_from(cwd), ] kw = { 'cwd': cwd.abspath(), 'stdout': subprocess.PIPE, 'stderr': subprocess.STDOUT, } ctx.log_command(cmd, kw) rc, out, _ = Utils.run_process(cmd, kw) if rc: sys.stderr.write(out.decode('utf-8')) return rc
def run(self): ctx = self.generator.bld cwd = ctx.srcnode cmd = [ ctx.env.FFMPEG[0], '-y', '-nostdin', '-i', self.inputs[0].path_from(cwd) ] cmd.extend(self.__args) cmd.append(self.outputs[0].path_from(cwd)) kw = { 'cwd': cwd.abspath(), 'stdout': subprocess.PIPE, 'stderr': subprocess.STDOUT, } ctx.log_command(cmd, kw) rc, out, _ = Utils.run_process(cmd, kw) if rc: sys.stderr.write(out.decode('utf-8')) return rc
def cmd_and_log(self, cmd, **kw): subprocess = Utils.subprocess kw['shell'] = isinstance(cmd, str) Logs.debug('runner: %r', cmd) if 'quiet' in kw: quiet = kw['quiet'] del kw['quiet'] else: quiet = None if 'output' in kw: to_ret = kw['output'] del kw['output'] else: to_ret = STDOUT if Logs.verbose and not kw['shell'] and not Utils.check_exe(cmd[0]): raise Errors.WafError('Program %r not found!' % cmd[0]) kw['stdout'] = kw['stderr'] = subprocess.PIPE if quiet is None: self.to_log(cmd) cargs = {} if 'timeout' in kw: if sys.hexversion >= 0x3030000: cargs['timeout'] = kw['timeout'] if not 'start_new_session' in kw: kw['start_new_session'] = True del kw['timeout'] if 'input' in kw: if kw['input']: cargs['input'] = kw['input'] kw['stdin'] = subprocess.PIPE del kw['input'] if 'cwd' in kw: if not isinstance(kw['cwd'], str): kw['cwd'] = kw['cwd'].abspath() try: ret, out, err = Utils.run_process(cmd, kw, cargs) except Exception, e: raise Errors.WafError('Execution failure: %s' % str(e), ex=e), None, sys.exc_info()[2]
def cmd_and_log(self,cmd,**kw): subprocess=Utils.subprocess kw['shell']=isinstance(cmd,str) Logs.debug('runner: %r',cmd) if'quiet'in kw: quiet=kw['quiet'] del kw['quiet'] else: quiet=None if'output'in kw: to_ret=kw['output'] del kw['output'] else: to_ret=STDOUT if Logs.verbose and not kw['shell']and not Utils.check_exe(cmd[0]): raise Errors.WafError('Program %r not found!'%cmd[0]) kw['stdout']=kw['stderr']=subprocess.PIPE if quiet is None: self.to_log(cmd) wargs={} if'timeout'in kw: if kw['timeout']is not None: wargs['timeout']=kw['timeout'] del kw['timeout'] if'input'in kw: if kw['input']: wargs['input']=kw['input'] kw['stdin']=subprocess.PIPE del kw['input'] if'cwd'in kw: if not isinstance(kw['cwd'],str): kw['cwd']=kw['cwd'].abspath() try: ret,out,err=Utils.run_process(cmd,kw,wargs) except Exception ,e: raise Errors.WafError('Execution failure: %s'%str(e),ex=e),None,sys.exc_info()[2]
def cmd_and_log(self, cmd, **kw): """ Executes a process and returns stdout/stderr if the execution is successful. An exception is thrown when the exit status is non-0. In that case, both stderr and stdout will be bound to the WafError object (configuration tests):: def configure(conf): out = conf.cmd_and_log(['echo', 'hello'], output=waflib.Context.STDOUT, quiet=waflib.Context.BOTH) (out, err) = conf.cmd_and_log(['echo', 'hello'], output=waflib.Context.BOTH) (out, err) = conf.cmd_and_log(cmd, input='\\n'.encode(), output=waflib.Context.STDOUT) try: conf.cmd_and_log(['which', 'someapp'], output=waflib.Context.BOTH) except Errors.WafError as e: print(e.stdout, e.stderr) :param cmd: args for subprocess.Popen :type cmd: list or string :param kw: keyword arguments for subprocess.Popen. The parameters input/timeout will be passed to wait/communicate. :type kw: dict :returns: a tuple containing the contents of stdout and stderr :rtype: string :raises: :py:class:`waflib.Errors.WafError` if an invalid executable is specified for a non-shell process :raises: :py:class:`waflib.Errors.WafError` in case of execution failure; stdout/stderr/returncode are bound to the exception object """ subprocess = Utils.subprocess kw["shell"] = isinstance(cmd, str) self.log_command(cmd, kw) quiet = kw.pop("quiet", None) to_ret = kw.pop("output", STDOUT) if Logs.verbose and not kw["shell"] and not Utils.check_exe(cmd[0]): raise Errors.WafError("Program %r not found!" % cmd[0]) kw["stdout"] = kw["stderr"] = subprocess.PIPE if quiet is None: self.to_log(cmd) cargs = {} if "timeout" in kw: if sys.hexversion >= 0x3030000: cargs["timeout"] = kw["timeout"] if not "start_new_session" in kw: kw["start_new_session"] = True del kw["timeout"] if "input" in kw: if kw["input"]: cargs["input"] = kw["input"] kw["stdin"] = subprocess.PIPE del kw["input"] if "cwd" in kw: if not isinstance(kw["cwd"], str): kw["cwd"] = kw["cwd"].abspath() encoding = kw.pop("decode_as", default_encoding) try: ret, out, err = Utils.run_process(cmd, kw, cargs) except Exception as e: raise Errors.WafError("Execution failure: %s" % str(e), ex=e) if not isinstance(out, str): out = out.decode(encoding, errors="replace") if not isinstance(err, str): err = err.decode(encoding, errors="replace") if out and quiet != STDOUT and quiet != BOTH: self.to_log("out: %s" % out) if err and quiet != STDERR and quiet != BOTH: self.to_log("err: %s" % err) if ret: e = Errors.WafError(f"Command {cmd!r} returned {ret!r}") e.returncode = ret e.stderr = err e.stdout = out raise e if to_ret == BOTH: return (out, err) elif to_ret == STDERR: return err return out
def exec_command(self, cmd, **kw): """ Runs an external process and returns the exit status:: def run(tsk): ret = tsk.generator.bld.exec_command('touch foo.txt') return ret If the context has the attribute 'log', then captures and logs the process stderr/stdout. Unlike :py:meth:`waflib.Context.Context.cmd_and_log`, this method does not return the stdout/stderr values captured. :param cmd: command argument for subprocess.Popen :type cmd: string or list :param kw: keyword arguments for subprocess.Popen. The parameters input/timeout will be passed to wait/communicate. :type kw: dict :returns: process exit status :rtype: integer """ subprocess = Utils.subprocess kw["shell"] = isinstance(cmd, str) Logs.debug("runner: %r", cmd) Logs.debug("runner_env: kw=%s", kw) if self.logger: self.logger.info(cmd) if "stdout" not in kw: kw["stdout"] = subprocess.PIPE if "stderr" not in kw: kw["stderr"] = subprocess.PIPE if Logs.verbose and not kw["shell"] and not Utils.check_exe(cmd[0]): raise Errors.WafError("Program %s not found!" % cmd[0]) cargs = {} if "timeout" in kw: if kw["timeout"] is not None: if kw["shell"]: Logs.warn("Shell commands cannot timeout %r", cmd) del kw["timeout"] if "input" in kw: if kw["input"]: cargs["input"] = kw["input"] kw["stdin"] = subprocess.PIPE del kw["input"] if "cwd" in kw: if not isinstance(kw["cwd"], str): kw["cwd"] = kw["cwd"].abspath() try: ret, out, err = Utils.run_process(cmd, kw, cargs) except Exception as e: raise Errors.WafError("Execution failure: %s" % str(e), ex=e) if out: if not isinstance(out, str): out = out.decode(sys.stdout.encoding or "iso8859-1") if self.logger: self.logger.debug("out: %s", out) else: Logs.info(out, extra={"stream": sys.stdout, "c1": ""}) if err: if not isinstance(err, str): err = err.decode(sys.stdout.encoding or "iso8859-1") if self.logger: self.logger.error("err: %s" % err) else: Logs.info(err, extra={"stream": sys.stderr, "c1": ""}) return ret
def cmd_and_log(self, cmd, **kw): """ Executes a process and returns stdout/stderr if the execution is successful. An exception is thrown when the exit status is non-0. In that case, both stderr and stdout will be bound to the WafError object (configuration tests):: def configure(conf): out = conf.cmd_and_log(['echo', 'hello'], output=waflib.Context.STDOUT, quiet=waflib.Context.BOTH) (out, err) = conf.cmd_and_log(['echo', 'hello'], output=waflib.Context.BOTH) (out, err) = conf.cmd_and_log(cmd, input='\\n'.encode(), output=waflib.Context.STDOUT) try: conf.cmd_and_log(['which', 'someapp'], output=waflib.Context.BOTH) except Errors.WafError as e: print(e.stdout, e.stderr) :param cmd: args for subprocess.Popen :type cmd: list or string :param kw: keyword arguments for subprocess.Popen. The parameters input/timeout will be passed to wait/communicate. :type kw: dict :returns: a tuple containing the contents of stdout and stderr :rtype: string :raises: :py:class:`waflib.Errors.WafError` if an invalid executable is specified for a non-shell process :raises: :py:class:`waflib.Errors.WafError` in case of execution failure; stdout/stderr/returncode are bound to the exception object """ subprocess = Utils.subprocess kw['shell'] = isinstance(cmd, str) self.log_command(cmd, kw) quiet = kw.pop('quiet', None) to_ret = kw.pop('output', STDOUT) if Logs.verbose and not kw['shell'] and not Utils.check_exe(cmd[0]): raise Errors.WafError('Program %r not found!' % cmd[0]) kw['stdout'] = kw['stderr'] = subprocess.PIPE if quiet is None: self.to_log(cmd) cargs = {} if 'timeout' in kw: if sys.hexversion >= 0x3030000: cargs['timeout'] = kw['timeout'] if not 'start_new_session' in kw: kw['start_new_session'] = True del kw['timeout'] if 'input' in kw: if kw['input']: cargs['input'] = kw['input'] kw['stdin'] = subprocess.PIPE del kw['input'] if 'cwd' in kw: if not isinstance(kw['cwd'], str): kw['cwd'] = kw['cwd'].abspath() encoding = kw.pop('decode_as', default_encoding) try: ret, out, err = Utils.run_process(cmd, kw, cargs) except Exception as e: raise Errors.WafError('Execution failure: %s' % str(e), ex=e) if not isinstance(out, str): out = out.decode(encoding, errors='replace') if not isinstance(err, str): err = err.decode(encoding, errors='replace') if out and quiet != STDOUT and quiet != BOTH: self.to_log('out: %s' % out) if err and quiet != STDERR and quiet != BOTH: self.to_log('err: %s' % err) if ret: e = Errors.WafError('Command %r returned %r' % (cmd, ret)) e.returncode = ret e.stderr = err e.stdout = out raise e if to_ret == BOTH: return (out, err) elif to_ret == STDERR: return err return out
def exec_command(self, cmd, **kw): """ Runs an external process and returns the exit status:: def run(tsk): ret = tsk.generator.bld.exec_command('touch foo.txt') return ret If the context has the attribute 'log', then captures and logs the process stderr/stdout. Unlike :py:meth:`waflib.Context.Context.cmd_and_log`, this method does not return the stdout/stderr values captured. :param cmd: command argument for subprocess.Popen :type cmd: string or list :param kw: keyword arguments for subprocess.Popen. The parameters input/timeout will be passed to wait/communicate. :type kw: dict :returns: process exit status :rtype: integer :raises: :py:class:`waflib.Errors.WafError` if an invalid executable is specified for a non-shell process :raises: :py:class:`waflib.Errors.WafError` in case of execution failure """ subprocess = Utils.subprocess kw['shell'] = isinstance(cmd, str) self.log_command(cmd, kw) if self.logger: self.logger.info(cmd) if 'stdout' not in kw: kw['stdout'] = subprocess.PIPE if 'stderr' not in kw: kw['stderr'] = subprocess.PIPE if Logs.verbose and not kw['shell'] and not Utils.check_exe(cmd[0]): raise Errors.WafError('Program %s not found!' % cmd[0]) cargs = {} if 'timeout' in kw: if sys.hexversion >= 0x3030000: cargs['timeout'] = kw['timeout'] if not 'start_new_session' in kw: kw['start_new_session'] = True del kw['timeout'] if 'input' in kw: if kw['input']: cargs['input'] = kw['input'] kw['stdin'] = subprocess.PIPE del kw['input'] if 'cwd' in kw: if not isinstance(kw['cwd'], str): kw['cwd'] = kw['cwd'].abspath() encoding = kw.pop('decode_as', default_encoding) try: ret, out, err = Utils.run_process(cmd, kw, cargs) except Exception as e: raise Errors.WafError('Execution failure: %s' % str(e), ex=e) if out: if not isinstance(out, str): out = out.decode(encoding, errors='replace') if self.logger: self.logger.debug('out: %s', out) else: Logs.info(out, extra={'stream':sys.stdout, 'c1': ''}) if err: if not isinstance(err, str): err = err.decode(encoding, errors='replace') if self.logger: self.logger.error('err: %s' % err) else: Logs.info(err, extra={'stream':sys.stderr, 'c1': ''}) return ret
def run(self): ctx = self.generator.bld success = True try: ini_path = os.path.join(ctx.top_dir, 'noisidev', 'mypy.ini') with mypy_cache_lock: if not mypy_caches: global mypy_next_cache # pylint: disable=global-statement cache_num = mypy_next_cache mypy_next_cache += 1 else: cache_num = mypy_caches.pop(-1) try: argv = [ os.path.join(ctx.env.VIRTUAL_ENV, 'bin', 'mypy'), '--config-file', ini_path, '--cache-dir=%s' % os.path.join(ctx.out_dir, 'mypy-cache.%d' % cache_num), '--show-traceback', '--no-error-summary', '-m', self.mod_name, ] if self.__strict: argv.append('--disallow-untyped-defs') env = dict(os.environ) env['MYPYPATH'] = os.path.join(ctx.top_dir, '3rdparty', 'typeshed') kw = { 'cwd': ctx.out_dir, 'env': env, 'stdout': subprocess.PIPE, 'stderr': subprocess.PIPE, } ctx.log_command(argv, kw) _, out, err = Utils.run_process(argv, kw) out = out.strip() if out: success = False finally: with mypy_cache_lock: mypy_caches.append(cache_num) if err: sys.stderr.write(err.decode('utf-8')) raise RuntimeError("mypy is unhappy") out_path = os.path.join(ctx.TEST_RESULTS_PATH, self.mod_name, 'mypy.log') os.makedirs(os.path.dirname(out_path), exist_ok=True) with open(out_path, 'wb') as fp: fp.write(out) if out and ctx.options.fail_fast: sys.stderr.write(out.decode('utf-8')) sys.stderr.write('\n') raise RuntimeError("mypy for %s failed." % self.mod_name) except Exception: success = False raise finally: ctx.record_test_state(self.test_id, success)
def cmd_and_log(self, cmd, **kw): """ Executes a proces and returns stdout/stderr if the execution is successful. An exception is thrown when the exit status is non-0. In that case, both stderr and stdout will be bound to the WafError object:: def configure(conf): out = conf.cmd_and_log(['echo', 'hello'], output=waflib.Context.STDOUT, quiet=waflib.Context.BOTH) (out, err) = conf.cmd_and_log(['echo', 'hello'], output=waflib.Context.BOTH) (out, err) = conf.cmd_and_log(cmd, input='\\n'.encode(), output=waflib.Context.STDOUT) try: conf.cmd_and_log(['which', 'someapp'], output=waflib.Context.BOTH) except Exception as e: print(e.stdout, e.stderr) :param cmd: args for subprocess.Popen :type cmd: list or string :param kw: keyword arguments for subprocess.Popen. The parameters input/timeout will be passed to wait/communicate. :type kw: dict :returns: process exit status :rtype: integer :raises: :py:class:`waflib.Errors.WafError` if an invalid executable is specified for a non-shell process :raises: :py:class:`waflib.Errors.WafError` in case of execution failure; stdout/stderr/returncode are bound to the exception object """ subprocess = Utils.subprocess kw["shell"] = isinstance(cmd, str) Logs.debug("runner: %r", cmd) if "quiet" in kw: quiet = kw["quiet"] del kw["quiet"] else: quiet = None if "output" in kw: to_ret = kw["output"] del kw["output"] else: to_ret = STDOUT if Logs.verbose and not kw["shell"] and not Utils.check_exe(cmd[0]): raise Errors.WafError("Program %r not found!" % cmd[0]) kw["stdout"] = kw["stderr"] = subprocess.PIPE if quiet is None: self.to_log(cmd) cargs = {} if "timeout" in kw: if kw["timeout"] is not None: if kw["shell"]: Logs.warn("Shell commands cannot timeout %r", cmd) del kw["timeout"] if "input" in kw: if kw["input"]: cargs["input"] = kw["input"] kw["stdin"] = subprocess.PIPE del kw["input"] if "cwd" in kw: if not isinstance(kw["cwd"], str): kw["cwd"] = kw["cwd"].abspath() try: ret, out, err = Utils.run_process(cmd, kw, cargs) except Exception as e: raise Errors.WafError("Execution failure: %s" % str(e), ex=e) if not isinstance(out, str): out = out.decode(sys.stdout.encoding or "iso8859-1") if not isinstance(err, str): err = err.decode(sys.stdout.encoding or "iso8859-1") if out and quiet != STDOUT and quiet != BOTH: self.to_log("out: %s" % out) if err and quiet != STDERR and quiet != BOTH: self.to_log("err: %s" % err) if ret: e = Errors.WafError("Command %r returned %r" % (cmd, ret)) e.returncode = ret e.stderr = err e.stdout = out raise e if to_ret == BOTH: return (out, err) elif to_ret == STDERR: return err return out
def exec_command(self, cmd, **kw): """ Runs an external process and returns the exit status:: def run(tsk): ret = tsk.generator.bld.exec_command('touch foo.txt') return ret If the context has the attribute 'log', then captures and logs the process stderr/stdout. Unlike :py:meth:`waflib.Context.Context.cmd_and_log`, this method does not return the stdout/stderr values captured. :param cmd: command argument for subprocess.Popen :type cmd: string or list :param kw: keyword arguments for subprocess.Popen. The parameters input/timeout will be passed to wait/communicate. :type kw: dict :returns: process exit status :rtype: integer :raises: :py:class:`waflib.Errors.WafError` if an invalid executable is specified for a non-shell process :raises: :py:class:`waflib.Errors.WafError` in case of execution failure """ subprocess = Utils.subprocess kw['shell'] = isinstance(cmd, str) self.log_command(cmd, kw) if self.logger: self.logger.info(cmd) if 'stdout' not in kw: kw['stdout'] = subprocess.PIPE if 'stderr' not in kw: kw['stderr'] = subprocess.PIPE if Logs.verbose and not kw['shell'] and not Utils.check_exe(cmd[0]): raise Errors.WafError('Program %s not found!' % cmd[0]) cargs = {} if 'timeout' in kw: if sys.hexversion >= 0x3030000: cargs['timeout'] = kw['timeout'] if not 'start_new_session' in kw: kw['start_new_session'] = True del kw['timeout'] if 'input' in kw: if kw['input']: cargs['input'] = kw['input'] kw['stdin'] = subprocess.PIPE del kw['input'] if 'cwd' in kw: if not isinstance(kw['cwd'], str): kw['cwd'] = kw['cwd'].abspath() try: ret, out, err = Utils.run_process(cmd, kw, cargs) except Exception as e: raise Errors.WafError('Execution failure: %s' % str(e), ex=e) if out: if not isinstance(out, str): out = out.decode(sys.stdout.encoding or 'latin-1', errors='replace') if self.logger: self.logger.debug('out: %s', out) else: Logs.info(out, extra={'stream':sys.stdout, 'c1': ''}) if err: if not isinstance(err, str): err = err.decode(sys.stdout.encoding or 'latin-1', errors='replace') if self.logger: self.logger.error('err: %s' % err) else: Logs.info(err, extra={'stream':sys.stderr, 'c1': ''}) return ret
def exec_command(self, cmd, **kw): """ Runs an external process and returns the exit status:: def run(tsk): ret = tsk.generator.bld.exec_command('touch foo.txt') return ret If the context has the attribute 'log', then captures and logs the process stderr/stdout. Unlike :py:meth:`waflib.Context.Context.cmd_and_log`, this method does not return the stdout/stderr values captured. :param cmd: command argument for subprocess.Popen :type cmd: string or list :param kw: keyword arguments for subprocess.Popen. The parameters input/timeout will be passed to wait/communicate. :type kw: dict :returns: process exit status :rtype: integer :raises: :py:class:`waflib.Errors.WafError` if an invalid executable is specified for a non-shell process :raises: :py:class:`waflib.Errors.WafError` in case of execution failure """ subprocess = Utils.subprocess kw["shell"] = isinstance(cmd, str) self.log_command(cmd, kw) if self.logger: self.logger.info(cmd) if "stdout" not in kw: kw["stdout"] = subprocess.PIPE if "stderr" not in kw: kw["stderr"] = subprocess.PIPE if Logs.verbose and not kw["shell"] and not Utils.check_exe(cmd[0]): raise Errors.WafError("Program %s not found!" % cmd[0]) cargs = {} if "timeout" in kw: if sys.hexversion >= 0x3030000: cargs["timeout"] = kw["timeout"] if not "start_new_session" in kw: kw["start_new_session"] = True del kw["timeout"] if "input" in kw: if kw["input"]: cargs["input"] = kw["input"] kw["stdin"] = subprocess.PIPE del kw["input"] if "cwd" in kw: if not isinstance(kw["cwd"], str): kw["cwd"] = kw["cwd"].abspath() encoding = kw.pop("decode_as", default_encoding) try: ret, out, err = Utils.run_process(cmd, kw, cargs) except Exception as e: raise Errors.WafError("Execution failure: %s" % str(e), ex=e) if out: if not isinstance(out, str): out = out.decode(encoding, errors="replace") if self.logger: self.logger.debug("out: %s", out) else: Logs.info(out, extra={"stream": sys.stdout, "c1": ""}) if err: if not isinstance(err, str): err = err.decode(encoding, errors="replace") if self.logger: self.logger.error("err: %s" % err) else: Logs.info(err, extra={"stream": sys.stderr, "c1": ""}) return ret
def cmd_and_log(self, cmd, **kw): """ Executes a process and returns stdout/stderr if the execution is successful. An exception is thrown when the exit status is non-0. In that case, both stderr and stdout will be bound to the WafError object (configuration tests):: def configure(conf): out = conf.cmd_and_log(['echo', 'hello'], output=waflib.Context.STDOUT, quiet=waflib.Context.BOTH) (out, err) = conf.cmd_and_log(['echo', 'hello'], output=waflib.Context.BOTH) (out, err) = conf.cmd_and_log(cmd, input='\\n'.encode(), output=waflib.Context.STDOUT) try: conf.cmd_and_log(['which', 'someapp'], output=waflib.Context.BOTH) except Errors.WafError as e: print(e.stdout, e.stderr) :param cmd: args for subprocess.Popen :type cmd: list or string :param kw: keyword arguments for subprocess.Popen. The parameters input/timeout will be passed to wait/communicate. :type kw: dict :returns: a tuple containing the contents of stdout and stderr :rtype: string :raises: :py:class:`waflib.Errors.WafError` if an invalid executable is specified for a non-shell process :raises: :py:class:`waflib.Errors.WafError` in case of execution failure; stdout/stderr/returncode are bound to the exception object """ subprocess = Utils.subprocess kw['shell'] = isinstance(cmd, str) self.log_command(cmd, kw) if 'quiet' in kw: quiet = kw['quiet'] del kw['quiet'] else: quiet = None if 'output' in kw: to_ret = kw['output'] del kw['output'] else: to_ret = STDOUT if Logs.verbose and not kw['shell'] and not Utils.check_exe(cmd[0]): raise Errors.WafError('Program %r not found!' % cmd[0]) kw['stdout'] = kw['stderr'] = subprocess.PIPE if quiet is None: self.to_log(cmd) cargs = {} if 'timeout' in kw: if sys.hexversion >= 0x3030000: cargs['timeout'] = kw['timeout'] if not 'start_new_session' in kw: kw['start_new_session'] = True del kw['timeout'] if 'input' in kw: if kw['input']: cargs['input'] = kw['input'] kw['stdin'] = subprocess.PIPE del kw['input'] if 'cwd' in kw: if not isinstance(kw['cwd'], str): kw['cwd'] = kw['cwd'].abspath() try: ret, out, err = Utils.run_process(cmd, kw, cargs) except Exception as e: raise Errors.WafError('Execution failure: %s' % str(e), ex=e) if not isinstance(out, str): out = out.decode(sys.stdout.encoding or 'latin-1', errors='replace') if not isinstance(err, str): err = err.decode(sys.stdout.encoding or 'latin-1', errors='replace') if out and quiet != STDOUT and quiet != BOTH: self.to_log('out: %s' % out) if err and quiet != STDERR and quiet != BOTH: self.to_log('err: %s' % err) if ret: e = Errors.WafError('Command %r returned %r' % (cmd, ret)) e.returncode = ret e.stderr = err e.stdout = out raise e if to_ret == BOTH: return (out, err) elif to_ret == STDERR: return err return out
def exec_command(self, cmd, **kw): """ Runs an external process and returns the exit status:: def run(tsk): ret = tsk.generator.bld.exec_command('touch foo.txt') return ret If the context has the attribute 'log', then captures and logs the process stderr/stdout. Unlike :py:meth:`waflib.Context.Context.cmd_and_log`, this method does not return the stdout/stderr values captured. :param cmd: command argument for subprocess.Popen :type cmd: string or list :param kw: keyword arguments for subprocess.Popen. The parameters input/timeout will be passed to wait/communicate. :type kw: dict :returns: process exit status :rtype: integer """ subprocess = Utils.subprocess kw['shell'] = isinstance(cmd, str) Logs.debug('runner: %r', cmd) Logs.debug('runner_env: kw=%s', kw) if self.logger: self.logger.info(cmd) if 'stdout' not in kw: kw['stdout'] = subprocess.PIPE if 'stderr' not in kw: kw['stderr'] = subprocess.PIPE if Logs.verbose and not kw['shell'] and not Utils.check_exe(cmd[0]): raise Errors.WafError('Program %s not found!' % cmd[0]) wargs = {} if 'timeout' in kw: if kw['timeout'] is not None: wargs['timeout'] = kw['timeout'] del kw['timeout'] if 'input' in kw: if kw['input']: wargs['input'] = kw['input'] kw['stdin'] = subprocess.PIPE del kw['input'] if 'cwd' in kw: if not isinstance(kw['cwd'], str): kw['cwd'] = kw['cwd'].abspath() try: ret, out, err = Utils.run_process(cmd, kw, wargs) except Exception as e: raise Errors.WafError('Execution failure: %s' % str(e), ex=e) if out: if not isinstance(out, str): out = out.decode(sys.stdout.encoding or 'iso8859-1') if self.logger: self.logger.debug('out: %s', out) else: Logs.info(out, extra={'stream':sys.stdout, 'c1': ''}) if err: if not isinstance(err, str): err = err.decode(sys.stdout.encoding or 'iso8859-1') if self.logger: self.logger.error('err: %s' % err) else: Logs.info(err, extra={'stream':sys.stderr, 'c1': ''}) return ret