Add simplified version of rules

This commit is contained in:
Jérémie Dimino 2017-05-28 03:38:16 +01:00
parent 7c9dcbf284
commit 1e41feaf8a
4 changed files with 47 additions and 0 deletions

View File

@ -474,6 +474,10 @@ module Gen(P : Params) = struct
| User rules |
+-----------------------------------------------------------------+ *)
let do_rule (conf : Do.t) ~dir =
SC.add_rule sctx
(SC.Do_action.run sctx conf.action ~dir)
let user_rule (rule : Rule.t) ~dir ~package_context =
let targets = List.map rule.targets ~f:(Path.relative dir) in
SC.add_rule sctx
@ -600,6 +604,7 @@ module Gen(P : Params) = struct
let dir = ctx_dir in
match (stanza : Stanza.t) with
| Rule rule -> user_rule rule ~dir ~package_context
| Do conf -> do_rule conf ~dir
| Alias alias -> alias_rules alias ~dir ~package_context
| Library _ | Executables _ | Provides _ | Install _ -> ());
let files = lazy (

View File

@ -727,6 +727,18 @@ module Rule = struct
})
end
module Do = struct
type t =
{ loc : Loc.t
; action : Action.Unexpanded.t
}
let v1 sexp =
{ loc = Sexp.Ast.loc sexp
; action = Action.Unexpanded.t sexp
}
end
module Menhir = struct
type t =
{ base : string option
@ -830,6 +842,7 @@ module Stanza = struct
| Library of Library.t
| Executables of Executables.t
| Rule of Rule.t
| Do of Do.t
| Provides of Provides.t
| Install of Install_conf.t
| Alias of Alias_conf.t
@ -852,6 +865,7 @@ module Stanza = struct
; cstr "menhir" (Menhir.v1 @> nil) (fun x -> rules (Menhir.v1_to_rule x))
; cstr "install" (Install_conf.v1 pkgs @> nil) (fun x -> [Install x])
; cstr "alias" (Alias_conf.v1 pkgs @> nil) (fun x -> [Alias x])
; cstr "do" (Do.v1 @> nil) (fun x -> [Do x])
(* Just for validation and error messages *)
; cstr "jbuild_version" (Jbuild_version.t @> nil) (fun _ -> [])
]

View File

@ -452,6 +452,25 @@ module Pkg_version = struct
Build.vpath spec
end
module Do_action = struct
open Build.O
module U = Action.Unexpanded
let run t action ~dir =
let action =
Action.Unexpanded.expand t.context dir action ~f:(function
| "ROOT" -> Path t.context.build_dir
| var ->
match expand_var_no_root t var with
| Some s -> Str s
| None -> Not_found)
in
let { Action.Infer.Outcome.deps; targets } = Action.Infer.infer action in
Build.path_set deps
>>>
Build.action ~dir ~targets:(Path.Set.elements targets) action
end
module Action = struct
open Build.O
module U = Action.Unexpanded

View File

@ -122,6 +122,15 @@ module Deps : sig
val only_plain_files : t -> dir:Path.t -> Dep_conf.t list -> Path.t option list
end
(** Interpret "do" actions, for which targes are inferred *)
module Do_action : sig
val run
: t
-> Action.Unexpanded.t
-> dir:Path.t
-> (unit, Action.t) Build.t
end
(** Interpret action written in jbuild files *)
module Action : sig
val run