package dune-site

  1. Overview
  2. Docs
Embed locations information inside executable and libraries

Install

Dune Dependency

Authors

Maintainers

Sources

dune-3.18.2.tbz
sha256=56be509ffc3c5ba652113d9e6b43edb04a691f1e1f6cbba17b9d243b1239a7af
sha512=ee04a0c4ab946817018c78cd9b19c8d3082ee3b1cef78c699fff4ea37fd79543823a9751d0b945d2fd1783396ceded045cbec986a85f7a8f7bac93e04650fff3

doc/src/dune-site.private/dune_site_private.ml.html

Source file dune_site_private.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
(* TODO already exists in stdune/bin.ml *)
let path_sep = if Sys.win32 then ';' else ':'
let dune_dir_locations_env_var = "DUNE_DIR_LOCATIONS"
let dune_ocaml_stdlib_env_var = "DUNE_OCAML_STDLIB"
let dune_ocaml_hardcoded_env_var = "DUNE_OCAML_HARDCODED"
let dune_sourceroot_env_var = "DUNE_SOURCEROOT"

type entry =
  { package : string
  ; section : Dune_section.t
  ; dir : string
  }

let decode_dune_dir_locations =
  let rec aux acc = function
    | [] -> Some (List.rev acc)
    | package :: section :: dir :: l ->
      let section =
        match Dune_section.of_string section with
        | None -> invalid_arg ("Dune-site: Unknown section " ^ section)
        | Some s -> s
      in
      aux ({ package; section; dir } :: acc) l
    | _ -> None
  in
  fun s ->
    let l = String.split_on_char path_sep s in
    aux [] l
;;

let encode_dune_dir_locations =
  let add b { package; section; dir } =
    Buffer.add_string b package;
    Buffer.add_char b path_sep;
    Buffer.add_string b (Dune_section.to_string section);
    Buffer.add_char b path_sep;
    Buffer.add_string b dir
  in
  let rec loop b = function
    | [] -> ()
    | [ x ] -> add b x
    | x :: xs ->
      add b x;
      Buffer.add_char b path_sep;
      loop b xs
  in
  fun s ->
    let b = Buffer.create 16 in
    loop b s;
    Buffer.contents b
;;
OCaml

Innovation. Community. Security.