diff --git a/CHANGES.md b/CHANGES.md index 598437208..51c0e71a9 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -22,6 +22,7 @@ ### Changed +- 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, @@ -38,6 +39,8 @@ ### Removed +- Drop support for lockfile versions 0.2 and lower (#285, @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"