Ejemplo n.º 1
0
    def construct_config_handler(cls, args, context):
        handler = config_handler_clangsa.ClangSAConfigHandler()
        handler.analyzer_plugins_dir = context.checker_plugin
        handler.analyzer_binary = context.analyzer_binaries.get(
            cls.ANALYZER_NAME)
        handler.compiler_resource_dir = \
            host_check.get_resource_dir(handler.analyzer_binary, context)

        handler.report_hash = args.report_hash \
            if 'report_hash' in args else None

        check_env = analyzer_env.get_check_env(context.path_env_extra,
                                               context.ld_lib_path_extra)

        if 'ctu_phases' in args:
            handler.ctu_dir = os.path.join(args.output_path, args.ctu_dir)

            handler.ctu_has_analyzer_display_ctu_progress = \
                host_check.has_analyzer_feature(
                    context.analyzer_binaries.get(cls.ANALYZER_NAME),
                    '-analyzer-display-ctu-progress',
                    check_env)
            handler.log_file = args.logfile
            handler.path_env_extra = context.path_env_extra
            handler.ld_lib_path_extra = context.ld_lib_path_extra

        try:
            with open(args.clangsa_args_cfg_file, 'rb') as sa_cfg:
                handler.analyzer_extra_arguments = \
                    re.sub(r'\$\((.*?)\)',
                           replace_env_var(args.clangsa_args_cfg_file),
                           sa_cfg.read().strip())
        except IOError as ioerr:
            LOG.debug_analyzer(ioerr)
        except AttributeError as aerr:
            # No clangsa arguments file was given in the command line.
            LOG.debug_analyzer(aerr)

        checkers = ClangSA.get_analyzer_checkers(handler, check_env)

        # Read clang-sa checkers from the config file.
        clang_sa_checkers = context.checker_config.get(cls.ANALYZER_NAME +
                                                       '_checkers')

        try:
            cmdline_checkers = args.ordered_checkers
        except AttributeError:
            LOG.debug_analyzer('No checkers were defined in '
                               'the command line for ' + cls.ANALYZER_NAME)
            cmdline_checkers = None

        handler.initialize_checkers(context.available_profiles,
                                    context.package_root, checkers,
                                    clang_sa_checkers, cmdline_checkers,
                                    'enable_all' in args and args.enable_all)

        return handler
Ejemplo n.º 2
0
def __get_compiler_resource_dir(context, analyzer_binary):
    if context.compiler_resource_dir:
        resource_dir = context.compiler_resource_dir
    # If not set then ask the binary for the resource dir.
    else:
        # Can be None if Clang is too old.
        resource_dir = host_check.get_resource_dir(analyzer_binary)
        if resource_dir is None:
            resource_dir = ""
    return resource_dir
Ejemplo n.º 3
0
    def construct_config_handler(cls, args, context):
        handler = config_handler_clang_tidy.ClangTidyConfigHandler()
        handler.analyzer_binary = context.analyzer_binaries.get(
            cls.ANALYZER_NAME)

        # FIXME We cannot get the resource dir from the clang-tidy binary,
        # therefore we get a sibling clang binary which of clang-tidy.
        # TODO Support "clang-tidy -print-resource-dir" .
        check_env = analyzer_env.get_check_env(context.path_env_extra,
                                               context.ld_lib_path_extra)
        # Overwrite PATH to contain only the parent of the clang binary.
        if os.path.isabs(handler.analyzer_binary):
            check_env['PATH'] = os.path.dirname(handler.analyzer_binary)
        clang_bin = ClangSA.resolve_missing_binary('clang', check_env)
        handler.compiler_resource_dir = \
            host_check.get_resource_dir(clang_bin, context)

        try:
            with open(args.tidy_args_cfg_file, 'rb') as tidy_cfg:
                handler.analyzer_extra_arguments = \
                    re.sub(r'\$\((.*?)\)', replace_env_var,
                           tidy_cfg.read().strip())
        except IOError as ioerr:
            LOG.debug_analyzer(ioerr)
        except AttributeError as aerr:
            # No clang tidy arguments file was given in the command line.
            LOG.debug_analyzer(aerr)

        try:
            # The config file dumped by clang-tidy contains "..." at the end.
            # This has to be emitted, otherwise -config flag of clang-tidy
            # cannot consume it.
            with open(args.tidy_config, 'rb') as tidy_config:
                lines = tidy_config.readlines()
                lines = filter(lambda x: x != '...\n', lines)
                handler.checker_config = ''.join(lines)
        except IOError as ioerr:
            LOG.debug_analyzer(ioerr)
        except AttributeError as aerr:
            # No clang tidy config file was given in the command line.
            LOG.debug_analyzer(aerr)

        check_env = analyzer_env.get_check_env(context.path_env_extra,
                                               context.ld_lib_path_extra)

        checkers = ClangTidy.get_analyzer_checkers(handler, check_env)

        # Read clang-tidy checkers from the config file.
        clang_tidy_checkers = context.checker_config.get(cls.ANALYZER_NAME +
                                                         '_checkers')

        try:
            cmdline_checkers = args.ordered_checkers
        except AttributeError:
            LOG.debug_analyzer('No checkers were defined in '
                               'the command line for ' + cls.ANALYZER_NAME)
            cmdline_checkers = None

        handler.initialize_checkers(context.available_profiles,
                                    context.package_root, checkers,
                                    clang_tidy_checkers, cmdline_checkers,
                                    'enable_all' in args and args.enable_all)

        return handler