[clang] new option to override `-I` paths

Summary: This is needed sometimes.

Reviewed By: mbouaziz

Differential Revision: D15469652

fbshipit-source-id: f5c5ca957
master
Jules Villard 6 years ago committed by Facebook Github Bot
parent 2fff66b1c9
commit 8330394eff

@ -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 <path matching the
regex> with -isystem
/path/to/infer/facebook-clang-plugins/clang/install/lib/clang/<version>/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 <path matching the regex> 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

@ -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 <path matching the regex>) with $(b,-isystem \
/path/to/infer/facebook-clang-plugins/clang/install/lib/clang/<version>/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 <path matching the regex>) 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

@ -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

@ -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

Loading…
Cancel
Save