ocamlbuild icon indicating copy to clipboard operation
ocamlbuild copied to clipboard

targets should be possible outside _build

Open agarwal opened this issue 9 years ago • 6 comments

99% of the time files should be built inside _build, and I'm very glad ocamlbuild does that by default. However, sometimes it makes sense to build files elsewhere, e.g. .merlin or a .install file for opam. OCamlbuild shouldn't disallow this as it appears to according to the discussion in gasche/manual-ocamlbuild#21.

agarwal avatar Dec 22 '15 20:12 agarwal

I think this should be handled with care and in a more general reflexion of what is the interaction between inside and outside _build. There are some problems for outside to inside, e.g. a file disappear from the repository and ocamlbuild still use the one in _build. And here a problem of inside to outside.

For me the problem is less to build files elsewhere than to make files built inside _build available outside. I agree with @gasche description of the current automatic linking as flaky (which are created, which are cleaned, ...)

Perhaps one way would be to add a tag available_outside. That indicate to ocamlbuild which files must be updated "outside" with the _build version at the end of a run. It would be done regardless of the target specified on the command line, and it would be used for -clean. By default <*.native> and <*.byte> would have available_outside and you would add this tag to .merlin and .install.

bobot avatar Dec 24 '15 23:12 bobot

I might be missing some subtlety, but my feeling is that the outside/inside distinction is wrong. I suspect the correct solution is to do the opposite; eliminate the special status of _build. The only bit of special status should be: in certain well defined places where a relative path is given, that path will by default have _build prefixed to it. The "by default" is important as it implies I can override this if desired.

The special status of _build should exist only in the UI. The core of ocamlbuild shouldn't know anything about it.

agarwal avatar Dec 28 '15 20:12 agarwal

Lets see if we go in this direction; in that case ocambuild must store a lot more informations in order to not have the same drawbacks than make ( make the difference between what have been previously built and what is from the user). Moreover you need to be able to restrict the application of rules to some subdirectory (you don't want ocaml rules to be applied outside _build). But you need rules that create links or copy file from/to _build. Finally what do we gain? For me _build could be seen just as a place to store computed files. We should just correct which results should be created in the usual filesystem.

bobot avatar Dec 28 '15 21:12 bobot

ocambuild must store a lot more informations in order to not have the same drawbacks than make ( make the difference between what have been previously built and what is from the user).

I'm not clear on the internals of ocamlbuild, and possibly my goals are different. With those disclaimers, I don't see the problem. OCamlbuild knows what rules it is applying, right? So it should be able to infer what file is in the original source tree vs what is generated, regardless of where it put that generated file. Or maybe not; maybe this knowledge really isn't there. Maybe when a rule gets activated, it is simply run for its side effect. If so, this is really terrible. I'm envisioning that there is a DAG somewhere internally that is created from all the activated rules, but maybe there isn't.

agarwal avatar Jan 13 '16 18:01 agarwal

@agarwal can you tell what is wrong with the tag available_outside approach described before for your use case?

bobot avatar Feb 10 '16 08:02 bobot

I still feel outside/inside is an awkward concept. Build systems have source files and generated files; to me source/generated is a valid thing to know, and that is more general than outside/inside. Maybe the suggestion will solve the one specific problem I'm mentioning here, but I feel it is headed down the wrong path. You're proposing yet another tag, but actually I don't much like the entire tags mechanism (so possibly I can't be satisfied).

More specific responses:

That indicate to ocamlbuild which files must be updated "outside" with the _build version at the end of a run.

Can you clarify how they would be updated? Do you mean a symlink is created on the outside and points to the file inside _build? If so, I still don't like that. I don't want to build a symlink outside. I want to build a regular file.

you would add this tag to .merlin and .install

Can you clarify? Neither of these files have tags, right. I don't get how they are related.

agarwal avatar Feb 10 '16 15:02 agarwal