caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Gabriel Scherer <gabriel.scherer@gmail.com>
To: "Christoph Höger" <christoph.hoeger@tu-berlin.de>
Cc: caml users <caml-list@inria.fr>
Subject: Re: [Caml-list] ocamlbuild pattern language OR
Date: Thu, 6 Oct 2016 21:23:14 -0400	[thread overview]
Message-ID: <CAPFanBEwiXTSeHactGkY0ojevOeRkpXZqp45HWpxe1119ae+YA@mail.gmail.com> (raw)
In-Reply-To: <838cb092-c371-2c79-75f6-7193e6ed6396@tu-berlin.de>

Hi Christoph,

ocamlbuild does not currently support patterns in dependencies, except
for names of variables defined in the productions. The productions can
contain patterns, including disjunctions, using the syntax
%(name:pattern), for example "%.%(ext:foo|bar)".

Note that the ~deps field only contains the static dependencies, which
are declaratively provided in the rule declaration. You have much more
flexibility in the dynamic dependencies, which are the target that the
rule action may request (they need not be part of the static
dependencies). In particular, in a rule you can request at any time
the build of a (conjunctive) list of (disjunctive) list of targets
(for each element of the outer list, at least one element of the inner
list must be buildable), so just calling the build on [[env "%.foo";
env "%.bar"]] will have the semantics you expect. See the
documentation of dynamic dependencies in the manual:

  https://github.com/ocaml/ocamlbuild/blob/master/manual/manual.adoc#Subsec_Rules__Dynamic_dependencies

That said, if you were willing to experiment with a patch to provide
that functionality (disjunctions in static dependencies), I have the
impression that it would be not be too difficult to implement, and I
don't see an immediate problem that this would cause -- with the
expected semantics that the rule would fire if all its dependency
patterns have at least one buildable match. Currently the ocamlbuild
solver recursively builds all dependencies of a rule,

  https://github.com/ocaml/ocamlbuild/blob/a4966a4/src/solver.ml#L74

if we allowed patterns in rules, we could have a pattern (a regular
expression) for each dependency instead of just a pathname. We would
have to write some code in glob.ml to enumerate all strings matched by
a pattern; mapping this function over the list of dependencies would
return a (conjunctive) list of (disjunctive) alternatives to build,
which can be passed to the solver.

On Thu, Oct 6, 2016 at 11:42 AM, Christoph Höger
<christoph.hoeger@tu-berlin.de> wrote:
> Dear all,
>
> I am in the process of writing a set of ocamlbuild rules.
> In order to simplify some rules, I'd wanted to merge them (as the
> invoked tool dispatches over the file extension anyway). However, I fail
> to create an OR-pattern in the rule-declaration:
>
>       rule "description"
>         ~prods:["%.out"]
>         ~deps:["%.{foo,bar}"] (* tried _tags syntax, does not work *)
>         ~doc:"Generate *.out from *.foo or *.bar"
>         make_out_command ;
>
> Does anyone know how to solve this?
>
> thanks,
>
> 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

      reply	other threads:[~2016-10-07  1:23 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-06 15:42 Christoph Höger
2016-10-07  1:23 ` 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=CAPFanBEwiXTSeHactGkY0ojevOeRkpXZqp45HWpxe1119ae+YA@mail.gmail.com \
    --to=gabriel.scherer@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;
as well as URLs for NNTP newsgroup(s).