From 77744eda97b9ea14ec72d1983edc5ad1ab342800 Mon Sep 17 00:00:00 2001 From: Andrey Epin Date: Thu, 13 Sep 2018 11:22:50 -0700 Subject: [PATCH] [infer][java] add support for Buck compilation commands with no source files Summary: Buck is allowing compiler commands with no source files and skipping them when using the in-memory complier mode. However, those commands are not skipped when using an external compiler. Simulating this behavior at the level of Infer. Reviewed By: mbouaziz, ngorogiannis Differential Revision: D9795043 fbshipit-source-id: e80cfa453 --- infer/src/integration/Javac.ml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/infer/src/integration/Javac.ml b/infer/src/integration/Javac.ml index a7241db29..6e36ffdc9 100644 --- a/infer/src/integration/Javac.ml +++ b/infer/src/integration/Javac.ml @@ -83,8 +83,25 @@ let compile compiler build_prog build_args = verbose_out_file +let no_source_file args = + let not_source_file arg = + let stripped_arg = String.strip ~drop:(fun char -> Char.equal char '\"') arg in + not (String.is_suffix ~suffix:".java" stripped_arg) + in + List.for_all args ~f:(fun arg -> + (* expand arg files *) + match String.chop_prefix ~prefix:"@" arg with + | None -> + not_source_file arg + | Some arg_file -> + List.for_all ~f:not_source_file (In_channel.read_lines arg_file) ) + + let capture compiler ~prog ~args = match (compiler, Config.capture_blacklist) with + (* Simulates Buck support for compilation commands with no source file *) + | _ when Config.buck_cache_mode && no_source_file args -> + () | Javac, Some blacklist when let re = Str.regexp blacklist in List.exists ~f:(fun arg -> Str.string_match re arg 0) args ->