예제 #1
0
        def on_result(**args):
            check_command = args['check_command']
            action_id = connection.add_build_action(action.original_command,
                                                    check_command)

            err_code = args['err_code']
            if err_code == 0:
                client.send_plist_content(connection,
                                          args['report_plist'],
                                          action_id,
                                          analyzer.run_id,
                                          analyzer.severity_map,
                                          analyzer.should_skip)
                msg = 'Checking %s is done.' % (args['source_file'])
                LOG.debug(msg + '\n' + check_command)
                LOG.info(msg)

            connection.finish_build_action(action_id, args['err_message'])
            return err_code
예제 #2
0
def run(analyzer, action):
    def signal_handler(*args, **kwargs):
        # Clang does not kill its child processes, so I have to
        try:
            g_pid = result.pid
            os.killpg(g_pid, signal.SIGTERM)
        finally:
            sys.exit(os.EX_OK)

    signal.signal(signal.SIGINT, signal_handler)
    current_cmd = list(analyzer.cmd)

    for checker_name, enabled in analyzer.checkers:
        if enabled:
            current_cmd.append('-Xclang')
            current_cmd.append('-analyzer-checker=' + checker_name)
        else:
            current_cmd.append('-Xclang')
            current_cmd.append('-analyzer-disable-checker')
            current_cmd.append('-Xclang')
            current_cmd.append(checker_name)

    current_cmd.extend(action.analyzer_options)

    # Add checker config
    if analyzer.config and analyzer.has_plugin:
        current_cmd.append('-Xclang')
        current_cmd.append('-plugin-arg-checkercfg')
        current_cmd.append('-Xclang')
        current_cmd.append(analyzer.config)

    # Set lang
    current_cmd.append('-x')
    current_cmd.append(action.lang)

    for source in action.sources:
        if analyzer.should_skip(source):
            LOG.debug(source + ' is skipped.')
            continue

        source_name = source[source.rfind('/') + 1:].replace('.', '_')
        if not os.path.exists(analyzer.workspace):
            os.mkdir(analyzer.workspace)
        report_plist = os.path.join(analyzer.workspace,
                                    source_name + '_' +
                                    str(action.id) + '.plist')

        extender = list()
        extender.append('-o')
        extender.append(report_plist)
        extender.append(source)

        check_cmd = current_cmd + extender

        check_cmd_str = ' '.join(check_cmd)

        with client.get_connection() as connection:

            action_id = connection.add_build_action(action.original_command,
                                                    check_cmd_str,
                                                    action.target)

            LOG.debug(' '.join(check_cmd))
            result = subprocess.Popen(check_cmd,
                                      bufsize=-1,
                                      env=analyzer.env,
                                      preexec_fn=os.setsid,
                                      stdout=subprocess.PIPE,
                                      stderr=subprocess.PIPE)
            (stdout, stderr) = result.communicate()

            failure = ''
            source_path, source_file = ntpath.split(source)
            if result.returncode != 0:
                failure = stdout + '\n' + stderr
                msg = 'Checking %s has failed.' % (source_file)
                LOG.debug(msg + '\n' + check_cmd_str + '\n' + failure)

                LOG.info(msg)
            else:
                client.send_plist_content(connection, report_plist, action_id,
                                          analyzer.run_id,
                                          analyzer.severity_map,
                                          analyzer.should_skip,
                                          analyzer.module_id)
                msg = 'Checking %s is done.' % (source_file)
                LOG.debug(msg + '\n' + check_cmd_str)
                LOG.info(msg)

            LOG.debug(stdout)
            LOG.debug(stderr)

            connection.finish_build_action(action_id, failure)

        return result.returncode