improve handling of symlinks in repo root
I've never been happy with how symlinks are created in the repo root. I think this should be off by default. Users should be in control of which files are created, even when those files are symlinks. In particular it is irritating to have foo.byte and foo.native links created. I certainly don't want both, and I actually don't want either one.
On the other hand, symlinks I do want get deleted!
$ cat myocamlbuild.ml
open Ocamlbuild_plugin
let () = dispatch (function
| After_rules ->
rule ".merlin"
~prod:".merlin"
(fun _ _ -> Echo (["PKG core"],".merlin"))
| _ -> ()
)
$ ocamlbuild .merlin
$ ln -s _build/.merlin
$ ls -l .merlin
lrwx------ 1 ashish staff 14B Dec 22 15:13 .merlin -> _build/.merlin
$ ocamlbuild -clean
$ ls -l .merlin
ls: .merlin: No such file or directory
The current semantics, which I don't think has ever changed since ocamlbuild was released, is to create links only on some specific targets (file extensions): byte, native, top (toplevels), and html targets (it then creates a link to the .docdir directory rather than html file itself). See the implementation in main.ml.
Note that you can use the -no-links option to never create links. We do not have a -make-links option (enabled by default), which mean that right now we cannot disable links by default as our users would have not explicit solution to re-enable them. We should add it as soon as possible.
The question of user-made links into _build is more subtle. OCamlbuild consider that anything in _build is its own territory, and in particular links will always become stale after ocamlbuild -clean, so arguably removing them at cleaning time is a correct move. I think we need to discuss your need of generating .install and .merlin file on its own: I think this is an important and useful feature to have, but we may need a broader design discussion than just changing some aspects of ocamlbuild one at a time to create one of the possible implementation paths.
Note that you can use the
-no-linksoption to never create links.
This sort of works for me, but it's not ideal. The .byte and .native files aren't created, as I want. But also ocamlbuild now disregards links upon a -clean, so my .merlin → _build/.merlin symlink doesn't get removed. That's kind of okay because I can consider the symlink as a part of my source code, i.e. git commit it. That's not ideal. I'd rather not checkin broken links.
we need to discuss your need of generating
.installand.merlinfile on its own
Indeed the real issue isn't about symlinks. The broader problem is #17. If that were resolved, we could simply eliminate this business about automatically creating symlinks. If someone did want them, they could easily write a rule to create them. That would be much better since the links would be first class build artifacts, unlike in the hack currently required.