[istd] `Format.pp_print_string` is a thing, use it

Summary: No need to rewrite code from the standard library /o\

Reviewed By: mbouaziz

Differential Revision: D7533573

fbshipit-source-id: d38b185
master
Jules Villard 7 years ago committed by Facebook Github Bot
parent 9b315d4d08
commit 80d83c2eea

@ -254,11 +254,11 @@ and pp_template_spec_info pe f = function
| TInt i ->
Int64.pp f i
| TNull ->
Pp.string f "null"
F.pp_print_string f "null"
| TNullPtr ->
Pp.string f "NullPtr"
F.pp_print_string f "NullPtr"
| TOpaque ->
Pp.string f "Opaque"
F.pp_print_string f "Opaque"
in
F.fprintf f "%s%a%s" (escape pe "<") (Pp.comma_seq pp_arg_opt) args (escape pe ">")

@ -25,7 +25,7 @@ module Target = struct
L.(die ExternalError) "cannot parse target %s" target
let to_string {name; flavors} = F.asprintf "%s#%a" name (Pp.comma_seq Pp.string) flavors
let to_string {name; flavors} = F.asprintf "%s#%a" name (Pp.comma_seq F.pp_print_string) flavors
let add_flavor_internal target flavor =
if List.mem ~equal:String.equal target.flavors flavor then
@ -104,7 +104,7 @@ module Query = struct
let rec pp fmt = function
| Target s ->
Pp.string fmt s
F.pp_print_string fmt s
| Kind {pattern; expr} ->
F.fprintf fmt "kind(%s, %a)" pattern pp expr
| Deps {depth= None; expr} ->
@ -112,7 +112,7 @@ module Query = struct
| Deps {depth= Some depth; expr} ->
F.fprintf fmt "deps(%a, %d)" pp expr depth
| Set sl ->
F.fprintf fmt "set(%a)" (Pp.seq Pp.string) sl
F.fprintf fmt "set(%a)" (Pp.seq F.pp_print_string) sl
| Union exprs ->
Pp.seq ~sep:" + " pp fmt exprs
@ -154,7 +154,7 @@ let resolve_alias_targets aliases =
let tmp_prefix = "buck_targets_" in
let on_result_lines =
die_if_empty (fun die ->
die "*** No alias found for: '%a'." (Pp.seq ~sep:"', '" Pp.string) aliases )
die "*** No alias found for: '%a'." (Pp.seq ~sep:"', '" F.pp_print_string) aliases )
in
Utils.with_process_lines ~debug ~cmd ~tmp_prefix ~f:on_result_lines
@ -175,8 +175,9 @@ let split_buck_command buck_cmd =
(command, args)
| _ ->
L.(die UserError)
"ERROR: cannot parse buck command `%a`. Expected %a." (Pp.seq Pp.string) buck_cmd
(Pp.seq ~sep:" or " Pp.string) accepted_buck_commands
"ERROR: cannot parse buck command `%a`. Expected %a." (Pp.seq F.pp_print_string) buck_cmd
(Pp.seq ~sep:" or " F.pp_print_string)
accepted_buck_commands
(** Given a list of arguments return the extended list of arguments where
@ -238,7 +239,8 @@ let add_flavors_to_buck_arguments ~filter_kind ~dep_depth ~extra_flavors origina
match targets with
| [] ->
L.(die UserError)
"ERROR: no targets found in Buck command `%a`." (Pp.seq Pp.string) original_buck_args
"ERROR: no targets found in Buck command `%a`." (Pp.seq F.pp_print_string)
original_buck_args
| _ ->
let rev_not_targets = parsed_args.rev_not_targets' in
let targets =

@ -107,7 +107,7 @@ let get_compilation_database_files_buck ~prog ~args =
("--config" :: "*//cxx.pch_enabled=false" :: targets_args)
in
Logging.(debug Linters Quiet)
"Processed buck command is: 'buck %a'@\n" (Pp.seq Pp.string) build_args ;
"Processed buck command is: 'buck %a'@\n" (Pp.seq F.pp_print_string) build_args ;
Process.create_process_and_wait ~prog ~args:build_args ;
let buck_targets_shell =
prog
@ -121,7 +121,9 @@ let get_compilation_database_files_buck ~prog ~args =
L.(die ExternalError) "There are no files to process, exiting"
| lines ->
L.(debug Capture Quiet)
"Reading compilation database from:@\n%a@\n" (Pp.seq ~sep:"\n" Pp.string) lines ;
"Reading compilation database from:@\n%a@\n"
(Pp.seq ~sep:"\n" F.pp_print_string)
lines ;
(* this assumes that flavors do not contain spaces *)
let split_regex = Str.regexp "#[^ ]* " in
let scan_output compilation_database_files line =
@ -139,7 +141,7 @@ let get_compilation_database_files_buck ~prog ~args =
~cmd:buck_targets_shell ~tmp_prefix:"buck_targets_" ~f:on_target_lines
| _ ->
Process.print_error_and_exit "Incorrect buck command: %s %a. Please use buck build <targets>"
prog (Pp.seq Pp.string) args
prog (Pp.seq F.pp_print_string) args
(** Compute the compilation database files. *)

@ -276,7 +276,7 @@ let capture ~changed_files mode =
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
Logging.(debug Capture Quiet)
"Processed buck command '%a'@\n" (Pp.seq Pp.string) updated_buck_cmd ;
"Processed buck command '%a'@\n" (Pp.seq F.pp_print_string) updated_buck_cmd ;
updated_buck_cmd )
else build_cmd ) )
in

@ -126,16 +126,19 @@ let current_time f () =
(** Print the time in seconds elapsed since the beginning of the execution of the current command. *)
let elapsed_time fmt () = Mtime.Span.pp fmt (Mtime_clock.elapsed ())
let string fmt s = F.fprintf fmt "%s" s
let option pp fmt = function
| None ->
F.pp_print_string fmt "None"
| Some x ->
F.fprintf fmt "Some %a" pp x
let option pp fmt = function None -> string fmt "None" | Some x -> F.fprintf fmt "Some %a" pp x
let to_string ~f fmt x = string fmt (f x)
let to_string ~f fmt x = F.pp_print_string fmt (f x)
let cli_args fmt args =
let pp_args fmt args =
F.fprintf fmt "@[<hov2> " ;
seq ~sep:"" ~print_env:{text with break_lines= true} string fmt args ;
seq ~sep:"" ~print_env:{text with break_lines= true} F.pp_print_string fmt args ;
F.fprintf fmt "@]@\n"
in
let rec pp_argfile_args in_argfiles fmt args =

@ -64,8 +64,6 @@ val color_string : color -> string
val option : (F.formatter -> 'a -> unit) -> F.formatter -> 'a option -> unit
val string : F.formatter -> string -> unit
val cli_args : F.formatter -> string list -> unit
(** pretty print command line arguments, expanding argument files to print their contents *)

Loading…
Cancel
Save