Skip to content

Commit 295c6c2

Browse files
committed
[API] Split the deprecated url and descr files implementations to their own submodules
1 parent 22b3869 commit 295c6c2

File tree

8 files changed

+178
-32
lines changed

8 files changed

+178
-32
lines changed

doc/pages/Manual.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,10 +1211,11 @@ files.
12111211
defines a long description (one or more paragraphs) for the package. This can
12121212
also be defined as the body of an external [`descr`](#descr) file.
12131213

1214-
- <a id="opamsection-url">`url "{" <url-file> "}"`</a>:
1215-
defines the URL where the package source can be obtained. This section has
1216-
contents in the same format as the [`url`](#url) file, and has the same effect
1217-
as using a separate `url` file.
1214+
- <a id="opamsection-url">`url "{" <url-section> "}"`</a>:
1215+
defines the URL where the package source can be obtained. Before opam 2.6,
1216+
this section' content was the same format as the [`url`](#url) file,
1217+
and had the same effect as using a separate `url` file.
1218+
As of opam 2.6, the `url` file now only supports the legacy opam 1.2 fields.
12181219

12191220
- <a id="opamfield-setenv">`setenv: [ <environment-update> ... ]`</a>: defines
12201221
environment variables updates that will be applied upon installing the
@@ -1249,7 +1250,7 @@ files.
12491250
See [`x-env-path-rewrite:`](#opamfield-x-env-path-rewrite)
12501251
for path portability of environment variables on Windows.
12511252

1252-
- <a id="opamsection-extra-sources">`extra-source <string> "{" <url-file> "}"`</a>:
1253+
- <a id="opamsection-extra-sources">`extra-source <string> "{" <url-section> "}"`</a>:
12531254
allows the definition of extra files that need downloading into the source
12541255
tree before the package can be patched (if necessary) and built. The format is
12551256
similar to that of the `url` section, but here it is expected to point to a

master_changes.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ users)
6565
## Env
6666

6767
## Opamfile
68+
* The `url` file now only supports the legacy opam 1.2 fields [#6827 @kit-ty-kate]
6869

6970
## External dependencies
7071

@@ -160,6 +161,10 @@ users)
160161
## opam-solver
161162

162163
## opam-format
164+
* `OpamFile.Descr` was moved to `OpamFile.Descr_legacy` and a simpler `OpamFile.Descr` module was created only containing non-IO functions removing the outdated `descr` file support [#6827 @kit-ty-kate]
165+
* `OpamFile.URL` was moved to `OpamFile.URL_legacy` and a simpler `OpamFile.URL` module was created only containing non-IO functions removing the outdated `url` file support [#6827 @kit-ty-kate]
166+
* `OpamFile.Descr.of_legacy`: was added [#6827 @kit-ty-kate]
167+
* `OpamFile.URL.of_legacy`: was added [#6827 @kit-ty-kate]
163168

164169
## opam-core
165170
* `OpamCmdliner` was added. It is accessible through a new `opam-core.cmdliner` sub-library [#6755 @kit-ty-kate]

src/client/opamAdminRepoUpgrade.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ let do_upgrade repo_root =
219219
let descr_file =
220220
OpamFilename.(opt_file (add_extension (chop_extension comp_file) "descr"))
221221
in
222-
let descr = descr_file >>| fun f -> OpamFile.Descr.read (OpamFile.make f) in
222+
let descr = descr_file >>| fun f -> OpamFile.Descr_legacy.read (OpamFile.make f) in
223223
let nv, ocaml_version, variant =
224224
match OpamStd.String.cut_at c '+' with
225225
| None ->

src/format/opamFile.ml

Lines changed: 108 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ end
170170
content. Formerly, (<repo>/packages/.../descr,
171171
<repo>/compilers/.../<v>.descr) *)
172172

173-
module DescrIO = struct
173+
module Descr_legacyIO = struct
174174

175175
let internal = "descr"
176176
let format_version = OpamVersion.of_string "0"
@@ -217,9 +217,34 @@ module DescrIO = struct
217217
let to_string _ = full
218218

219219
end
220+
module Descr_legacy = struct
221+
include Descr_legacyIO
222+
include MakeIO(Descr_legacyIO)
223+
end
224+
220225
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
223248
end
224249

225250
(* module Comp_descr = Descr *)
@@ -2412,11 +2437,85 @@ end
24122437
(** Package url field in opam file. Formerly, file
24132438
(<repo>/packages/.../url) *)
24142439

2415-
module URLSyntax = struct
2440+
module URL_legacySyntax = struct
24162441

24172442
let internal = "url-file"
24182443
let format_version = OpamVersion.of_string "1.2"
24192444

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+
24202519
type t = {
24212520
url : url;
24222521
mirrors : url list;
@@ -2485,7 +2584,7 @@ module URLSyntax = struct
24852584
]
24862585

24872586
let pp_contents =
2488-
let name = internal in
2587+
let name = "url-file" in
24892588
Pp.I.fields ~name ~empty fields -|
24902589
Pp.I.on_errors ~name (fun t e -> {t with errors = e::t.errors}) -|
24912590
Pp.pp ~name
@@ -2513,12 +2612,8 @@ module URLSyntax = struct
25132612
swhid = None;
25142613
mirrors = OpamSWHID.to_url swhid :: t.mirrors })
25152614

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}
25222617
end
25232618

25242619

@@ -3102,7 +3197,7 @@ module OPAMSyntax = struct
31023197
Pp.V.os_constraint;
31033198
"descr", no_cleanup Pp.ppacc_opt with_descr OpamStd.Option.none
31043199
(Pp.V.string_tr -|
3105-
Pp.of_pair "descr" Descr.(of_string (), to_string ()));
3200+
Pp.of_pair "descr" Descr.(of_string, to_string));
31063201
"extra-sources", no_cleanup Pp.ppacc_opt
31073202
with_extra_sources OpamStd.Option.none
31083203
(Pp.V.map_list ~depth:2 @@
@@ -4199,7 +4294,7 @@ module CompSyntax = struct
41994294
env = comp.env;
42004295
flags = [Pkgflag_Compiler];
42014296
url;
4202-
descr = descr_opt;
4297+
descr = Option.map Descr.of_legacy descr_opt;
42034298
}
42044299

42054300
end

src/format/opamFile.mli

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ module InitConfig: sig
297297
end
298298

299299
(** Package descriptions: [$opam/descr/] *)
300-
module Descr: sig
300+
module Descr_legacy: sig
301301

302302
include IO_FILE
303303

@@ -317,11 +317,53 @@ module Descr: sig
317317

318318
end
319319

320+
module Descr: sig
321+
322+
type t
323+
324+
val empty: t
325+
val create: string -> t
326+
327+
(** Return the first line *)
328+
val synopsis: t -> string
329+
330+
(** Return the body *)
331+
val body: t -> string
332+
333+
val of_legacy: Descr_legacy.t -> t
334+
335+
end
336+
320337
(** {2 Urls for OPAM repositories} *)
321-
module URL: sig
338+
module URL_legacy: sig
322339

323340
include IO_FILE
324341

342+
val create:
343+
?mirrors:url list -> ?checksum:OpamHash.t list ->
344+
url -> t
345+
346+
(** URL address *)
347+
val url: t -> url
348+
349+
val mirrors: t -> url list
350+
351+
(** Archive checksum *)
352+
val checksum: t -> OpamHash.t list
353+
354+
(** Constructor *)
355+
val with_url: url -> t -> t
356+
val with_checksum: OpamHash.t list -> t -> t
357+
val with_mirrors: OpamUrl.t list -> t -> t
358+
359+
end
360+
361+
module URL: sig
362+
363+
type t
364+
365+
val empty: t
366+
325367
val create:
326368
?mirrors:url list -> ?checksum:OpamHash.t list ->
327369
?swhid:OpamSWHID.t -> ?subpath:subpath ->
@@ -347,6 +389,7 @@ module URL: sig
347389

348390
val subpath: t -> subpath option
349391

392+
val of_legacy: URL_legacy.t -> t
350393
end
351394

352395
(** OPAM files *)
@@ -872,7 +915,7 @@ module Comp: sig
872915
created with "VARIANT" the part of the compiler name on the right of the
873916
"+". In both case, the version corresponds to the OCaml version and is
874917
[version comp]. *)
875-
val to_package: ?package:package -> t -> Descr.t option -> OPAM.t
918+
val to_package: ?package:package -> t -> Descr_legacy.t option -> OPAM.t
876919

877920
end
878921

src/state/opamFileTools.ml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,20 +1321,21 @@ let add_aux_files ?dir ?(files_subdir_hashes=false) opam =
13211321
match dir with
13221322
| None -> opam
13231323
| Some dir ->
1324-
let (url_file: OpamFile.URL.t OpamFile.t) =
1324+
let (url_file: OpamFile.URL_legacy.t OpamFile.t) =
13251325
OpamFile.make (dir // "url")
13261326
in
1327-
let (descr_file: OpamFile.Descr.t OpamFile.t) =
1327+
let (descr_file: OpamFile.Descr_legacy.t OpamFile.t) =
13281328
OpamFile.make (dir // "descr")
13291329
in
13301330
let files_dir =
13311331
OpamFilename.Op.(dir / "files")
13321332
in
13331333
let opam =
1334-
match OpamFile.OPAM.url opam, try_read OpamFile.URL.read_opt url_file with
1335-
| None, (Some url, None) -> OpamFile.OPAM.with_url url opam
1334+
match OpamFile.OPAM.url opam, try_read OpamFile.URL_legacy.read_opt url_file with
1335+
| None, (Some url, None) ->
1336+
OpamFile.OPAM.with_url (OpamFile.URL.of_legacy url) opam
13361337
| Some opam_url, (Some url, errs) ->
1337-
if url = opam_url && errs = None then
1338+
if (OpamFile.URL.of_legacy url) = opam_url && errs = None then
13381339
log "Duplicate definition of url in '%s' and opam file"
13391340
(OpamFile.to_string url_file)
13401341
else
@@ -1349,8 +1350,9 @@ let add_aux_files ?dir ?(files_subdir_hashes=false) opam =
13491350
in
13501351
let opam =
13511352
match OpamFile.OPAM.descr opam,
1352-
try_read OpamFile.Descr.read_opt descr_file with
1353-
| None, (Some descr, None) -> OpamFile.OPAM.with_descr descr opam
1353+
try_read OpamFile.Descr_legacy.read_opt descr_file with
1354+
| None, (Some descr, None) ->
1355+
OpamFile.OPAM.with_descr (OpamFile.Descr.of_legacy descr) opam
13541356
| Some _, (Some _, _) ->
13551357
log "Duplicate descr in '%s' and opam file"
13561358
(OpamFile.to_string descr_file);

src/state/opamFormatUpgrade.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,9 +561,9 @@ let from_1_3_dev2_to_1_3_dev5 ~on_the_fly:_ root conf =
561561
in
562562
let descr =
563563
OpamStd.Option.default
564-
(OpamFile.Descr.create
564+
(OpamFile.Descr_legacy.create
565565
"Switch relying on a system-wide installation of OCaml")
566-
(OpamFile.Descr.read_opt descr_f)
566+
(OpamFile.Descr_legacy.read_opt descr_f)
567567
in
568568
let comp_opam =
569569
OpamFile.Comp.to_package comp (Some descr)

src/state/opamFormatUpgrade.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ val opam_file:
7979
(** Convert the comp file to an opam one, using {!OpamFile.Comp.to_package} and
8080
applying filter rewriting *)
8181
val comp_file:
82-
?package:package -> ?descr:OpamFile.Descr.t -> OpamFile.Comp.t ->
82+
?package:package -> ?descr:OpamFile.Descr_legacy.t -> OpamFile.Comp.t ->
8383
OpamFile.OPAM.t
8484

8585
(** Runs the opam file format from the file's format to current, and adds data

0 commit comments

Comments
 (0)