ocaml / ocamlbuild

The legacy OCamlbuild build manager
Other
121 stars 81 forks source link

MPR#6097: Allow user to add new commandline options in the plugin. #193

Open damiendoligez opened 7 years ago

damiendoligez commented 7 years ago

PR transferred from https://caml.inria.fr/mantis/view.php?id=6097 [original reporter: @danmey ]

For instance user wants to options and tags for the js_of_ocaml compiler.

Then in his myocamlbuild.ml (s)he will say (roughly):

let jopts := ref ""
dispatch begin function
| Before_construct_options ->
  add_option ("-jopts", String (fun x -> jopts := !jopts ^ " " ^ x, " js_of_ocaml 
options")
| _ -> () end

of course that, and possibility of passing the options to the plugin, make is relatively easy to extend ocamlbuild itself not only with rules but also with new funcionality.

Then we can use the new options like this (hypothetically):

ocamlbuild -popts "-package js_of_ocaml.build" -jopts -pretty foo.js

(or use _tags to get the same functionality)

whitequark commented 7 years ago

Triage: this seems hard to implement as described for the same reasons as in https://github.com/ocaml/ocamlbuild/issues/185#issuecomment-283486418, but trivial to do with -tag.

gasche commented 7 years ago

It is not clear to me why you say that this falls under the same issue as the comment in #185. Here the ideas is to add new options in the myocamlbuild plugin, so it seems that myocamlbuild.ml is a reasonable place to implement this (as long as it is put in Before_options, of course). Camlp4 plugins had access to a nice API to add their own command-line flag, and it was not used by many plugins but it was a nice convenience for those that had a use for it.

My own triaging judgment would be "that sounds reasonable, we welcome a pull request".