Skip to content

Commit eb4b3e7

Browse files
authored
Add support for x-maintenance-intent in dune-project (#11274)
* Add support for opam x-maintenance-intent in dune-project Signed-off-by: ArthurW <[email protected]> Signed-off-by: Marek Kubica <[email protected]> * Add tests for maintenance_intent Signed-off-by: ArthurW <[email protected]> Signed-off-by: Marek Kubica <[email protected]> * Document maintenance_intent Signed-off-by: ArthurW <[email protected]> Signed-off-by: Marek Kubica <[email protected]> * Default maintenance_intent to (latest) Signed-off-by: ArthurW <[email protected]> Signed-off-by: Marek Kubica <[email protected]> * No x-maintenance-intent in opam files for dune<3.18 Signed-off-by: ArthurW <[email protected]> Signed-off-by: Marek Kubica <[email protected]> --------- Signed-off-by: ArthurW <[email protected]> Signed-off-by: Marek Kubica <[email protected]>
1 parent aac2ce9 commit eb4b3e7

File tree

14 files changed

+125
-18
lines changed

14 files changed

+125
-18
lines changed

doc/changes/11274.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Support for opam `(maintenance_intent ...)` in dune-project (#11274, @art-w)

doc/howto/opam-file-generation.rst

+2
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,15 @@ For example, if your opam file looks like:
8181
"conduit-async" { >= "1.0.3" }
8282
"async" { >= "v0.10.0" }
8383
]
84+
x-maintenance-intent: [ "(latest)" ]
8485
8586
You can express this as::
8687

8788
(source (github mirage/ocaml-cohttp))
8889
(license ISC)
8990
(authors "Anil Madhavapeddy" "Rudi Grinberg")
9091
(maintainers "[email protected]")
92+
(maintenance_intent "(latest)")
9193

9294
(package
9395
(name cohttp-async)

doc/reference/dune-project/generate_opam_files.rst

+13
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,19 @@ defined in the project:
6363
"Jane Doe <[email protected]>"
6464
"John Doe <[email protected]>")
6565
66+
.. _maintenance_intent:
67+
.. describe:: (maintenance_intent <strings>)
68+
69+
.. versionadded:: 3.18
70+
71+
Specify the `opam maintenance intent <https://github.com/ocaml/opam-repository/blob/master/governance/policies/archiving.md#specification-of-the-x--fields-used-in-the-archiving-process>`__.
72+
73+
Example:
74+
75+
.. code:: dune
76+
77+
(maintenance_intent "(latest)")
78+
6679
.. describe:: (source ...)
6780

6881
.. versionadded:: 1.7

doc/reference/dune-project/package.rst

+7
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ package
6060

6161
The same as (and takes precedences over) the corresponding global field.
6262

63+
.. describe:: (maintenance_intent ...)
64+
65+
.. versionadded:: 3.18
66+
67+
The same as (and takes precedences over) the corresponding global field.
68+
See :doc:`the global field for details </reference/dune-project/generate_opam_files>`.
69+
6370
.. describe:: (source ...)
6471

6572
.. versionadded:: 2.0

src/dune_config_file/dune_config_file.ml

+9-2
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,27 @@ module Dune_config = struct
2020
type t =
2121
{ authors : string list option
2222
; maintainers : string list option
23+
; maintenance_intent : string list option
2324
; license : string list option
2425
}
2526

2627
let decode =
2728
fields
2829
(let+ authors = field_o "authors" (repeat string)
2930
and+ maintainers = field_o "maintainers" (repeat string)
31+
and+ maintenance_intent = field_o "maintenance_intent" (repeat string)
3032
and+ license = field_o "license" (repeat string) in
31-
{ authors; maintainers; license })
33+
{ authors; maintainers; maintenance_intent; license })
3234
;;
3335

3436
let to_dyn t =
3537
let f = Dyn.(option (list string)) in
3638
Dyn.record
37-
[ "authors", f t.authors; "maintainers", f t.maintainers; "license", f t.license ]
39+
[ "authors", f t.authors
40+
; "maintainers", f t.maintainers
41+
; "maintenance_intent", f t.maintenance_intent
42+
; "license", f t.license
43+
]
3844
;;
3945
end
4046

@@ -359,6 +365,7 @@ module Dune_config = struct
359365
; project_defaults =
360366
{ authors = Some [ "Author Name <[email protected]>" ]
361367
; maintainers = Some [ "Maintainer Name <[email protected]>" ]
368+
; maintenance_intent = None
362369
; license = Some [ "LICENSE" ]
363370
}
364371
; experimental = []

src/dune_config_file/dune_config_file.mli

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module Dune_config : sig
88
type t =
99
{ authors : string list option
1010
; maintainers : string list option
11+
; maintenance_intent : string list option
1112
; license : string list option
1213
}
1314

src/dune_lang/package_info.ml

+56-5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ type t =
99
; bug_reports : string option
1010
; documentation : string option
1111
; maintainers : string list option
12+
; maintenance_intent : string list option
1213
}
1314

1415
let source t = t.source
@@ -29,6 +30,7 @@ let bug_reports t =
2930

3031
let documentation t = t.documentation
3132
let maintainers t = t.maintainers
33+
let maintenance_intent t = t.maintenance_intent
3234

3335
let empty =
3436
{ source = None
@@ -38,6 +40,7 @@ let empty =
3840
; bug_reports = None
3941
; documentation = None
4042
; maintainers = None
43+
; maintenance_intent = None
4144
}
4245
;;
4346

@@ -54,10 +57,20 @@ let example ~authors ~maintainers ~license =
5457
(* homepage and bug_reports are inferred from the source *)
5558
; homepage = None
5659
; bug_reports = None
60+
; maintenance_intent = None
5761
}
5862
;;
5963

60-
let to_dyn { source; license; authors; homepage; bug_reports; documentation; maintainers }
64+
let to_dyn
65+
{ source
66+
; license
67+
; authors
68+
; homepage
69+
; bug_reports
70+
; documentation
71+
; maintainers
72+
; maintenance_intent
73+
}
6174
=
6275
let open Dyn in
6376
record
@@ -67,18 +80,28 @@ let to_dyn { source; license; authors; homepage; bug_reports; documentation; mai
6780
; "documentation", (option string) documentation
6881
; "bug_reports", (option string) bug_reports
6982
; "maintainers", option (list string) maintainers
83+
; "maintenance_intent", option (list string) maintenance_intent
7084
; "authors", option (list string) authors
7185
]
7286
;;
7387

7488
let encode_fields
75-
{ source; authors; license; homepage; documentation; bug_reports; maintainers }
89+
{ source
90+
; authors
91+
; license
92+
; homepage
93+
; documentation
94+
; bug_reports
95+
; maintainers
96+
; maintenance_intent
97+
}
7698
=
7799
let open Encoder in
78100
record_fields
79101
[ field_o "source" Source_kind.encode source
80102
; field_l "authors" string (Option.value ~default:[] authors)
81103
; field_l "maintainers" string (Option.value ~default:[] maintainers)
104+
; field_l "maintenance_intent" string (Option.value ~default:[] maintenance_intent)
82105
; field_l "license" string (Option.value ~default:[] license)
83106
; field_o "homepage" string homepage
84107
; field_o "documentation" string documentation
@@ -109,8 +132,18 @@ let decode ?since () =
109132
field_o "bug_reports" (Syntax.since Stanza.syntax (v (1, 10)) >>> string)
110133
and+ maintainers =
111134
field_o "maintainers" (Syntax.since Stanza.syntax (v (1, 10)) >>> repeat string)
135+
and+ maintenance_intent =
136+
field_o "maintenance_intent" (Syntax.since Stanza.syntax (v (3, 18)) >>> repeat string)
112137
in
113-
{ source; authors; license; homepage; documentation; bug_reports; maintainers }
138+
{ source
139+
; authors
140+
; license
141+
; homepage
142+
; documentation
143+
; bug_reports
144+
; maintainers
145+
; maintenance_intent
146+
}
114147
;;
115148

116149
let superpose t1 t2 =
@@ -126,9 +159,27 @@ let superpose t1 t2 =
126159
; documentation = f t1.documentation t2.documentation
127160
; bug_reports = f t1.bug_reports t2.bug_reports
128161
; maintainers = f t1.maintainers t2.maintainers
162+
; maintenance_intent = f t1.maintenance_intent t2.maintenance_intent
129163
}
130164
;;
131165

132-
let create ~maintainers ~authors ~homepage ~bug_reports ~documentation ~license ~source =
133-
{ maintainers; authors; homepage; bug_reports; documentation; license; source }
166+
let create
167+
~maintainers
168+
~maintenance_intent
169+
~authors
170+
~homepage
171+
~bug_reports
172+
~documentation
173+
~license
174+
~source
175+
=
176+
{ maintainers
177+
; authors
178+
; homepage
179+
; bug_reports
180+
; documentation
181+
; license
182+
; source
183+
; maintenance_intent
184+
}
134185
;;

src/dune_lang/package_info.mli

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ val homepage : t -> string option
77
val bug_reports : t -> string option
88
val documentation : t -> string option
99
val maintainers : t -> string list option
10+
val maintenance_intent : t -> string list option
1011

1112
(** example package info (used for project initialization ) *)
1213
val example
@@ -28,6 +29,7 @@ val superpose : t -> t -> t
2829

2930
val create
3031
: maintainers:string list option
32+
-> maintenance_intent:string list option
3133
-> authors:string list option
3234
-> homepage:string option
3335
-> bug_reports:string option

src/dune_pkg/opam_file.ml

+1
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ let load_opam_file_with_contents ~contents:opam_file_string file name =
260260
let info =
261261
Dune_lang.Package_info.create
262262
~maintainers:(get_many "maintainer")
263+
~maintenance_intent:(get_many "x-maintenance-intent")
263264
~authors:(get_many "authors")
264265
~homepage:(get_one "homepage")
265266
~bug_reports:(get_one "bug-reports")

src/dune_rules/opam_create.ml

+10
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,15 @@ let insert_odoc_dep depends =
196196
loop [] depends
197197
;;
198198

199+
let maintenance_intent dune_version info =
200+
if dune_version < (3, 18)
201+
then None
202+
else (
203+
match Package_info.maintenance_intent info with
204+
| None -> Some [ "(latest)" ]
205+
| x -> x)
206+
;;
207+
199208
let opam_fields project (package : Package.t) =
200209
let dune_version = Dune_project.dune_version project in
201210
let package_name = Package.name package in
@@ -228,6 +237,7 @@ let opam_fields project (package : Package.t) =
228237
in
229238
let list_fields =
230239
[ "maintainer", Package_info.maintainers info
240+
; "x-maintenance-intent", maintenance_intent dune_version info
231241
; "authors", Package_info.authors info
232242
; ( "license"
233243
, match Package_info.license info with

test/blackbox-tests/test-cases/config-project-defaults.t

+6-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ generated 'dune-project' file.
44

55
$ touch dune-config
66
$ cat >dune-config <<EOF
7-
> (lang dune 3.17)
7+
> (lang dune 3.18)
88
> (project_defaults
99
> (authors AuthorTest)
1010
> (maintainers MaintainerTest)
11+
> (maintenance_intent "(latest)")
1112
> (license MIT))
1213
> EOF
1314

@@ -33,11 +34,12 @@ Change the version of the config file to one which does not support the
3334

3435
$ sed -i -e '1s|.*|(lang dune 3.16)|' dune-config
3536
$ dune init proj test_proj1 --config-file=dune-config
36-
File "$TESTCASE_ROOT/dune-config", lines 2-5, characters 0-85:
37+
File "$TESTCASE_ROOT/dune-config", lines 2-6, characters 0-118:
3738
2 | (project_defaults
3839
3 | (authors AuthorTest)
3940
4 | (maintainers MaintainerTest)
40-
5 | (license MIT))
41+
5 | (maintenance_intent "(latest)")
42+
6 | (license MIT))
4143
Error: 'project_defaults' is only available since version 3.17 of the dune
4244
language. Please update your dune config file to have (lang dune 3.17).
4345
[1]
@@ -47,7 +49,7 @@ Change the version of the config file to one which does not support the
4749
Check to ensure that the default values are used when optional stanzas are
4850
removed/not used.
4951

50-
$ sed -i -e '3,5c\
52+
$ sed -i -e '3,6c\
5153
> )' dune-config
5254
$ dune init proj test_proj1 --config-file=dune-config
5355
Entering directory 'test_proj1'

test/blackbox-tests/test-cases/dune-init.t/run.t

+2
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ And the opam file will be generated as expected
403403
]
404404
]
405405
dev-repo: "git+https://github.com/username/reponame.git"
406+
x-maintenance-intent: ["(latest)"]
406407

407408
We can build and run the resulting executable:
408409

@@ -513,6 +514,7 @@ And the opam file will be generated as expected
513514
]
514515
]
515516
dev-repo: "git+https://github.com/username/reponame.git"
517+
x-maintenance-intent: ["(latest)"]
516518

517519
And we we can run the tests:
518520

test/blackbox-tests/test-cases/dune-project-meta/override.t

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
Package information fields can be overridden per-package:
22

33
$ cat >dune-project <<EOF
4-
> (lang dune 2.5)
4+
> (lang dune 3.18)
55
> (name foo)
66
> (version 1.0.0)
77
> (source (github mirage/ocaml-cohttp))
88
> (license ISC)
99
> (authors "Anil Madhavapeddy" "Rudi Grinberg")
1010
> (homepage https://my.home.page)
11+
> (maintenance_intent "(none)")
1112
> ;
1213
> (generate_opam_files true)
1314
> ;
@@ -16,7 +17,9 @@ Package information fields can be overridden per-package:
1617
> (version 1.0.1)
1718
> (source (github mirage/foo))
1819
> (license MIT)
19-
> (authors "Foo" "Bar"))
20+
> (authors "Foo" "Bar")
21+
> (maintenance_intent "0.9" "1.0.1")
22+
> (allow_empty))
2023
> EOF
2124

2225
$ dune build @install
@@ -30,10 +33,11 @@ Package information fields can be overridden per-package:
3033
homepage: "https://my.home.page"
3134
bug-reports: "https://github.com/mirage/foo/issues"
3235
depends: [
33-
"dune" {>= "2.5"}
36+
"dune" {>= "3.18"}
37+
"odoc" {with-doc}
3438
]
3539
build: [
36-
["dune" "subst"] {pinned}
40+
["dune" "subst"] {dev}
3741
[
3842
"dune"
3943
"build"
@@ -47,3 +51,4 @@ Package information fields can be overridden per-package:
4751
]
4852
]
4953
dev-repo: "git+https://github.com/mirage/foo.git"
54+
x-maintenance-intent: ["0.9" "1.0.1"]

0 commit comments

Comments
 (0)