[config] Allow regex in --skip-translation-headers

Reviewed By: ngorogiannis

Differential Revision: D28363661

fbshipit-source-id: 30817cbba
master
Daiva Naudziuniene 4 years ago committed by Facebook GitHub Bot
parent 9980c4f614
commit 6d75961a87

@ -267,8 +267,9 @@ CLANG OPTIONS
Activates: Skip clang commands that Infer doesn't use to capture
data (Conversely: --no-skip-non-capture-clang-commands)
--skip-translation-headers +path_prefix
Ignore headers whose path matches the given prefix
--skip-translation-headers +path_regex
Ignore declarations in headers whose path matches the given OCaml
regex from the start of the string during capture.
--Xclang +string
Pass values as command-line arguments to invocations of clang

@ -1203,8 +1203,9 @@ OPTIONS
data (Conversely: --no-skip-non-capture-clang-commands)
See also infer-capture(1).
--skip-translation-headers +path_prefix
Ignore headers whose path matches the given prefix See also infer-capture(1).
--skip-translation-headers +path_regex
Ignore declarations in headers whose path matches the given OCaml
regex from the start of the string during capture. See also infer-capture(1).
--source-files
Activates: Print source files discovered by infer (Conversely:

@ -1203,8 +1203,9 @@ OPTIONS
data (Conversely: --no-skip-non-capture-clang-commands)
See also infer-capture(1).
--skip-translation-headers +path_prefix
Ignore headers whose path matches the given prefix See also infer-capture(1).
--skip-translation-headers +path_regex
Ignore declarations in headers whose path matches the given OCaml
regex from the start of the string during capture. See also infer-capture(1).
--source-files
Activates: Print source files discovered by infer (Conversely:

@ -2330,7 +2330,9 @@ and skip_non_capture_clang_commands =
and skip_translation_headers =
CLOpt.mk_string_list ~deprecated:["skip_translation_headers"] ~long:"skip-translation-headers"
~in_help:InferCommand.[(Capture, manual_clang)]
~meta:"path_prefix" "Ignore headers whose path matches the given prefix"
~meta:"path_regex"
"Ignore declarations in headers whose path matches the given OCaml regex from the start of the \
string during capture."
and source_preview =

@ -20,14 +20,19 @@ let clang_to_sil_location default_source_file clang_loc =
Location.{line; col; file}
let matches_skip_translation_headers =
match Config.skip_translation_headers with
| [] ->
fun _ -> false
| reg_list ->
let regex = Re.Str.regexp (String.concat ~sep:"\\|" reg_list) in
fun file -> Re.Str.string_match regex file 0
let source_file_in_project source_file =
let file_in_project = SourceFile.is_under_project_root source_file in
let rel_source_file = SourceFile.to_string source_file in
let file_should_be_skipped =
List.exists
~f:(fun path -> String.is_prefix ~prefix:path rel_source_file)
Config.skip_translation_headers
in
let source_file_path = SourceFile.to_string source_file in
let file_should_be_skipped = matches_skip_translation_headers source_file_path in
file_in_project && not file_should_be_skipped

Loading…
Cancel
Save