Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
ocamlbuild does not give correct switches to ocamldep when running menhir #4572
Original bug ID: 4572
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:
To make this compile, I define a tags file:
Then, I define a myocamlbuild.ml file with:
let _ = dispatch begin function
(* 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.
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 menhir_ocamldep_command' tags ~menhir_spec ~ocamldep_spec out =
let menhir_ocamldep_command arg out env _build =
| After_rules ->