From 8330394effaca50c7559d992d6c3dc4116fdfa28 Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Tue, 28 May 2019 07:10:37 -0700 Subject: [PATCH] [clang] new option to override `-I` paths Summary: This is needed sometimes. Reviewed By: mbouaziz Differential Revision: D15469652 fbshipit-source-id: f5c5ca957 --- infer/man/man1/infer-full.txt | 19 +++++++++++++++---- infer/src/base/Config.ml | 30 +++++++++++++++++++++--------- infer/src/base/Config.mli | 4 +++- infer/src/clang/ClangCommand.ml | 15 +++++++++++++-- 4 files changed, 52 insertions(+), 16 deletions(-) diff --git a/infer/man/man1/infer-full.txt b/infer/man/man1/infer-full.txt index 5e71cc46d..c3009b0db 100644 --- a/infer/man/man1/infer-full.txt +++ b/infer/man/man1/infer-full.txt @@ -1187,15 +1187,26 @@ INTERNAL OPTIONS --clang-ignore-regex-reset Cancel the effect of --clang-ignore-regex. - --clang-include-to-override-regex dir_OCaml_regex + --clang-isystem-to-override-regex dir_OCaml_regex Use this option in the uncommon case where the normal compilation process overrides the location of internal compiler headers. This option should specify regular expression with the path to those headers so that infer can use its own clang internal headers - instead. + instead. Concretely, this will replace -isystem with -isystem + /path/to/infer/facebook-clang-plugins/clang/install/lib/clang//include. - --clang-include-to-override-regex-reset - Cancel the effect of --clang-include-to-override-regex. + --clang-isystem-to-override-regex-reset + Cancel the effect of --clang-isystem-to-override-regex. + + --clang-libcxx-include-to-override-regex dir_OCaml_regex + Use this option in the uncommon case where the normal compilation + process overrides the location of libc++. Concretely, this will + replace -I with -I + /path/to/infer/facebook-clang-plugins/clang/install/include/c++/v1. + + --clang-libcxx-include-to-override-regex-reset + Cancel the effect of --clang-libcxx-include-to-override-regex. --class-loads-roots +string Report class loads of this list of Java methods diff --git a/infer/src/base/Config.ml b/infer/src/base/Config.ml index bf625b1f3..2fc275f41 100644 --- a/infer/src/base/Config.ml +++ b/infer/src/base/Config.ml @@ -914,14 +914,6 @@ and clang_frontend_action = "use --capture and --linters instead" ~symbols:clang_frontend_action_symbols -and clang_include_to_override_regex = - CLOpt.mk_string_opt ~long:"clang-include-to-override-regex" - ~deprecated:["-clang-include-to-override"] ~meta:"dir_OCaml_regex" - "Use this option in the uncommon case where the normal compilation process overrides the \ - location of internal compiler headers. This option should specify regular expression with \ - the path to those headers so that infer can use its own clang internal headers instead." - - and clang_ignore_regex = CLOpt.mk_string_opt ~long:"clang-ignore-regex" ~meta:"dir_OCaml_regex" "The files in this regex will be ignored in the compilation process and an empty file will be \ @@ -929,6 +921,24 @@ and clang_ignore_regex = around missing generated files." +and clang_isystem_to_override_regex = + CLOpt.mk_string_opt ~long:"clang-isystem-to-override-regex" + ~deprecated:["-clang-include-to-override-regex"; "-clang-include-to-override"] + ~meta:"dir_OCaml_regex" + "Use this option in the uncommon case where the normal compilation process overrides the \ + location of internal compiler headers. This option should specify regular expression with \ + the path to those headers so that infer can use its own clang internal headers instead. \ + Concretely, this will replace $(b,-isystem ) with $(b,-isystem \ + /path/to/infer/facebook-clang-plugins/clang/install/lib/clang//include)." + + +and clang_libcxx_include_to_override_regex = + CLOpt.mk_string_opt ~long:"clang-libcxx-include-to-override-regex" ~meta:"dir_OCaml_regex" + "Use this option in the uncommon case where the normal compilation process overrides the \ + location of libc++. Concretely, this will replace $(b,-I ) with \ + $(b,-I /path/to/infer/facebook-clang-plugins/clang/install/include/c++/v1)." + + and class_loads_roots = CLOpt.mk_string_list ~long:"class-loads-roots" "Report class loads of this list of Java methods" @@ -2650,7 +2660,9 @@ and clang_extra_flags = !clang_extra_flags and clang_ignore_regex = !clang_ignore_regex -and clang_include_to_override_regex = !clang_include_to_override_regex +and clang_isystem_to_override_regex = !clang_isystem_to_override_regex + +and clang_libcxx_include_to_override_regex = !clang_libcxx_include_to_override_regex and classpath = !classpath diff --git a/infer/src/base/Config.mli b/infer/src/base/Config.mli index 2c46fdf0f..9177bb470 100644 --- a/infer/src/base/Config.mli +++ b/infer/src/base/Config.mli @@ -280,7 +280,9 @@ val clang_frontend_action_string : string val clang_ignore_regex : string option -val clang_include_to_override_regex : string option +val clang_isystem_to_override_regex : string option + +val clang_libcxx_include_to_override_regex : string option val class_loads : bool diff --git a/infer/src/clang/ClangCommand.ml b/infer/src/clang/ClangCommand.ml index 7678bb31a..ea3dcdbc4 100644 --- a/infer/src/clang/ClangCommand.ml +++ b/infer/src/clang/ClangCommand.ml @@ -84,7 +84,11 @@ let file_arg_cmd_sanitizer cmd = {cmd with argv= [Format.sprintf "@%s" file]} -let include_override_regex = Option.map ~f:Str.regexp Config.clang_include_to_override_regex +let isystem_to_override_regex = Option.map ~f:Str.regexp Config.clang_isystem_to_override_regex + +let libcxx_include_to_override_regex = + Option.map ~f:Str.regexp Config.clang_libcxx_include_to_override_regex + (** Filter arguments from [args], looking into argfiles too. [replace_options_arg prev arg] returns [arg'], where [arg'] is the new version of [arg] given the preceding arguments (in reverse order) [prev]. *) @@ -161,11 +165,18 @@ let clang_cc1_cmd_sanitizer cmd = (* In compilation database mode, dependency files are not assumed to exist *) "/dev/null" | "-isystem" :: _, arg -> ( - match include_override_regex with + match isystem_to_override_regex with | Some isystem_to_override_regex when Str.string_match isystem_to_override_regex arg 0 -> fcp_dir ^/ "clang" ^/ "install" ^/ "lib" ^/ "clang" ^/ "7.0.1" ^/ "include" | _ -> arg ) + | "-I" :: _, arg -> ( + match libcxx_include_to_override_regex with + | Some libcxx_include_to_override_regex + when Str.string_match libcxx_include_to_override_regex arg 0 -> + fcp_dir ^/ "clang" ^/ "install" ^/ "include" ^/ "c++" ^/ "v1" + | _ -> + arg ) | _ -> arg in