From 2f21d223ac017801260c9049923c057c381d9d70 Mon Sep 17 00:00:00 2001 From: Nikos Gorogiannis Date: Mon, 1 Jul 2019 10:23:04 -0700 Subject: [PATCH] [buck] don't fail on empty list of targets found from query Reviewed By: jvillard Differential Revision: D16071738 fbshipit-source-id: 2cff0b931 --- infer/src/integration/Buck.ml | 19 +-- infer/src/integration/BuckGenrule.ml | 12 +- .../integration/CaptureCompilationDatabase.ml | 3 + infer/src/integration/Driver.ml | 115 ++++++++++-------- 4 files changed, 77 insertions(+), 72 deletions(-) diff --git a/infer/src/integration/Buck.ml b/infer/src/integration/Buck.ml index 31fa6ccd3..6d3908561 100644 --- a/infer/src/integration/Buck.ml +++ b/infer/src/integration/Buck.ml @@ -179,8 +179,7 @@ let resolve_pattern_targets ~filter_kind ~dep_depth targets = |> (if filter_kind then Query.kind ~pattern:(get_accepted_buck_kinds_pattern ()) else Fn.id) |> (if Config.genrule_master_mode then Query.label_filter ~label:infer_enabled_label else Fn.id) |> Query.exec ~buck_config:(Lazy.force buck_config) - |> (if Config.genrule_master_mode then List.rev_map ~f:(fun s -> s ^ genrule_suffix) else Fn.id) - |> die_if_empty (fun die -> die "*** buck query returned no targets.") + |> if Config.genrule_master_mode then List.rev_map ~f:(fun s -> s ^ genrule_suffix) else Fn.id let resolve_alias_targets aliases = @@ -292,17 +291,11 @@ let add_flavors_to_buck_arguments ~filter_kind ~dep_depth ~extra_flavors origina let command, rev_not_targets, targets = parse_command_and_targets ~filter_kind ~dep_depth original_buck_args in - match targets with - | [] -> - L.(die UserError) - "ERROR: no targets found in Buck command `%a`." (Pp.seq F.pp_print_string) - original_buck_args - | _ -> - let targets = - List.rev_map targets ~f:(fun t -> - Target.(t |> of_string |> add_flavor ~extra_flavors |> to_string) ) - in - {command; rev_not_targets; targets} + let targets = + List.rev_map targets ~f:(fun t -> + Target.(t |> of_string |> add_flavor ~extra_flavors |> to_string) ) + in + {command; rev_not_targets; targets} let rec exceed_length ~max = function diff --git a/infer/src/integration/BuckGenrule.ml b/infer/src/integration/BuckGenrule.ml index 9934e69c4..77c0d253b 100644 --- a/infer/src/integration/BuckGenrule.ml +++ b/infer/src/integration/BuckGenrule.ml @@ -52,8 +52,10 @@ let capture build_cmd = in L.(debug Capture Quiet) "Processed buck command '%a'@." (Pp.seq F.pp_print_string) updated_buck_cmd ; - let time0 = Mtime_clock.counter () in - run_buck_capture updated_buck_cmd ; - L.progress "Genrule capture took %a.@." Mtime.Span.pp (Mtime_clock.count time0) ; - RunState.set_merge_capture true ; - RunState.store () + if List.is_empty targets then L.external_warning "WARNING: found no buck targets to analyze.@." + else + let time0 = Mtime_clock.counter () in + run_buck_capture updated_buck_cmd ; + L.progress "Genrule capture took %a.@." Mtime.Span.pp (Mtime_clock.count time0) ; + RunState.set_merge_capture true ; + RunState.store () diff --git a/infer/src/integration/CaptureCompilationDatabase.ml b/infer/src/integration/CaptureCompilationDatabase.ml index 0378685cc..dc19ba437 100644 --- a/infer/src/integration/CaptureCompilationDatabase.ml +++ b/infer/src/integration/CaptureCompilationDatabase.ml @@ -71,6 +71,9 @@ let get_compilation_database_files_buck ~prog ~args = Buck.add_flavors_to_buck_arguments ~filter_kind:`Yes ~dep_depth ~extra_flavors:Config.append_buck_flavors args with + | {targets} when List.is_empty targets -> + L.external_warning "WARNING: found no buck targets to analyze.@." ; + [] | {command= "build" as command; rev_not_targets; targets} -> let targets_args = Buck.store_args_in_file targets in let build_args = diff --git a/infer/src/integration/Driver.ml b/infer/src/integration/Driver.ml index 2393a0e66..f841bfa54 100644 --- a/infer/src/integration/Driver.ml +++ b/infer/src/integration/Driver.ml @@ -193,35 +193,37 @@ let capture_with_compilation_database db_files = CaptureCompilationDatabase.capture_files_in_database compilation_database -let capture ~changed_files = function - | Analyze -> - () - | BuckCompilationDB (prog, args) -> - L.progress "Capturing using Buck's compilation database...@." ; - let json_cdb = CaptureCompilationDatabase.get_compilation_database_files_buck ~prog ~args in - capture_with_compilation_database ~changed_files json_cdb - | BuckGenrule path -> - L.progress "Capturing for Buck genrule compatibility...@." ; - JMain.from_arguments path - | BuckGenruleMaster build_cmd -> - L.progress "Capturing for BuckGenruleMaster integration...@." ; - BuckGenrule.capture build_cmd - | Clang (compiler, prog, args) -> - if CLOpt.is_originator then L.progress "Capturing in make/cc mode...@." ; - Clang.capture compiler ~prog ~args - | ClangCompilationDB db_files -> - L.progress "Capturing using compilation database...@." ; - capture_with_compilation_database ~changed_files db_files - | Javac (compiler, prog, args) -> - if CLOpt.is_originator then L.progress "Capturing in javac mode...@." ; - Javac.capture compiler ~prog ~args - | Maven (prog, args) -> - L.progress "Capturing in maven mode...@." ; - Maven.capture ~prog ~args - | PythonCapture (build_system, build_cmd) -> - register_perf_stats_report PerfStats.TotalFrontend ; +let python_capture build_system build_cmd = + register_perf_stats_report PerfStats.TotalFrontend ; + let in_buck_mode = Config.equal_build_system build_system BBuck in + let build_cmd_opt = + if in_buck_mode && Config.flavors then ( + (* let children infer processes know that they are inside Buck *) + let infer_args_with_buck = + String.concat + ~sep:(String.of_char CLOpt.env_var_sep) + (Option.to_list (Sys.getenv CLOpt.args_env_var) @ ["--buck"]) + in + Unix.putenv ~key:CLOpt.args_env_var ~data:infer_args_with_buck ; + let prog, buck_args = (List.hd_exn build_cmd, List.tl_exn build_cmd) in + let {Buck.command; rev_not_targets; targets} = + Buck.add_flavors_to_buck_arguments ~filter_kind:`Auto ~dep_depth:None ~extra_flavors:[] + buck_args + in + if List.is_empty targets then None + else + let all_args = List.rev_append rev_not_targets targets 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 ; + Some updated_buck_cmd ) + else Some build_cmd + in + Option.iter build_cmd_opt ~f:(fun updated_build_cmd -> L.progress "Capturing in %s mode...@." (Config.string_of_build_system build_system) ; - let in_buck_mode = Config.equal_build_system build_system BBuck in let infer_py = Config.lib_dir ^/ "python" ^/ "infer.py" in let args = List.rev_append Config.anon_args @@ -261,31 +263,7 @@ let capture ~changed_files = function [] | Some d -> ["--xcode-developer-dir"; d] ) - @ "--" - :: - ( if in_buck_mode && Config.flavors then ( - (* let children infer processes know that they are inside Buck *) - let infer_args_with_buck = - String.concat - ~sep:(String.of_char CLOpt.env_var_sep) - (Option.to_list (Sys.getenv CLOpt.args_env_var) @ ["--buck"]) - in - Unix.putenv ~key:CLOpt.args_env_var ~data:infer_args_with_buck ; - let prog, buck_args = (List.hd_exn build_cmd, List.tl_exn build_cmd) in - let {Buck.command; rev_not_targets; targets} = - Buck.add_flavors_to_buck_arguments ~filter_kind:`Auto ~dep_depth:None - ~extra_flavors:[] buck_args - in - let all_args = List.rev_append rev_not_targets targets 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 ) - else build_cmd ) ) + @ ("--" :: updated_build_cmd) ) in if in_buck_mode && Config.flavors then ( RunState.set_merge_capture true ; RunState.store () ) ; run_command ~prog:infer_py ~args @@ -297,7 +275,36 @@ let capture ~changed_files = function | status -> command_error_handling ~always_die:true ~prog:infer_py ~args status ) () ; - PerfStats.get_reporter PerfStats.TotalFrontend () + PerfStats.get_reporter PerfStats.TotalFrontend () ) + + +let capture ~changed_files = function + | Analyze -> + () + | BuckCompilationDB (prog, args) -> + L.progress "Capturing using Buck's compilation database...@." ; + let json_cdb = CaptureCompilationDatabase.get_compilation_database_files_buck ~prog ~args in + capture_with_compilation_database ~changed_files json_cdb + | BuckGenrule path -> + L.progress "Capturing for Buck genrule compatibility...@." ; + JMain.from_arguments path + | BuckGenruleMaster build_cmd -> + L.progress "Capturing for BuckGenruleMaster integration...@." ; + BuckGenrule.capture build_cmd + | Clang (compiler, prog, args) -> + if CLOpt.is_originator then L.progress "Capturing in make/cc mode...@." ; + Clang.capture compiler ~prog ~args + | ClangCompilationDB db_files -> + L.progress "Capturing using compilation database...@." ; + capture_with_compilation_database ~changed_files db_files + | Javac (compiler, prog, args) -> + if CLOpt.is_originator then L.progress "Capturing in javac mode...@." ; + Javac.capture compiler ~prog ~args + | Maven (prog, args) -> + L.progress "Capturing in maven mode...@." ; + Maven.capture ~prog ~args + | PythonCapture (build_system, build_cmd) -> + python_capture build_system build_cmd | XcodeXcpretty (prog, args) -> L.progress "Capturing using xcodebuild and xcpretty...@." ; check_xcpretty () ;