diff --git a/src/gen_rules.ml b/src/gen_rules.ml index 968f5147..6394161f 100644 --- a/src/gen_rules.ml +++ b/src/gen_rules.ml @@ -1,4 +1,5 @@ open Import +module Menhir_rules = Menhir open Jbuild open Build.O open! No_io @@ -223,6 +224,10 @@ module Gen(P : Install_rules.Params) = struct let generated_files = List.concat_map stanzas ~f:(fun stanza -> match (stanza : Stanza.t) with + | Menhir menhir -> + Menhir_rules.to_rules menhir + |> List.concat_map ~f:(user_rule ~dir ~scope) + |> List.map ~f:Path.basename | Rule rule -> List.map (user_rule rule ~dir ~scope) ~f:Path.basename | Copy_files def -> diff --git a/src/jbuild.ml b/src/jbuild.ml index 4d13b680..4ab84962 100644 --- a/src/jbuild.ml +++ b/src/jbuild.ml @@ -945,6 +945,7 @@ module Menhir = struct ; flags : String_with_vars.t list ; modules : string list ; mode : Rule.Mode.t + ; loc : Loc.t } let v1 = @@ -958,48 +959,9 @@ module Menhir = struct ; flags ; modules ; mode + ; loc = Loc.none } ) - - let v1_to_rule loc t = - let module S = String_with_vars in - let targets n = [n ^ ".ml"; n ^ ".mli"] in - match t.merge_into with - | None -> - List.map t.modules ~f:(fun name -> - let src = name ^ ".mly" in - { Rule. - targets = Static (targets name) - ; deps = [Dep_conf.File (S.virt_text __POS__ src)] - ; action = - Chdir - (S.virt_var __POS__ "ROOT", - Run (S.virt_text __POS__ "menhir", - t.flags @ [S.virt_var __POS__ "<"])) - ; mode = t.mode - ; locks = [] - ; loc - }) - | Some merge_into -> - let mly m = S.virt_text __POS__ (m ^ ".mly") in - [{ Rule. - targets = Static (targets merge_into) - ; deps = List.map ~f:(fun m -> Dep_conf.File (mly m)) t.modules - ; action = - Chdir - (S.virt_var __POS__ "ROOT", - Run (S.virt_text __POS__ "menhir", - List.concat - [ [ S.virt_text __POS__ "--base" - ; S.virt_var __POS__ ("path-no-dep:" ^ merge_into) - ] - ; t.flags - ; [ S.virt_var __POS__ "^" ] - ])) - ; mode = t.mode - ; locks = [] - ; loc - }] end module Provides = struct @@ -1067,6 +1029,7 @@ module Stanza = struct | Install of Install_conf.t | Alias of Alias_conf.t | Copy_files of Copy_files.t + | Menhir of Menhir.t end module Stanzas = struct @@ -1096,7 +1059,7 @@ module Stanzas = struct ; cstr_loc "ocamlyacc" (Rule.ocamlyacc_v1 @> nil) (fun loc x -> rules (Rule.ocamlyacc_to_rule loc x)) ; cstr_loc "menhir" (Menhir.v1 @> nil) - (fun loc x -> rules (Menhir.v1_to_rule loc x)) + (fun loc x -> [Menhir { x with loc }]) ; cstr "install" (Install_conf.v1 pkgs @> nil) (fun x -> [Install x]) ; cstr "alias" (Alias_conf.v1 pkgs @> nil) (fun x -> [Alias x]) ; cstr "copy_files" (Copy_files.v1 @> nil) diff --git a/src/jbuild.mli b/src/jbuild.mli index a2d84fd4..e994d553 100644 --- a/src/jbuild.mli +++ b/src/jbuild.mli @@ -284,6 +284,16 @@ module Rule : sig } end +module Menhir : sig + type t = + { merge_into : string option + ; flags : String_with_vars.t list + ; modules : string list + ; mode : Rule.Mode.t + ; loc : Loc.t + } +end + module Provides : sig type t = { name : string @@ -317,6 +327,7 @@ module Stanza : sig | Install of Install_conf.t | Alias of Alias_conf.t | Copy_files of Copy_files.t + | Menhir of Menhir.t end module Stanzas : sig diff --git a/src/menhir.ml b/src/menhir.ml new file mode 100644 index 00000000..b857568c --- /dev/null +++ b/src/menhir.ml @@ -0,0 +1,42 @@ +open Import +open Jbuild + +let to_rules (t : Jbuild.Menhir.t) = + let module S = String_with_vars in + let targets n = [n ^ ".ml"; n ^ ".mli"] in + match t.merge_into with + | None -> + List.map t.modules ~f:(fun name -> + let src = name ^ ".mly" in + { Jbuild.Rule. + targets = Static (targets name) + ; deps = [Dep_conf.File (S.virt_text __POS__ src)] + ; action = + Chdir + (S.virt_var __POS__ "ROOT", + Run (S.virt_text __POS__ "menhir", + t.flags @ [S.virt_var __POS__ "<"])) + ; mode = t.mode + ; locks = [] + ; loc = t.loc + }) + | Some merge_into -> + let mly m = S.virt_text __POS__ (m ^ ".mly") in + [{ Rule. + targets = Static (targets merge_into) + ; deps = List.map ~f:(fun m -> Dep_conf.File (mly m)) t.modules + ; action = + Chdir + (S.virt_var __POS__ "ROOT", + Run (S.virt_text __POS__ "menhir", + List.concat + [ [ S.virt_text __POS__ "--base" + ; S.virt_var __POS__ ("path-no-dep:" ^ merge_into) + ] + ; t.flags + ; [ S.virt_var __POS__ "^" ] + ])) + ; mode = t.mode + ; locks = [] + ; loc = t.loc + }] diff --git a/src/menhir.mli b/src/menhir.mli new file mode 100644 index 00000000..e57e35d0 --- /dev/null +++ b/src/menhir.mli @@ -0,0 +1,2 @@ + +val to_rules : Jbuild.Menhir.t -> Jbuild.Rule.t list