Move menhir rules to own module
This commit is contained in:
parent
09aa2cd1cf
commit
288de19920
|
@ -1,4 +1,5 @@
|
||||||
open Import
|
open Import
|
||||||
|
module Menhir_rules = Menhir
|
||||||
open Jbuild
|
open Jbuild
|
||||||
open Build.O
|
open Build.O
|
||||||
open! No_io
|
open! No_io
|
||||||
|
@ -223,6 +224,10 @@ module Gen(P : Install_rules.Params) = struct
|
||||||
let generated_files =
|
let generated_files =
|
||||||
List.concat_map stanzas ~f:(fun stanza ->
|
List.concat_map stanzas ~f:(fun stanza ->
|
||||||
match (stanza : Stanza.t) with
|
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 ->
|
| Rule rule ->
|
||||||
List.map (user_rule rule ~dir ~scope) ~f:Path.basename
|
List.map (user_rule rule ~dir ~scope) ~f:Path.basename
|
||||||
| Copy_files def ->
|
| Copy_files def ->
|
||||||
|
|
|
@ -945,6 +945,7 @@ module Menhir = struct
|
||||||
; flags : String_with_vars.t list
|
; flags : String_with_vars.t list
|
||||||
; modules : string list
|
; modules : string list
|
||||||
; mode : Rule.Mode.t
|
; mode : Rule.Mode.t
|
||||||
|
; loc : Loc.t
|
||||||
}
|
}
|
||||||
|
|
||||||
let v1 =
|
let v1 =
|
||||||
|
@ -958,48 +959,9 @@ module Menhir = struct
|
||||||
; flags
|
; flags
|
||||||
; modules
|
; modules
|
||||||
; mode
|
; 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
|
end
|
||||||
|
|
||||||
module Provides = struct
|
module Provides = struct
|
||||||
|
@ -1067,6 +1029,7 @@ module Stanza = struct
|
||||||
| Install of Install_conf.t
|
| Install of Install_conf.t
|
||||||
| Alias of Alias_conf.t
|
| Alias of Alias_conf.t
|
||||||
| Copy_files of Copy_files.t
|
| Copy_files of Copy_files.t
|
||||||
|
| Menhir of Menhir.t
|
||||||
end
|
end
|
||||||
|
|
||||||
module Stanzas = struct
|
module Stanzas = struct
|
||||||
|
@ -1096,7 +1059,7 @@ module Stanzas = struct
|
||||||
; cstr_loc "ocamlyacc" (Rule.ocamlyacc_v1 @> nil)
|
; cstr_loc "ocamlyacc" (Rule.ocamlyacc_v1 @> nil)
|
||||||
(fun loc x -> rules (Rule.ocamlyacc_to_rule loc x))
|
(fun loc x -> rules (Rule.ocamlyacc_to_rule loc x))
|
||||||
; cstr_loc "menhir" (Menhir.v1 @> nil)
|
; 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 "install" (Install_conf.v1 pkgs @> nil) (fun x -> [Install x])
|
||||||
; cstr "alias" (Alias_conf.v1 pkgs @> nil) (fun x -> [Alias x])
|
; cstr "alias" (Alias_conf.v1 pkgs @> nil) (fun x -> [Alias x])
|
||||||
; cstr "copy_files" (Copy_files.v1 @> nil)
|
; cstr "copy_files" (Copy_files.v1 @> nil)
|
||||||
|
|
|
@ -284,6 +284,16 @@ module Rule : sig
|
||||||
}
|
}
|
||||||
end
|
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
|
module Provides : sig
|
||||||
type t =
|
type t =
|
||||||
{ name : string
|
{ name : string
|
||||||
|
@ -317,6 +327,7 @@ module Stanza : sig
|
||||||
| Install of Install_conf.t
|
| Install of Install_conf.t
|
||||||
| Alias of Alias_conf.t
|
| Alias of Alias_conf.t
|
||||||
| Copy_files of Copy_files.t
|
| Copy_files of Copy_files.t
|
||||||
|
| Menhir of Menhir.t
|
||||||
end
|
end
|
||||||
|
|
||||||
module Stanzas : sig
|
module Stanzas : sig
|
||||||
|
|
|
@ -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
|
||||||
|
}]
|
|
@ -0,0 +1,2 @@
|
||||||
|
|
||||||
|
val to_rules : Jbuild.Menhir.t -> Jbuild.Rule.t list
|
Loading…
Reference in New Issue