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 and bootstrapping projects
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-08-06 (10:11)
From: Erick Tryzelaar <erickt@d...>
Subject: Re: [Caml-list] ocamlbuild and bootstrapping projects wrote:
> I was trying to adapt the parser dypgen ('s build
> system to use ocamlbuild, but I ran into a problem. The final dypgen
> grammar is generated by an internal intermediary generator called pgen.
> The problem I'm having is that I don't know how to get ocamlbuild to
> automatically build pgen before we can process a %.dyp file. I suppose I
> could do this in two separate calls to ocamlbuild, but I feel like this
> can be done using a plugin. Is this possible?

For those that are interested, here's the solution I came up with. We 
use the "build" function we get in the rule to dynamically dispatch the 
building of the parser if we haven't generated it yet:
dispatch begin function
  | After_rules ->
      rule "dypgen: .dyp -> .ml & .mli"
        ~prods:[""; "%.mli"]
        begin fun env build ->
          let dyp = env "%.dyp" in
          let tags = tags_of_pathname dyp++"ocaml"++"parser" in
          (* Since pgen and dypgen programs use the same extension, we need
           * to be able to switch between the two. Do this by tagging 
the pgen
           * files with "use_pgen".
           * I'm not sure how we should do byte/native, so we'll just 
use the
           * native. *)
          let dypgen, tags =
            if Tags.mem "use_pgen" tags
            then "dyp/generators/pgen/pgen.native", tags++"pgen"
            else "dyp/generators/dypgen/dypgen.native", tags++"dypgen"
          (* try to build the parser if it doesn't exist yet *)
          List.iter begin function
            | Outcome.Good o -> ()
            | Outcome.Bad exn -> raise exn
          end (build [[dypgen]]);
          Cmd(S[A dypgen; T tags; Px dyp])
  | _ -> ()