@@ -29,10 +29,14 @@ let find_name_space cmt =
29
29
cmt |> Filename. basename |> (Filename. chop_extension [@ doesNotRaise])
30
30
|> keep_after_dash
31
31
32
- let remove_project_root_from_absolute_path ~(config : Config.t ) source_path =
33
- let i = String. length config.project_root + 1 in
34
- let n = String. length source_path - i in
35
- (String. sub source_path i n [@ doesNotRaise])
32
+ let remove_path_prefix ~prefix path =
33
+ let normalized_prefix = Filename. concat prefix " " in
34
+ let prefix_len = String. length normalized_prefix in
35
+ let path_len = String. length path in
36
+ let is_prefix =
37
+ prefix_len < = path_len && String. sub path 0 prefix_len = normalized_prefix
38
+ in
39
+ if is_prefix then String. sub path prefix_len (path_len - prefix_len) else path
36
40
37
41
let append_suffix ~config source_path =
38
42
(source_path |> handle_namespace)
@@ -42,7 +46,7 @@ let get_output_file_relative ~(config : Config.t) source_path =
42
46
if Filename. is_relative source_path then append_suffix ~config source_path
43
47
else
44
48
let relative_path =
45
- remove_project_root_from_absolute_path ~ config source_path
49
+ remove_path_prefix ~prefix: config.project_root source_path
46
50
in
47
51
append_suffix ~config relative_path
48
52
@@ -56,7 +60,7 @@ let get_output_file ~(config : Config.t) sourcePath =
56
60
else
57
61
(* for absolute paths we want to place the output beside the source file *)
58
62
let relative_path =
59
- remove_project_root_from_absolute_path ~ config sourcePath
63
+ remove_path_prefix ~prefix: config.project_root sourcePath
60
64
in
61
65
compute_absolute_output_file_path ~config relative_path
62
66
0 commit comments