caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* OCamlBuild question
@ 2008-09-30  7:27 David Teller
  2008-09-30 10:40 ` Nicolas Pouillard
  0 siblings, 1 reply; 5+ messages in thread
From: David Teller @ 2008-09-30  7:27 UTC (permalink / raw)
  To: OCaml; +Cc: Nicolas Pouillard

	Hi everyone,
I'm trying to write a OCamlBuild plug-in to automatically generate
the .mli corresponding to a .mlpack (for documentation purposes).

I've written a [rule] which lets me depend a .mli on the
corresponding .mlpack .  From this .mlpack, I can obtain the list of
modules involved in the construction of the pack. Now, I only have to
1. find the corresponding source .mli files
2. find the corresponding .mli.depends files
3. do a topological sort and create the destination .mli .

Part 3 is no problem. On the other hand, I haven't been able to progress
much with parts 1 and 2. 

Part 2 requires waiting until the corresponding .mli.depends have been
created, but 
* neither [~insert:`bottom] nor [~insert:(`after foo)] seem to help here
* attempting to [build] an ad-hoc list of files somehow extracted from
the mlpack only gives me dependency errors
* attempting [Solve.solve_target] doesn't seem to help any further.

As for part 1, it requires the ability to find which source .ml / .mli
correspond to a given module. I can only assume OCamlBuild offers some
kind of API for this purpose, because I'd rather avoid folding through
the whole tree, resolving [include] directives myself to find a .ml or
a .mli which may be the right file.

Does anyone have suggestions?

Thanks,
 David
-- 
David Teller-Rajchenbach
 Security of Distributed Systems
  http://www.univ-orleans.fr/lifo/Members/David.Teller
 Angry researcher: French Universities need reforms, but the LRU act brings liquidations. 


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

* Re: OCamlBuild question
  2008-09-30  7:27 OCamlBuild question David Teller
@ 2008-09-30 10:40 ` Nicolas Pouillard
  2008-09-30 14:49   ` David Teller
  2008-09-30 15:12   ` David Teller
  0 siblings, 2 replies; 5+ messages in thread
From: Nicolas Pouillard @ 2008-09-30 10:40 UTC (permalink / raw)
  To: david.teller; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 2023 bytes --]

Excerpts from david.teller's message of Tue Sep 30 09:27:11 +0200 2008:
>     Hi everyone,
> I'm trying to write a OCamlBuild plug-in to automatically generate
> the .mli corresponding to a .mlpack (for documentation purposes).
> 
> I've written a [rule] which lets me depend a .mli on the
> corresponding .mlpack .  From this .mlpack, I can obtain the list of
> modules involved in the construction of the pack. Now, I only have to
> 1. find the corresponding source .mli files
> 2. find the corresponding .mli.depends files
> 3. do a topological sort and create the destination .mli .
> 
> Part 3 is no problem. On the other hand, I haven't been able to progress
> much with parts 1 and 2. 
> 
> Part 2 requires waiting until the corresponding .mli.depends have been
> created, but 
> * neither [~insert:`bottom] nor [~insert:(`after foo)] seem to help here
> * attempting to [build] an ad-hoc list of files somehow extracted from
> the mlpack only gives me dependency errors
> * attempting [Solve.solve_target] doesn't seem to help any further.

If you need (depend) on files that you statically know then the ~deps argument
is fine (~deps:["%.mli.depends"; "%.mli"]). If you need files that you only
know dynamically then the 'build' argument function is for that purpose.

> As for part 1, it requires the ability to find which source .ml / .mli
> correspond to a given module. I can only assume OCamlBuild offers some
> kind of API for this purpose, because I'd rather avoid folding through
> the whole tree, resolving [include] directives myself to find a .ml or
> a .mli which may be the right file.

Yes the function is called expand_module it takes 3 arguments, the include
directories, the module name, the extensions.

   Example: let include_dirs = Pathname.include_dirs_of (Pathname.dirname mlpack)
            in build (expand_module include_dirs module_name ["mli"; "mli.depends"])

Have a look to the ocamlbuild/ocaml_tools.ml file for a similar function
(import_mlypack).

-- 
Nicolas Pouillard aka Ertai

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 194 bytes --]

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

* Re: OCamlBuild question
  2008-09-30 10:40 ` Nicolas Pouillard
@ 2008-09-30 14:49   ` David Teller
  2008-09-30 15:12   ` David Teller
  1 sibling, 0 replies; 5+ messages in thread
From: David Teller @ 2008-09-30 14:49 UTC (permalink / raw)
  To: Nicolas Pouillard; +Cc: caml-list

Merci, avec ces explications, je suis enfin arrivé à faire fonctionner
[build]. Maintenant, reste un problème tout bête : j'arrive à écrire le
contenu de mon .mli dans _build mais pour des raisons qui m'échappent,
celui-ci est effacé avant la fin de la compilation. J'ai essayé de
l'ouvrir avec [open_out] et avec [with_output_file], avec le même
résultat. C'est assez frustrant. Des idées ?

Merci,
 David


On Tue, 2008-09-30 at 12:40 +0200, Nicolas Pouillard wrote: 
> If you need (depend) on files that you statically know then the ~deps argument
> is fine (~deps:["%.mli.depends"; "%.mli"]). If you need files that you only
> know dynamically then the 'build' argument function is for that purpose.
>
> > As for part 1, it requires the ability to find which source .ml / .mli
> > correspond to a given module. I can only assume OCamlBuild offers some
> > kind of API for this purpose, because I'd rather avoid folding through
> > the whole tree, resolving [include] directives myself to find a .ml or
> > a .mli which may be the right file.
> 
> Yes the function is called expand_module it takes 3 arguments, the include
> directories, the module name, the extensions.
> 
>    Example: let include_dirs = Pathname.include_dirs_of (Pathname.dirname mlpack)
>             in build (expand_module include_dirs module_name ["mli"; "mli.depends"])
> 
> Have a look to the ocamlbuild/ocaml_tools.ml file for a similar function
> (import_mlypack).
> 
-- 
David Teller-Rajchenbach
 Security of Distributed Systems
  http://www.univ-orleans.fr/lifo/Members/David.Teller
 Angry researcher: French Universities need reforms, but the LRU act brings liquidations. 


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

* Re: OCamlBuild question
  2008-09-30 10:40 ` Nicolas Pouillard
  2008-09-30 14:49   ` David Teller
@ 2008-09-30 15:12   ` David Teller
  1 sibling, 0 replies; 5+ messages in thread
From: David Teller @ 2008-09-30 15:12 UTC (permalink / raw)
  To: Nicolas Pouillard; +Cc: caml-list

Merci, avec ces explications, je suis enfin arrivé à faire fonctionner
[build]. Maintenant, reste un problème que je n'arrive pas à
comprendre : mon fichier disparaît. Pour être plus précis, j'écris le
contenu de mon .mli dans un fichier que j'ai créé pour l'occasion, à
l'intérieur de _build -- mais pour des raisons qui m'échappent,
ocamlbuild trouve moyen de l'effacer avant la fin de la compilation.

J'ai vérifié, une fois que j'ai écrit mon fichier, il existe bien. J'ai
aussi vérifié, si je place mon fichier dans /tmp au lieu de _build, ça
marche.   J'ai aussi vérifié, si je remplace l'extension de mon .mli
par .mlpack.mli, ça ne change rien. J'ai essayé de l'ouvrir avec
[open_out] et avec [with_output_file], avec la même absence de
résultats.

Ah, et pour compliquer les choses, ça ne marche pas quand j'appelle
ocamlbuild une seule fois. Mais il arrive que, si j'invoque ocamlbuild
deux fois de suite, ça se mette à marcher.

C'est assez frustrant. Des idées ?

Merci,
 David


On Tue, 2008-09-30 at 12:40 +0200, Nicolas Pouillard wrote: 
> If you need (depend) on files that you statically know then the ~deps argument
> is fine (~deps:["%.mli.depends"; "%.mli"]). If you need files that you only
> know dynamically then the 'build' argument function is for that purpose.
>
> > As for part 1, it requires the ability to find which source .ml / .mli
> > correspond to a given module. I can only assume OCamlBuild offers some
> > kind of API for this purpose, because I'd rather avoid folding through
> > the whole tree, resolving [include] directives myself to find a .ml or
> > a .mli which may be the right file.
> 
> Yes the function is called expand_module it takes 3 arguments, the include
> directories, the module name, the extensions.
> 
>    Example: let include_dirs = Pathname.include_dirs_of (Pathname.dirname mlpack)
>             in build (expand_module include_dirs module_name ["mli"; "mli.depends"])
> 
> Have a look to the ocamlbuild/ocaml_tools.ml file for a similar function
> (import_mlypack).
> 
-- 
David Teller-Rajchenbach
 Security of Distributed Systems
  http://www.univ-orleans.fr/lifo/Members/David.Teller
 Angry researcher: French Universities need reforms, but the LRU act brings liquidations. 


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

* Ocamlbuild question
@ 2009-02-11 22:26 Matthieu Dubuget
  0 siblings, 0 replies; 5+ messages in thread
From: Matthieu Dubuget @ 2009-02-11 22:26 UTC (permalink / raw)
  To: caml-list

Hello,

I'm trying to manage "internal" camlfind packages. I use "internal" with
the same meanning than in ocamlbuild documentation when speaking about
libraries.

I want my camlfind packages to be re-installed if one of their
dependency was modified. For this, I wrote a simple rule, based on
%.iocamlfind files containing the files to install into findlib
directory. This rule also produces a stamp file : %.oocamlfind.

I also want my camlfind package to be installed if they are needed by
another rule. For this, I do: dep ["pkg_"^nm][nm ^ ".oocamlfind"] for
each internal package.

It seems to work ok: Suppose that package toto requires package tutu.
When I ask ocamlbuild toto.oocamlfind, the packages tutu is re-built if
needed. And if I modify one file of tutu, and then ask ocamlbuild to
generate toto.oocamlbuild, tutu is re-built and installed into findlib
directories. fine.

BUT, when I'm producing a %.native from %.cmx, my dependencies (ie
%.oocamlfind files) are inserted in the command line...

Here is an example:
ocamlfind ocamlopt -linkpkg -package mtsvrac -package log
logtest/test.cmx mtsvrac.oocamlfind log.oocamlfind -o logtest/test.native

mtsvrac.oocamlfind and log.oocamlfind where added to the dependencies of
logtest/test.native.

What would be the right solution to avoid this problem?
Is there something like a "dependency that should not be linked?"

Thanks

Salutations

Matt



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

end of thread, other threads:[~2009-02-11 22:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-09-30  7:27 OCamlBuild question David Teller
2008-09-30 10:40 ` Nicolas Pouillard
2008-09-30 14:49   ` David Teller
2008-09-30 15:12   ` David Teller
2009-02-11 22:26 Ocamlbuild question Matthieu Dubuget

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).