-
Notifications
You must be signed in to change notification settings - Fork 465
/
Copy pathPaths.ml
75 lines (66 loc) · 2.46 KB
/
Paths.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
open GenTypeCommon
let concat = Filename.concat
let handle_namespace cmt =
let cut_after_dash s =
match String.index s '-' with
| n -> String.sub s 0 n [@doesNotRaise]
| exception Not_found -> s
in
let no_dir = Filename.basename cmt = cmt in
if no_dir then
cmt |> (Filename.chop_extension [@doesNotRaise]) |> cut_after_dash
else
let dir = cmt |> Filename.dirname in
let base =
cmt |> Filename.basename |> (Filename.chop_extension [@doesNotRaise])
|> cut_after_dash
in
Filename.concat dir base
let find_name_space cmt =
let keep_after_dash s =
match String.index s '-' with
| n ->
Some ((String.sub s (n + 1) [@doesNotRaise]) (String.length s - n - 1))
| exception Not_found -> None
in
cmt |> Filename.basename |> (Filename.chop_extension [@doesNotRaise])
|> keep_after_dash
let get_output_file_relative ~config cmt =
(cmt |> handle_namespace) ^ ModuleExtension.ts_input_file_suffix ~config
let get_output_file ~(config : Config.t) cmt =
Filename.concat config.project_root (get_output_file_relative ~config cmt)
let get_module_name cmt =
cmt |> handle_namespace |> Filename.basename |> ModuleName.from_string_unsafe
let get_cmt_file cmt =
let path_cmt = Filename.concat (Sys.getcwd ()) cmt in
let cmt_file =
if Filename.check_suffix path_cmt ".cmt" then
let path_cmt_lower_case =
let dir_name = path_cmt |> Filename.dirname in
let base_name = path_cmt |> Filename.basename in
Filename.concat dir_name (base_name |> String.uncapitalize_ascii)
in
let path_cmti =
(Filename.chop_extension path_cmt [@doesNotRaise]) ^ ".cmti"
in
let path_cmti_lower_case =
(Filename.chop_extension path_cmt_lower_case [@doesNotRaise]) ^ ".cmti"
in
if Sys.file_exists path_cmti_lower_case then path_cmti_lower_case
else if Sys.file_exists path_cmti then path_cmti
else if Sys.file_exists path_cmt_lower_case then path_cmt_lower_case
else if Sys.file_exists path_cmt then path_cmt
else ""
else ""
in
cmt_file
let get_config_file ~project_root =
let config = concat project_root Config.compiler_config_file in
match config |> Sys.file_exists with
| true -> Some config
| false -> (
let config = concat project_root Config.legacy_compiler_config_file in
match config |> Sys.file_exists with
| true -> Some config
| false -> None)
let read_config ~namespace = Config.read_config ~get_config_file ~namespace