From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 8C161800D1 for ; Wed, 1 Feb 2017 11:20:47 +0100 (CET) Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=gabriel.scherer@gmail.com; spf=Pass smtp.mailfrom=gabriel.scherer@gmail.com; spf=None smtp.helo=postmaster@mail-qt0-f173.google.com Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of gabriel.scherer@gmail.com) identity=pra; client-ip=209.85.216.173; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of gabriel.scherer@gmail.com designates 209.85.216.173 as permitted sender) identity=mailfrom; client-ip=209.85.216.173; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-qt0-f173.google.com) identity=helo; client-ip=209.85.216.173; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="postmaster@mail-qt0-f173.google.com"; x-conformance=sidf_compatible IronPort-PHdr: =?us-ascii?q?9a23=3AH4hO+RW8pLYuYn3JlXFyOoPb/ADV8LGtZVwlr6E/?= =?us-ascii?q?grcLSJyIuqrYZhaPt8tkgFKBZ4jH8fUM07OQ6PG8HzJfqs/b+DBaKdoXCE9D0Z?= =?us-ascii?q?1X1yUbQ+e7SmTDZMbwaCI7GMkQHHRExFqcdXZvJcDlelfJqWez5zNBUj/2NA5y?= =?us-ascii?q?O/inUtWK15f//6mI9pbSewRFgiamKfM3dU3u7FaZis5Dr5FrLCk2ywD+mnxUZ+?= =?us-ascii?q?Vb3ys8K0iamR3759z25Jl/7yVdodog8dRBWOP0ZfJrY6ZfCWEJOmov5cDv/SLI?= =?us-ascii?q?TQaV62FUBmofmABJDgyD9xr6U438qAP1s+N83G+ROsigHuN8Yiir86o+EEygsy?= =?us-ascii?q?wALTNstTiP0sE=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0DoAQAstpFYhq3YVdFdFgUBAQEDAQEBC?= =?us-ascii?q?QEBARUBAQEBAgEBAQEIAQEBAYNKP4EJB4NQnBCIfIw5gg0shXYCgj4HQRYBAQE?= =?us-ascii?q?BAQEBAQEBARIBAQEICwsKHS+CMwQBFgEEghcBBSMEGQEbHQEDDAYFCw0CAiYCA?= =?us-ascii?q?iIBEQEFARwGE4lZAQMVDp99P4wCgWsYBQEcgwkFR4MdChknDVWDFQEBAQEGAQE?= =?us-ascii?q?BAQEbAgYSeYVAg2aBCYRNgwaCXwWPNowlgX2EaoscgkyOL4pZhmIUHoEUJgiBR?= =?us-ascii?q?BMdUBeEHSCBbT81hWEHZ4FOAQEB?= X-IPAS-Result: =?us-ascii?q?A0DoAQAstpFYhq3YVdFdFgUBAQEDAQEBCQEBARUBAQEBAgE?= =?us-ascii?q?BAQEIAQEBAYNKP4EJB4NQnBCIfIw5gg0shXYCgj4HQRYBAQEBAQEBAQEBARIBA?= =?us-ascii?q?QEICwsKHS+CMwQBFgEEghcBBSMEGQEbHQEDDAYFCw0CAiYCAiIBEQEFARwGE4l?= =?us-ascii?q?ZAQMVDp99P4wCgWsYBQEcgwkFR4MdChknDVWDFQEBAQEGAQEBAQEbAgYSeYVAg?= =?us-ascii?q?2aBCYRNgwaCXwWPNowlgX2EaoscgkyOL4pZhmIUHoEUJgiBRBMdUBeEHSCBbT8?= =?us-ascii?q?1hWEHZ4FOAQEB?= X-IronPort-AV: E=Sophos;i="5.33,319,1477954800"; d="scan'208";a="258365103" Received: from mail-qt0-f173.google.com ([209.85.216.173]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 01 Feb 2017 11:20:25 +0100 Received: by mail-qt0-f173.google.com with SMTP id v23so259430648qtb.0; Wed, 01 Feb 2017 02:20:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=oknMeUdGTlU20+qbP3YNPRVoj5rSXkxNBbH9Ksyy2qo=; b=Qy0NX0MTKDuhovZogI8+8hFlCxN3ULO0QfMaXWD3gMpS1RomSMyo1MTHtMd2DjluNw x1ob2SntFeGvCbzUlLFlqcT7ZT1gWE8hJltyIoy+A9aGkAaBkFGmOkY7s84/75Gkj0Bh GsQrzL/qFP9lpew7EuWEarz0FxjS4Vmwi14tmMQAywPkQ7fORRx+CK7xLhiU+Ur9Gx+G ounw2+H4nHSIfAfuBBzmKBpqmCQK8TqZUXKWwZ0PPkNXhAMqt2Cl1OSRVs1SdLJlMTYE n4TFWLVIFYn4GdbOFDSrMi/ooGLNxOeCemTNnmO9Ky+fG7wBCxJNeFqLtiQ0oagbw58o clmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=oknMeUdGTlU20+qbP3YNPRVoj5rSXkxNBbH9Ksyy2qo=; b=kZC3sG8DVzHWcRARdDJWf+bRXhrCastWvAEP8Tn6KXFLhcIoHa+UInaFRWPJzRUnNP D7xVbHCS2YX8bXcwagvBrUFaHa5bPvRmT4AvR1Ygu+Rx2ef8+YUia0+rt4lcM1IFRR92 4G747BIztfNlNILnoXA/ZQyKO4y5ksorDDOLRU7uVjBi6akNejGFmvjTvblegzWzFACk p+Kiv+xVzveAnuNblFaWdOU7pmD99u0pvLFSLqrJgu0/l2Tna048q9QUoa+paQ1Oogrz 5mMg99dhCgXezaUYBfz3mRe56yHhN4zXDxptIpOypldwZDKYVy/lYVldFsxNFsv5y8J2 ViEw== X-Gm-Message-State: AIkVDXJMDcLw1k7uW7UDR58t1JwMGEzLRfu7tEnefknveEH0wLSBjxRg6h67xe5F9hNgG8kPJII/yHq/F3WTjw== X-Received: by 10.200.43.201 with SMTP id n9mr1972944qtn.243.1485944424729; Wed, 01 Feb 2017 02:20:24 -0800 (PST) MIME-Version: 1.0 Received: by 10.12.177.154 with HTTP; Wed, 1 Feb 2017 02:19:44 -0800 (PST) In-Reply-To: <58910692.1060706@inria.fr> References: <58910692.1060706@inria.fr> From: Gabriel Scherer Date: Wed, 1 Feb 2017 11:19:44 +0100 Message-ID: To: =?UTF-8?Q?Fran=C3=A7ois_Pottier?= Cc: caml users , github@mjambon.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Caml-list] cppo, ocamlbuild, and dependencies Yes, the cppo ocamlbuild plugin https://github.com/mjambon/cppo/blob/master/ocamlbuild_plugin/ocamlbuild_= cppo.ml does not currently perform any kind of dynamic dependency computation. I think the best way for this to be implemented would be at the level of cppo, have a kind of -list-includes flag that would run on a .cppo.* file and return the list of includes. Then you could easily change the cppo rule to call this first, dynamically build all these dependencies, and proceed with normal cppo processing. (I believe this is roughly how `gcc -M` works.) In the meantime, I implemented an amusing hack at the ocamlbuild level which is to simply parse the failure message and, if it complains about a missing file, recursively build that file as a dynamic dependency. It seems to work. (The code below is just a change over the main function of cppo's ocamlbuild plugin. To use it in your program, copy the cppo's ocamlbuild source in your myocamlbuild.ml, replace the relevant function, and at the end add "let () =3D dispatch dispatcher" or whatever dispatch logic you wish.) let cppo_rules ext =3D let dep =3D "%(name).cppo"-.-ext and prod1 =3D "%(name: <*> and not <*.cppo>)"-.-ext and prod2 =3D "%(name: <**/*> and not <**/*.cppo>)"-.-ext in let cppo_rule prod env build =3D let dep =3D env dep in let prod =3D env prod in let tags =3D tags_of_pathname prod ++ "cppo" in let cppo =3D S[A "cppo"; T tags; S [A "-o"; Px prod]; P dep] in let rec retry tmp =3D let cppo_to_tmp =3D S[cppo; Sh "2>"; P tmp ] in let cppo_cmd =3D Command.to_string (Cmd cppo_to_tmp) in match Sys.command cppo_cmd with | 0 -> Nop | _ -> let cppo_result =3D read_file tmp in let error =3D Str.regexp {|Error: Cannot find included file "\([^"]*\)"|} in (* If we cannot find the dependency, or if building the dependency fails, we return the original cppo command. This will do a bit of useless work but give a better error message than having the rule raise an exception here, as it will present the failure in terms of the cppo error message the user knows about, instead of backtracking in other rules. *) match Str.search_forward error cppo_result 0 with | exception Not_found -> Cmd cppo | _pos -> let dep =3D Str.matched_group 1 cppo_result in match build [[dep]] with | [Outcome.Good _dep] -> retry tmp | _ -> Cmd cppo in with_temp_file "ocamlbuild_cppo" "stderr" retry in rule ("cppo: *.cppo."-.-ext^" -> *."-.-ext) ~dep ~prod:prod1 (cppo_rule prod1); rule ("cppo: **/*.cppo."-.-ext^" -> **/*."-.-ext) ~dep ~prod:prod2 (cppo_rule prod2) P.S.: Upon sending this message, GMail says: > It seems like you forgot to attach a file. > You wrote "find included" in your message, but there are no files attache= d. > Send anyway? On Tue, Jan 31, 2017 at 10:50 PM, Fran=C3=A7ois Pottier wrote: > > Dear OCaml users, > > I am trying to use cppo and ocamlbuild together. > > Suppose the file a.cppo.ml contains the line: > #include "b.cppo.ml". > > Then, the build fails. As far as I understand, ocamlbuild is not aware of > the > dependency a.cppo.ml -> b.cppo.ml, so the source file b.cppo.ml is not ev= en > copied to the _build directory. > > I am using the build rules bundled with cppo (in the module > Ocamlbuild_cppo). > > Shouldn't these build rules be improved so as to perform a genuine > dependency > computation? Has anyone run into this issue? > > Thanks, > > -- > Fran=C3=A7ois Pottier > francois.pottier@inria.fr > http://gallium.inria.fr/~fpottier/