From 28b74e622f0f395a174bbb646996caed8638391d Mon Sep 17 00:00:00 2001 From: Nathan Rebours Date: Fri, 15 Apr 2022 11:11:52 +0200 Subject: [PATCH 1/3] Bump lockfile version and drop support for older lockfiles Signed-off-by: Nathan Rebours --- CHANGES.md | 3 ++ lib/lockfile.ml | 32 +++++++++++-------- .../lockfile-version.t/lockfile-version.opam | 8 +++++ test/bin/lockfile-version.t/run.t | 24 ++++++++++++++ test/bin/simple-lock.t/run.t | 2 +- 5 files changed, 55 insertions(+), 14 deletions(-) create mode 100644 test/bin/lockfile-version.t/lockfile-version.opam create mode 100644 test/bin/lockfile-version.t/run.t diff --git a/CHANGES.md b/CHANGES.md index 598437208..063341b09 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -22,6 +22,7 @@ ### Changed +- Bump lockfile version to 0.3 (#, @NathanReb) - Mark packages to be pulled by opam-monorepo with the `vendor` variable so using OPAM with `opam install --deps-only --locked .` will not install packages that will be installed with `opam-monorepo pull` (#237, @@ -38,6 +39,8 @@ ### Removed +- Drop support for lockfile versions 0.2 and lower (#, @NathanReb) + ### Security ## 0.2.7 diff --git a/lib/lockfile.ml b/lib/lockfile.ml index 7f067f4cf..0eafd3b36 100644 --- a/lib/lockfile.ml +++ b/lib/lockfile.ml @@ -20,7 +20,12 @@ end module Version = struct type t = int * int - let current = (0, 2) + let compare (major, minor) (major', minor') = + match Ordering.of_int (Int.compare major major') with + | Eq -> Ordering.of_int (Int.compare minor minor') + | ordering -> ordering + + let current = (0, 3) let pp fmt (major, minor) = Format.fprintf fmt "%d.%d" major minor let to_string (major, minor) = Printf.sprintf "%d.%d" major minor @@ -35,19 +40,20 @@ module Version = struct | Some major, Some minor -> Ok (major, minor) | _ -> err ()) - let backward_compatible (major, minor) (major', minor') = - major = major' && minor >= minor' - let compatible t = - (* We still support 0.1 lockfiles but we'll need to update that if we stop doing so *) - if backward_compatible current t then Ok () - else - Error - (`Msg - (Format.asprintf - "Incompatible opam-monorepo lockfile version %a. Please upgrade \ - your opam-monorepo plugin." - pp t)) + match compare current t with + | Eq -> Ok () + | Lt -> + Rresult.R.error_msgf + "Incompatible opam-monorepo lockfile version %a. Please upgrade your \ + opam-monorepo plugin." + pp t + | Gt -> + Rresult.R.error_msgf + "opam-monorepo lockfile version %a is too old. Please regenerate the \ + lockfile using your current opam-monorepo plugin or install an \ + older version of the plugin." + pp t let to_opam_value t = Opam.Value.String.to_value (to_string t) diff --git a/test/bin/lockfile-version.t/lockfile-version.opam b/test/bin/lockfile-version.t/lockfile-version.opam new file mode 100644 index 000000000..8272969cf --- /dev/null +++ b/test/bin/lockfile-version.t/lockfile-version.opam @@ -0,0 +1,8 @@ +opam-version: "2.0" +depends: [ + "ocaml" + "dune" +] +x-opam-monorepo-opam-repositories: [ + "file://$OPAM_MONOREPO_CWD/minimal-repo" +] diff --git a/test/bin/lockfile-version.t/run.t b/test/bin/lockfile-version.t/run.t new file mode 100644 index 000000000..84c6337b1 --- /dev/null +++ b/test/bin/lockfile-version.t/run.t @@ -0,0 +1,24 @@ +We have a simple project with a single package that we will use to generate +a lockfile for our current version. + + $ gen-minimal-repo + $ opam-monorepo lock > /dev/null + $ opam show --no-lint --raw -fx-opam-monorepo-version ./lockfile-version.opam.locked + "0.3" + +This is our current version. +At the moment we are not backward compatible so if we downgrade this version number, +pull will refuse the lockfile and suggest it is regenerated with the current plugin: + + $ sed -i "s/x-opam-monorepo-version: \"0.3\"/x-opam-monorepo-version: \"0.2\"/" lockfile-version.opam.locked + $ opam-monorepo pull > /dev/null + opam-monorepo: [ERROR] opam-monorepo lockfile version 0.2 is too old. Please regenerate the lockfile using your current opam-monorepo plugin or install an older version of the plugin. + [1] + +We also obviously do not support future versions and they should be rejected as well, +suggesting that the user upgrade their plugin to be able to interpret that lockfile: + + $ sed -i "s/x-opam-monorepo-version: \"0.2\"/x-opam-monorepo-version: \"0.999\"/" lockfile-version.opam.locked + $ opam-monorepo pull > /dev/null + opam-monorepo: [ERROR] Incompatible opam-monorepo lockfile version 0.999. Please upgrade your opam-monorepo plugin. + [1] diff --git a/test/bin/simple-lock.t/run.t b/test/bin/simple-lock.t/run.t index 978700f18..fc401da24 100644 --- a/test/bin/simple-lock.t/run.t +++ b/test/bin/simple-lock.t/run.t @@ -67,4 +67,4 @@ The lockfile should contain the base packages, dune and our 2 dependencies "file://$OPAM_MONOREPO_CWD/minimal-repo" "file://$OPAM_MONOREPO_CWD/repo" ] x-opam-monorepo-root-packages: ["a"] - x-opam-monorepo-version: "0.2" + x-opam-monorepo-version: "0.3" From 4319ad37afa861f48bc08f704cbf3aa10a92132c Mon Sep 17 00:00:00 2001 From: Nathan Rebours Date: Fri, 15 Apr 2022 11:14:44 +0200 Subject: [PATCH 2/3] Update CHANGES.md Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 063341b09..fbc92412c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -22,7 +22,7 @@ ### Changed -- Bump lockfile version to 0.3 (#, @NathanReb) +- Bump lockfile version to 0.3 (#285, @NathanReb) - Mark packages to be pulled by opam-monorepo with the `vendor` variable so using OPAM with `opam install --deps-only --locked .` will not install packages that will be installed with `opam-monorepo pull` (#237, From 57f7f3533e27ef66ea74e329802ad2b4202979e9 Mon Sep 17 00:00:00 2001 From: Nathan Rebours Date: Fri, 15 Apr 2022 11:14:53 +0200 Subject: [PATCH 3/3] Update CHANGES.md Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index fbc92412c..51c0e71a9 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -39,7 +39,7 @@ ### Removed -- Drop support for lockfile versions 0.2 and lower (#, @NathanReb) +- Drop support for lockfile versions 0.2 and lower (#285, @NathanReb) ### Security