Skip to content

Commit

Permalink
fix(coq): unescape :\ to :
Browse files Browse the repository at this point in the history
coqdep outputs escaped paths for makefile which means on Windows that
`C:\foo\bar` gets escaped to `C\:\\foo\\bar` causing Dune to interpret
escaped absolute Windows directories as relative ones.

This patch searches for `:\` in the deps output of coqdep and replaces it
with `:` allowing the paths to be interpreted correctly.

Signed-off-by: Ali Caglayan <alizter@gmail.com>
  • Loading branch information
Alizter authored and ejgallego committed Nov 28, 2023
1 parent f140a17 commit ee0c78e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions doc/changes/9231_coq.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Fixed a bug where Dune was incorrectly parsing the output of coqdep when it was escaped,
as is the case on Windows. (#9231, fixes #9218, @Alizter)
13 changes: 12 additions & 1 deletion src/dune_rules/coq/coq_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,15 @@ let coqdep_invalid phase line =
[ "phase", Dyn.string phase; "line", Dyn.string line ]
;;

(* Handle the case where the path contains ":" and coqdep escapes this
as "\:" causing Dune to misinterpret the path. We revert
the escaping, which allows dune to work on Windows.
Note that coqdep escapes a few more things, including spaces, $, #,
[], ?, %, homedir... How to handle that seems tricky.
*)
let unescape_coqdep string = Re.replace_string (Re.compile (Re.str "\\:")) ~by:":" string

let parse_line ~dir line =
match String.lsplit2 line ~on:':' with
| None -> coqdep_invalid "split" line
Expand All @@ -463,7 +472,9 @@ let parse_line ~dir line =
in
(* let depname, ext = Filename.split_extension ff in *)
let target = Path.relative (Path.build dir) target in
let deps = String.extract_blank_separated_words deps in
(* EJGA: XXX using `String.extract_blank_separated_words` works
for OCaml, but not for Coq as we don't use `-modules` *)
let deps = unescape_coqdep deps |> String.extract_blank_separated_words in
(* Add prelude deps for when stdlib is in scope and we are not actually
compiling the prelude *)
let deps = List.map ~f:(Path.relative (Path.build dir)) deps in
Expand Down

0 comments on commit ee0c78e

Please sign in to comment.