Summary: Adding #infer-capture-all et al. by hand is annoying and I always forget to do it. Let infer figure that out. Reviewed By: dulmarod Differential Revision: D4339799 fbshipit-source-id: 55e52dcmaster
parent
1a5ac9e62b
commit
4b77b07be5
@ -0,0 +1,64 @@
|
||||
(*
|
||||
* Copyright (c) 2016 - present Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*)
|
||||
|
||||
open! IStd
|
||||
|
||||
type target = { name: string; flavors: string list; }
|
||||
|
||||
let target_of_string target =
|
||||
match String.split target ~on:'#' with
|
||||
| name::flavors_string::[] ->
|
||||
let flavors = String.split flavors_string ~on:',' in
|
||||
{name; flavors}
|
||||
| name::[] -> { name; flavors=[] }
|
||||
| _ -> failwithf "Error: cannot parse target %s" target
|
||||
|
||||
let string_of_target { name; flavors } =
|
||||
let pp_string fmt s = Format.fprintf fmt "%s" s in
|
||||
Format.asprintf "%s#%a" name (Pp.comma_seq pp_string) flavors
|
||||
|
||||
|
||||
let is_target_string =
|
||||
let target_regexp = Str.regexp "[^/]*//[^/]+.*:.*" in
|
||||
fun s ->
|
||||
Str.string_match target_regexp s 0
|
||||
|
||||
let no_targets_found_error_and_exit buck_cmd =
|
||||
Process.print_error_and_exit
|
||||
"No targets found in Buck command %s.@\nOnly fully qualified Buck targets are supported. \
|
||||
In particular, aliases are not allowed.@."
|
||||
(String.concat ~sep:" " buck_cmd)
|
||||
|
||||
let add_flavor_to_target target =
|
||||
let infer_flavor =
|
||||
match Config.analyzer with
|
||||
| Compile ->
|
||||
None
|
||||
| Linters | Capture ->
|
||||
Some "infer-capture-all"
|
||||
| Checkers | Infer ->
|
||||
Some "infer"
|
||||
| Eradicate | Tracing | Crashcontext | Quandary | Threadsafety ->
|
||||
failwithf "Unsupported infer analyzer with Buck flavors: %s"
|
||||
(Config.string_of_analyzer Config.analyzer) in
|
||||
if List.exists ~f:(String.is_prefix ~prefix:"infer") target.flavors then
|
||||
(* there's already an infer flavor associated to the target, do nothing *)
|
||||
target
|
||||
else
|
||||
{ target with flavors = (Option.to_list infer_flavor) @ target.flavors }
|
||||
|
||||
|
||||
let add_flavors_to_buck_command build_cmd =
|
||||
let add_infer_if_target s (cmd, found_one_target) =
|
||||
if not (is_target_string s) then (s::cmd, found_one_target)
|
||||
else (string_of_target (add_flavor_to_target (target_of_string s))::cmd, true) in
|
||||
let (cmd', found_one_target) =
|
||||
List.fold_right build_cmd ~f:add_infer_if_target ~init:([], false) in
|
||||
if not found_one_target then no_targets_found_error_and_exit build_cmd;
|
||||
cmd'
|
@ -0,0 +1,22 @@
|
||||
(*
|
||||
* Copyright (c) 2016 - present Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*)
|
||||
|
||||
(** is this a Buck target string, eg //foo/bar:baz or boo//foo/bar:baz *)
|
||||
val is_target_string : string -> bool
|
||||
|
||||
(** prints an error that no Buck targets were identified in the given list, and exits *)
|
||||
val no_targets_found_error_and_exit : string list -> unit
|
||||
|
||||
(** Add infer flavors to the targets in the given buck command, depending on the infer analyzer. For
|
||||
instance, in capture mode, the buck command:
|
||||
buck build //foo/bar:baz#some,flavor
|
||||
becomes:
|
||||
buck build //foo/bar:baz#infer-capture-all,some,flavor
|
||||
*)
|
||||
val add_flavors_to_buck_command : string list -> string list
|
Loading…
Reference in new issue