Source file opam_conf_file.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
open OpamPp.Op
let conf_default = OpamFilename.of_string "opam-oui.conf"
module Syntax = struct
let internal = "conf"
let format_version = OpamVersion.of_string "0.2"
type images = { ico: string option; dlg: string option; ban: string option }
type t = {
c_version: OpamVersion.t;
c_wix_version: Wix.Version.t option;
c_images: images;
c_binary_path: string option;
c_binary: string option;
c_embedded : (string * string option) list;
c_envvar: (string * string) list;
}
let empty = {
c_version = format_version;
c_wix_version = None;
c_images = {
ico = None;
dlg = None;
ban = None;
};
c_binary_path = None;
c_binary = None;
c_embedded = [];
c_envvar = [];
}
let embedded_pp : (OpamParserTypes.FullPos.value, string * string option) OpamPp.t =
let from_list ~pos = function
| [ path ] -> path, None
| [ path; alias ] -> path, Some alias
| _ -> OpamPp.bad_format ~pos
"embedded declaration should contain 1 (path) or 2 (path and alias) elements."
in
let to_list = function
| (path, Some alias) -> [ path; alias ]
| (path, None) -> [ path ]
in
OpamPp.Op.(OpamFormat.V.map_list OpamFormat.V.string -| OpamPp.pp from_list to_list)
let fields = [
"opamwix-version", OpamPp.ppacc
(fun c_version t -> { t with c_version}) (fun t -> t.c_version)
(OpamFormat.V.string -| OpamPp.of_module "version" (module OpamVersion));
"wix-version", OpamPp.ppacc_opt
(fun c_wix_version t -> { t with c_wix_version = Some c_wix_version })
(fun t -> t.c_wix_version)
(OpamFormat.V.string -| OpamPp.of_module "wix_version" (module Wix.Version));
"ico", OpamPp.ppacc_opt
(fun ico t -> { t with c_images = { t.c_images with ico = Some ico } })
(fun t -> t.c_images.ico)
OpamFormat.V.string;
"bng", OpamPp.ppacc_opt
(fun dlg t -> { t with c_images = { t.c_images with dlg = Some dlg } })
(fun t -> t.c_images.dlg)
OpamFormat.V.string;
"ban", OpamPp.ppacc_opt
(fun ban t -> { t with c_images = { t.c_images with ban = Some ban } })
(fun t -> t.c_images.ban)
OpamFormat.V.string;
"binary-path", OpamPp.ppacc_opt
(fun bp t -> { t with c_binary_path = Some bp})
(fun t -> t.c_binary_path)
OpamFormat.V.string;
"binary", OpamPp.ppacc_opt
(fun binary t -> { t with c_binary = Some binary }) (fun t -> t.c_binary)
OpamFormat.V.string;
"embedded", OpamPp.ppacc
(fun file t -> { t with c_embedded = file }) (fun t -> t.c_embedded)
(OpamFormat.V.map_list ~depth:2 embedded_pp);
"envvar", OpamPp.ppacc
(fun c_envvar t -> { t with c_envvar }) (fun t -> t.c_envvar)
(OpamFormat.V.map_list ~depth:2
(OpamFormat.V.map_pair OpamFormat.V.string OpamFormat.V.string));
]
let pp =
let name = internal in
OpamFormat.I.map_file
@@ OpamFormat.I.fields ~name ~empty fields
-| OpamFormat.I.show_errors ~name ~strict:true ()
(** XXX Add some checks *)
end
module Conf = struct
include Syntax
include OpamFile.SyntaxFile(Syntax)
end