[buck] don't fail on empty list of targets found from query

Reviewed By: jvillard

Differential Revision: D16071738

fbshipit-source-id: 2cff0b931
master
Nikos Gorogiannis 5 years ago committed by Facebook Github Bot
parent 38e66d6f91
commit 2f21d223ac

@ -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 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) |> (if Config.genrule_master_mode then Query.label_filter ~label:infer_enabled_label else Fn.id)
|> Query.exec ~buck_config:(Lazy.force buck_config) |> 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) |> 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.")
let resolve_alias_targets aliases = 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 = let command, rev_not_targets, targets =
parse_command_and_targets ~filter_kind ~dep_depth original_buck_args parse_command_and_targets ~filter_kind ~dep_depth original_buck_args
in in
match targets with let targets =
| [] -> List.rev_map targets ~f:(fun t ->
L.(die UserError) Target.(t |> of_string |> add_flavor ~extra_flavors |> to_string) )
"ERROR: no targets found in Buck command `%a`." (Pp.seq F.pp_print_string) in
original_buck_args {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 let rec exceed_length ~max = function

@ -52,8 +52,10 @@ let capture build_cmd =
in in
L.(debug Capture Quiet) L.(debug Capture Quiet)
"Processed buck command '%a'@." (Pp.seq F.pp_print_string) updated_buck_cmd ; "Processed buck command '%a'@." (Pp.seq F.pp_print_string) updated_buck_cmd ;
let time0 = Mtime_clock.counter () in if List.is_empty targets then L.external_warning "WARNING: found no buck targets to analyze.@."
run_buck_capture updated_buck_cmd ; else
L.progress "Genrule capture took %a.@." Mtime.Span.pp (Mtime_clock.count time0) ; let time0 = Mtime_clock.counter () in
RunState.set_merge_capture true ; run_buck_capture updated_buck_cmd ;
RunState.store () L.progress "Genrule capture took %a.@." Mtime.Span.pp (Mtime_clock.count time0) ;
RunState.set_merge_capture true ;
RunState.store ()

@ -71,6 +71,9 @@ let get_compilation_database_files_buck ~prog ~args =
Buck.add_flavors_to_buck_arguments ~filter_kind:`Yes ~dep_depth Buck.add_flavors_to_buck_arguments ~filter_kind:`Yes ~dep_depth
~extra_flavors:Config.append_buck_flavors args ~extra_flavors:Config.append_buck_flavors args
with 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} -> | {command= "build" as command; rev_not_targets; targets} ->
let targets_args = Buck.store_args_in_file targets in let targets_args = Buck.store_args_in_file targets in
let build_args = let build_args =

@ -193,35 +193,37 @@ let capture_with_compilation_database db_files =
CaptureCompilationDatabase.capture_files_in_database compilation_database CaptureCompilationDatabase.capture_files_in_database compilation_database
let capture ~changed_files = function let python_capture build_system build_cmd =
| Analyze -> register_perf_stats_report PerfStats.TotalFrontend ;
() let in_buck_mode = Config.equal_build_system build_system BBuck in
| BuckCompilationDB (prog, args) -> let build_cmd_opt =
L.progress "Capturing using Buck's compilation database...@." ; if in_buck_mode && Config.flavors then (
let json_cdb = CaptureCompilationDatabase.get_compilation_database_files_buck ~prog ~args in (* let children infer processes know that they are inside Buck *)
capture_with_compilation_database ~changed_files json_cdb let infer_args_with_buck =
| BuckGenrule path -> String.concat
L.progress "Capturing for Buck genrule compatibility...@." ; ~sep:(String.of_char CLOpt.env_var_sep)
JMain.from_arguments path (Option.to_list (Sys.getenv CLOpt.args_env_var) @ ["--buck"])
| BuckGenruleMaster build_cmd -> in
L.progress "Capturing for BuckGenruleMaster integration...@." ; Unix.putenv ~key:CLOpt.args_env_var ~data:infer_args_with_buck ;
BuckGenrule.capture build_cmd let prog, buck_args = (List.hd_exn build_cmd, List.tl_exn build_cmd) in
| Clang (compiler, prog, args) -> let {Buck.command; rev_not_targets; targets} =
if CLOpt.is_originator then L.progress "Capturing in make/cc mode...@." ; Buck.add_flavors_to_buck_arguments ~filter_kind:`Auto ~dep_depth:None ~extra_flavors:[]
Clang.capture compiler ~prog ~args buck_args
| ClangCompilationDB db_files -> in
L.progress "Capturing using compilation database...@." ; if List.is_empty targets then None
capture_with_compilation_database ~changed_files db_files else
| Javac (compiler, prog, args) -> let all_args = List.rev_append rev_not_targets targets in
if CLOpt.is_originator then L.progress "Capturing in javac mode...@." ; let updated_buck_cmd =
Javac.capture compiler ~prog ~args [prog; command]
| Maven (prog, args) -> @ List.rev_append Config.buck_build_args_no_inline (Buck.store_args_in_file all_args)
L.progress "Capturing in maven mode...@." ; in
Maven.capture ~prog ~args Logging.(debug Capture Quiet)
| PythonCapture (build_system, build_cmd) -> "Processed buck command '%a'@\n" (Pp.seq F.pp_print_string) updated_buck_cmd ;
register_perf_stats_report PerfStats.TotalFrontend ; 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) ; 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 infer_py = Config.lib_dir ^/ "python" ^/ "infer.py" in
let args = let args =
List.rev_append Config.anon_args List.rev_append Config.anon_args
@ -261,31 +263,7 @@ let capture ~changed_files = function
[] []
| Some d -> | Some d ->
["--xcode-developer-dir"; d] ) ["--xcode-developer-dir"; d] )
@ "--" @ ("--" :: updated_build_cmd) )
::
( 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 ) )
in in
if in_buck_mode && Config.flavors then ( RunState.set_merge_capture true ; RunState.store () ) ; if in_buck_mode && Config.flavors then ( RunState.set_merge_capture true ; RunState.store () ) ;
run_command ~prog:infer_py ~args run_command ~prog:infer_py ~args
@ -297,7 +275,36 @@ let capture ~changed_files = function
| status -> | status ->
command_error_handling ~always_die:true ~prog:infer_py ~args 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) -> | XcodeXcpretty (prog, args) ->
L.progress "Capturing using xcodebuild and xcpretty...@." ; L.progress "Capturing using xcodebuild and xcpretty...@." ;
check_xcpretty () ; check_xcpretty () ;

Loading…
Cancel
Save