Add syntax for binding dependencies to names
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
This commit is contained in:
parent
4be37dd140
commit
93b0c618d1
|
@ -233,7 +233,7 @@ module Pps_and_flags = struct
|
||||||
end
|
end
|
||||||
|
|
||||||
module Dep_conf = struct
|
module Dep_conf = struct
|
||||||
type t =
|
type dep =
|
||||||
| File of String_with_vars.t
|
| File of String_with_vars.t
|
||||||
| Alias of String_with_vars.t
|
| Alias of String_with_vars.t
|
||||||
| Alias_rec of String_with_vars.t
|
| Alias_rec of String_with_vars.t
|
||||||
|
@ -241,38 +241,59 @@ module Dep_conf = struct
|
||||||
| Source_tree of String_with_vars.t
|
| Source_tree of String_with_vars.t
|
||||||
| Package of String_with_vars.t
|
| Package of String_with_vars.t
|
||||||
| Universe
|
| Universe
|
||||||
| List of t list
|
|
||||||
|
|
||||||
let t =
|
type t =
|
||||||
let t =
|
| Unnamed of dep list
|
||||||
let sw = String_with_vars.t in
|
| Named of string * dep list
|
||||||
fix (fun t ->
|
|
||||||
sum
|
let dep_cons =
|
||||||
[ "file" , (sw >>| fun x -> File x)
|
let sw = String_with_vars.t in
|
||||||
; "alias" , (sw >>| fun x -> Alias x)
|
[ "file" , (sw >>| fun x -> File x)
|
||||||
; "alias_rec" , (sw >>| fun x -> Alias_rec x)
|
; "alias" , (sw >>| fun x -> Alias x)
|
||||||
; "glob_files" , (sw >>| fun x -> Glob_files x)
|
; "alias_rec" , (sw >>| fun x -> Alias_rec x)
|
||||||
; "package" , (sw >>| fun x -> Package x)
|
; "glob_files" , (sw >>| fun x -> Glob_files x)
|
||||||
; "universe" , return Universe
|
; "package" , (sw >>| fun x -> Package x)
|
||||||
; "files_recursively_in",
|
; "universe" , return Universe
|
||||||
(Syntax.renamed_in Stanza.syntax (1, 0) ~to_:"source_tree"
|
; "files_recursively_in",
|
||||||
>>= fun () ->
|
(Syntax.renamed_in Stanza.syntax (1, 0) ~to_:"source_tree"
|
||||||
sw >>| fun x -> Source_tree x)
|
>>= fun () ->
|
||||||
; "source_tree",
|
sw >>| fun x -> Source_tree x)
|
||||||
(Syntax.since Stanza.syntax (1, 0) >>= fun () ->
|
; "source_tree",
|
||||||
sw >>| fun x -> Source_tree x)
|
(Syntax.since Stanza.syntax (1, 0) >>= fun () ->
|
||||||
; "list",
|
sw >>| fun x -> Source_tree x)
|
||||||
(Syntax.since Stanza.syntax (1, 0) >>= fun () ->
|
]
|
||||||
(repeat t) >>| fun x -> List x)
|
|
||||||
])
|
let make_dep_parser ~single ~many =
|
||||||
in
|
|
||||||
peek_exn >>= function
|
peek_exn >>= function
|
||||||
| Template _ | Atom _ | Quoted_string _ ->
|
| Template _ | Atom _ | Quoted_string _ ->
|
||||||
String_with_vars.t >>| fun x -> File x
|
String_with_vars.t >>| fun x -> single (File x)
|
||||||
| List _ -> t
|
| List _ -> many
|
||||||
|
|
||||||
|
let dep =
|
||||||
|
let dep =
|
||||||
|
let dep_no_list =
|
||||||
|
make_dep_parser ~single:(fun x -> x) ~many:(sum dep_cons) in
|
||||||
|
sum (("list", repeat dep_no_list)
|
||||||
|
:: (List.map dep_cons ~f:(fun (n, d) -> (n, d >>| List.singleton))))
|
||||||
|
in
|
||||||
|
make_dep_parser ~single:List.singleton ~many:dep
|
||||||
|
|
||||||
|
let t =
|
||||||
|
peek_exn >>= function
|
||||||
|
| Atom (loc, A s) when String.length s > 1 && s.[0] = ':' ->
|
||||||
|
begin
|
||||||
|
string >>= fun name ->
|
||||||
|
peek >>= function
|
||||||
|
| None -> of_sexp_errorf loc "Naked binding %s" s
|
||||||
|
| Some _ -> dep
|
||||||
|
>>| fun deps ->
|
||||||
|
Named (name, deps)
|
||||||
|
end
|
||||||
|
| _ ->
|
||||||
|
dep >>| fun dep -> Unnamed dep
|
||||||
|
|
||||||
open Sexp
|
open Sexp
|
||||||
let rec sexp_of_t = function
|
let sexp_of_dep = function
|
||||||
| File t ->
|
| File t ->
|
||||||
List [Sexp.unsafe_atom_of_string "file" ; String_with_vars.sexp_of_t t]
|
List [Sexp.unsafe_atom_of_string "file" ; String_with_vars.sexp_of_t t]
|
||||||
| Alias t ->
|
| Alias t ->
|
||||||
|
@ -291,9 +312,12 @@ module Dep_conf = struct
|
||||||
String_with_vars.sexp_of_t t]
|
String_with_vars.sexp_of_t t]
|
||||||
| Universe ->
|
| Universe ->
|
||||||
Sexp.unsafe_atom_of_string "universe"
|
Sexp.unsafe_atom_of_string "universe"
|
||||||
| List ts ->
|
|
||||||
List (Sexp.unsafe_atom_of_string "list"
|
let sexp_of_t =
|
||||||
:: (List.map ~f:sexp_of_t ts))
|
let open Sexp.To_sexp in
|
||||||
|
function
|
||||||
|
| Unnamed dep -> (list sexp_of_dep) dep
|
||||||
|
| Named (name, dep) -> List [Sexp.atom name; (list sexp_of_dep) dep]
|
||||||
end
|
end
|
||||||
|
|
||||||
module Preprocess = struct
|
module Preprocess = struct
|
||||||
|
@ -1239,7 +1263,7 @@ module Rule = struct
|
||||||
let src = name ^ ".mll" in
|
let src = name ^ ".mll" in
|
||||||
let dst = name ^ ".ml" in
|
let dst = name ^ ".ml" in
|
||||||
{ targets = Static [dst]
|
{ targets = Static [dst]
|
||||||
; deps = [File (S.virt_text __POS__ src)]
|
; deps = [Unnamed [File (S.virt_text __POS__ src)]]
|
||||||
; action =
|
; action =
|
||||||
(loc,
|
(loc,
|
||||||
Chdir
|
Chdir
|
||||||
|
@ -1260,7 +1284,7 @@ module Rule = struct
|
||||||
List.map modules ~f:(fun name ->
|
List.map modules ~f:(fun name ->
|
||||||
let src = name ^ ".mly" in
|
let src = name ^ ".mly" in
|
||||||
{ targets = Static [name ^ ".ml"; name ^ ".mli"]
|
{ targets = Static [name ^ ".ml"; name ^ ".mli"]
|
||||||
; deps = [File (S.virt_text __POS__ src)]
|
; deps = [Unnamed [File (S.virt_text __POS__ src)]]
|
||||||
; action =
|
; action =
|
||||||
(loc,
|
(loc,
|
||||||
Chdir
|
Chdir
|
||||||
|
|
|
@ -82,7 +82,7 @@ module Lib_deps : sig
|
||||||
end
|
end
|
||||||
|
|
||||||
module Dep_conf : sig
|
module Dep_conf : sig
|
||||||
type t =
|
type dep =
|
||||||
| File of String_with_vars.t
|
| File of String_with_vars.t
|
||||||
| Alias of String_with_vars.t
|
| Alias of String_with_vars.t
|
||||||
| Alias_rec of String_with_vars.t
|
| Alias_rec of String_with_vars.t
|
||||||
|
@ -90,7 +90,10 @@ module Dep_conf : sig
|
||||||
| Source_tree of String_with_vars.t
|
| Source_tree of String_with_vars.t
|
||||||
| Package of String_with_vars.t
|
| Package of String_with_vars.t
|
||||||
| Universe
|
| Universe
|
||||||
| List of t list
|
|
||||||
|
type t =
|
||||||
|
| Unnamed of dep list
|
||||||
|
| Named of string * dep list
|
||||||
|
|
||||||
val t : t Sexp.Of_sexp.t
|
val t : t Sexp.Of_sexp.t
|
||||||
val sexp_of_t : t -> Sexp.t
|
val sexp_of_t : t -> Sexp.t
|
||||||
|
|
|
@ -487,7 +487,7 @@ module Deps = struct
|
||||||
let loc = String_with_vars.loc s in
|
let loc = String_with_vars.loc s in
|
||||||
Alias.of_user_written_path ~loc ((expand_vars_path t ~scope ~dir s))
|
Alias.of_user_written_path ~loc ((expand_vars_path t ~scope ~dir s))
|
||||||
|
|
||||||
let rec dep t ~scope ~dir = function
|
let dep t ~scope ~dir = function
|
||||||
| File s ->
|
| File s ->
|
||||||
let path = expand_vars_path t ~scope ~dir s in
|
let path = expand_vars_path t ~scope ~dir s in
|
||||||
Build.path path
|
Build.path path
|
||||||
|
@ -521,12 +521,12 @@ module Deps = struct
|
||||||
| Universe ->
|
| Universe ->
|
||||||
Build.path Build_system.universe_file
|
Build.path Build_system.universe_file
|
||||||
>>^ fun () -> []
|
>>^ fun () -> []
|
||||||
| List ts ->
|
|
||||||
Build.all (List.map ~f:(dep t ~scope ~dir) ts)
|
|
||||||
>>^ List.concat
|
|
||||||
|
|
||||||
let interpret t ~scope ~dir l =
|
let interpret t ~scope ~dir l =
|
||||||
Build.all (List.map l ~f:(dep t ~scope ~dir))
|
List.concat_map l ~f:(function
|
||||||
|
| Unnamed d
|
||||||
|
| Named (_, d) -> List.map ~f:(dep t ~scope ~dir) d)
|
||||||
|
|> Build.all
|
||||||
>>^ List.concat
|
>>^ List.concat
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -80,6 +80,14 @@
|
||||||
test-cases/custom-build-dir
|
test-cases/custom-build-dir
|
||||||
(progn (run %{exe:cram.exe} -test run.t) (diff? run.t run.t.corrected)))))
|
(progn (run %{exe:cram.exe} -test run.t) (diff? run.t run.t.corrected)))))
|
||||||
|
|
||||||
|
(alias
|
||||||
|
(name dep-vars)
|
||||||
|
(deps (package dune) (source_tree test-cases/dep-vars))
|
||||||
|
(action
|
||||||
|
(chdir
|
||||||
|
test-cases/dep-vars
|
||||||
|
(progn (run %{exe:cram.exe} -test run.t) (diff? run.t run.t.corrected)))))
|
||||||
|
|
||||||
(alias
|
(alias
|
||||||
(name depend-on-the-universe)
|
(name depend-on-the-universe)
|
||||||
(deps (package dune) (source_tree test-cases/depend-on-the-universe))
|
(deps (package dune) (source_tree test-cases/depend-on-the-universe))
|
||||||
|
@ -680,6 +688,7 @@
|
||||||
(alias copy_files)
|
(alias copy_files)
|
||||||
(alias cross-compilation)
|
(alias cross-compilation)
|
||||||
(alias custom-build-dir)
|
(alias custom-build-dir)
|
||||||
|
(alias dep-vars)
|
||||||
(alias depend-on-the-universe)
|
(alias depend-on-the-universe)
|
||||||
(alias dune-jbuild-var-case)
|
(alias dune-jbuild-var-case)
|
||||||
(alias dune-ppx-driver-system)
|
(alias dune-ppx-driver-system)
|
||||||
|
@ -762,6 +771,7 @@
|
||||||
(alias copy_files)
|
(alias copy_files)
|
||||||
(alias cross-compilation)
|
(alias cross-compilation)
|
||||||
(alias custom-build-dir)
|
(alias custom-build-dir)
|
||||||
|
(alias dep-vars)
|
||||||
(alias depend-on-the-universe)
|
(alias depend-on-the-universe)
|
||||||
(alias dune-jbuild-var-case)
|
(alias dune-jbuild-var-case)
|
||||||
(alias dune-ppx-driver-system)
|
(alias dune-ppx-driver-system)
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
|
||||||
|
(rule
|
||||||
|
(deps :foo (list a b) :baz foo (list (alias test)) (list a b c))
|
||||||
|
(targets bar)
|
||||||
|
(action (with-stdout-to bar (echo "foo"))))
|
|
@ -0,0 +1 @@
|
||||||
|
(lang dune 1.0)
|
|
@ -0,0 +1,3 @@
|
||||||
|
Dependencies are allowed :patterns
|
||||||
|
|
||||||
|
$ dune build
|
Loading…
Reference in New Issue