Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add possibilité to customize ocamlbuild options #5139

Closed
vicuna opened this issue Aug 31, 2010 · 11 comments
Closed

add possibilité to customize ocamlbuild options #5139

vicuna opened this issue Aug 31, 2010 · 11 comments

Comments

@vicuna
Copy link

vicuna commented Aug 31, 2010

Original bug ID: 5139
Reporter: daweil
Assigned to: @xclerc
Status: closed (set by @xavierleroy on 2012-09-25T18:06:17Z)
Resolution: fixed
Priority: normal
Severity: feature
Fixed in version: 3.12.1+dev
Category: -for ocamlbuild use https://github.com/ocaml/ocamlbuild/issues
Monitored by: daweil

Bug description

Could the list "spec" in the module Command of ocamlbuild be a reference on a liste, so that the writer of plugin could add its own options ?

@vicuna
Copy link
Author

vicuna commented Feb 15, 2011

Comment author: @xclerc

A function named 'add' has been added to 'Ocamlbuild_plugin.Options'.
A command-line option named '-plugin-option' has been added to
ocamlbuild (as it is necessary for the 'pristine' ocamlbuild to ignore
added options).

Here is a 'myocamlbuild.ml' example:

open Ocamlbuild_plugin

let () =
dispatch begin function
| Before_options ->
Options.add ("-hello",
Arg.String (Printf.printf "Hello %s.\n"),
" classical example")
| _ -> ()
end

and an example of its execution:
ocamlbuild -plugin-option '-hello' -plugin-option 'world'

@vicuna
Copy link
Author

vicuna commented Feb 15, 2011

Comment author: daweil

That works but it is not what I wished! It looks quite heavy to use for the user and it looks redundant with the "--" option of ocamlbuild?
What I wish is really to overwrite any ocamlbuild option, of course, at the own risk, of the plugin developper!
and to call ocamlbuild directly with the option I want :
ocamlbuild -myoption "hello world"

I use ocamlbuild to build project which do not compile any ocaml code. I even want to hide from the user of the plugin I develop that my plugin is able to compile Ocaml code.
That's why I was proposing to change the "spec" list of Ocamlbuild/options.ml into a reference to a list, or to offer a function in the plugin API that overwrite this list.

@vicuna
Copy link
Author

vicuna commented Feb 15, 2011

Comment author: @xclerc

First, this is not redundant with the "--" option of ocamlbuild that is used to pass
arguments to a produced executable, not to a plugin. Then, the ability to add an
option, but not to bypass / remove any existing one is coherent with the behavior
of both camlp4 and ocamldoc. Finally, my understanding is that what you are
trying to achieve is not to be seen as a plugin task (I reckon this is a matter of taste).

For what you are trying to achieve, I would suggest to use ocamlbuild as
a library (that is "ocamlbuildlib.cm[x]a" in "$PREFIX/lib/ocaml/ocamlbuild").

@vicuna
Copy link
Author

vicuna commented Feb 15, 2011

Comment author: daweil

You're right. It's not a plugin that I wish but a "custom" build tool. In that case, what should be my entry points ?

@vicuna
Copy link
Author

vicuna commented Feb 15, 2011

Comment author: @xclerc

You could take a look at "$ROOT/ocamlbuild/ocamlbuildlib.mllib" that defines
the contents of the library. It contains the following modules:

  • Ocamlbuild_pack;
  • Ocamlbuild_plugin;
  • Ocamlbuild_unix_plugin;
  • Ocamlbuild_executor;
    where the three last ones are "top" modules while the first one is a package
    whose contents is defined by "$ROOT/ocamlbuild/ocamlbuild_pack.mlpack".
    It is too lengthy to list here, but basically you have access to all modules
    of the "$ROOT/ocamlbuild/directory" except "Ocamlbuild" that is just the
    entry point whose role is to call "Main.main".
    In "Ocamlbuild_pack", you will have access to the tags, rules, commands, etc.

@vicuna
Copy link
Author

vicuna commented Feb 15, 2011

Comment author: daweil

OK. I understand that I should link with this library, specify my own command line options, customize the main.ml file to parse my options and link it with a copy of ocamlbuild.ml and of course with myocamlbuild.ml file.

@vicuna
Copy link
Author

vicuna commented Feb 15, 2011

Comment author: @xclerc

Well, if your tool is a build tool that need no OCaml support, you can leave
"Main" as it is today, and have your dedicated module that does its own analysis
of the command line. This dedicated module can also receive was used to be
in your "myocamlbuild.ml" file. After, all is a matter of taste and architecture;
the only things you should not do is to call "Main.main", or "Options.init"...

@vicuna
Copy link
Author

vicuna commented Feb 15, 2011

Comment author: daweil

OK, I'll try.

@vicuna
Copy link
Author

vicuna commented Feb 16, 2011

Comment author: @ygrek

Why would one want to add cmdline options to plugin when there is _tags file for that? It looks like duplicate functionality with no benefits..

@vicuna
Copy link
Author

vicuna commented Feb 16, 2011

Comment author: @xclerc

The "_tags" file is essentially a static one describing how to build
while one may want to orthogonally pass options to dynamically
change some parameters (e.g. debug enabled/disabled).

Some simple things may be done through the "-tag" / "-tags" /
"-tag-line" options, but more complex behavior may need the
computation of a plugin. Hence the possibility to add a need
command-line option. Moreover, as pointed out above, this
possibility is coherent with camlp4 and ocamldoc plugins.

@vicuna
Copy link
Author

vicuna commented Feb 16, 2011

Comment author: @xclerc

I mark the issue as "resolved/fixed", but the original reporter
should feel free to add notes or to contact me by mail if the
suggested path does not lead to success.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant