|
170 | 170 | content. Formerly, (<repo>/packages/.../descr, |
171 | 171 | <repo>/compilers/.../<v>.descr) *) |
172 | 172 |
|
173 | | -module DescrIO = struct |
| 173 | +module Descr_legacyIO = struct |
174 | 174 |
|
175 | 175 | let internal = "descr" |
176 | 176 | let format_version = OpamVersion.of_string "0" |
@@ -217,9 +217,34 @@ module DescrIO = struct |
217 | 217 | let to_string _ = full |
218 | 218 |
|
219 | 219 | end |
| 220 | +module Descr_legacy = struct |
| 221 | + include Descr_legacyIO |
| 222 | + include MakeIO(Descr_legacyIO) |
| 223 | +end |
| 224 | + |
220 | 225 | module Descr = struct |
221 | | - include DescrIO |
222 | | - include MakeIO(DescrIO) |
| 226 | + type t = string * string |
| 227 | + |
| 228 | + let empty = "", "" |
| 229 | + |
| 230 | + let synopsis = fst |
| 231 | + let body = snd |
| 232 | + |
| 233 | + let to_string (x,y) = |
| 234 | + match y with |
| 235 | + | "" -> x ^ "\n" |
| 236 | + | y -> String.concat "" [x; "\n\n"; y; "\n"] |
| 237 | + |
| 238 | + let of_string str = |
| 239 | + let head, tail = |
| 240 | + match OpamStd.String.cut_at str '\n' with |
| 241 | + | None -> str, "" |
| 242 | + | Some (h,t) -> h, t in |
| 243 | + OpamStd.String.strip head, OpamStd.String.strip tail |
| 244 | + |
| 245 | + let create = of_string |
| 246 | + |
| 247 | + let of_legacy (x : Descr_legacy.t) : t = x |
223 | 248 | end |
224 | 249 |
|
225 | 250 | (* module Comp_descr = Descr *) |
@@ -2412,11 +2437,85 @@ end |
2412 | 2437 | (** Package url field in opam file. Formerly, file |
2413 | 2438 | (<repo>/packages/.../url) *) |
2414 | 2439 |
|
2415 | | -module URLSyntax = struct |
| 2440 | +module URL_legacySyntax = struct |
2416 | 2441 |
|
2417 | 2442 | let internal = "url-file" |
2418 | 2443 | let format_version = OpamVersion.of_string "1.2" |
2419 | 2444 |
|
| 2445 | + type t = { |
| 2446 | + url : url; |
| 2447 | + mirrors : url list; |
| 2448 | + checksum: OpamHash.t list; |
| 2449 | + errors : (string * Pp.bad_format) list; |
| 2450 | + } |
| 2451 | + |
| 2452 | + let create ?(mirrors=[]) ?(checksum=[]) url = |
| 2453 | + { |
| 2454 | + url; mirrors; checksum; errors = []; |
| 2455 | + } |
| 2456 | + |
| 2457 | + let empty = { |
| 2458 | + url = OpamUrl.empty; |
| 2459 | + mirrors = []; |
| 2460 | + checksum= []; |
| 2461 | + errors = []; |
| 2462 | + } |
| 2463 | + |
| 2464 | + let url t = t.url |
| 2465 | + let mirrors t = t.mirrors |
| 2466 | + let checksum t = t.checksum |
| 2467 | + |
| 2468 | + let with_url url t = { t with url } |
| 2469 | + let with_mirrors mirrors t = { t with mirrors } |
| 2470 | + let with_checksum checksum t = { t with checksum = checksum } |
| 2471 | + |
| 2472 | + let fields = |
| 2473 | + let with_url url t = |
| 2474 | + if t.url <> OpamUrl.empty then Pp.bad_format "Too many URLS" |
| 2475 | + else with_url url t |
| 2476 | + in |
| 2477 | + [ |
| 2478 | + "src", Pp.ppacc with_url url |
| 2479 | + Pp.V.url; |
| 2480 | + "archive", Pp.ppacc_opt with_url OpamStd.Option.none |
| 2481 | + (Pp.V.url_with_backend `http); |
| 2482 | + "http", Pp.ppacc_opt with_url OpamStd.Option.none |
| 2483 | + (Pp.V.url_with_backend `http); |
| 2484 | + "git", Pp.ppacc_opt with_url OpamStd.Option.none |
| 2485 | + (Pp.V.url_with_backend `git); |
| 2486 | + "darcs", Pp.ppacc_opt with_url OpamStd.Option.none |
| 2487 | + (Pp.V.url_with_backend `darcs); |
| 2488 | + "hg", Pp.ppacc_opt with_url OpamStd.Option.none |
| 2489 | + (Pp.V.url_with_backend `hg); |
| 2490 | + "local", Pp.ppacc_opt with_url OpamStd.Option.none |
| 2491 | + (Pp.V.url_with_backend `rsync); |
| 2492 | + "checksum", Pp.ppacc with_checksum checksum |
| 2493 | + (Pp.V.map_list ~depth:1 |
| 2494 | + (Pp.V.string -| Pp.of_module "checksum" (module OpamHash))); |
| 2495 | + "mirrors", Pp.ppacc with_mirrors mirrors |
| 2496 | + (Pp.V.map_list ~depth:1 Pp.V.url); |
| 2497 | + ] |
| 2498 | + |
| 2499 | + let pp_contents = |
| 2500 | + let name = internal in |
| 2501 | + Pp.I.fields ~name ~empty fields -| |
| 2502 | + Pp.I.on_errors ~name (fun t e -> {t with errors = e::t.errors}) -| |
| 2503 | + Pp.pp ~name |
| 2504 | + (fun ~pos t -> |
| 2505 | + if t.url = OpamUrl.empty then OpamPp.bad_format ~pos "missing URL" |
| 2506 | + else t) |
| 2507 | + (fun x -> x) |
| 2508 | + |
| 2509 | + let pp = Pp.I.map_file pp_contents |
| 2510 | + |
| 2511 | +end |
| 2512 | +module URL_legacy = struct |
| 2513 | + include URL_legacySyntax |
| 2514 | + include SyntaxFile(URL_legacySyntax) |
| 2515 | +end |
| 2516 | + |
| 2517 | +module URL = struct |
| 2518 | + |
2420 | 2519 | type t = { |
2421 | 2520 | url : url; |
2422 | 2521 | mirrors : url list; |
@@ -2485,7 +2584,7 @@ module URLSyntax = struct |
2485 | 2584 | ] |
2486 | 2585 |
|
2487 | 2586 | let pp_contents = |
2488 | | - let name = internal in |
| 2587 | + let name = "url-file" in |
2489 | 2588 | Pp.I.fields ~name ~empty fields -| |
2490 | 2589 | Pp.I.on_errors ~name (fun t e -> {t with errors = e::t.errors}) -| |
2491 | 2590 | Pp.pp ~name |
@@ -2513,12 +2612,8 @@ module URLSyntax = struct |
2513 | 2612 | swhid = None; |
2514 | 2613 | mirrors = OpamSWHID.to_url swhid :: t.mirrors }) |
2515 | 2614 |
|
2516 | | - let pp = Pp.I.map_file pp_contents |
2517 | | - |
2518 | | -end |
2519 | | -module URL = struct |
2520 | | - include URLSyntax |
2521 | | - include SyntaxFile(URLSyntax) |
| 2615 | + let of_legacy {URL_legacy.url; mirrors; checksum; errors} = |
| 2616 | + {empty with mirrors; checksum; errors; url} |
2522 | 2617 | end |
2523 | 2618 |
|
2524 | 2619 |
|
@@ -3102,7 +3197,7 @@ module OPAMSyntax = struct |
3102 | 3197 | Pp.V.os_constraint; |
3103 | 3198 | "descr", no_cleanup Pp.ppacc_opt with_descr OpamStd.Option.none |
3104 | 3199 | (Pp.V.string_tr -| |
3105 | | - Pp.of_pair "descr" Descr.(of_string (), to_string ())); |
| 3200 | + Pp.of_pair "descr" Descr.(of_string, to_string)); |
3106 | 3201 | "extra-sources", no_cleanup Pp.ppacc_opt |
3107 | 3202 | with_extra_sources OpamStd.Option.none |
3108 | 3203 | (Pp.V.map_list ~depth:2 @@ |
@@ -4199,7 +4294,7 @@ module CompSyntax = struct |
4199 | 4294 | env = comp.env; |
4200 | 4295 | flags = [Pkgflag_Compiler]; |
4201 | 4296 | url; |
4202 | | - descr = descr_opt; |
| 4297 | + descr = Option.map Descr.of_legacy descr_opt; |
4203 | 4298 | } |
4204 | 4299 |
|
4205 | 4300 | end |
|
0 commit comments