-
Notifications
You must be signed in to change notification settings - Fork 0
/
managerTools.ml
138 lines (114 loc) · 4.01 KB
/
managerTools.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
open ManagerMisc
open ManagerWrapper
open ManagerInit
type switch_status = {
available_and_managed : string list;
available_not_managed : string list;
unavailable : string list;
}
let get_switch_status c =
let binaries = Sys.readdir manager_bindir in
let managed_binaries = ref StringMap.empty in
Array.iter (fun tool ->
if tool <> "ocp-manager" then
managed_binaries := StringMap.add tool (ref false) !managed_binaries)
binaries;
let available_and_managed = ref [] in
let available_not_managed = ref [] in
let unavailable = ref [] in
List.iter (fun line ->
try
let ref = StringMap.find line !managed_binaries in
ref := true;
available_and_managed := line :: !available_and_managed
with Not_found ->
available_not_managed := line :: !available_not_managed
) (list_directory (compiler_bindir c));
StringMap.iter (fun tool ref ->
if not !ref then unavailable := tool :: !unavailable
) !managed_binaries;
{ available_not_managed = !available_not_managed;
available_and_managed = !available_and_managed;
unavailable = !unavailable
}
let print_commands () =
let c = get_current_compiler () in
let s = get_switch_status c in
Printf.printf "Available tools in %s:\n" c.compiler_name;
Printf.printf "Tools managed:\n";
list_printer " " (List.sort compare s.available_and_managed);
Printf.printf "Tools not managed:\n";
list_printer " " (List.sort compare s.available_not_managed);
Printf.printf "Tools missing:\n";
list_printer " " (List.sort compare s.unavailable);
Printf.printf "%!"
let print_missing () =
let c = get_current_compiler () in
let s = get_switch_status c in
Printf.printf "Tools missing:\n";
list_printer " " (List.sort compare s.unavailable);
Printf.printf "%!"
let add_command basename =
let filename = Filename.concat manager_bindir basename in
if Sys.file_exists filename then
Printf.eprintf "Warning: %S is already managed\n%!" basename
else
begin
Printf.eprintf "Creating wrapper for %S\n%!" basename;
symlink "ocp-manager" filename;
end
let remove_command cmd =
let filename = Filename.concat manager_bindir cmd in
if Sys.file_exists filename then begin
Printf.eprintf "Removing %S from managed commands\n%!" basename;
(try Sys.remove filename with _ -> ());
end else begin
Printf.eprintf "Warning: command %S was not managed.\n%!" basename;
end
let add_all_commands () =
let c = get_current_compiler () in
let s = get_switch_status c in
List.iter (fun basename ->
let filename = Filename.concat manager_bindir basename in
if Sys.file_exists filename then
Printf.eprintf "Warning: %S is already managed\n%!" basename
else
begin
Printf.eprintf "Creating wrapper for %S\n%!" basename;
symlink "ocp-manager" filename;
end
) s.available_not_managed
let add_default_command cmd =
let basename = Filename.basename cmd in
begin
let filename = Filename.concat manager_bindir basename in
if not ( Sys.file_exists filename ) then
begin
Printf.eprintf "Creating wrapper for %S\n%!" basename;
symlink "ocp-manager" filename;
end
end;
if not (Sys.file_exists cmd) then begin
Printf.eprintf "Error: Command %S does not exist !\n" cmd;
Printf.eprintf " You must specify the command path.\n%!";
exit 2
end;
let cmd =
if Filename.is_relative cmd then
Filename.concat pwd cmd
else cmd
in
if not (Sys.file_exists manager_defaults) then
safe_mkdir manager_defaults;
let cmd_default = Filename.concat manager_defaults basename in
Printf.eprintf "Creating default for %S\n%!" basename;
(try Sys.remove cmd_default with _ -> ());
symlink cmd cmd_default
let remove_default cmd =
let cmd_default = Filename.concat manager_defaults cmd in
if Sys.file_exists cmd_default then begin
Printf.eprintf "Removing default for %S\n%!" basename;
(try Sys.remove cmd_default with _ -> ());
end else begin
Printf.eprintf "Warning: no default for %S\n%!" basename;
end