English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
OCamlBuild question
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2008-09-30 (10:41)
From: Nicolas Pouillard <nicolas.pouillard@g...>
Subject: Re: OCamlBuild question
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

Nicolas Pouillard aka Ertai