Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to opam 2.1 #343

Merged
merged 7 commits into from
Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
- Make git-related mdx tests more robust in unusual environments (#334, @sternenseemann)
- Set the default tag message to "Release <tag>" instead of "Distribution <tag>"
- Opam file linter: check for `synopsis` instead of `description` (#291, @kit-ty-kate)
- Upgrade the use of the opam libraries to opam 2.1 (#343, @kit-ty-kate)

### Deprecated

Expand Down
16 changes: 11 additions & 5 deletions bin/opam.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,24 @@ module D = struct
let distrib_uri = "${distrib_uri}"
end

let remove_generated_dune_comment opam =
let sep = "# This file is generated by dune, edit dune-project instead\n" in
match Astring.String.cut ~sep opam with Some ("", opam) -> opam | _ -> opam

let write_opam_file ~dry_run ~id ~url ~opam_f pkg dest_opam_file =
OS.File.read opam_f >>= fun opam ->
let filename = Fpath.filename dest_opam_file in
let filename = OpamFilename.of_string (Fpath.filename dest_opam_file) in
let opam_t = OpamFile.OPAM.read_from_string opam in
match OpamVersion.to_string (OpamFile.OPAM.opam_version opam_t) with
| "2.0" ->
let file x = OpamFile.make (OpamFilename.of_string (Fpath.to_string x)) in
let opam_t = Opam_file.upgrade ~filename ~url ~id opam_t ~version:`V2 in
if not dry_run then
OpamFile.OPAM.write_with_preserved_format ~format_from:(file opam_f)
(file dest_opam_file) opam_t;
Ok ()
let opam =
OpamFile.OPAM.to_string_with_preserved_format ~format_from:(file opam_f)
(file dest_opam_file) opam_t
|> remove_generated_dune_comment
in
Sos.write_file ~dry_run dest_opam_file opam
| ("1.0" | "1.1" | "1.2") as v ->
App_log.unhappy (fun l -> l "%s" Deprecate.Opam_1_x.file_format_warning);
App_log.status (fun l ->
Expand Down
9 changes: 5 additions & 4 deletions dune-release.opam
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ bug-reports: "https://github.com/ocamllabs/dune-release/issues"
doc: "https://ocamllabs.github.io/dune-release/"

build: [
["dune" "subst"] {pinned}
["dune" "subst"] {dev}
["dune" "build" "-p" name "-j" jobs]
["dune" "runtest" "-p" name "-j" jobs] {with-test}
]
Expand All @@ -21,9 +21,10 @@ depends: [
"bos"
"cmdliner"
"re"
"opam-format" {< "2.1.0~beta"}
"opam-state" {< "2.1.0~beta"}
"opam-core" {< "2.1.0~beta"}
"astring"
"opam-format" {>= "2.1.0~beta"}
"opam-state" {>= "2.1.0~beta"}
"opam-core" {>= "2.1.0~beta"}
"rresult"
"logs"
"odoc"
Expand Down
7 changes: 6 additions & 1 deletion lib/opam_file.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
let upgrade ~filename ~url ~id ~version opam_t =
let commit_hash = OpamTypes.String ((filename, 0, 0), id) in
let commit_hash =
{
OpamParserTypes.FullPos.pelem = OpamParserTypes.FullPos.String id;
pos = OpamTypesBase.pos_file filename;
}
in
match version with
| `V1 descr ->
opam_t |> OpamFormatUpgrade.opam_file_from_1_2_to_2_0
Expand Down
2 changes: 1 addition & 1 deletion lib/opam_file.mli
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
val upgrade :
filename:string ->
filename:OpamTypes.filename ->
url:OpamFile.URL.t ->
id:string ->
version:[ `V1 of OpamFile.Descr.t | `V2 ] ->
Expand Down
4 changes: 2 additions & 2 deletions tests/bin/url-file/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,15 @@ We make a dry-run release:
[-] Creating opam package description for whatever
[+] Wrote opam package description _build/whatever.0.1.0/opam

$ cat _build/whatever.0.1.0/opam
$ cat _build/whatever.0.1.0/opam | sed -e 's/\(x-commit-hash:\) "[0-9a-f]*"/\1/'
opam-version: "2.0"
homepage: "https://github.com/foo/whatever"
dev-repo: "git+https://github.com/foo/whatever.git"
synopsis: "whatever"
x-commit-hash: ...
url {
src: "https://foo.fr/archive/foo/foo.tbz"
checksum: [
...
]
}
x-commit-hash:
16 changes: 8 additions & 8 deletions tests/lib/test_opam_file.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ let test_upgrade =
let url = OpamFile.URL.create (OpamUrl.of_string url) in
let test_fun () =
let opam_t = OpamFile.OPAM.read_from_string opam in
let filename = "opam" in
let filename = OpamFilename.of_string "opam" in
let id = "6814f8b26946358c72b926706f210025f36619b0" in
let actual =
Dune_release.Opam_file.upgrade ~filename ~url ~id opam_t ~version:v
Expand All @@ -31,22 +31,21 @@ description: "This package is nice"
|}
in
let expected_v1 =
{|x-commit-hash: "6814f8b26946358c72b926706f210025f36619b0"
opam-version: "2.0"
{|opam-version: "2.0"
synopsis: "This package is great"
maintainer: "Foo"
authors: ["Foo" "Bar"]
license: "ISC"
homepage: "https://github.com/foo/bar"
depends: ["ocaml" "foo" "bar"]
depends: ["foo" "bar"]
dev-repo: "git+https://github.com/foo/bar.git"
url {
src: "https://github.com/foo/foo/foo/foo/bar"
}|}
}
x-commit-hash: "6814f8b26946358c72b926706f210025f36619b0"|}
in
let expected_v2 =
{|x-commit-hash: "6814f8b26946358c72b926706f210025f36619b0"
opam-version: "2.0"
{|opam-version: "2.0"
synopsis: ""
description: "This package is nice"
maintainer: "Foo"
Expand All @@ -57,7 +56,8 @@ depends: ["foo" "bar"]
dev-repo: "git+https://github.com/foo/bar.git"
url {
src: "https://github.com/foo/foo/foo/foo/bar"
}|}
}
x-commit-hash: "6814f8b26946358c72b926706f210025f36619b0"|}
in
let descr = OpamFile.Descr.create "This package is great" in
[
Expand Down