示例#1
0
def run_argv(argv, env, os_env=None, cwd=None, force_no_valgrind=False):
    proc_env = get_proc_env(os_env)
    if Options.options.valgrind and not force_no_valgrind:
        if Options.options.command_template:
            raise Utils.WafError("Options --command-template and --valgrind are conflicting")
        if not env['VALGRIND']:
            raise Utils.WafError("valgrind is not installed")
        argv = [env['VALGRIND'], "--leak-check=full", "--show-reachable=yes", "--error-exitcode=1"] + argv
        proc = subprocess.Popen(argv, env=proc_env, cwd=cwd, stderr=subprocess.PIPE)
        error = False
        for line in proc.stderr:
            sys.stderr.write(line)
            if "== LEAK SUMMARY" in line:
                error = True
        retval = proc.wait()
        if retval == 0 and error:
            retval = 1
    else:
        try:
            WindowsError
        except NameError:
            retval = subprocess.Popen(argv, env=proc_env, cwd=cwd).wait()
        else:
            try:
                retval = subprocess.Popen(argv, env=proc_env, cwd=cwd).wait()
            except WindowsError, ex:
                raise Utils.WafError("Command %s raised exception %s" % (argv, ex))
示例#2
0
def pkg_check_modules(conf,uselib_name,expression,mandatory=True):
	pkg_config=conf.env['PKG_CONFIG']
	if not pkg_config:
		if mandatory:
			conf.fatal("pkg-config is not available")
		else:
			return False
	argv=[pkg_config,'--cflags','--libs',expression]
	cmd=subprocess.Popen(argv,stdout=subprocess.PIPE)
	out,dummy=cmd.communicate()
	retval=cmd.wait()
	msg_checking=("pkg-config flags for %s"%(uselib_name,))
	if Options.options.verbose:
		if retval==0:
			conf.check_message_custom(msg_checking,('(%s)'%expression),out)
		else:
			conf.check_message(msg_checking,('(%s)'%expression),False)
	else:
		conf.check_message(msg_checking,'',(retval==0),'')
	conf.log.write('%r: %r (exit code %i)\n'%(argv,out,retval))
	if retval==0:
		config_c.parse_flags(out,uselib_name,conf.env)
		conf.env[uselib_name]=True
		return True
	else:
		conf.env[uselib_name]=False
		if mandatory:
			raise Configure.ConfigurationError('pkg-config check failed')
		else:
			return False
示例#3
0
	def run(self):
		code = '\n'.join(['%s = %s' % (x, self.pars[x]) for x in self.pars])
		if not self.env['DOXYFLAGS']:
			self.env['DOXYFLAGS'] = ''
		fmt = DOXY_STR % (self.inputs[0].parent.abspath())
		cmd = Utils.subst_vars(fmt, self.env)
		proc = pproc.Popen(cmd, shell=True, stdin=pproc.PIPE)
		proc.communicate(code)
		return proc.returncode
示例#4
0
 def run(self):
     doc_dir = self.inputs[0].parent
     rule = '"${SPHINX}" -b html "%s" "%s"' % (doc_dir.srcpath(),
                                               doc_dir.bldpath(self.env))
     cmd = Utils.subst_vars(rule, self.env)
     proc = pproc.Popen(cmd, shell=True, stdin=pproc.PIPE)
     proc.communicate()
     self.update_build_dir(self.generator.path)
     return proc.returncode
示例#5
0
def run_proc(cmd, cwd, env=None):
    '''
    Run the specified command with working directory cwd until
    completion and return its returncode. The command is run in a
    sub-shell.

    @param cmd: command to run.
    @param cwd: working directory for command.
    @param env: process environment to use.
    @return: return code of command.
    '''
    proc = pproc.Popen(cmd, shell=True, env=env, cwd=cwd)
    proc.communicate()
    return proc.returncode
示例#6
0
def pkg_check_module_variable(conf,module,variable):
	pkg_config=conf.env['PKG_CONFIG']
	if not pkg_config:
		conf.fatal("pkg-config is not available")
	argv=[pkg_config,'--variable',variable,module]
	cmd=subprocess.Popen(argv,stdout=subprocess.PIPE)
	out,dummy=cmd.communicate()
	retval=cmd.wait()
	out=out.rstrip()
	msg_checking=("pkg-config variable %r in %s"%(variable,module,))
	conf.check_message_custom(msg_checking,'',out)
	conf.log.write('%r: %r (exit code %i)\n'%(argv,out,retval))
	if retval==0:
		return out
	else:
		raise Configure.ConfigurationError('pkg-config check failed')
示例#7
0
def _log_exec_command(s, **kw):
    """Like pproc.exec_command, but returns both return code as well as
	stdout/stderr."""
    if 'log' in kw:
        kw["stdout"] = pproc.PIPE
        kw["stderr"] = pproc.STDOUT
        log = kw["log"]
        del kw["log"]
    kw['shell'] = isinstance(s, str)

    p = pproc.Popen(s, **kw)
    ret = p.wait()
    lout = p.communicate()[0]
    log.write(lout)

    return ret, lout
示例#8
0
def get_msvc_version(conf, compiler, version, target, vcvars):
    debug('msvc: get_msvc_version: ' + compiler + ' ' + version + ' ' +
          target + ' ...')
    batfile = os.path.join(conf.blddir, "waf-print-msvc.bat")
    f = open(batfile, 'w')
    f.write("""@echo off
set INCLUDE=
set LIB=
call "%s" %s
echo PATH=%%PATH%%
echo INCLUDE=%%INCLUDE%%
echo LIB=%%LIB%%
""" % (vcvars, target))
    f.close()
    sout = Utils.cmd_output(['cmd', '/E:on', '/V:on', '/C', batfile])
    lines = sout.splitlines()
    if lines[0].find("Setting environment") == -1 and lines[0].find(
            "Setting SDK environment") == -1 and lines[1].find(
                'Intel(R) C++ Compiler') == -1:
        debug('msvc: get_msvc_version: ' + compiler + ' ' + version + ' ' +
              target + ' -> not found')
        conf.fatal(
            'msvc: Impossible to find a valid architecture for building (in get_msvc_version)'
        )
    for line in lines[1:]:
        if line.startswith('PATH='):
            path = line[5:]
            MSVC_PATH = path.split(';')
        elif line.startswith('INCLUDE='):
            MSVC_INCDIR = [i for i in line[8:].split(';') if i]
        elif line.startswith('LIB='):
            MSVC_LIBDIR = [i for i in line[4:].split(';') if i]
    env = {}
    env.update(os.environ)
    env.update(PATH=path)
    compiler_name, linker_name, lib_name = _get_prog_names(conf, compiler)
    cxx = conf.find_program(compiler_name, path_list=MSVC_PATH)
    import pproc
    try:
        p = pproc.Popen([cxx], env=env, stdout=pproc.PIPE, stderr=pproc.PIPE)
        out, err = p.communicate()
        if p.returncode != 0:
            raise Exception('return code: ' + str(p.returncode) + ': ' + err)
    except Exception, e:
        print('msvc: get_msvc_version: ' + compiler + ' ' + version + ' ' +
              target + ' -> failed: ' + str(e))
        conf.fatal('msvc: Compiler is not runnable (in get_msvc_version)')
示例#9
0
    def call(self, commands):
        """
		call: subprocess call method with (by default) silent stdout and stderr,
						test its return value to make sure it succeeded"
		@param commands [list] commands to run.
		@return:
				[tuple] (returncode, stdout, stderr):
		"""
        kwargs = dict()

        cmd = " ".join(commands)

        # Don't show output, run `waf check -vv` when need to check-out what went wrong...
        kwargs['stdout'] = kwargs['stderr'] = pproc.PIPE

        proc = pproc.Popen(cmd, shell=1, **kwargs)
        (stdout, stderr) = proc.communicate()
        if verbose:
            sys.stdout.write(stdout)
            sys.stderr.write(stderr)

        return (proc.returncode, stdout, stderr)