Skip to content

Commit

Permalink
Remove Concat_or_split
Browse files Browse the repository at this point in the history
Thie property will now be determined from the context

Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
  • Loading branch information
rgrinberg committed Jun 4, 2018
1 parent a0fc548 commit a9d3b5c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 64 deletions.
50 changes: 15 additions & 35 deletions src/action.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 *)

Expand All @@ -297,38 +290,25 @@ 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 "", [])
end

module VE = Var_expansion
Expand Down
10 changes: 2 additions & 8 deletions src/action.mli
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
5 changes: 2 additions & 3 deletions src/inline_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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
Expand Down
36 changes: 18 additions & 18 deletions src/super_context.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 ->
Expand All @@ -674,23 +674,23 @@ 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
| Some ("read-lines", s) -> begin
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
| Some ("read-strings", s) -> begin
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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit a9d3b5c

Please sign in to comment.