From 863b4160fccadff4606d6a7b697d6046ce7c74ce Mon Sep 17 00:00:00 2001 From: Nikos Gorogiannis Date: Tue, 19 May 2020 01:21:41 -0700 Subject: [PATCH] [buck] move config flags to Buck module Summary: Centralise buck-config management. Reviewed By: jberdine Differential Revision: D21600336 fbshipit-source-id: 5c7d7e2f1 --- infer/src/integration/Buck.ml | 38 +++++++++++++++++++++---- infer/src/integration/Buck.mli | 7 ++++- infer/src/integration/BuckFlavors.ml | 42 ++++------------------------ infer/src/integration/BuckGenrule.ml | 2 +- 4 files changed, 45 insertions(+), 44 deletions(-) diff --git a/infer/src/integration/Buck.ml b/infer/src/integration/Buck.ml index 04b3a3cd4..dd2de3f4b 100644 --- a/infer/src/integration/Buck.ml +++ b/infer/src/integration/Buck.ml @@ -209,11 +209,37 @@ let infer_enabled_label = "infer_enabled" (** for genrule_master_mode, this is the target name suffix for the capture genrules *) let genrule_suffix = "_infer" -let buck_config buck_mode = - if BuckMode.is_java_genrule_master buck_mode then - ["infer.version=" ^ Version.versionString; "infer.mode=capture"] - |> List.fold ~init:[] ~f:(fun acc f -> "--config" :: f :: acc) - else [] +let config buck_mode = + let clang_path = + List.fold ["clang"; "install"; "bin"; "clang"] ~init:Config.fcp_dir ~f:Filename.concat + in + let args = + match (buck_mode : BuckMode.t) with + | JavaGenruleMaster -> + ["infer.version=" ^ Version.versionString; "infer.mode=capture"] + | ClangFlavors -> + [ "client.id=infer.clang" + ; Printf.sprintf "*//infer.infer_bin=%s" Config.bin_dir + ; Printf.sprintf "*//infer.clang_compiler=%s" clang_path + ; Printf.sprintf "*//infer.clang_plugin=%s" Config.clang_plugin_path + ; "*//cxx.pch_enabled=false" + ; (* Infer doesn't support C++ modules yet (T35656509) *) + "*//cxx.modules_default=false" + ; "*//cxx.modules=false" ] + @ ( match Config.xcode_developer_dir with + | Some d -> + [Printf.sprintf "apple.xcode_developer_dir=%s" d] + | None -> + [] ) + @ + if List.is_empty Config.buck_blacklist then [] + else + [ Printf.sprintf "*//infer.blacklist_regex=(%s)" + (String.concat ~sep:")|(" Config.buck_blacklist) ] + | ClangCompilationDB _ -> + [] + in + List.fold args ~init:[] ~f:(fun acc f -> "--config" :: f :: acc) let resolve_pattern_targets (buck_mode : BuckMode.t) ~filter_kind targets = @@ -229,7 +255,7 @@ let resolve_pattern_targets (buck_mode : BuckMode.t) ~filter_kind targets = |> ( if BuckMode.is_java_genrule_master buck_mode then Query.label_filter ~label:infer_enabled_label else Fn.id ) - |> Query.exec ~buck_config:(buck_config buck_mode) + |> Query.exec ~buck_config:(config buck_mode) |> if BuckMode.is_java_genrule_master buck_mode then List.rev_map ~f:(fun s -> s ^ genrule_suffix) else Fn.id diff --git a/infer/src/integration/Buck.mli b/infer/src/integration/Buck.mli index 8660d6372..0b75620d7 100644 --- a/infer/src/integration/Buck.mli +++ b/infer/src/integration/Buck.mli @@ -29,13 +29,18 @@ val wrap_buck_call : quick identification; [cmd] is a list of strings making up the shell command to execute; the return value is the standard output of the command split on newlines. *) -val buck_config : BuckMode.t -> string list +val config : BuckMode.t -> string list +(** return list of string parameters of the form + ["--config" :: param_a :: "--config" :: param_b :: ...] describing the buck config flags for the + given Buck mode. *) val parse_command_and_targets : BuckMode.t -> filter_kind:[< `Yes | `No | `Auto] -> string list -> string * string list * string list +(** parses given buck command, using the buck configuration returned by [config] above and returns a + triple [(buck_command, non_target_params, target_params)] *) val store_args_in_file : string list -> string list (** Given a list of arguments, stores them in a file if needed and returns the new command line *) diff --git a/infer/src/integration/BuckFlavors.ml b/infer/src/integration/BuckFlavors.ml index 46767f3e6..bdb9c8719 100644 --- a/infer/src/integration/BuckFlavors.ml +++ b/infer/src/integration/BuckFlavors.ml @@ -23,41 +23,11 @@ let add_flavors_to_buck_arguments buck_mode ~filter_kind ~extra_flavors original {command; rev_not_targets; targets} -let capture_buck_args = - let clang_path = - List.fold ["clang"; "install"; "bin"; "clang"] ~init:Config.fcp_dir ~f:Filename.concat - in - List.append - [ "--show-output" - ; "--config" - ; "client.id=infer.clang" - ; "--config" - ; Printf.sprintf "*//infer.infer_bin=%s" Config.bin_dir - ; "--config" - ; Printf.sprintf "*//infer.clang_compiler=%s" clang_path - ; "--config" - ; Printf.sprintf "*//infer.clang_plugin=%s" Config.clang_plugin_path - ; "--config" - ; "*//cxx.pch_enabled=false" - ; "--config" - ; (* Infer doesn't support C++ modules yet (T35656509) *) - "*//cxx.modules_default=false" - ; "--config" - ; "*//cxx.modules=false" ] - ( ( match Config.xcode_developer_dir with - | Some d -> - ["--config"; Printf.sprintf "apple.xcode_developer_dir=%s" d] - | None -> - [] ) - @ (if Config.keep_going then ["--keep-going"] else []) - @ ["-j"; Int.to_string Config.jobs] - @ (match Config.load_average with Some l -> ["-L"; Float.to_string l] | None -> []) - @ List.rev_append Config.buck_build_args - ( if not (List.is_empty Config.buck_blacklist) then - [ "--config" - ; Printf.sprintf "*//infer.blacklist_regex=(%s)" - (String.concat ~sep:")|(" Config.buck_blacklist) ] - else [] ) ) +let capture_buck_args () = + ["--show-output"; "-j"; Int.to_string Config.jobs] + @ (if Config.keep_going then ["--keep-going"] else []) + @ (match Config.load_average with Some l -> ["-L"; Float.to_string l] | None -> []) + @ Buck.config ClangFlavors @ List.rev Config.buck_build_args let run_buck_build prog buck_build_args = @@ -121,7 +91,7 @@ let merge_deps_files depsfiles = let clang_flavor_capture ~prog ~buck_build_cmd = if Config.keep_going && not Config.continue_capture then Process.create_process_and_wait ~prog ~args:["clean"] ; - let depsfiles = run_buck_build prog (buck_build_cmd @ capture_buck_args) in + let depsfiles = run_buck_build prog (buck_build_cmd @ capture_buck_args ()) in let deplines = merge_deps_files depsfiles in let infer_out_depsfile = ResultsDir.get_path BuckDependencies in Utils.with_file_out infer_out_depsfile ~f:(fun out_chan -> diff --git a/infer/src/integration/BuckGenrule.ml b/infer/src/integration/BuckGenrule.ml index 4cb90fc61..af61c9f84 100644 --- a/infer/src/integration/BuckGenrule.ml +++ b/infer/src/integration/BuckGenrule.ml @@ -121,7 +121,7 @@ let capture build_cmd = in let updated_buck_cmd = (* make buck tell us where in buck-out are the capture directories for merging *) - (prog :: command :: "--build-report" :: build_report_file :: Buck.buck_config JavaGenruleMaster) + (prog :: command :: "--build-report" :: build_report_file :: Buck.config JavaGenruleMaster) @ List.rev_append Config.buck_build_args_no_inline (Buck.store_args_in_file all_args) in L.(debug Capture Quiet)