예제 #1
0
def analyze_compiler_wrapper_impl(result, execution):
    """ Implements analyzer compiler wrapper functionality. """

    # don't run analyzer when compilation fails. or when it's not requested.
    if result or not os.getenv('ANALYZE_BUILD_CLANG'):
        return

    # check is it a compilation?
    compilation = split_command(execution.cmd)
    if compilation is None:
        return
    # collect the needed parameters from environment, crash when missing
    parameters = {
        'clang': os.getenv('ANALYZE_BUILD_CLANG'),
        'output_dir': os.getenv('ANALYZE_BUILD_REPORT_DIR'),
        'output_format': os.getenv('ANALYZE_BUILD_REPORT_FORMAT'),
        'output_failures': os.getenv('ANALYZE_BUILD_REPORT_FAILURES'),
        'direct_args': os.getenv('ANALYZE_BUILD_PARAMETERS',
                                 '').split(' '),
        'force_debug': os.getenv('ANALYZE_BUILD_FORCE_DEBUG'),
        'directory': execution.cwd,
        'command': [execution.cmd[0], '-c'] + compilation.flags
    }
    # call static analyzer against the compilation
    for source in compilation.files:
        parameters.update({'file': source})
        logging.debug('analyzer parameters %s', parameters)
        current = run(parameters)
        # display error message from the static analyzer
        if current is not None:
            for line in current['error_output']:
                logging.info(line.rstrip())
예제 #2
0
파일: analyze.py 프로젝트: pombredanne/Beye
def analyze_build_wrapper(**kwargs):
    """ Entry point for `analyze-cc` and `analyze-c++` compiler wrappers. """

    # don't run analyzer when compilation fails.
    if kwargs['result'] or not os.getenv('ANALYZE_BUILD_CLANG'):
        return
    # don't run analyzer when the command is not a compilation
    # (can be preprocessing or a linking only execution of the compiler)
    compilation = split_command(kwargs['command'])
    if compilation is None:
        return
    # collect the needed parameters from environment, crash when missing
    env = os.environ.copy()
    parameters = {
        'clang': env['ANALYZE_BUILD_CLANG'],
        'output_dir': env['ANALYZE_BUILD_REPORT_DIR'],
        'output_format': env['ANALYZE_BUILD_REPORT_FORMAT'],
        'output_failures': env.get('ANALYZE_BUILD_REPORT_FAILURES', False),
        'direct_args': env.get('ANALYZE_BUILD_PARAMETERS', '').split(' '),
        'force_debug': env.get('ANALYZE_BUILD_FORCE_DEBUG', False),
        'directory': os.getcwd(),
        'command': [kwargs['compiler'], '-c'] + compilation.flags
    }
    # call static analyzer against the compilation
    for source in compilation.files:
        current = run(dict(parameters, file=source))
        # display error message from the static analyzer
        logging_analyzer_output(current)
예제 #3
0
def analyze_build_wrapper(cplusplus):
    """ Entry point for `analyze-cc` and `analyze-c++` compiler wrappers. """

    # initialize wrapper logging
    logging.basicConfig(format='analyze: %(levelname)s: %(message)s',
                        level=os.getenv('ANALYZE_BUILD_VERBOSE', 'INFO'))
    # execute with real compiler
    compiler = os.getenv('ANALYZE_BUILD_CXX', 'c++') if cplusplus \
        else os.getenv('ANALYZE_BUILD_CC', 'cc')
    compilation = [compiler] + sys.argv[1:]
    logging.info('execute compiler: %s', compilation)
    result = subprocess.call(compilation)
    # exit when it fails, ...
    if result or not os.getenv('ANALYZE_BUILD_CLANG'):
        return result
    # ... and run the analyzer if all went well.
    try:
        # check is it a compilation
        compilation = split_command(sys.argv)
        if compilation is None:
            return result
        # collect the needed parameters from environment, crash when missing
        parameters = {
            'clang': os.getenv('ANALYZE_BUILD_CLANG'),
            'output_dir': os.getenv('ANALYZE_BUILD_REPORT_DIR'),
            'output_format': os.getenv('ANALYZE_BUILD_REPORT_FORMAT'),
            'output_failures': os.getenv('ANALYZE_BUILD_REPORT_FAILURES'),
            'direct_args': os.getenv('ANALYZE_BUILD_PARAMETERS',
                                     '').split(' '),
            'force_debug': os.getenv('ANALYZE_BUILD_FORCE_DEBUG'),
            'directory': os.getcwd(),
            'command': [sys.argv[0], '-c'] + compilation.flags
        }
        # call static analyzer against the compilation
        for source in compilation.files:
            parameters.update({'file': source})
            logging.debug('analyzer parameters %s', parameters)
            current = run(parameters)
            # display error message from the static analyzer
            if current is not None:
                for line in current['error_output']:
                    logging.info(line.rstrip())
    except Exception:
        logging.exception("run analyzer inside compiler wrapper failed.")
    return result
예제 #4
0
파일: analyze.py 프로젝트: AnachroNia/clang
def analyze_build_wrapper(cplusplus):
    """ Entry point for `analyze-cc` and `analyze-c++` compiler wrappers. """

    # initialize wrapper logging
    logging.basicConfig(format='analyze: %(levelname)s: %(message)s',
                        level=os.getenv('ANALYZE_BUILD_VERBOSE', 'INFO'))
    # execute with real compiler
    compiler = os.getenv('ANALYZE_BUILD_CXX', 'c++') if cplusplus \
        else os.getenv('ANALYZE_BUILD_CC', 'cc')
    compilation = [compiler] + sys.argv[1:]
    logging.info('execute compiler: %s', compilation)
    result = subprocess.call(compilation)
    # exit when it fails, ...
    if result or not os.getenv('ANALYZE_BUILD_CLANG'):
        return result
    # ... and run the analyzer if all went well.
    try:
        # check is it a compilation
        compilation = split_command(sys.argv)
        if compilation is None:
            return result
        # collect the needed parameters from environment, crash when missing
        parameters = {
            'clang': os.getenv('ANALYZE_BUILD_CLANG'),
            'output_dir': os.getenv('ANALYZE_BUILD_REPORT_DIR'),
            'output_format': os.getenv('ANALYZE_BUILD_REPORT_FORMAT'),
            'output_failures': os.getenv('ANALYZE_BUILD_REPORT_FAILURES'),
            'direct_args': os.getenv('ANALYZE_BUILD_PARAMETERS',
                                     '').split(' '),
            'force_debug': os.getenv('ANALYZE_BUILD_FORCE_DEBUG'),
            'directory': os.getcwd(),
            'command': [sys.argv[0], '-c'] + compilation.flags
        }
        # call static analyzer against the compilation
        for source in compilation.files:
            parameters.update({'file': source})
            logging.debug('analyzer parameters %s', parameters)
            current = run(parameters)
            # display error message from the static analyzer
            if current is not None:
                for line in current['error_output']:
                    logging.info(line.rstrip())
    except Exception:
        logging.exception("run analyzer inside compiler wrapper failed.")
    return result