Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce usage of Sementic_Versioning when printing Alire/Alr version #1643

Merged
merged 2 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/alire/alire-github.adb
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ package body Alire.GitHub is
Args => "state" = "closed");
begin
Comment (Number,
"Closed using `alr " & Version.Current & "` with reason: "
"Closed using `alr " & Version.Current.Image & "` with reason: "
& Reason);
end Close;

Expand Down Expand Up @@ -423,7 +423,7 @@ package body Alire.GitHub is

Mutation : constant String
:= "mutation { markPullRequestReadyForReview (input: { "
& "clientMutationId: ""alr-" & Version.Current & """, "
& "clientMutationId: ""alr-" & Version.Current.Image & """, "
& "pullRequestId: ""PRID"" }) {clientMutationId}}";

Response : constant Minirest.Response
Expand Down
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;
2 changes: 1 addition & 1 deletion src/alire/alire-publish-submit.adb
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ package body Alire.Publish.Submit is
Title => Context.PR_Name,
Message =>
"Created via `alr publish` with `alr "
& Version.Current & "`");
& Version.Current.Image & "`");
begin
Put_Success ("Pull request created successfully");
Put_Info ("Visit " & TTY.URL (States.Webpage (Number))
Expand Down
4 changes: 2 additions & 2 deletions src/alire/alire-settings-edit.adb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ with Alire.Platforms.Folders;
with Alire.Platforms.Current;
with Alire.Settings.Builtins;
with Alire.Utils.Text_Files;
with Alire.Version.Semver;
with Alire.Version;
with Alire.Warnings;

with CLIC.Config.Edit;
Expand Down Expand Up @@ -224,7 +224,7 @@ package body Alire.Settings.Edit is
begin
-- Warn or fail depending on version
if OS_Lib.Getenv (Environment.Config, Unset) /= Unset then
if Version.Semver.Current < Features.Config_Deprecated then
if Version.Current < Features.Config_Deprecated then
Warnings.Warn_Once (Msg, Level => Warning);
else
Raise_Checked_Error (Msg);
Expand Down
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
14 changes: 0 additions & 14 deletions src/alire/alire-version-semver.ads

This file was deleted.

16 changes: 14 additions & 2 deletions src/alire/alire-version.ads
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
package Alire.Version with Preelaborate is
with Semantic_Versioning;

package Alire.Version is

package Semver renames Semantic_Versioning;

subtype Version is Semver.Version;

Current : constant Version;

private

-- Remember to update Alire.Index branch if needed too

Current : constant String := "2.1-dev";
Current_Str : constant String := "2.1-dev";
-- 2.0.0: alr settings refactor and minor fixes
-- 2.0.0-rc1: release candidate for 2.0
-- 2.0.0-b1: first public release on the 2.0 branch
Expand All @@ -23,4 +33,6 @@ package Alire.Version with Preelaborate is
-- 0.8.1-dev: update to devel-0.5 index branch
-- 0.8.0-dev: post-0.7-beta changes

Current : constant Version := Semver.New_Version (Current_Str);

end Alire.Version;
4 changes: 2 additions & 2 deletions src/alire/alire_early_elaboration.adb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ with Ada.Directories;

with Alire.Features;
with Alire.Settings.Edit.Early_Load;
with Alire.Version.Semver;
with Alire.Version;

with GNAT.Command_Line;
with GNAT.OS_Lib;
Expand Down Expand Up @@ -110,7 +110,7 @@ package body Alire_Early_Elaboration is

use type Alire.Version.Semver.Version;
Config_Deprecated : constant Boolean
:= Alire.Version.Semver.Current >= Alire.Features.Config_Deprecated;
:= Alire.Version.Current >= Alire.Features.Config_Deprecated;

procedure Check_Config_Deprecated is
begin
Expand Down
8 changes: 5 additions & 3 deletions src/alr/alr-commands-version.adb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ with Alire.Properties;
with Alire.Roots.Optional;
with Alire.Toolchains;
with Alire.Utils.Tables;
with Alire.Version;

with Alr.Bootstrap;

Expand Down Expand Up @@ -61,9 +62,10 @@ package body Alr.Commands.Version is
end if;

Table.Append ("APPLICATION").Append ("").New_Row;
Table.Append ("alr version:").Append (Alire.Version.Current).New_Row;
Table.Append ("alr version:")
.Append (Alire.Version.Current.Image).New_Row;
Table.Append ("libalire version:")
.Append (Alire.Version.Current).New_Row;
.Append (Alire.Version.Current.Image).New_Row;
Table.Append ("compilation date:")
.Append (GNAT.Source_Info.Compilation_ISO_Date & " "
& GNAT.Source_Info.Compilation_Time).New_Row;
Expand Down Expand Up @@ -193,7 +195,7 @@ package body Alr.Commands.Version is

procedure Print_Version is
begin
Trace.Always ("alr " & Alire.Version.Current);
Trace.Always ("alr " & Alire.Version.Current.Image);
end Print_Version;

end Alr.Commands.Version;
3 changes: 1 addition & 2 deletions src/alr/alr-commands.adb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ with Alire.Platforms.Current;
with Alire.Root;
with Alire.Solutions;
with Alire.Toolchains;
with Alire.Version.Semver;

with Alr.Commands.Action;
with Alr.Commands.Build;
Expand Down Expand Up @@ -143,7 +142,7 @@ package body Alr.Commands is
use CLIC.Subcommand;
use type Alire.Version.Semver.Version;
begin
if Alire.Version.Semver.Current < Features.Config_Deprecated then
if Alire.Version.Current < Features.Config_Deprecated then
Define_Switch (Config,
Command_Line_Config_Path'Access,
"-c=", "--config=",
Expand Down
2 changes: 1 addition & 1 deletion src/alr/alr-commands.ads
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private

package Sub_Cmd is new CLIC.Subcommand.Instance
(Main_Command_Name => "alr",
Version => Alire.Version.Current,
Version => Alire.Version.Current.Image,
Put => GNAT.IO.Put,
Put_Line => GNAT.IO.Put_Line,
Put_Error => Put_Error,
Expand Down
Loading