caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] ocamlbuild add unexpected directories to including-dirs while building multi-targets
@ 2015-10-18  8:18 ZAN DoYe
  2015-10-18  9:44 ` Christian Lindig
  0 siblings, 1 reply; 5+ messages in thread
From: ZAN DoYe @ 2015-10-18  8:18 UTC (permalink / raw)
  To: caml-list

suppose the dir tree is:

.
├── a
│   ├── a.ml (let v= I.a)
│   ├── i
│   │   └── i.ml (let a= 1)
│   └── _tags ("i": include)
├── b
│   ├── b.ml (let v= I.b)
│   ├── i
│   │   └── i.ml (let b= 1)
│   └── _tags ("i": include)
├── myocamlbuild.ml (an empty file)
└── o.itarget (a/a.byte \n b/b.byte)

after running ocamlbuild o.otarget, the error info:

Finished, 1 target (0 cached) in 00:00:00.
+ /home/kandu/.opam/4.02.3/bin/ocamlc.opt -c -I a -I b/i -I a/i -o a/a.cmo a/a.ml
File "a/a.ml", line 1, characters 7-10:
Error: Unbound value I.a

Is there any way to isolate including-dirs while compiling multi-targets?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] ocamlbuild add unexpected directories to including-dirs while building multi-targets
  2015-10-18  8:18 [Caml-list] ocamlbuild add unexpected directories to including-dirs while building multi-targets ZAN DoYe
@ 2015-10-18  9:44 ` Christian Lindig
  2015-10-18 11:03   ` ZAN DoYe
       [not found]   ` <5623788A.2030302@gmail.com>
  0 siblings, 2 replies; 5+ messages in thread
From: Christian Lindig @ 2015-10-18  9:44 UTC (permalink / raw)
  To: ZAN DoYe; +Cc: caml-list


> On 18 Oct 2015, at 10:18, ZAN DoYe <zandoye@gmail.com> wrote:
> 
> Is there any way to isolate including-dirs while compiling multi-targets?

> .
> ├── a
> │   ├── a.ml (let v= I.a)
> │   ├── i
> │   │   └── i.ml (let a= 1)
> │   └── _tags ("i": include)
> ├── b
> │   ├── b.ml (let v= I.b)
> │   ├── i
> │   │   └── i.ml (let b= 1)
> │   └── _tags ("i": include)
> ├── myocamlbuild.ml (an empty file)
> └── o.itarget (a/a.byte \n b/b.byte)

I believe you can’t have two modules I (a/i/i.ml and b/i/i.ml) in the project. While the two are in different directories, they are both top-level modules in the language.

— Christian

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] ocamlbuild add unexpected directories to including-dirs while building multi-targets
  2015-10-18  9:44 ` Christian Lindig
@ 2015-10-18 11:03   ` ZAN DoYe
  2015-10-18 11:12     ` Daniel Bünzli
       [not found]   ` <5623788A.2030302@gmail.com>
  1 sibling, 1 reply; 5+ messages in thread
From: ZAN DoYe @ 2015-10-18 11:03 UTC (permalink / raw)
  To: Christian Lindig; +Cc: caml-list

On 2015-10-18 17:44, Christian Lindig wrote:
> I believe you can’t have two modules I (a/i/i.ml and b/i/i.ml) in the project. While the two are in different directories, they are both top-level modules in the language.
Thanks. I think it's common that two targets contain modules with the same name. e.g. targetA.Init and targetB.Init. each target has a Init module to initialize themself. It'll be convenient if ocamlbuild isolates inc-dir for each target.

For now, Do I have to structure my targets as separate ocamlbuild projects?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] ocamlbuild add unexpected directories to including-dirs while building multi-targets
       [not found]   ` <5623788A.2030302@gmail.com>
@ 2015-10-18 11:05     ` Christian Lindig
  0 siblings, 0 replies; 5+ messages in thread
From: Christian Lindig @ 2015-10-18 11:05 UTC (permalink / raw)
  To: ZAN DoYe; +Cc: caml-list


> On 18 Oct 2015, at 12:46, ZAN DoYe <zandoye@gmail.com> wrote:
> 
> On 2015-10-18 17:44, Christian Lindig wrote:
>> I believe you can’t have two modules I (a/i/i.ml and b/i/i.ml) in the project. While the two are in different directories, they are both top-level modules in the language.
> Thanks. I think it's common that two targets contain modules with the same name. e.g. targetA.Init and targetB.Init. each target has a Init module to initialize themself.
> It's be more convenient if ocamlbuild isolates inc-dir for each target.
> 
> For now, Do I have to structure my targets as separate ocamlbuild projects?
> 

If you want sub-modules A.I and B.I, it would be easiest to implement the respective I inside A and B but not as separate files:

a.ml:
module I = struct
  let a = 1
end 
let v = I.a

b.ml:
module I = struct
  let b = 1
end 
let v = I.b

— Christian




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] ocamlbuild add unexpected directories to including-dirs while building multi-targets
  2015-10-18 11:03   ` ZAN DoYe
@ 2015-10-18 11:12     ` Daniel Bünzli
  0 siblings, 0 replies; 5+ messages in thread
From: Daniel Bünzli @ 2015-10-18 11:12 UTC (permalink / raw)
  To: ZAN DoYe; +Cc: Christian Lindig, caml-list

Le dimanche, 18 octobre 2015 à 12:03, ZAN DoYe a écrit :
> Thanks. I think it's common that two targets contain modules with the same name. e.g. targetA.Init and targetB.Init. each target has a Init module to initialize themself. It'll be convenient if ocamlbuild isolates inc-dir for each target.

Note that if you are writing libraries you should prefix these names anyway as they would exist in the global toplevel namespace and hence potentially clash with other libraries.  

That said I'm also often hit by the limitations you mention when I have libraries that provide multiple implementations of the same interface. The work around is to avoid `include`ing the directories in your _tags file and invoke ocamlbuild with the `-I` option, see for example [1].  

Best,

Daniel

[1] https://github.com/dbuenzli/mtime/blob/a9dafd38002bfd8bdc5d3c3963e2d2d446c2ad6a/build#L19-L20



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-10-18 11:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-18  8:18 [Caml-list] ocamlbuild add unexpected directories to including-dirs while building multi-targets ZAN DoYe
2015-10-18  9:44 ` Christian Lindig
2015-10-18 11:03   ` ZAN DoYe
2015-10-18 11:12     ` Daniel Bünzli
     [not found]   ` <5623788A.2030302@gmail.com>
2015-10-18 11:05     ` Christian Lindig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).