| 1 |
(* TODO already exists in stdune/bin.ml *) |
| 2 |
let path_sep = if Sys.win32 then ';' else ':' |
| 3 |
let dune_dir_locations_env_var = "DUNE_DIR_LOCATIONS" |
| 4 |
let dune_ocaml_stdlib_env_var = "DUNE_OCAML_STDLIB" |
| 5 |
let dune_ocaml_hardcoded_env_var = "DUNE_OCAML_HARDCODED" |
| 6 |
let dune_sourceroot_env_var = "DUNE_SOURCEROOT" |
| 7 |
|
| 8 |
type entry = |
| 9 |
{ package : string |
| 10 |
; section : Dune_section.t |
| 11 |
; dir : string |
| 12 |
} |
| 13 |
|
| 14 |
let decode_dune_dir_locations = |
| 15 |
let rec aux acc = function |
| 16 |
| [] -> Some (List.rev acc) |
| 17 |
| package :: section :: dir :: l -> |
| 18 |
let section = |
| 19 |
match Dune_section.of_string section with |
| 20 |
| None -> invalid_arg ("Dune-site: Unknown section " ^ section) |
| 21 |
| Some s -> s |
| 22 |
in |
| 23 |
aux ({ package; section; dir } :: acc) l |
| 24 |
| _ -> None |
| 25 |
in |
| 26 |
fun s -> |
| 27 |
let l = String.split_on_char path_sep s in |
| 28 |
aux [] l |
| 29 |
;; |
| 30 |
|
| 31 |
let encode_dune_dir_locations = |
| 32 |
let add b { package; section; dir } = |
| 33 |
Buffer.add_string b package; |
| 34 |
Buffer.add_char b path_sep; |
| 35 |
Buffer.add_string b (Dune_section.to_string section); |
| 36 |
Buffer.add_char b path_sep; |
| 37 |
Buffer.add_string b dir |
| 38 |
in |
| 39 |
let rec loop b = function |
| 40 |
| [] -> () |
| 41 |
| [ x ] -> add b x |
| 42 |
| x :: xs -> |
| 43 |
add b x; |
| 44 |
Buffer.add_char b path_sep; |
| 45 |
loop b xs |
| 46 |
in |
| 47 |
fun s -> |
| 48 |
let b = Buffer.create 16 in |
| 49 |
loop b s; |
| 50 |
Buffer.contents b |
| 51 |
;; |