From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=AWL,DNS_FROM_RFC_ABUSE autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id C655FBC69 for ; Mon, 6 Aug 2007 12:11:22 +0200 (CEST) Received: from mail9.dslextreme.com (mail9.dslextreme.com [66.51.199.94]) by discorde.inria.fr (8.13.6/8.13.6) with SMTP id l76ABL9S020947 for ; Mon, 6 Aug 2007 12:11:22 +0200 Received: (qmail 18376 invoked from network); 6 Aug 2007 10:11:20 -0000 Received: from unknown (HELO foobears.local) (erickt@68.183.27.254) by mail9.dslextreme.com with (RC4-MD5 encrypted) SMTP; Mon, 06 Aug 2007 03:11:20 -0700 Message-ID: <46B6F3C4.7050408@dslextreme.com> Date: Mon, 06 Aug 2007 03:11:16 -0700 From: Erick Tryzelaar User-Agent: Thunderbird 2.0.0.6 (Macintosh/20070728) MIME-Version: 1.0 To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] ocamlbuild and bootstrapping projects References: <6b94a12183a2ab7a191d6a.20070804031527.revpxg@www.dslextreme.com> In-Reply-To: <6b94a12183a2ab7a191d6a.20070804031527.revpxg@www.dslextreme.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Miltered: at discorde with ID 46B6F3C9.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; parser:01 parser:01 mli:01 deps:01 mli:01 pathname:01 ocaml:01 byte:01 iter:01 exn:01 exn:01 wrote:01 dynamically:01 caml-list:01 grammar:02 erickt@dslextreme.com wrote: > I was trying to adapt the parser dypgen (http://dypgen.free.fr/)'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: myocamlbuild.ml: dispatch begin function | After_rules -> rule "dypgen: .dyp -> .ml & .mli" ~deps:["%.dyp"] ~prods:["%.ml"; "%.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" in (* 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]) end; | _ -> () end;;