caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Stéphane Gimenez" <gimenez@pps.jussieu.fr>
To: caml-list@yquem.inria.fr
Subject: ocamlbuild, menhir and include directories
Date: Mon, 14 May 2007 18:56:20 +0200	[thread overview]
Message-ID: <20070514165620.GA15565@ghost.is-a-geek.org> (raw)

[-- Attachment #1: Type: text/plain, Size: 668 bytes --]

Hi Caml list,

I got stuck with calls from ocamlbuild to
  menhir --infer ...
failing because include dirs (-I dir) were not given as parameters.

The fact is that menhir currently does not accept such parameters.
I found a dirty workaround using
  menhir --ocamlc "ocamlc -I dir" ...
but this could override an other --ocamlc parameter.

Looking at menhir and ocamlbuild code, I thought a tiny patch to both
was the best choice:
   - a patch to learn menhir about -I options
   - a patch to ocamlbuild to feed menhir --infer calls with -I options
     (using the same argument generation code as for other commands)

Those patches are attached.

Regards,
Stéphane.


[-- Attachment #2: menhir-20070322.incl_dirs.patch --]
[-- Type: text/plain, Size: 2152 bytes --]

diff -ru menhir-20070322/infer.ml menhir-20070322.patched/infer.ml
--- menhir-20070322/infer.ml	2007-03-22 21:12:49.000000000 +0100
+++ menhir-20070322.patched/infer.ml	2007-05-14 18:07:02.000000000 +0200
@@ -332,9 +332,12 @@
   (* Invoke ocamlc to do type inference for us. *)
 
   let output =
+    let incl_dirs =
+      String.concat " " (List.map (fun s -> "-I " ^ s) Settings.incl_dirs)
+    in
     IO.winvoke
       [ write grammar ]
-      (Printf.sprintf "%s -c -i %s" Settings.ocamlc (Filename.quote mlname))
+      (Printf.sprintf "%s %s -c -i %s" Settings.ocamlc incl_dirs (Filename.quote mlname))
       [ remove mlname ]
   in
 
diff -ru menhir-20070322/settings.ml menhir-20070322.patched/settings.ml
--- menhir-20070322/settings.ml	2007-03-22 21:12:49.000000000 +0100
+++ menhir-20070322.patched/settings.ml	2007-05-14 18:50:58.000000000 +0200
@@ -93,6 +93,9 @@
 let ocamldep =
   ref "ocamldep"
 
+let incl_dirs =
+  ref []
+
 let logG, logA, logC =
   ref 0, ref 0, ref 0
 
@@ -131,6 +134,7 @@
   "--no-stdlib", Arg.Set no_stdlib, " Do not load the standard library";
   "--ocamlc", Arg.Set_string ocamlc, "<command> Specifies how ocamlc should be invoked";
   "--ocamldep", Arg.Set_string ocamldep, "<command> Specifies how ocamldep should be invoked";
+  "-I", Arg.String (fun s -> incl_dirs := s :: !incl_dirs), "<dir> Add <dir> to the list of include directories";
   "--only-preprocess", Arg.Set preprocess_only, " Print a simplified grammar and exit";
   "--only-tokens", Arg.Unit tokentypeonly, " Generate token type definition only, no code";
   "--raw-depend", Arg.Unit (fun () -> depend := OMRaw), " Invoke ocamldep and echo its raw output";
@@ -237,6 +241,9 @@
 let ocamldep =
   !ocamldep
 
+let incl_dirs =
+  !incl_dirs
+
 let logG, logA, logC =
   !logG, !logA, !logC
 
diff -ru menhir-20070322/settings.mli menhir-20070322.patched/settings.mli
--- menhir-20070322/settings.mli	2007-03-22 21:12:50.000000000 +0100
+++ menhir-20070322.patched/settings.mli	2007-05-14 18:05:47.000000000 +0200
@@ -97,6 +97,7 @@
 
 val ocamlc: string
 val ocamldep: string
+val incl_dirs: string list
 
 (* How verbose we should be. *)
 

[-- Attachment #3: ocaml-menhir-incl_dirs.patch --]
[-- Type: text/plain, Size: 683 bytes --]

Index: ocaml_tools.ml
===================================================================
RCS file: /caml/ocaml/ocamlbuild/ocaml_tools.ml,v
retrieving revision 1.2
diff -u -r1.2 ocaml_tools.ml
--- ocaml_tools.ml	8 Feb 2007 16:53:39 -0000	1.2
+++ ocaml_tools.ml	14 May 2007 16:18:24 -0000
@@ -37,7 +37,8 @@
 let menhir mly env build =
   let mly = env mly in
   Ocaml_compiler.prepare_compile build mly;
-  Cmd(S[!Options.ocamlyacc; T(tags_of_pathname mly++"ocaml"++"parser"++"menhir");
+  Cmd(S[!Options.ocamlyacc; ocaml_include_flags mly;
+	T(tags_of_pathname mly++"ocaml"++"parser"++"menhir");
         A"--infer"; flags_of_pathname mly; Px mly])
 
 let ocamldoc_c tags arg odoc =

             reply	other threads:[~2007-05-14 16:56 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-14 16:56 Stéphane Gimenez [this message]
2007-05-15  7:02 ` [Caml-list] " Nicolas Pouillard
2007-05-15 12:50   ` Stéphane Gimenez

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070514165620.GA15565@ghost.is-a-geek.org \
    --to=gimenez@pps.jussieu.fr \
    --cc=caml-list@yquem.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).