Skip to content

Commit

Permalink
[menhir] Call menhir from root scope directory as to improve error re…
Browse files Browse the repository at this point in the history
…porting.

This is a common problem in a few Dune tools: if a menhir file is
inside a sub-directory, the tool will be invoked from the subdir,
however the Dune call was likely from the top-level directory and the
error/warning messages won't be correct.

I am not sure this is the right way to address this problem, in
particular what will happen if Dune is called from some parallel
sub-directory. Suggestions welcome.

Signed-off-by: Emilio Jesus Gallego Arias <e+git@x80.org>
  • Loading branch information
ejgallego committed Apr 17, 2019
1 parent 745d4e7 commit 99ade10
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/menhir.ml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ module type PARAMS = sig
is of the form [_build/<context>/src], e.g., [_build/default/src]. *)
val dir : Path.t

(* [root_dir] is the base directory of the context, usually where
the build is invoked from; we run menhir from this directoy to we
get correct error paths. *)
val root_dir : Path.t

(* [stanza] is the [(menhir ...)] stanza, as found in the [jbuild] file. *)

val stanza: stanza
Expand Down Expand Up @@ -122,7 +127,7 @@ module Run (P : PARAMS) : sig end = struct
(* [menhir args] generates a Menhir command line (a build action). *)

let menhir (args : 'a args) : (string list, Action.t) Build.t =
Build.run ~dir menhir_binary args
Build.run ~dir:root_dir menhir_binary args

let rule ?(mode=stanza.mode) : (unit, Action.t) Build.t -> unit =
SC.add_rule sctx ~dir ~mode ~loc:stanza.loc
Expand Down Expand Up @@ -322,6 +327,7 @@ let gen_rules ~dir cctx stanza =
Run (struct
let cctx = cctx
let dir = dir
let root_dir = Scope.root (Compilation_context.scope cctx)
let stanza = stanza
end) in
()

0 comments on commit 99ade10

Please sign in to comment.