Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 296 lines (228 sloc) 6.905 kb
aa67aa9 @samoht Big refactoring work.
samoht authored
1 (***********************************************************************)
2 (* *)
3 (* Copyright 2012 OCamlPro *)
4 (* Copyright 2012 INRIA *)
5 (* *)
6 (* All rights reserved. This file is distributed under the terms of *)
7 (* the GNU Public License version 3.0. *)
8 (* *)
9 (* OPAM is distributed in the hope that it will be useful, *)
10 (* but WITHOUT ANY WARRANTY; without even the implied warranty of *)
11 (* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *)
12 (* GNU General Public License for more details. *)
13 (* *)
14 (***********************************************************************)
15
16 type basename = OpamFilename.Base.t
17
18 type dirname = OpamFilename.Dir.t
19
20 type filename = OpamFilename.t
21
22 type filename_set = OpamFilename.Set.t
23
24 type 'a filename_map = 'a OpamFilename.Map.t
25
26 type 'a download =
27 | Up_to_date of 'a
28 | Not_available
29 | Result of 'a
30
31 type generic_file =
32 | D of dirname
33 | F of filename
34
35 type version = OpamPackage.Version.t
36
37 type version_set = OpamPackage.Version.Set.t
38
39 type name = OpamPackage.Name.t
40
41 type name_set = OpamPackage.Name.Set.t
42
43 type 'a name_map = 'a OpamPackage.Name.Map.t
44
45 type package = OpamPackage.t
46
47 type package_set = OpamPackage.Set.t
48
49 type 'a package_map = 'a OpamPackage.Map.t
50
51 type kind = string
52
53 type address = dirname
54
55 type repository = {
56 repo_name: string;
57 repo_kind: kind;
58 repo_address: address;
59 }
60
61 let create_repository ~name ~kind ~address =
62 let address =
63 if Sys.file_exists address
64 then OpamFilename.Dir.of_string address
65 else OpamFilename.raw_dir address in
66 {
67 repo_name = name;
68 repo_kind = kind;
69 repo_address = address
70 }
71
72 type variable = OpamVariable.t
73
74 type full_variable = OpamVariable.Full.t
75
76 type section = OpamVariable.Section.t
77
78 type full_section = OpamVariable.Section.Full.t
79
80 type alias = OpamAlias.t
81
82 type alias_set = OpamAlias.Set.t
83
84 type file_attribute = OpamFilename.Attribute.t
85
86 type file_attribute_set = OpamFilename.Attribute.Set.t
87
88 type compiler_version = OpamVersion.Compiler.t
89
90 type compiler_version_set = OpamVersion.Compiler.Set.t
91
92 type opam_version = OpamVersion.OPAM.t
93
94 type 'a generic_formula = 'a OpamFormula.formula =
95 | Empty
96 | Atom of 'a
97 | Block of 'a generic_formula
98 | And of 'a generic_formula * 'a generic_formula
99 | Or of 'a generic_formula * 'a generic_formula
100
101 type formula = OpamFormula.t
102
103 type conjunction = OpamFormula.conjunction
104
105 type compiler_constraint = OpamVersion.Compiler.constr
106
107 type ppflag =
108 | Camlp4 of string list
109 | Cmd of string list
110
111 (* Command line arguments *)
112
113 (* Upload arguments *)
114 type upload = {
115 upl_opam : filename;
116 upl_descr : filename;
117 upl_archive: filename;
118 }
119
120 let string_of_upload u =
121 Printf.sprintf "opam=%s descr=%s archive=%s"
122 (OpamFilename.to_string u.upl_opam)
123 (OpamFilename.to_string u.upl_descr)
124 (OpamFilename.to_string u.upl_archive)
125
126 (* Remote arguments *)
127 type remote =
128 | RList
129 | RAdd of repository
130 | RRm of string
131
132 let string_of_repository r =
133 Printf.sprintf "%s(%s %s)"
134 r.repo_name
135 (OpamFilename.Dir.to_string r.repo_address)
136 r.repo_kind
137
138 let string_of_remote = function
139 | RList -> "list"
140 | RAdd s -> Printf.sprintf "add %s" (string_of_repository s)
141 | RRm s -> Printf.sprintf "rm %s" s
142
143 type config_option = {
144 conf_is_rec : bool;
145 conf_is_byte: bool;
146 conf_is_link: bool;
147 conf_options: OpamVariable.Section.Full.t list;
148 }
149
150 type pin_option =
151 | Version of version
152 | Path of dirname
153 | Git of dirname
154 | Unpin
155
156 let pin_option_of_string ?kind s =
157 match kind with
158 | Some "version" -> Version (OpamPackage.Version.of_string s)
159 | Some "git" ->
160 if Sys.file_exists s then
161 Git (OpamFilename.Dir.of_string s)
162 else
163 Git (OpamFilename.raw_dir s)
164 | Some "rsync" -> Path (OpamFilename.Dir.of_string s)
165 | None | Some _ ->
166 let d = OpamSystem.real_path s in
167 if s = "none" then
168 Unpin
169 else if Sys.file_exists d then
170 Path (OpamFilename.Dir.of_string s)
171 else if OpamMisc.contains d ('/') then
172 Git (OpamFilename.raw_dir s)
173 else
174 Version (OpamPackage.Version.of_string s)
175
176 type pin = {
177 pin_package: name;
178 pin_arg: pin_option;
179 }
180
181 let path_of_pin_option = function
182 | Version v -> OpamPackage.Version.to_string v
183 | Git p
184 | Path p -> OpamFilename.Dir.to_string p
185 | Unpin -> "none"
186
187 let kind_of_pin_option = function
188 | Version _ -> "version"
189 | Git _ -> "git"
190 | Path _ -> "rsync"
191 | Unpin -> "<none>"
192
193 let string_of_pin p =
194 Printf.sprintf "{package=%s; path=%s; kind=%s}"
195 (OpamPackage.Name.to_string p.pin_package)
196 (path_of_pin_option p.pin_arg)
197 (kind_of_pin_option p.pin_arg)
198
199 type config =
200 | CEnv
201 | CList
202 | CVariable of full_variable
203 | CIncludes of bool * (name list)
204 | CCompil of config_option
205 | CSubst of basename list
206
207 (** Variable contents *)
208 type variable_contents = OpamVariable.variable_contents =
209 | B of bool
210 | S of string
211
212 type symbol =
213 | Eq | Neq | Le | Ge | Lt | Gt
214
215 type filter =
216 | FBool of bool
217 | FString of string
218 | FOp of filter * symbol * filter
219 | FAnd of filter * filter
220 | FOr of filter * filter
221
222 type arg = string * filter option
223
224 type command = arg list * filter option
225
226 type 'a optional = {
227 c: 'a;
228 optional: bool;
229 }
230
231 type stats = {
232 s_install : int;
233 s_reinstall: int;
234 s_upgrade : int;
235 s_downgrade: int;
236 s_remove : int;
237 }
238
239
240 (** Untyped generic file format. *)
241
242 (** Base values *)
243 type value =
244 | Bool of bool
245 | Int of int
246 | String of string
247 | Symbol of string
248 | Ident of string
249 | List of value list
250 | Group of value list
251 | Option of value * value list
252
253 (** A file section *)
254 type file_section = {
255 section_kind : string;
256 section_name : string;
257 section_items : file_item list;
258 }
259
260 (** A file is composed of sections and variable definitions *)
261 and file_item =
262 | Section of file_section
263 | Variable of string * value
264
265 (** A file is a list of items and the filename *)
266 type file = {
267 file_contents: file_item list;
268 file_name : string;
269 }
270
271 type action =
272 | To_change of package option * package
273 | To_delete of package
274 | To_recompile of package
275
276 type ('a, 'b) result =
277 | Success of 'a
278 | Conflicts of (unit -> 'b)
279
280 type request = {
281 wish_install: conjunction;
282 wish_remove : conjunction;
283 wish_upgrade: conjunction;
284 }
285
286 type 'a solution = {
287 to_remove: package list;
288 to_add : 'a;
289 }
290
291 type env = {
292 add_to_env : (string * string) list;
293 add_to_path: dirname;
294 new_env : (string * string) list;
295 }
Something went wrong with that request. Please try again.