Implement menhir rules from scrath
Rather than changing them to user_rules and then compiling those.
This commit is contained in:
parent
288de19920
commit
f06519e231
|
@ -225,8 +225,7 @@ module Gen(P : Install_rules.Params) = struct
|
||||||
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 menhir ->
|
||||||
Menhir_rules.to_rules menhir
|
Menhir_rules.gen_rules sctx ~dir ~scope menhir
|
||||||
|> List.concat_map ~f:(user_rule ~dir ~scope)
|
|
||||||
|> List.map ~f:Path.basename
|
|> 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
|
||||||
|
|
|
@ -1,42 +1,35 @@
|
||||||
open Import
|
open Import
|
||||||
open Jbuild
|
|
||||||
|
|
||||||
let to_rules (t : Jbuild.Menhir.t) =
|
let gen_rules sctx ~dir ~scope (t : Jbuild.Menhir.t) =
|
||||||
let module S = String_with_vars in
|
let targets n = List.map ~f:(Path.relative dir) [n ^ ".ml"; n ^ ".mli"] in
|
||||||
let targets n = [n ^ ".ml"; n ^ ".mli"] in
|
let flags =
|
||||||
|
List.map ~f:(Super_context.expand_vars sctx ~scope ~dir) t.flags in
|
||||||
|
let menhir =
|
||||||
|
let menhir =
|
||||||
|
Super_context.resolve_program sctx ~hint:"opam install menhir" "menhir" in
|
||||||
|
fun ~extra_targets ->
|
||||||
|
Build.run ~extra_targets
|
||||||
|
menhir
|
||||||
|
~dir
|
||||||
|
~context:(Super_context.context sctx) in
|
||||||
|
let add_rule_get_targets =
|
||||||
|
Super_context.add_rule_get_targets sctx ~mode:t.mode ~loc:t.loc in
|
||||||
|
let mly name = Path.relative dir (name ^ ".mly") in
|
||||||
match t.merge_into with
|
match t.merge_into with
|
||||||
| None ->
|
| None ->
|
||||||
List.map t.modules ~f:(fun name ->
|
List.concat_map ~f:(fun name ->
|
||||||
let src = name ^ ".mly" in
|
add_rule_get_targets (
|
||||||
{ Jbuild.Rule.
|
menhir
|
||||||
targets = Static (targets name)
|
~extra_targets:(targets name)
|
||||||
; deps = [Dep_conf.File (S.virt_text __POS__ src)]
|
[ As flags
|
||||||
; action =
|
; Dep (mly name)]
|
||||||
Chdir
|
)) t.modules
|
||||||
(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 ->
|
| Some merge_into ->
|
||||||
let mly m = S.virt_text __POS__ (m ^ ".mly") in
|
add_rule_get_targets (
|
||||||
[{ Rule.
|
menhir
|
||||||
targets = Static (targets merge_into)
|
~extra_targets:(targets merge_into)
|
||||||
; deps = List.map ~f:(fun m -> Dep_conf.File (mly m)) t.modules
|
[ A "--base" ; A merge_into
|
||||||
; action =
|
; As flags
|
||||||
Chdir
|
; Deps (List.map ~f:mly t.modules)
|
||||||
(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
|
|
||||||
}]
|
|
||||||
|
|
|
@ -1,2 +1,7 @@
|
||||||
|
|
||||||
val to_rules : Jbuild.Menhir.t -> Jbuild.Rule.t list
|
val gen_rules
|
||||||
|
: Super_context.t
|
||||||
|
-> dir:Path.t
|
||||||
|
-> scope:Scope.t
|
||||||
|
-> Jbuild.Menhir.t
|
||||||
|
-> Path.t list
|
||||||
|
|
Loading…
Reference in New Issue