def __build_clang_tidy_config_handler(args, context): """ Build the config handler for clang tidy analyzer. Handle config options from the command line and config files. """ config_handler = config_handler_clang_tidy.ClangTidyConfigHandler() config_handler.analyzer_binary = context.analyzer_binaries.get(CLANG_TIDY) # FIXME We cannot get the resource dir from the clang-tidy binary, # therefore now we get a clang binary which is a sibling of the 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(config_handler.analyzer_binary): check_env['PATH'] = os.path.dirname(config_handler.analyzer_binary) clang_bin = analyzer_clangsa.ClangSA.resolve_missing_binary( 'clang', check_env) if os.path.isfile(clang_bin): config_handler.compiler_resource_dir =\ __get_compiler_resource_dir(context, clang_bin) else: config_handler.compiler_resource_dir =\ __get_compiler_resource_dir(context, config_handler.analyzer_binary) try: with open(args.tidy_args_cfg_file, 'rb') as tidy_cfg: config_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) analyzer = construct_analyzer_type(CLANG_TIDY, config_handler, None) check_env = analyzer_env.get_check_env(context.path_env_extra, context.ld_lib_path_extra) checkers = analyzer.get_analyzer_checkers(config_handler, check_env) # Read clang-tidy checkers from the config file. clang_tidy_checkers = context.checker_config.get(CLANG_TIDY + '_checkers') try: cmdline_checkers = args.ordered_checkers except AttributeError: LOG.debug_analyzer('No checkers were defined in ' 'the command line for ' + CLANG_TIDY) cmdline_checkers = None initialize_checkers(config_handler, context.available_profiles, context.package_root, checkers, clang_tidy_checkers, cmdline_checkers, 'enable_all' in args and args.enable_all) return config_handler
def __build_clang_tidy_config_handler(args, context): """ Build the config handler for clang tidy analyzer. Handle config options from the command line and config files. """ config_handler = config_handler_clang_tidy.ClangTidyConfigHandler() config_handler.analyzer_binary = context.analyzer_binaries.get(CLANG_TIDY) config_handler.compiler_resource_dir = context.compiler_resource_dir try: with open(args.tidy_args_cfg_file, 'rb') as tidy_cfg: config_handler.analyzer_extra_arguments = \ re.sub('\$\((.*?)\)', __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) analyzer = construct_analyzer_type(CLANG_TIDY, config_handler, None) check_env = analyzer_env.get_check_env(context.path_env_extra, context.ld_lib_path_extra) checkers = analyzer.get_analyzer_checkers(config_handler, check_env) # Read clang-tidy checkers from the config file. clang_tidy_checkers = context.checker_config.get(CLANG_TIDY + '_checkers') try: cmdline_checkers = args.ordered_checkers except AttributeError: LOG.debug_analyzer('No checkers were defined in ' 'the command line for ' + CLANG_TIDY) cmdline_checkers = None initialize_checkers(config_handler, context.available_profiles, context.package_root, checkers, clang_tidy_checkers, cmdline_checkers, 'enable_all' in args and args.enable_all) return config_handler
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