Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Gabriel Scherer <gabriel.scherer@gmail.com>
To: Ashish Agarwal <agarwal1975@gmail.com>
Cc: "Christoph Höger" <christoph.hoeger@tu-berlin.de>,
	"caml users" <caml-list@inria.fr>
Subject: Re: [Caml-list] glob-ing dependencies for a custom ocamlbuild rule
Date: Tue, 12 Apr 2016 11:33:12 -0400	[thread overview]
Message-ID: <CAPFanBFidJm1pYzY5UhCjD4VOPeRdv=OtVGHjKgEKcB0xXWbJQ@mail.gmail.com> (raw)
In-Reply-To: <CAMu2m2+vedKoBsUZQF06F3QyFVxXjX4auLSZu=o21=NsXL0-jA@mail.gmail.com>

For the record, below is the code of a small plugin that will list
files in %.modlib/*.mo in the source dir, import them all in the build
directory, and also build a %.modlib.list file (in the build
directory) containing the list of imported files.

open Ocamlbuild_plugin

let modlibc_command env build =
  let dir = env "%.modlib" in
  let dir_in_source = Pathname.concat Pathname.pwd dir in
  let files = (* filenames found in %.modlib/*.mo *)
    Pathname.readdir dir_in_source |> Array.to_list
    |> List.filter (fun path -> Pathname.check_extension path "mo") in
  let () =
    (* "build" all these files; imports them in the build directory *)
    List.map (fun file -> [Pathname.concat dir file]) files
    |> build
    |> List.iter Outcome.ignore_good in
  (* then populate %.modlib.list with the list of files we found *)
  Echo (List.map (fun s -> s ^ "\n") files, env "%.modlib.list")

let _ = dispatch begin function
  | After_rules ->
     rule "modelica listing: %.modlib/ => %.modlib.list"
          ~prods:["%.modlib.list"]
          ~doc:"list the files of a Modelica library"
          modlibc_command;
  | _ -> ()
end

On Tue, Apr 12, 2016 at 9:15 AM, Ashish Agarwal <agarwal1975@gmail.com> wrote:
> On Tue, Apr 12, 2016 at 8:59 AM, Christoph Höger
> <christoph.hoeger@tu-berlin.de> wrote:
>
>> _all_ source files in <dir>
>
>
> I think that is Gabriel's point. The definition of _all_ depends on when you
> think this pattern will be evaluated.
>
>
>> It would be a major PITA to add all these files manually...
>
>
> Not really. The nice thing about ocamlbuild is that you can write arbitrary
> OCaml code, so just compute deps by traversing the directory yourself.
>
>
>
>
>> Am 12.04.2016 um 14:48 schrieb Gabriel Scherer:
>> > Ocamlbuild distinguishes "static dependencies", which are expressed in
>> > the ~deps argument of the rule declaration, and "dynamic dependencies"
>> > which are files required by the rule command.
>> >
>> > The notion of pattern accepted for static dependencies is indeed
>> > rather rigid (less expressive than the patterns used in the _tags
>> > file), and what you have in mind does not work. The supported patterns
>> > are deterministic: given one file, there is a unique way a pattern can
>> > match, and a pattern is instantiated into a single file by any
>> > substitution environment. There is a good reason for that: it is not
>> > clear what the semantics of your proposal would be. Indeed, ocamlbuild
>> > tries to recursively build all static dependencies before deciding to
>> > apply a rule, but what does it mean to build all **/*.mo? Listing the
>> > one that exist in the source directory is easy, but how would you
>> > guess which one to try to build recursively using other rules?
>> >
>> > Notions such as "all files matching P in this directory" are not
>> > stable to the replacement of a source file by an intermediate target:
>> > for example if tomorrow you decide that one of the .mo file will be
>> > itself pre-processed from a .mo.pp file, it won't be seen by a
>> > existing-file globbing technique anymore. You have a lot of
>> > flexibility in the behaviors you implement in the build command, so
>> > you can easily do the matching there and "build" those files, but it
>> > will result in a relatively fragile rule; this is you decision to
>> > make, and not in the path of least resistance.
>> >
>> >
>> > On Tue, Apr 12, 2016 at 8:00 AM, Christoph Höger
>> > <christoph.hoeger@tu-berlin.de> wrote:
>> >> Dear all,
>> >>
>> >> I want to write a custom ocamlbuild rule that basically combines all
>> >> source files from a given (sub-)directory and thus depends on these
>> >> files.
>> >>
>> >> However, the following does not work:
>> >>
>> >>         rule "normalize (preprocess) a Modelica library"
>> >>           ~prods:["%.modlib.impl"; "%.modlib.sign"]
>> >>           ~deps:["%.modlib/**/*.mo"; "%.modlib.depends"]
>> >>           ~doc:"Preprocesses a Modelica library"
>> >>           modlibc_command
>> >>
>> >> It seems that the rule does not expand the pattern in the dependency.
>> >> Is
>> >> there a way to achieve something similar? It would be a major PITA to
>> >> add all these files manually...
>> >>
>> >> regards,
>> >>
>> >> Christoph
>> >> --
>> >> Christoph Höger
>> >>
>> >> Technische Universität Berlin
>> >> Fakultät IV - Elektrotechnik und Informatik
>> >> Übersetzerbau und Programmiersprachen
>> >>
>> >> Sekr. TEL12-2, Ernst-Reuter-Platz 7, 10587 Berlin
>> >>
>> >> Tel.: +49 (30) 314-24890
>> >> E-Mail: christoph.hoeger@tu-berlin.de
>> >>
>> >> --
>> >> Caml-list mailing list.  Subscription management and archives:
>> >> https://sympa.inria.fr/sympa/arc/caml-list
>> >> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>> >> Bug reports: http://caml.inria.fr/bin/caml-bugs
>> >
>>
>>
>> --
>> Christoph Höger
>>
>> Technische Universität Berlin
>> Fakultät IV - Elektrotechnik und Informatik
>> Übersetzerbau und Programmiersprachen
>>
>> Sekr. TEL12-2, Ernst-Reuter-Platz 7, 10587 Berlin
>>
>> Tel.: +49 (30) 314-24890
>> E-Mail: christoph.hoeger@tu-berlin.de
>>
>> --
>> Caml-list mailing list.  Subscription management and archives:
>> https://sympa.inria.fr/sympa/arc/caml-list
>> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
>

      reply	other threads:[~2016-04-12 15:33 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-12 12:00 Christoph Höger
2016-04-12 12:48 ` Gabriel Scherer
2016-04-12 12:59   ` Christoph Höger
2016-04-12 13:15     ` Ashish Agarwal
2016-04-12 15:33       ` Gabriel Scherer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAPFanBFidJm1pYzY5UhCjD4VOPeRdv=OtVGHjKgEKcB0xXWbJQ@mail.gmail.com' \
    --to=gabriel.scherer@gmail.com \
    --cc=agarwal1975@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=christoph.hoeger@tu-berlin.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox