Skip to content

Commit 4f4a1c3

Browse files
committed
make find source file return only absolute paths
1 parent 8e1921e commit 4f4a1c3

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

compiler/gentype/FindSourceFile.ml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,17 @@ let rec implementation items =
1414
| false -> Some str_loc.loc_start.pos_fname)
1515
| [] -> None
1616

17+
let transform_to_absolute_path (path : string option) =
18+
let transform path =
19+
if Filename.is_relative path then Filename.concat (Sys.getcwd ()) path
20+
else path
21+
in
22+
Option.map transform path
23+
1724
let cmt cmt_annots =
1825
match cmt_annots with
19-
| Cmt_format.Interface signature -> interface signature.sig_items
20-
| Implementation structure -> implementation structure.str_items
26+
| Cmt_format.Interface signature ->
27+
transform_to_absolute_path (interface signature.sig_items)
28+
| Implementation structure ->
29+
transform_to_absolute_path (implementation structure.str_items)
2130
| _ -> None

compiler/gentype/FindSourceFile.mli

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
val cmt : Cmt_format.binary_annots -> string option
2+
(**
3+
[cmt annots] given [Cmt_format.binary_annots] it returns an absolute source file path
4+
if the file exists, otherwise it returns None.
5+
6+
@param annots The binary annotations to be processed.
7+
@return An optional absolute path to the source file.
8+
*)

0 commit comments

Comments
 (0)