From 65b6bbbb73b8e78073d39658bc3112a71bfee944 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Mon, 4 Jun 2018 17:35:49 +0700 Subject: [PATCH] Remove Concat_or_split Thie property will now be determined from the context Signed-off-by: Rudi Grinberg --- src/action.ml | 61 +++++++++++++++++++------------------------- src/action.mli | 10 ++------ src/inline_tests.ml | 5 ++-- src/super_context.ml | 36 +++++++++++++------------- 4 files changed, 48 insertions(+), 64 deletions(-) diff --git a/src/action.ml b/src/action.ml index e21fcb30e146..b2a34873447f 100644 --- a/src/action.ml +++ b/src/action.ml @@ -271,21 +271,14 @@ module Unresolved = struct end module Var_expansion = struct - module Concat_or_split = struct - type t = - | Concat (* default *) - | Split (* the variable is a "split" list of items *) - end - - open Concat_or_split - type t = - | Paths of Path.t list * Concat_or_split.t - | Strings of string list * Concat_or_split.t + | Paths of Path.t list + | Strings of string list let is_multivalued = function - | Paths (_, Split) | Strings (_, Split) -> true - | Paths (_, Concat) | Strings (_, Concat) -> false + | Paths [_] -> false + | Strings [_] -> false + | _ -> false type context = Path.t (* For String_with_vars.Expand_to *) @@ -297,38 +290,36 @@ module Var_expansion = struct let path_of_string dir s = Path.relative dir s let to_strings dir = function - | Strings (l, Split ) -> l - | Strings (l, Concat) -> [concat l] - | Paths (l, Split ) -> List.map l ~f:(string_of_path ~dir) - | Paths (l, Concat) -> [concat (List.map l ~f:(string_of_path ~dir))] + | Strings l -> l + | Paths l -> List.map l ~f:(string_of_path ~dir) let to_string (dir: context) = function - | Strings (l, _) -> concat l - | Paths (l, _) -> concat (List.map l ~f:(string_of_path ~dir)) + | Strings l -> concat l + | Paths l -> concat (List.map l ~f:(string_of_path ~dir)) let to_path dir = function - | Strings (l, _) -> path_of_string dir (concat l) - | Paths ([p], _) -> p - | Paths (l, _) -> + | Strings l -> path_of_string dir (concat l) + | Paths [p] -> p + | Paths l -> path_of_string dir (concat (List.map l ~f:(string_of_path ~dir))) let to_prog_and_args dir exp : Unresolved.Program.t * string list = let module P = Unresolved.Program in match exp with - | Paths ([p], _) -> (This p, []) - | Strings ([s], _) -> (P.of_string ~dir s, []) - | Paths ([], _) | Strings ([], _) -> (Search "", []) - | Paths (l, Concat) -> - (This - (path_of_string dir - (concat (List.map l ~f:(string_of_path ~dir)))), - []) - | Strings (l, Concat) -> - (P.of_string ~dir (concat l), l) - | Paths (p :: l, Split) -> - (This p, List.map l ~f:(string_of_path ~dir)) - | Strings (s :: l, Split) -> - (P.of_string ~dir s, l) + | Paths (x::xs) -> (This x, to_strings dir (Paths xs)) + | Strings (s::xs) -> (P.of_string ~dir s, to_strings dir (Strings xs)) + | Paths [] | Strings [] -> (Search "", []) + (* | Paths (l, Concat) -> + * (This + * (path_of_string dir + * (concat (List.map l ~f:(string_of_path ~dir)))), + * []) + * | Strings (l, Concat) -> + * (P.of_string ~dir (concat l), l) + * | Paths (p :: l, Split) -> + * (This p, List.map l ~f:(string_of_path ~dir)) + * | Strings (s :: l, Split) -> + * (P.of_string ~dir s, l) *) end module VE = Var_expansion diff --git a/src/action.mli b/src/action.mli index 484debf39ff9..89e0a91faef9 100644 --- a/src/action.mli +++ b/src/action.mli @@ -1,15 +1,9 @@ open! Import module Var_expansion : sig - module Concat_or_split : sig - type t = - | Concat (** default *) - | Split (** the variable is a "split" list of items *) - end - type t = - | Paths of Path.t list * Concat_or_split.t - | Strings of string list * Concat_or_split.t + | Paths of Path.t list + | Strings of string list val to_string : Path.t -> t -> string (** [to_string dir v] convert the variable expansion to a string. diff --git a/src/inline_tests.ml b/src/inline_tests.ml index 31d9ea5b44a4..80f9de61a516 100644 --- a/src/inline_tests.ml +++ b/src/inline_tests.ml @@ -191,7 +191,7 @@ include Sub_system.Register_end_point( let extra_vars = String.Map.singleton "library-name" - (Action.Var_expansion.Strings ([lib.name], Concat)) + (Action.Var_expansion.Strings [lib.name]) in let runner_libs = @@ -215,8 +215,7 @@ include Sub_system.Register_end_point( let files ml_kind = Action.Var_expansion.Paths ( List.filter_map source_modules ~f:(fun m -> - Module.file m ~dir ml_kind), - Split) + Module.file m ~dir ml_kind)) in let extra_vars = List.fold_left diff --git a/src/super_context.ml b/src/super_context.ml index deb6ff961393..63a354975df9 100644 --- a/src/super_context.ml +++ b/src/super_context.ml @@ -251,15 +251,15 @@ let create let open Action.Var_expansion in let make = match Bin.make with - | None -> Strings (["make"], Split) - | Some p -> Paths ([p], Split) + | None -> Strings ["make"] + | Some p -> Paths [p] in let cflags = context.ocamlc_cflags in - let strings l = Strings (l , Split) in - let string s = Strings ([s], Concat) in - let path p = Paths ([p], Split) in + let strings l = Strings l in + let string s = Strings [s] in + let path p = Paths [p] in let vars = - [ "-verbose" , Strings ([] (*"-verbose";*), Concat) + [ "-verbose" , Strings ([] (*"-verbose";*)) ; "CPP" , strings (context.c_compiler :: cflags @ ["-E"]) ; "PA_CPP" , strings (context.c_compiler :: cflags @ ["-undef"; "-traditional"; @@ -580,8 +580,8 @@ module Action = struct acc.ddeps <- String.Map.add acc.ddeps key dep; None - let path_exp path = Action.Var_expansion.Paths ([path], Concat) - let str_exp path = Action.Var_expansion.Strings ([path], Concat) + let path_exp path = Action.Var_expansion.Paths [path] + let str_exp path = Action.Var_expansion.Strings [path] let map_exe sctx = match sctx.host with @@ -661,8 +661,8 @@ module Action = struct | Some p -> let x = Pkg_version.read sctx p >>^ function - | None -> Strings ([""], Concat) - | Some s -> Strings ([s], Concat) + | None -> Strings [""] + | Some s -> Strings [s] in add_ddep acc ~key x | None -> @@ -674,7 +674,7 @@ module Action = struct let path = Path.relative dir s in let data = Build.contents path - >>^ fun s -> Strings ([s], Concat) + >>^ fun s -> Strings [s] in add_ddep acc ~key data end @@ -682,7 +682,7 @@ module Action = struct let path = Path.relative dir s in let data = Build.lines_of path - >>^ fun l -> Strings (l, Split) + >>^ fun l -> Strings l in add_ddep acc ~key data end @@ -690,7 +690,7 @@ module Action = struct let path = Path.relative dir s in let data = Build.strings path - >>^ fun l -> Strings (l, Split) + >>^ fun l -> Strings l in add_ddep acc ~key data end @@ -712,7 +712,7 @@ module Action = struct match targets_written_by_user with | Infer -> Loc.fail loc "You cannot use ${@} with inferred rules." | Alias -> Loc.fail loc "You cannot use ${@} in aliases." - | Static l -> Some (Paths (l, Split)) + | Static l -> Some (Paths l) end | _ -> match String.lsplit2 var ~on:':' with @@ -721,7 +721,7 @@ module Action = struct | x -> let exp = expand loc key var x in (match exp with - | Some (Paths (ps, _)) -> + | Some (Paths ps) -> acc.sdeps <- Path.Set.union (Path.Set.of_list ps) acc.sdeps | _ -> ()); exp) @@ -742,10 +742,10 @@ module Action = struct | [] -> Loc.warn loc "Variable '<' used with no explicit \ dependencies@."; - Strings ([""], Concat) + Strings [""] | dep :: _ -> - Paths ([dep], Concat)) - | "^" -> Some (Paths (deps_written_by_user, Split)) + Paths [dep]) + | "^" -> Some (Paths deps_written_by_user) | _ -> None) let run sctx ~loc ?(extra_vars=String.Map.empty)