forked from na4zagin3/satyrographos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsatysfiDirs.ml
50 lines (43 loc) · 1.24 KB
/
satysfiDirs.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
open Core
let runtime_dirs () =
if Sys.os_type = "Win32" then
match Sys.getenv "SATYSFI_RUNTIME" with
| None -> []
| Some(s) -> [s]
else
["/usr/local/share/satysfi"; "/usr/share/satysfi"]
let home_dir () = if Sys.os_type = "Win32"
then Sys.getenv "userprofile"
else Sys.getenv "HOME"
let user_dir () =
Option.map ~f:(fun s -> Filename.concat s ".satysfi") (home_dir ())
let is_runtime_dir dir =
FileUtil.(test Is_dir) (Filename.concat dir "packages")
let opam_share_dir () =
try
Unix.open_process_in "opam var share"
|> In_channel.input_all
|> String.strip
|> begin function
| "" -> None
| x -> Some x
end
with
Failure x ->
print_endline "Failed to get opam directory.";
print_endline x;
None
let option_to_list = function
| Some x -> [x]
| None -> []
let satysfi_dist_dir () =
let shares = option_to_list (opam_share_dir ()) @ ["/usr/local/share"; "/usr/share"] in
let dist_dirs = List.map shares ~f:(fun d -> Filename.concat d "satysfi" |> (fun d -> Filename.concat d "dist")) in
let rec f = function
| [] -> failwith "Can't find SATySFi lib. Please install it."
| (d :: ds) ->
if is_runtime_dir d
then d
else f ds
in
f dist_dirs