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
|
and dune_version = Syntax.get_exn Stanza.syntax
|
||||||
in
|
in
|
||||||
let name =
|
let name =
|
||||||
|
let open Syntax.Version.Infix in
|
||||||
match name, public with
|
match name, public with
|
||||||
| Some n, _ ->
|
| Some n, _ ->
|
||||||
Lib_name.validate n ~wrapped
|
Lib_name.validate n ~wrapped
|
||||||
|
@ -1202,6 +1203,7 @@ module Executables = struct
|
||||||
in
|
in
|
||||||
fun names public_names ~multi ->
|
fun names public_names ~multi ->
|
||||||
let names =
|
let names =
|
||||||
|
let open Syntax.Version.Infix in
|
||||||
match names, public_names with
|
match names, public_names with
|
||||||
| Some names, _ -> names
|
| Some names, _ -> names
|
||||||
| None, Some public_names ->
|
| None, Some public_names ->
|
||||||
|
|
|
@ -157,6 +157,7 @@ module Map = struct
|
||||||
|
|
||||||
let rec expand map ~syntax_version ~pform =
|
let rec expand map ~syntax_version ~pform =
|
||||||
let open Option.O in
|
let open Option.O in
|
||||||
|
let open Syntax.Version.Infix in
|
||||||
let name = String_with_vars.Var.name pform in
|
let name = String_with_vars.Var.name pform in
|
||||||
String.Map.find map name >>= fun v ->
|
String.Map.find map name >>= fun v ->
|
||||||
let describe = String_with_vars.Var.describe in
|
let describe = String_with_vars.Var.describe in
|
||||||
|
|
|
@ -19,3 +19,5 @@ let of_string_exn s =
|
||||||
| exception Failure _ ->
|
| exception Failure _ ->
|
||||||
failwith (Printf.sprintf "of_string_exn: invalid int %S" s)
|
failwith (Printf.sprintf "of_string_exn: invalid int %S" s)
|
||||||
| 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
|
module Map : Map.S with type key = t
|
||||||
|
|
||||||
val of_string_exn : string -> t
|
val of_string_exn : string -> t
|
||||||
|
|
||||||
|
module Infix : Comparable.OPS with type t = t
|
||||||
|
|
|
@ -1,8 +1,19 @@
|
||||||
open Import
|
open Import
|
||||||
|
|
||||||
module Version = struct
|
module Version = struct
|
||||||
|
module T = struct
|
||||||
type t = int * int
|
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
|
let to_string (a, b) = sprintf "%u.%u" a b
|
||||||
|
|
||||||
let sexp_of_t t = Sexp.unsafe_atom_of_string (to_string t)
|
let sexp_of_t t = Sexp.unsafe_atom_of_string (to_string t)
|
||||||
|
@ -19,8 +30,11 @@ module Version = struct
|
||||||
| sexp ->
|
| sexp ->
|
||||||
of_sexp_error (Sexp.Ast.loc sexp) "Atom expected"
|
of_sexp_error (Sexp.Ast.loc sexp) "Atom expected"
|
||||||
|
|
||||||
let can_read ~parser_version:(pa, pb) ~data_version:(da, db) =
|
let can_read
|
||||||
pa = da && db <= pb
|
~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
|
end
|
||||||
|
|
||||||
module Supported_versions = struct
|
module Supported_versions = struct
|
||||||
|
@ -92,6 +106,7 @@ let check_supported t (loc, ver) =
|
||||||
(String.concat ~sep:"\n"
|
(String.concat ~sep:"\n"
|
||||||
(List.map (Supported_versions.supported_ranges t.supported_versions)
|
(List.map (Supported_versions.supported_ranges t.supported_versions)
|
||||||
~f:(fun (a, b) ->
|
~f:(fun (a, b) ->
|
||||||
|
let open Version.Infix in
|
||||||
if a = b then
|
if a = b then
|
||||||
sprintf "- %s" (Version.to_string a)
|
sprintf "- %s" (Version.to_string a)
|
||||||
else
|
else
|
||||||
|
@ -125,6 +140,7 @@ let desc () =
|
||||||
| Fields (loc, Some s) -> (loc, sprintf "Field '%s'" s)
|
| Fields (loc, Some s) -> (loc, sprintf "Field '%s'" s)
|
||||||
|
|
||||||
let deleted_in t ver =
|
let deleted_in t ver =
|
||||||
|
let open Version.Infix in
|
||||||
get_exn t >>= fun current_ver ->
|
get_exn t >>= fun current_ver ->
|
||||||
if current_ver < ver then
|
if current_ver < ver then
|
||||||
return ()
|
return ()
|
||||||
|
@ -134,6 +150,7 @@ let deleted_in t ver =
|
||||||
end
|
end
|
||||||
|
|
||||||
let renamed_in t ver ~to_ =
|
let renamed_in t ver ~to_ =
|
||||||
|
let open Version.Infix in
|
||||||
get_exn t >>= fun current_ver ->
|
get_exn t >>= fun current_ver ->
|
||||||
if current_ver < ver then
|
if current_ver < ver then
|
||||||
return ()
|
return ()
|
||||||
|
@ -143,6 +160,7 @@ let renamed_in t ver ~to_ =
|
||||||
end
|
end
|
||||||
|
|
||||||
let since t ver =
|
let since t ver =
|
||||||
|
let open Version.Infix in
|
||||||
get_exn t >>= fun current_ver ->
|
get_exn t >>= fun current_ver ->
|
||||||
if current_ver >= ver then
|
if current_ver >= ver then
|
||||||
return ()
|
return ()
|
||||||
|
|
|
@ -16,6 +16,9 @@ module Version : sig
|
||||||
|
|
||||||
(** Whether the parser can read the data or not *)
|
(** Whether the parser can read the data or not *)
|
||||||
val can_read : parser_version:t -> data_version:t -> bool
|
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
|
end
|
||||||
|
|
||||||
type t
|
type t
|
||||||
|
|
Loading…
Reference in New Issue