From 451f8f1efa1e17f90ab283c2d147eb0e3b70feb4 Mon Sep 17 00:00:00 2001 From: Martin Trojer Date: Wed, 15 Aug 2018 08:18:55 -0700 Subject: [PATCH] Add --Xbuck-no-inline and --Xclang flags to enable jackalope/ios builds. Reviewed By: jvillard Differential Revision: D9296445 fbshipit-source-id: 196e527eb --- infer/src/base/Config.ml | 17 +++++++++ infer/src/base/Config.mli | 4 ++ infer/src/clang/ClangCommand.ml | 1 + infer/src/integration/Buck.ml | 2 +- .../integration/CaptureCompilationDatabase.ml | 10 ++--- infer/src/integration/Driver.ml | 38 ++++++++++++------- 6 files changed, 52 insertions(+), 20 deletions(-) diff --git a/infer/src/base/Config.ml b/infer/src/base/Config.ml index f8b2dd3b0..9903bf072 100644 --- a/infer/src/base/Config.ml +++ b/infer/src/base/Config.ml @@ -843,6 +843,13 @@ and buck_build_args = "Pass values as command-line arguments to invocations of $(i,`buck build`)" +and buck_build_args_no_inline = + CLOpt.mk_string_list ~long:"Xbuck-no-inline" + ~in_help:InferCommand.[(Capture, manual_buck_flavors)] + "Pass values as command-line arguments to invocations of $(i,`buck build`), don't inline any \ + args starting with '@'" + + and buck_compilation_database_depth = CLOpt.mk_int_opt ~long:"buck-compilation-database-depth" ~in_help:InferCommand.[(Capture, manual_buck_compilation_db)] @@ -888,6 +895,12 @@ and clang_biniou_file = ~meta:"file" "Specify a file containing the AST of the program, in biniou format" +and clang_extra_flags = + CLOpt.mk_string_list ~long:"Xclang" + ~in_help:InferCommand.[(Capture, manual_clang)] + "Pass values as command-line arguments to invocations of clang" + + and clang_compilation_dbs = ref [] and clang_frontend_action = @@ -2457,6 +2470,8 @@ and buck = !buck and buck_build_args = !buck_build_args +and buck_build_args_no_inline = !buck_build_args_no_inline + and buck_cache_mode = (!buck || !genrule_mode) && not !debug and buck_compilation_database = @@ -2492,6 +2507,8 @@ and check_version = !check_version and clang_biniou_file = !clang_biniou_file +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 diff --git a/infer/src/base/Config.mli b/infer/src/base/Config.mli index aca0ab6b5..8f8f710fc 100644 --- a/infer/src/base/Config.mli +++ b/infer/src/base/Config.mli @@ -246,6 +246,8 @@ val buck : bool val buck_build_args : string list +val buck_build_args_no_inline : string list + val buck_cache_mode : bool val buck_compilation_database : compilation_database_dependencies option @@ -267,6 +269,8 @@ val check_version : string option val clang_biniou_file : string option +val clang_extra_flags : string list + val clang_frontend_action_string : string val clang_ignore_regex : string option diff --git a/infer/src/clang/ClangCommand.ml b/infer/src/clang/ClangCommand.ml index b4d691a35..d22350eac 100644 --- a/infer/src/clang/ClangCommand.ml +++ b/infer/src/clang/ClangCommand.ml @@ -190,6 +190,7 @@ let mk ~is_driver quoting_style ~prog ~args = let sanitized_args = filter_and_replace_unsupported_args ~blacklisted_flags:clang_blacklisted_flags ~blacklisted_flags_with_arg args + @ List.rev Config.clang_extra_flags in {exec= prog; orig_argv= sanitized_args; argv= sanitized_args; quoting_style; is_driver} diff --git a/infer/src/integration/Buck.ml b/infer/src/integration/Buck.ml index 7bcd9ec63..bd992a0f6 100644 --- a/infer/src/integration/Buck.ml +++ b/infer/src/integration/Buck.ml @@ -117,7 +117,7 @@ module Query = struct let exec expr = let query = F.asprintf "%a" pp expr in - let cmd = ["buck"; "query"; query] in + let cmd = ["buck"; "query"] @ List.rev_append Config.buck_build_args_no_inline [query] in let tmp_prefix = "buck_query_" in let debug = L.(debug Capture Medium) in Utils.with_process_lines ~debug ~cmd ~tmp_prefix ~f:Fn.id diff --git a/infer/src/integration/CaptureCompilationDatabase.ml b/infer/src/integration/CaptureCompilationDatabase.ml index 076365094..d9283cd33 100644 --- a/infer/src/integration/CaptureCompilationDatabase.ml +++ b/infer/src/integration/CaptureCompilationDatabase.ml @@ -21,7 +21,7 @@ let create_cmd (source_file, (compilation_data: CompilationDatabase.compilation_ ( source_file , { CompilationDatabase.directory= compilation_data.directory ; executable= swap_executable compilation_data.executable - ; escaped_arguments= ["@" ^ arg_file; "-fsyntax-only"] } ) + ; escaped_arguments= ["@" ^ arg_file; "-fsyntax-only"] @ List.rev Config.clang_extra_flags } ) let invoke_cmd (source_file, (cmd: CompilationDatabase.compilation_data)) = @@ -74,9 +74,8 @@ let get_compilation_database_files_buck ~prog ~args = | {command= "build" as command; rev_not_targets; targets} -> let targets_args = Buck.store_args_in_file targets in let build_args = - command - :: List.rev_append rev_not_targets - ("--config" :: "*//cxx.pch_enabled=false" :: targets_args) + command :: List.rev_append rev_not_targets (List.rev Config.buck_build_args_no_inline) + @ "--config" :: "*//cxx.pch_enabled=false" :: targets_args in Logging.(debug Linters Quiet) "Processed buck command is: 'buck %a'@\n" (Pp.seq F.pp_print_string) build_args ; @@ -86,7 +85,8 @@ let get_compilation_database_files_buck ~prog ~args = :: "targets" :: List.rev_append (Buck.filter_compatible `Targets rev_not_targets) - ("--show-output" :: targets_args) + (List.rev Config.buck_build_args_no_inline) + @ "--show-output" :: targets_args in let on_target_lines = function | [] -> diff --git a/infer/src/integration/Driver.ml b/infer/src/integration/Driver.ml index 1fc21bb61..1923d7332 100644 --- a/infer/src/integration/Driver.ml +++ b/infer/src/integration/Driver.ml @@ -29,17 +29,24 @@ type mode = let equal_mode = [%compare.equal : mode] -let pp_mode fmt mode = - match mode with - | Analyze - | BuckGenrule _ - | BuckCompilationDB _ - | ClangCompilationDB _ - | Python _ - | PythonCapture (_, _) - | XcodeXcpretty _ -> - (* these are pretty boring, do not log anything *) - () +let pp_mode fmt = function + | Analyze -> + F.fprintf fmt "Analyze driver mode" + | BuckGenrule prog -> + F.fprintf fmt "BuckGenRule driver mode:@\nprog = '%s'" prog + | BuckCompilationDB (prog, args) -> + F.fprintf fmt "BuckCompilationDB driver mode:@\nprog = '%s'@\nargs = %a" prog Pp.cli_args + args + | ClangCompilationDB _ -> + F.fprintf fmt "ClangCompilationDB driver mode" + | Python args -> + F.fprintf fmt "Python driver mode:@\nargs = %a" Pp.cli_args args + | PythonCapture (bs, args) -> + F.fprintf fmt "PythonCapture driver mode:@\nbuild system = '%s'@\nargs = %a" + (Config.string_of_build_system bs) + Pp.cli_args args + | XcodeXcpretty (prog, args) -> + F.fprintf fmt "XcodeXcpretty driver mode:@\nprog = '%s'@\nargs = %a" prog Pp.cli_args args | Javac (_, prog, args) -> F.fprintf fmt "Javac driver mode:@\nprog = '%s'@\nargs = %a" prog Pp.cli_args args | Maven (prog, args) -> @@ -184,8 +191,7 @@ let capture_with_compilation_database db_files = CaptureCompilationDatabase.capture_files_in_database compilation_database -let capture ~changed_files mode = - match mode with +let capture ~changed_files = function | Analyze -> () | BuckCompilationDB (prog, args) -> @@ -271,7 +277,11 @@ let capture ~changed_files mode = ~extra_flavors:[] buck_args in let all_args = List.rev_append rev_not_targets targets in - let updated_buck_cmd = prog :: command :: Buck.store_args_in_file all_args in + let updated_buck_cmd = + [prog; command] + @ List.rev_append Config.buck_build_args_no_inline + (Buck.store_args_in_file all_args) + in Logging.(debug Capture Quiet) "Processed buck command '%a'@\n" (Pp.seq F.pp_print_string) updated_buck_cmd ; updated_buck_cmd )