From 4be37dd140a48f8bde20490785448e9dc81457f9 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Tue, 3 Jul 2018 23:41:56 +0700 Subject: [PATCH] Add a list constructor to Dep_conf.t Signed-off-by: Rudi Grinberg --- src/jbuild.ml | 40 ++++++++++++++++++++++++---------------- src/jbuild.mli | 1 + src/super_context.ml | 5 ++++- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/jbuild.ml b/src/jbuild.ml index acfa7daf..2e03e39a 100644 --- a/src/jbuild.ml +++ b/src/jbuild.ml @@ -241,25 +241,30 @@ module Dep_conf = struct | Source_tree of String_with_vars.t | Package of String_with_vars.t | Universe + | List of t list let t = let t = let sw = String_with_vars.t in - sum - [ "file" , (sw >>| fun x -> File x) - ; "alias" , (sw >>| fun x -> Alias x) - ; "alias_rec" , (sw >>| fun x -> Alias_rec x) - ; "glob_files" , (sw >>| fun x -> Glob_files x) - ; "package" , (sw >>| fun x -> Package x) - ; "universe" , return Universe - ; "files_recursively_in", - (Syntax.renamed_in Stanza.syntax (1, 0) ~to_:"source_tree" - >>= fun () -> - sw >>| fun x -> Source_tree x) - ; "source_tree", - (Syntax.since Stanza.syntax (1, 0) >>= fun () -> - sw >>| fun x -> Source_tree x) - ] + fix (fun t -> + sum + [ "file" , (sw >>| fun x -> File x) + ; "alias" , (sw >>| fun x -> Alias x) + ; "alias_rec" , (sw >>| fun x -> Alias_rec x) + ; "glob_files" , (sw >>| fun x -> Glob_files x) + ; "package" , (sw >>| fun x -> Package x) + ; "universe" , return Universe + ; "files_recursively_in", + (Syntax.renamed_in Stanza.syntax (1, 0) ~to_:"source_tree" + >>= fun () -> + sw >>| fun x -> Source_tree x) + ; "source_tree", + (Syntax.since Stanza.syntax (1, 0) >>= fun () -> + sw >>| fun x -> Source_tree x) + ; "list", + (Syntax.since Stanza.syntax (1, 0) >>= fun () -> + (repeat t) >>| fun x -> List x) + ]) in peek_exn >>= function | Template _ | Atom _ | Quoted_string _ -> @@ -267,7 +272,7 @@ module Dep_conf = struct | List _ -> t open Sexp - let sexp_of_t = function + let rec sexp_of_t = function | File t -> List [Sexp.unsafe_atom_of_string "file" ; String_with_vars.sexp_of_t t] | Alias t -> @@ -286,6 +291,9 @@ module Dep_conf = struct String_with_vars.sexp_of_t t] | Universe -> Sexp.unsafe_atom_of_string "universe" + | List ts -> + List (Sexp.unsafe_atom_of_string "list" + :: (List.map ~f:sexp_of_t ts)) end module Preprocess = struct diff --git a/src/jbuild.mli b/src/jbuild.mli index f8493f7a..55c39671 100644 --- a/src/jbuild.mli +++ b/src/jbuild.mli @@ -90,6 +90,7 @@ module Dep_conf : sig | Source_tree of String_with_vars.t | Package of String_with_vars.t | Universe + | List of t list val t : t Sexp.Of_sexp.t val sexp_of_t : t -> Sexp.t diff --git a/src/super_context.ml b/src/super_context.ml index 1c8dd76f..9252a051 100644 --- a/src/super_context.ml +++ b/src/super_context.ml @@ -487,7 +487,7 @@ module Deps = struct let loc = String_with_vars.loc s in Alias.of_user_written_path ~loc ((expand_vars_path t ~scope ~dir s)) - let dep t ~scope ~dir = function + let rec dep t ~scope ~dir = function | File s -> let path = expand_vars_path t ~scope ~dir s in Build.path path @@ -521,6 +521,9 @@ module Deps = struct | Universe -> Build.path Build_system.universe_file >>^ fun () -> [] + | List ts -> + Build.all (List.map ~f:(dep t ~scope ~dir) ts) + >>^ List.concat let interpret t ~scope ~dir l = Build.all (List.map l ~f:(dep t ~scope ~dir))