Exemple #1
0
def perform_build_command(logfile, command, context, silent=False):
    """
    Build the project and create a log file.
    """
    LOG.info("Starting build ...")

    try:
        original_env_file = os.environ['CODECHECKER_ORIGINAL_BUILD_ENV']
        LOG.debug_analyzer('Loading original build env from: ' +
                           original_env_file)

        with open(original_env_file, 'rb') as env_file:
            original_env = pickle.load(env_file)

    except Exception as ex:
        LOG.warning(str(ex))
        LOG.warning('Failed to get saved original_env'
                    'using a current copy for logging.')
        original_env = os.environ.copy()

    # Run user's commands with intercept.
    if host_check.check_intercept(original_env):
        LOG.debug_analyzer("with intercept ...")
        final_command = command
        command = "intercept-build " + "--cdb " + logfile + " " + final_command
        log_env = original_env
        LOG.debug_analyzer(command)

    # Run user's commands in shell.
    else:
        # TODO: better platform detection.
        if platform.system() == 'Linux':
            LOG.debug_analyzer("with ld logger ...")
            open(logfile, 'a').close()  # Same as linux's touch.
            log_env = analyzer_env.get_log_env(logfile, context, original_env)
            if 'CC_LOGGER_GCC_LIKE' not in log_env:
                log_env['CC_LOGGER_GCC_LIKE'] = 'gcc:g++:clang:clang++:cc:c++'
        else:
            LOG.error("Intercept-build is required"
                      " to run CodeChecker in OS X.")
            sys.exit(1)

    LOG.debug_analyzer(log_env)
    try:
        ret_code = execute_buildcmd(command, silent, log_env)

        if ret_code == 0:
            LOG.info("Build finished successfully.")
            LOG.debug_analyzer("The logfile is: " + logfile)
        else:
            LOG.info("Build failed.")
            sys.exit(ret_code)

    except Exception as ex:
        LOG.error("Calling original build command failed.")
        LOG.error(str(ex))
        sys.exit(1)
def perform_build_command(logfile, command, context, silent=False):
    """
    Build the project and create a log file.
    """
    if not silent:
        LOG.info("Starting build ...")

    try:
        original_env_file = os.environ["CODECHECKER_ORIGINAL_BUILD_ENV"]
        LOG.debug_analyzer("Loading original build env from: " + original_env_file)

        with open(original_env_file, "rb") as env_file:
            original_env = pickle.load(env_file)

    except Exception as ex:
        LOG.warning(str(ex))
        LOG.warning("Failed to get saved original_env using a current copy for logging")
        original_env = os.environ.copy()

    return_code = 0

    # Run user's commands with intercept
    if host_check.check_intercept(original_env):
        LOG.debug_analyzer("with intercept ...")
        final_command = command
        command = "intercept-build " + "--cdb " + logfile + " " + final_command
        log_env = original_env
        LOG.debug_analyzer(command)

    # Run user's commands in shell
    else:
        # TODO better platform detection
        if platform.system() == "Linux":
            LOG.debug_analyzer("with ld logger ...")
            log_env = analyzer_env.get_log_env(logfile, context, original_env)
            if "CC_LOGGER_GCC_LIKE" not in log_env:
                log_env["CC_LOGGER_GCC_LIKE"] = "gcc:g++:clang:clang++:cc:c++"
        else:
            LOG.error("Intercept-build is required to run CodeChecker in OS X.")
            sys.exit(1)

    LOG.debug_analyzer(log_env)
    try:
        ret_code = execute_buildcmd(command, silent, log_env)

        if not silent:
            if ret_code == 0:
                LOG.info("Build finished successfully.")
                LOG.debug_analyzer("The logfile is: " + logfile)
            else:
                LOG.info("Build failed.")
                sys.exit(ret_code)

    except Exception as ex:
        LOG.error("Calling original build command failed")
        LOG.error(str(ex))
        sys.exit(1)
Exemple #3
0
def perform_build_command(logfile, command, context, silent=False):
    """ Build the project and create a log file. """
    if not silent:
        LOG.info("Build has started..")

    try:
        original_env_file = os.environ['CODECHECKER_ORIGINAL_BUILD_ENV']
        LOG.debug('Loading original build env from: ' + original_env_file)

        with open(original_env_file, 'rb') as env_file:
            original_env = pickle.load(env_file)

    except Exception as ex:
        LOG.warning(str(ex))
        LOG.warning('Failed to get saved original_env using a current copy for logging')
        original_env = os.environ.copy()

    return_code = 0
    # Run user's commands in shell
    log_env = analyzer_env.get_log_env(logfile, context, original_env)
    LOG.debug(log_env)
    try:
        proc = subprocess.Popen(command,
                                bufsize=-1,
                                env=log_env,
                                stdout=subprocess.PIPE,
                                stderr=subprocess.STDOUT,
                                shell=True)
        while True:
            line = proc.stdout.readline()
            if not silent:
                print line,
            if line == '' and proc.poll() is not None:
                break

        return_code = proc.returncode

        if not silent:
            if return_code == 0:
                LOG.info("Build finished successfully.")
                LOG.debug("The logfile is: " + logfile)
            else:
                LOG.info("Build failed.")
                sys.exit(1)
    except Exception as ex:
        LOG.error("Calling original build command failed")
        LOG.error(str(ex))
        sys.exit(1)
Exemple #4
0
def perform_build_command(logfile, command, context, silent=False):
    """
    Build the project and create a log file.
    """
    if not silent:
        LOG.info("Starting build ...")

    try:
        original_env_file = os.environ['CODECHECKER_ORIGINAL_BUILD_ENV']
        LOG.debug_analyzer('Loading original build env from: ' + original_env_file)

        with open(original_env_file, 'rb') as env_file:
            original_env = pickle.load(env_file)

    except Exception as ex:
        LOG.warning(str(ex))
        LOG.warning('Failed to get saved original_env using a current copy for logging')
        original_env = os.environ.copy()

    return_code = 0
    # Run user's commands in shell
    log_env = analyzer_env.get_log_env(logfile, context, original_env)

    if 'CC_LOGGER_GCC_LIKE' not in log_env:
      log_env['CC_LOGGER_GCC_LIKE'] = 'gcc:g++:clang:clang++:cc:c++'

    LOG.debug_analyzer(log_env)
    try:
        ret_code = execute_buildcmd(command, silent, log_env)

        if not silent:
            if ret_code == 0:
                LOG.info("Build finished successfully.")
                LOG.debug_analyzer("The logfile is: " + logfile)
            else:
                LOG.info("Build failed.")
                sys.exit(ret_code)

    except Exception as ex:
        LOG.error("Calling original build command failed")
        LOG.error(str(ex))
        sys.exit(1)
def perform_build_command(logfile, command, context, silent=False):
    """
    Build the project and create a log file.
    """
    if not silent:
        LOG.info("Starting build ...")

    try:
        original_env_file = os.environ['CODECHECKER_ORIGINAL_BUILD_ENV']
        LOG.debug_analyzer('Loading original build env from: ' +
                           original_env_file)

        with open(original_env_file, 'rb') as env_file:
            original_env = pickle.load(env_file)

    except Exception as ex:
        LOG.warning(str(ex))
        LOG.warning(
            'Failed to get saved original_env using a current copy for logging'
        )
        original_env = os.environ.copy()

    return_code = 0

    # Run user's commands with intercept
    if host_check.check_intercept(original_env):
        LOG.info("  with intercept ...")
        original_command = command
        if platform.system() == 'Linux':
            command = "intercept-build " + original_command
        elif platform.system() == 'Darwin':
            command = "sudo intercept-build " + original_command
        log_env = original_env

    # Run user's commands in shell
    else:
        LOG.info("  with ld logger ...")
        log_env = analyzer_env.get_log_env(logfile, context, original_env)
        if 'CC_LOGGER_GCC_LIKE' not in log_env:
            log_env['CC_LOGGER_GCC_LIKE'] = 'gcc:g++:clang:clang++:cc:c++'

    LOG.debug_analyzer(log_env)
    try:
        proc = subprocess.Popen(command,
                                bufsize=-1,
                                env=log_env,
                                stdout=subprocess.PIPE,
                                stderr=subprocess.STDOUT,
                                shell=True)
        while True:
            line = proc.stdout.readline()
            if not silent:
                sys.stdout.write(line)
            if line == '' and proc.poll() is not None:
                break

        return_code = proc.returncode

        command_json_path = os.path.join(os.getcwd(), 'compile_commands.json')
        shutil.copyfile(command_json_path, logfile)
        os.remove(command_json_path)

        if not silent:
            if return_code == 0:
                LOG.info("Build finished successfully.")
                LOG.debug_analyzer("The logfile is: " + logfile)
            else:
                LOG.info("Build failed.")
                sys.exit(1)
    except Exception as ex:
        LOG.error("Calling original build command failed")
        LOG.error(str(ex))
        sys.exit(1)