Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
ocamlbuild: args to tags?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-09-24 (12:29)
From: Nicolas Pouillard <nicolas.pouillard@g...>
Subject: Re: [Caml-list] ocamlbuild: args to tags?
Excerpts from jake.donham's message of Tue Sep 18 20:01:56 +0200 2007:
> Hi,
> Is there a way to pass arguments to a preprocessor via the _tags file? 

Yes,  but  that's  not  what  you  want.  Moreover  this feature is not really

> (In particular, I have added a -classes option to Deriving to give 
> default classes to all the types in a file.). Following the recent 
> discussion, I have this in
>    dispatch begin function
>      | After_rules ->
>          flag ["ocaml"; "pp"; "deriving"] (A"deriving");
>          flag ["ocaml"; "pp"; "Show"] (S[A"-classes"; A"Show"]);
> So now if I put
>    <> : deriving,Show
> in _tags I get -pp 'deriving -classes Show' in the command line. What I 
> would like, however, is to be able to write
>    <> : deriving(Show,Typeable)
> or
>    <> : deriving,classes(Show,Typeable)

Yes but you cannot do that for now. One feasible feature would be:

  <>: deriving, classes{Show,Typeable}

Which will expands to:

  <>: deriving, classesShow, classesTypeable

And then in your plugin you can do:

  List.iter begin fun class_name ->
    flag ["ocaml"; "pp"; "classes"^class_name] (S[A"-classes"; A class_name])
  end ["Show"; "Typeable"]

> i.e. to be able to pass some arbitrary args rather than hard-coding Show 
> as a tag. Is there any way to do this?

No I don't really want to complicate tags...

> I don't understand how Ocamlbuild 
> decides whether flags should be associated with the main command or with 
> the preprocessor command; if I write classes(Foo) in _tags I get 
> -classes Foo in the main command, no matter what I have tried in 

Yes  thats the not encouraged feature by using the syntax `flag(arg)' you pass
the arguments `-flag arg' to *any* command that reference the matched file. It's
merely because you cannot control when the flag is applied that this form is not encouraged.

However the classic way of using tag have a fine grained control:

  flag ["ocaml"; "pp"; "Show"] (S[A"-classes"; A"Show"]);

Here  only  commands  tagged  "ocaml",  "pp"  and  "Show"  will  add the flags
"-classes  Show".  Both commands and files contribute to this set of tags, and
that's  the  conjunction  that  trigger the flags (but I think that you've got
this one, and that's the flag(arg) behavior that leads to confusion).


Nicolas Pouillard aka Ertai