Skip to content

Commit

Permalink
Enforce usage of Sementic_Versioning for index versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabien-Chouteau committed Mar 14, 2024
1 parent 9519d65 commit 1f21405
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
39 changes: 28 additions & 11 deletions src/alire/alire-index.ads
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,14 @@ package Alire.Index is
-- The branch used for the community index. Must be updated when new index
-- features are introduced.

Min_Compatible_Version : constant String := "1.1";
-- Update as needed in case of backward-incompatible changes

Max_Compatible_Version : constant String :=
AAA.Strings.Tail (Community_Branch, '-');
Min_Compatible_Version : constant Semantic_Versioning.Version;
-- Based on the constant defined in private section

-- We store here the indexes we are able to load. As long as we do not
-- break back compatibility, we can keep on simply updating the minor value
Valid_Versions : constant Semantic_Versioning.Extended.Version_Set :=
Semantic_Versioning.Extended.Value
("^" & Min_Compatible_Version
& " & <=" & Max_Compatible_Version);
Valid_Versions : constant Semantic_Versioning.Extended.Version_Set;

Version : constant Semantic_Versioning.Version :=
Semantic_Versioning.New_Version (Max_Compatible_Version);
Version : constant Semantic_Versioning.Version;
-- The index version understood by alire must match the one in the indexes
-- being loaded.

Expand Down Expand Up @@ -173,4 +166,28 @@ package Alire.Index is
-- applied during load:
-- * Whether some origin is not in our allowed hosting sites.

private

-- The string constants for versions are kept in the private section to
-- avoid using them in command output or other message. The only option
-- is to use the Sementic_Versioning.Image function which will provide a
-- consistant output.

Min_Compatible_Version_Str : constant String := "1.1";
-- Update as needed in case of backward-incompatible changes

Max_Compatible_Version_Str : constant String :=
AAA.Strings.Tail (Community_Branch, '-');

Min_Compatible_Version : constant Semantic_Versioning.Version :=
Semantic_Versioning.New_Version (Min_Compatible_Version_Str);

Valid_Versions : constant Semantic_Versioning.Extended.Version_Set :=
Semantic_Versioning.Extended.Value
("^" & Min_Compatible_Version_Str
& " & <=" & Max_Compatible_Version_Str);

Version : constant Semantic_Versioning.Version :=
Semantic_Versioning.New_Version (Max_Compatible_Version_Str);

end Alire.Index;
5 changes: 2 additions & 3 deletions src/alire/alire-toml_index.adb
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,13 @@ package body Alire.TOML_Index is
& ") is newer than that expected by alr ("
& Alire.Index.Version.Image & ")."
& " You may have to update alr");
elsif Loading_Index_Version < Semver.Parse
(Alire.Index.Min_Compatible_Version)
elsif Loading_Index_Version < Alire.Index.Min_Compatible_Version
then
Set_Error
(Result, Filename,
"index version (" & Loading_Index_Version.Image
& ") is too old. The minimum compatible version is "
& Alire.Index.Min_Compatible_Version & ASCII.LF
& Alire.Index.Min_Compatible_Version.Image & ASCII.LF
& (if Index.Name = Alire.Index.Community_Name then
" Resetting the community index ("
& TTY.Terminal ("alr index --reset-community")
Expand Down

0 comments on commit 1f21405

Please sign in to comment.