You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original bug ID: 4572 Reporter: inalan Assigned to: ertai Status: closed (set by ertai on 2008-07-25T14:50:18Z) Resolution: fixed Priority: normal Severity: block Version: 3.10.1 Fixed in version: 3.11+dev Category: ~DO NOT USE (was: OCaml general) Monitored by: kanig inalan
Bug description
Generally, ocamlbuild finds dependencies for menhir .mly files by invoking menhir with the switch: --ocamldep '<ocamldep_options>'. The ocamldep options are however taken from the same list of options as are given to menhir itself during the dependency check. Thus, if menhir requires options that ocamldep does not support, an error is thrown.
Suppose, for example, I have written a parser using menhir and it uses an external token file. Thus, my files are:
main.ml
parser.mly
tokens.mly
lexer.mll
To make this compile, I define a tags file:
"tokens.mly": only-tokens
Then, I define a myocamlbuild.ml file with:
let parserFlags =
(atomize
["--external-tokens";
"Tokens";
"--base";
"Parser";
"tokens.mly";
]
)
let _ = dispatch begin function
| After_rules ->
flag ["ocaml"; "menhir_ocamldep"; "only-tokens"] (A "--only-tokens");
flag ["ocaml"; "parser"; "menhir"; "only-tokens"] (A "--only-tokens");
flag ["ocaml"; "menhir_ocamldep"; "parser.mly"] parserFlags
flag ["ocaml"; "parser"; "menhir"; "parser.mly"] parserFlags
(* plus some dep lines, not shown *)
When running a Make with this myocamlbuild.ml file, ocamlbuild ends up giving both menhir and ocamldep the --base and --external-tokens arguments, like so:
Then ocamldep throws an error and we can't proceed any further. Actually, the switches are given three times in the same command; once to menhir, once to ocamldep, and then once to pp. The real issue here is that when figuring out the dependencies, menhir requires a different set of arguments than does ocamldep. There is no easy way to hack around this using tags.
Additional information
The only quick workaround I've found is to copy the menhir dependencies rule into myocamlbuild.ml along with its supporting functions, and then throw out the tags when passed to ocamldep. A full, working example (of just the myocamlbuild.ml file) is attached. Here is the short version:
let notags=Ocamlbuild_pack.Tags.of_list []
(* copied and modified from ocamlbuild sources: *)
let ocamldep_command' tags spec =
let tags' = tags++"ocaml"++"ocamldep" in
S [!Options.ocamldep; T tags'; Ocamlbuild_pack.Ocaml_utils.ocaml_ppflags (tags++"pp:dep");
spec; A "-modules"]
let menhir_ocamldep_command' tags ~menhir_spec ~ocamldep_spec out =
let menhir = if !Options.ocamlyacc = N then V"MENHIR" else !Options.ocamlyacc
in Cmd(S[menhir; T tags; A"--raw-depend";
(A"--ocamldep"; Quote (ocamldep_command' tags ocamldep_spec);)
A"--ocamldep"; Quote (ocamldep_command' notags ocamldep_spec);
menhir_spec ; Sh ">"; Px out])
let menhir_ocamldep_command arg out env _build =
let arg = env arg and out = env out in
let tags = tags_of_pathname arg++"ocaml"++"menhir_ocamldep" in
let ocamldep_spec = ignore (Ocamlbuild_pack.Tools.flags_of_pathname arg) in
menhir_ocamldep_command' tags ~menhir_spec:(P arg) ~ocamldep_spec out
Original bug ID: 4572
Reporter: inalan
Assigned to: ertai
Status: closed (set by ertai on 2008-07-25T14:50:18Z)
Resolution: fixed
Priority: normal
Severity: block
Version: 3.10.1
Fixed in version: 3.11+dev
Category: ~DO NOT USE (was: OCaml general)
Monitored by: kanig inalan
Bug description
Generally, ocamlbuild finds dependencies for menhir .mly files by invoking menhir with the switch: --ocamldep '<ocamldep_options>'. The ocamldep options are however taken from the same list of options as are given to menhir itself during the dependency check. Thus, if menhir requires options that ocamldep does not support, an error is thrown.
Suppose, for example, I have written a parser using menhir and it uses an external token file. Thus, my files are:
main.ml
parser.mly
tokens.mly
lexer.mll
To make this compile, I define a tags file:
"tokens.mly": only-tokens
Then, I define a myocamlbuild.ml file with:
let parserFlags =
(atomize
["--external-tokens";
"Tokens";
"--base";
"Parser";
"tokens.mly";
]
)
let _ = dispatch begin function
| After_rules ->
flag ["ocaml"; "menhir_ocamldep"; "only-tokens"] (A "--only-tokens");
flag ["ocaml"; "parser"; "menhir"; "only-tokens"] (A "--only-tokens");
(* plus some dep lines, not shown *)
When running a Make with this myocamlbuild.ml file, ocamlbuild ends up giving both menhir and ocamldep the --base and --external-tokens arguments, like so:
menhir --base Parser --external-tokens Tokens --raw-depends --ocamldep '--base Parser --external-tokens Tokens' etc.
Then ocamldep throws an error and we can't proceed any further. Actually, the switches are given three times in the same command; once to menhir, once to ocamldep, and then once to pp. The real issue here is that when figuring out the dependencies, menhir requires a different set of arguments than does ocamldep. There is no easy way to hack around this using tags.
Additional information
The only quick workaround I've found is to copy the menhir dependencies rule into myocamlbuild.ml along with its supporting functions, and then throw out the tags when passed to ocamldep. A full, working example (of just the myocamlbuild.ml file) is attached. Here is the short version:
let notags=Ocamlbuild_pack.Tags.of_list []
(* copied and modified from ocamlbuild sources: *)
let ocamldep_command' tags spec =
let tags' = tags++"ocaml"++"ocamldep" in
S [!Options.ocamldep; T tags'; Ocamlbuild_pack.Ocaml_utils.ocaml_ppflags (tags++"pp:dep");
spec; A "-modules"]
let menhir_ocamldep_command' tags ~menhir_spec ~ocamldep_spec out =
let menhir = if !Options.ocamlyacc = N then V"MENHIR" else !Options.ocamlyacc
in Cmd(S[menhir; T tags; A"--raw-depend";
(A"--ocamldep"; Quote (ocamldep_command' tags ocamldep_spec);)
A"--ocamldep"; Quote (ocamldep_command' notags ocamldep_spec);
menhir_spec ; Sh ">"; Px out])
let menhir_ocamldep_command arg out env _build =
let arg = env arg and out = env out in
let tags = tags_of_pathname arg++"ocaml"++"menhir_ocamldep" in
let ocamldep_spec = ignore (Ocamlbuild_pack.Tools.flags_of_pathname arg) in
menhir_ocamldep_command' tags ~menhir_spec:(P arg) ~ocamldep_spec out
| After_rules ->
rule "ocaml: menhir dependencies0"
~prod: "%.mly.depends"
~dep: "%.mly"
~insert: (`before "ocaml: menhir dependencies")
(menhir_ocamldep_command "%.mly" "%.mly.depends");
File attachments
The text was updated successfully, but these errors were encountered: