Use explicit comparison for Syntax.Version.t
Signed-off-by: Etienne Millon <me@emillon.org>
This commit is contained in:
parent
4f1d1a0ea5
commit
da1f65bc56
|
@ -958,6 +958,7 @@ module Library = struct
|
|||
and dune_version = Syntax.get_exn Stanza.syntax
|
||||
in
|
||||
let name =
|
||||
let open Syntax.Version.Infix in
|
||||
match name, public with
|
||||
| Some n, _ ->
|
||||
Lib_name.validate n ~wrapped
|
||||
|
@ -1202,6 +1203,7 @@ module Executables = struct
|
|||
in
|
||||
fun names public_names ~multi ->
|
||||
let names =
|
||||
let open Syntax.Version.Infix in
|
||||
match names, public_names with
|
||||
| Some names, _ -> names
|
||||
| None, Some public_names ->
|
||||
|
|
|
@ -157,6 +157,7 @@ module Map = struct
|
|||
|
||||
let rec expand map ~syntax_version ~pform =
|
||||
let open Option.O in
|
||||
let open Syntax.Version.Infix in
|
||||
let name = String_with_vars.Var.name pform in
|
||||
String.Map.find map name >>= fun v ->
|
||||
let describe = String_with_vars.Var.describe in
|
||||
|
|
|
@ -19,3 +19,5 @@ let of_string_exn s =
|
|||
| exception Failure _ ->
|
||||
failwith (Printf.sprintf "of_string_exn: invalid int %S" s)
|
||||
| s -> s
|
||||
|
||||
module Infix = Comparable.Operators(T)
|
||||
|
|
|
@ -5,3 +5,5 @@ module Set : Set.S with type elt = t
|
|||
module Map : Map.S with type key = t
|
||||
|
||||
val of_string_exn : string -> t
|
||||
|
||||
module Infix : Comparable.OPS with type t = t
|
||||
|
|
|
@ -1,7 +1,18 @@
|
|||
open Import
|
||||
|
||||
module Version = struct
|
||||
type t = int * int
|
||||
module T = struct
|
||||
type t = int * int
|
||||
|
||||
let compare (major_a, minor_a) (major_b, minor_b) =
|
||||
match Int.compare major_a major_b with
|
||||
| (Gt | Lt) as ne -> ne
|
||||
| Eq -> Int.compare minor_a minor_b
|
||||
end
|
||||
|
||||
include T
|
||||
|
||||
module Infix = Comparable.Operators(T)
|
||||
|
||||
let to_string (a, b) = sprintf "%u.%u" a b
|
||||
|
||||
|
@ -19,8 +30,11 @@ module Version = struct
|
|||
| sexp ->
|
||||
of_sexp_error (Sexp.Ast.loc sexp) "Atom expected"
|
||||
|
||||
let can_read ~parser_version:(pa, pb) ~data_version:(da, db) =
|
||||
pa = da && db <= pb
|
||||
let can_read
|
||||
~parser_version:(parser_major, parser_minor)
|
||||
~data_version:(data_major, data_minor) =
|
||||
let open Int.Infix in
|
||||
parser_major = data_major && parser_minor >= data_minor
|
||||
end
|
||||
|
||||
module Supported_versions = struct
|
||||
|
@ -92,6 +106,7 @@ let check_supported t (loc, ver) =
|
|||
(String.concat ~sep:"\n"
|
||||
(List.map (Supported_versions.supported_ranges t.supported_versions)
|
||||
~f:(fun (a, b) ->
|
||||
let open Version.Infix in
|
||||
if a = b then
|
||||
sprintf "- %s" (Version.to_string a)
|
||||
else
|
||||
|
@ -125,6 +140,7 @@ let desc () =
|
|||
| Fields (loc, Some s) -> (loc, sprintf "Field '%s'" s)
|
||||
|
||||
let deleted_in t ver =
|
||||
let open Version.Infix in
|
||||
get_exn t >>= fun current_ver ->
|
||||
if current_ver < ver then
|
||||
return ()
|
||||
|
@ -134,6 +150,7 @@ let deleted_in t ver =
|
|||
end
|
||||
|
||||
let renamed_in t ver ~to_ =
|
||||
let open Version.Infix in
|
||||
get_exn t >>= fun current_ver ->
|
||||
if current_ver < ver then
|
||||
return ()
|
||||
|
@ -143,6 +160,7 @@ let renamed_in t ver ~to_ =
|
|||
end
|
||||
|
||||
let since t ver =
|
||||
let open Version.Infix in
|
||||
get_exn t >>= fun current_ver ->
|
||||
if current_ver >= ver then
|
||||
return ()
|
||||
|
|
|
@ -16,6 +16,9 @@ module Version : sig
|
|||
|
||||
(** Whether the parser can read the data or not *)
|
||||
val can_read : parser_version:t -> data_version:t -> bool
|
||||
|
||||
val compare : t -> t -> Ordering.t
|
||||
module Infix : Comparable.OPS with type t = t
|
||||
end
|
||||
|
||||
type t
|
||||
|
|
Loading…
Reference in New Issue