Move Value.t list functions to Value.L

Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
This commit is contained in:
Rudi Grinberg 2018-06-06 21:34:47 +07:00
parent c96df4dc15
commit 6ebff9d388
6 changed files with 36 additions and 31 deletions

View File

@ -274,9 +274,9 @@ end
let prog_and_args_of_values p ~dir = let prog_and_args_of_values p ~dir =
match p with match p with
| [] -> (Unresolved.Program.Search "", []) | [] -> (Unresolved.Program.Search "", [])
| Value.Path p :: xs -> (This p, Value.to_strings ~dir xs) | Value.Path p :: xs -> (This p, Value.L.to_strings ~dir xs)
| String s :: xs -> | String s :: xs ->
(Unresolved.Program.of_string ~dir s, Value.to_strings ~dir xs) (Unresolved.Program.of_string ~dir s, Value.L.to_strings ~dir xs)
module SW = String_with_vars module SW = String_with_vars
@ -327,7 +327,7 @@ module Unexpanded = struct
let strings = let strings =
expand ~mode:Many expand ~mode:Many
~l:(fun x -> [x]) ~l:(fun x -> [x])
~r:Value.to_strings ~r:Value.L.to_strings
let path e = let path e =
let error_loc = let error_loc =
@ -410,8 +410,8 @@ module Unexpanded = struct
| Unexpanded x -> Right x | Unexpanded x -> Right x
let string = expand ~mode:Single ~map:Value.to_string let string = expand ~mode:Single ~map:Value.to_string
let strings = expand ~mode:Many ~map:Value.to_strings let strings = expand ~mode:Many ~map:Value.L.to_strings
let cat_strings = expand ~mode:Many ~map:Value.concat let cat_strings = expand ~mode:Many ~map:Value.L.concat
let path x = let path x =
let error_loc = String_with_vars.loc x in let error_loc = String_with_vars.loc x in
expand ~mode:Single ~map:(Value.to_path ~error_loc) x expand ~mode:Single ~map:(Value.to_path ~error_loc) x

View File

@ -209,7 +209,7 @@ include Sub_system.Register_end_point(
let target = Path.relative inline_test_dir main_module_filename in let target = Path.relative inline_test_dir main_module_filename in
let source_modules = Module.Name.Map.values source_modules in let source_modules = Module.Name.Map.values source_modules in
let files ml_kind = let files ml_kind =
Value.paths ( Value.L.paths (
List.filter_map source_modules ~f:(fun m -> List.filter_map source_modules ~f:(fun m ->
Module.file m ~dir ml_kind)) Module.file m ~dir ml_kind))
in in

View File

@ -160,7 +160,7 @@ let partial_expand t ~mode ~dir ~f =
| Some ([] | _::_::_ as e) when not t.quoted -> | Some ([] | _::_::_ as e) when not t.quoted ->
invalid_multivalue syntax ~var t e invalid_multivalue syntax ~var t e
| Some t -> | Some t ->
loop (List.rev_append (Value.to_strings ~dir t) acc_text) acc items loop (List.rev_append (Value.L.to_strings ~dir t) acc_text) acc items
| None -> loop [] (it :: commit_text acc_text acc) items | None -> loop [] (it :: commit_text acc_text acc) items
end end
in in

View File

@ -287,7 +287,7 @@ let create
| Some p -> path p | Some p -> path p
in in
let cflags = context.ocamlc_cflags in let cflags = context.ocamlc_cflags in
let strings = Value.strings in let strings = Value.L.strings in
let vars = let vars =
[ "-verbose" , [] [ "-verbose" , []
; "CPP" , strings (context.c_compiler :: cflags @ ["-E"]) ; "CPP" , strings (context.c_compiler :: cflags @ ["-E"])
@ -707,7 +707,7 @@ module Action = struct
let path = Path.relative dir s in let path = Path.relative dir s in
let data = let data =
Build.lines_of path Build.lines_of path
>>^ Value.strings >>^ Value.L.strings
in in
add_ddep acc ~key data add_ddep acc ~key data
end end
@ -715,7 +715,7 @@ module Action = struct
let path = Path.relative dir s in let path = Path.relative dir s in
let data = let data =
Build.strings path Build.strings path
>>^ Value.strings >>^ Value.L.strings
in in
add_ddep acc ~key data add_ddep acc ~key data
end end
@ -737,7 +737,7 @@ module Action = struct
match targets_written_by_user with match targets_written_by_user with
| Infer -> Loc.fail loc "You cannot use ${@} with inferred rules." | Infer -> Loc.fail loc "You cannot use ${@} with inferred rules."
| Alias -> Loc.fail loc "You cannot use ${@} in aliases." | Alias -> Loc.fail loc "You cannot use ${@} in aliases."
| Static l -> Some (Value.paths l) | Static l -> Some (Value.L.paths l)
end end
| _ -> | _ ->
match String.lsplit2 var ~on:':' with match String.lsplit2 var ~on:':' with
@ -746,8 +746,8 @@ module Action = struct
| x -> | x ->
let exp = expand loc key var x in let exp = expand loc key var x in
Option.iter exp ~f:(fun vs -> Option.iter exp ~f:(fun vs ->
acc.sdeps <- acc.sdeps <- Path.Set.union (Path.Set.of_list
Path.Set.union (Path.Set.of_list (Value.paths_only vs)) acc.sdeps; (Value.L.paths_only vs)) acc.sdeps;
); );
exp) exp)
in in
@ -769,7 +769,7 @@ module Action = struct
[Value.String ""] [Value.String ""]
| dep :: _ -> | dep :: _ ->
[Path dep]) [Path dep])
| "^" -> Some (Value.paths deps_written_by_user) | "^" -> Some (Value.L.paths deps_written_by_user)
| _ -> None) | _ -> None)
let run sctx ~loc ?(extra_vars=String.Map.empty) let run sctx ~loc ?(extra_vars=String.Map.empty)

View File

@ -11,21 +11,24 @@ let to_string t ~dir =
| String s -> s | String s -> s
| Path p -> string_of_path ~dir p | Path p -> string_of_path ~dir p
let to_strings t ~dir = List.map t ~f:(to_string ~dir)
let to_path ?error_loc t ~dir = let to_path ?error_loc t ~dir =
match t with match t with
| String s -> Path.relative ?error_loc dir s | String s -> Path.relative ?error_loc dir s
| Path p -> p | Path p -> p
let strings = List.map ~f:(fun x -> String x) module L = struct
let paths = List.map ~f:(fun x -> Path x) let to_strings t ~dir = List.map t ~f:(to_string ~dir)
let concat ts ~dir = let concat ts ~dir =
List.map ~f:(to_string ~dir) ts List.map ~f:(to_string ~dir) ts
|> String.concat ~sep:" " |> String.concat ~sep:" "
let paths_only = let paths_only =
List.filter_map ~f:(function List.filter_map ~f:(function
| String _ -> None | String _ -> None
| Path p -> Some p) | Path p -> Some p)
let strings = List.map ~f:(fun x -> String x)
let paths = List.map ~f:(fun x -> Path x)
end

View File

@ -6,14 +6,16 @@ type t =
val to_string : t -> dir:Path.t -> string val to_string : t -> dir:Path.t -> string
val to_strings : t list -> dir:Path.t -> string list
val to_path : ?error_loc:Loc.t -> t -> dir:Path.t -> Path.t val to_path : ?error_loc:Loc.t -> t -> dir:Path.t -> Path.t
val strings : string list -> t list module L : sig
val strings : string list -> t list
val paths : Path.t list -> t list val paths : Path.t list -> t list
val paths_only : t list -> Path.t list val paths_only : t list -> Path.t list
val concat : t list -> dir:Path.t -> string val concat : t list -> dir:Path.t -> string
val to_strings : t list -> dir:Path.t -> string list
end