namespaces icon indicating copy to clipboard operation
namespaces copied to clipboard

Usage with child packages

Open fxfactorial opened this issue 8 years ago • 2 comments

Say I have module A that is built using findlib library a. Then I want to conditionally built a.b where the building of a.b to create a module A.B

How to do this and make sure it works with oasis

fxfactorial avatar Jun 18 '16 18:06 fxfactorial

I wanted to do exactly this, but I don't have a satisfactory solution ready. I do have "a" solution. I experimented in a namespaces branch of Markup.ml. The exploratory "solution" I was working towards, using Namespaces 0.5.1, was:

  1. Define a module alias in Markup: module Lwt = Markup__lwt. In your example, it would be, in A, module B = A__b. This is not good because it uses an internal name generated by Namespaces, and I was thinking of maybe some PPX, or some other approach, to deal with that in a future version.
  2. Apply tags as you see here, lines 9 and 10 (not 11). Again, A corresponds to Markup, and A.B to Markup.Lwt. This tells Namespaces which modules to put in what ocamlfind package.

It actually kind of works. The packaging is correct – installed packages contain the right modules, and refer to each other, and can be used by other packages. But the dependency analysis is broken during build (as expected with 4.02 ocamldep). The problem is that when you ask to build A.B, it builds A.B. But when you ask to build A, it builds A and A.B (and then correctly doesn't include A.B in the package). So, if A.B depends on a missing optional dependency (which is probably the point of packaging it separately in the first place), compilation of A will fail.

EDIT: on the packaging being correct: Markup refers to Markup.Lwt weakly, and Markup.Lwt to Markup strongly, which is correct.

To resolve this, I was working on making the dependency analysis smarter, first using new features of 4.03 ocamldep, but eventually realizing that I might need to write my own dependency tool (or modify ocamldep extensively).

As for OASIS, I didn't try it, but I don't see why it wouldn't work. Keep in mind that you control which modules go into which library package using the Namespaces tags, not in OASIS. But, because I haven't yet implemented META generation from Namespaces, you have to keep Library sections in _oasis, though with dummy module lists.

If only I had more time......!

aantron avatar Jun 18 '16 20:06 aantron

Oh, BTW, the extra line 11 is there for libraries that already have Foo_Bar packages but want to make them into Foo.Bar. It and the content of Foo_Bar make Foo_Bar into a synonym for Foo.Bar, for backwards compatibility.

aantron avatar Jun 18 '16 20:06 aantron