Skip to content

Commit

Permalink
Some more version logic
Browse files Browse the repository at this point in the history
Add an --exact-version command that checks a specific version exactly

Use this in the CI check, rather than try to parse `sail -v`
  • Loading branch information
Alasdair committed May 15, 2024
1 parent cc5122f commit 1a6e3ed
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 24 deletions.
11 changes: 1 addition & 10 deletions etc/ci_core_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,7 @@

set -eu

# Verify `sail --version` matches `git describe`.
SAIL_VERSION="$(sail --version)"
GIT_DESCRIBE="Sail $(git describe --abbrev=0) ($(git rev-parse --abbrev-ref HEAD) @ $(git rev-parse HEAD))"

if [[ "$SAIL_VERSION" != "$GIT_DESCRIBE" ]]; then
echo "Sail version not set correctly:"
echo "sail --version: $SAIL_VERSION"
echo "git describe: $GIT_DESCRIBE"
exit 1
fi
echo "sail --version: $(sail --version)"

export TEST_PAR=4

Expand Down
4 changes: 1 addition & 3 deletions src/bin/manifest.ml.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
let dir = "%{sail:share}%"

let commit = "opam-v%{opam-version}%"
let commit = "opam-v%{opam-version}% %{sail:version}%"

let branch = "%{sail:name}%"

let version = "%{sail:version}%"
32 changes: 22 additions & 10 deletions src/bin/sail.ml
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@

open Libsail

type version = { major : int; minor : int; patch : int }

(* Current version of Sail. Must be updated manually. CI checks this matches
`git describe`. *)
let version = [0; 15]
the tag given by `git describe`. *)
let version = { major = 0; minor = 17; patch = 1 }

let opt_new_cli = ref false
let opt_free_arguments : string list ref = ref []
Expand Down Expand Up @@ -169,13 +171,28 @@ let load_plugin opts plugin =
with Dynlink.Error msg -> prerr_endline ("Failed to load plugin " ^ plugin ^ ": " ^ Dynlink.error_message msg)

(* Version as a string, e.g. "1.2.3". *)
let version_string = String.concat "." (List.map string_of_int version)
let version_string = Printf.sprintf "%d.%d.%d" version.major version.minor version.patch

(* Full version string including Git branch & commit. *)
let version_full =
let open Manifest in
Printf.sprintf "Sail %s (%s @ %s)" version_string branch commit

(* Convert a string like "1.2.3" to a list [1; 2; 3] *)
let parse_version dotted_version =
let open Util.Option_monad in
let* version = String.split_on_char '.' dotted_version |> List.map int_of_string_opt |> Util.option_all in
match version with
| [major; minor; patch] -> Some { major; minor; patch }
| [major; minor] -> Some { major; minor; patch = 0 }
| [major] -> Some { major; minor = 0; patch = 0 }
| _ -> None

let version_check ~required =
required.major < version.major
|| (required.major = version.major && required.minor < version.minor)
|| (required.major = version.major && required.minor = version.minor && required.patch <= version.patch)

let usage_msg = version_string ^ "\nusage: sail <options> <file1.sail> ... <fileN.sail>\n"

let help options = raise (Arg.Help (Arg.usage_string options usage_msg))
Expand Down Expand Up @@ -539,10 +556,6 @@ let parse_config_file file =
Reporting.warn "" Parse_ast.Unknown (Printf.sprintf "Failed to parse configuration file: %s" message);
None

(* Convert a string like "1.2.3" to a list [1; 2; 3] *)
let parse_version dotted_version =
String.split_on_char '.' dotted_version |> List.map int_of_string_opt |> Util.option_all

let main () =
if Option.is_some (Sys.getenv_opt "SAIL_NEW_CLI") then opt_new_cli := true;

Expand Down Expand Up @@ -578,9 +591,8 @@ let main () =
| Some v -> v
| None -> raise (Reporting.err_general Unknown ("Couldn't parse required version '" ^ required_version ^ "'"))
in
if version < required_version_parsed then (
print_endline
("Sail compiler version " ^ version_string ^ " is older than requested version " ^ required_version);
if not (version_check ~required:required_version_parsed) then (
Printf.eprintf "Sail version %s is older than requested version %s" version_string required_version;
exit 1
)
| None -> ()
Expand Down
2 changes: 1 addition & 1 deletion src/sail_manifest/sail_manifest.ml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ let gen_manifest () =
ksprintf print_endline "let branch = \"%s\""
(Option.value (git_command "rev-parse --abbrev-ref HEAD") ~default:"unknown branch")

let usage = "sail_install_tool <options>"
let usage = "sail_manifest <options>"

let main () =
Arg.parse options (fun _ -> ()) usage;
Expand Down

0 comments on commit 1a6e3ed

Please sign in to comment.