[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| 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
encouraged.
> (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 myocamlbuild.ml:
>
> 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
>
> <foo.ml> : 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
>
> <foo.ml> : deriving(Show,Typeable)
>
> or
>
> <foo.ml> : deriving,classes(Show,Typeable)
Yes but you cannot do that for now. One feasible feature would be:
<foo.ml>: deriving, classes{Show,Typeable}
Which will expands to:
<foo.ml>: 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
> myocamlbuild.ml.
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).
Regards,
HTH
--
Nicolas Pouillard aka Ertai