caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] ocamlbuild pattern language OR
@ 2016-10-06 15:42 Christoph Höger
  2016-10-07  1:23 ` Gabriel Scherer
  0 siblings, 1 reply; 2+ messages in thread
From: Christoph Höger @ 2016-10-06 15:42 UTC (permalink / raw)
  To: caml users

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

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

* Re: [Caml-list] ocamlbuild pattern language OR
  2016-10-06 15:42 [Caml-list] ocamlbuild pattern language OR Christoph Höger
@ 2016-10-07  1:23 ` Gabriel Scherer
  0 siblings, 0 replies; 2+ messages in thread
From: Gabriel Scherer @ 2016-10-07  1:23 UTC (permalink / raw)
  To: Christoph Höger; +Cc: caml users

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

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

end of thread, other threads:[~2016-10-07  1:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-06 15:42 [Caml-list] ocamlbuild pattern language OR Christoph Höger
2016-10-07  1:23 ` Gabriel Scherer

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