Skip to content

Commit

Permalink
Revamped alr version output (#852)
Browse files Browse the repository at this point in the history
* Revamped `alr version` output

* New test to verify basic `alr version` operation

* Cosmetic tweaks

* Tweaks for old tests
  • Loading branch information
mosteo authored Sep 16, 2021
1 parent ff02df6 commit 40af47f
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 77 deletions.
15 changes: 14 additions & 1 deletion src/alire/alire-toolchains.ads
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ with AAA.Strings;

with Alire.Config;
with Alire.Dependencies;
private with Alire.Milestones;
with Alire.Milestones;
with Alire.Releases;
with Alire.Utils;
with Alire.Utils.TTY;
Expand Down Expand Up @@ -37,6 +37,8 @@ package Alire.Toolchains is
procedure Set_Automatic_Assistant (Enabled : Boolean; Level : Config.Level);
-- Enable/Disable the automatic assistant on next run

function Assistant_Enabled return Boolean;

procedure Set_As_Default (Release : Releases.Release; Level : Config.Level);
-- Mark the given release as the default to be used. Does not check that it
-- be already installed.
Expand All @@ -48,6 +50,10 @@ package Alire.Toolchains is
with Pre => Tool_Is_Configured (Crate);
-- Return the configured compiler as an exact compiler=version dependency

function Tool_Key (Crate : Crate_Name) return Config.Config_Key;

function Tool_Milestone (Crate : Crate_Name) return Milestones.Milestone;

function Tool_Release (Crate : Crate_Name) return Releases.Release;
-- Will raise Checked_Error for unconfigured, or configured but without the
-- release being deployed (e.g. the user messed with files and deleted it
Expand Down Expand Up @@ -82,6 +88,13 @@ package Alire.Toolchains is

private

-----------------------
-- Assistant_Enabled --
-----------------------

function Assistant_Enabled return Boolean
is (Config.Get (Config.Keys.Toolchain_Assistant, Default => True));

--------------
-- Tool_Key --
--------------
Expand Down
22 changes: 0 additions & 22 deletions src/alr/alr-bootstrap.adb
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
with Ada.Calendar;

with Alire.Directories;
with Alire_Early_Elaboration;
with Alire.Index;
with Alire.Root;

with Alr.OS_Lib;
with Alr.Utils;

with GNAT.Ctrl_C;

Expand All @@ -25,22 +19,6 @@ package body Alr.Bootstrap is
OS_Lib.Bailout (1);
end Interrupted;

-----------------
-- Status_Line --
-----------------

function Status_Line return String is
use Ada.Calendar;
type Milliseconds is delta 0.001 range 0.0 .. 24.0 * 60.0 * 60.0;
Elapsed : constant Duration :=
Ada.Calendar.Clock - Alire_Early_Elaboration.Start;
begin
return
"(" & Utils.To_Lower_Case (Alire.Root.Current.Status'Img) & ") (" &
Utils.Trim (Alire.Index.Release_Count'Img) & " releases indexed)" &
(" (loaded in" & Milliseconds'Image (Milliseconds (Elapsed)) & "s)");
end Status_Line;

begin
GNAT.Ctrl_C.Install_Handler (Interrupted'Access);
end Alr.Bootstrap;
3 changes: 1 addition & 2 deletions src/alr/alr-bootstrap.ads
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package Alr.Bootstrap with Elaborate_Body is

function Status_Line return String;
-- One-liner reporting most interesting information
-- Body contains the handler for Ctrl-C

end Alr.Bootstrap;
130 changes: 87 additions & 43 deletions src/alr/alr-commands-version.adb
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
with Alire.Config.Edit;
with Alire.Features.Index;
with Alire.Index;
with Alire.Milestones;
with Alire.Properties;
with Alire.Roots.Optional;
with Alire.Toolchains;
with Alire.Utils.Tables;

with Alr.Bootstrap;
with Alr.Files;
with Alr.OS_Lib;
with Alr.Paths;

with GNAT.Compiler_Version;
Expand All @@ -24,59 +27,100 @@ package body Alr.Commands.Version is
procedure Execute (Cmd : in out Command;
Args : AAA.Strings.Vector)
is
use Ada.Text_IO;
use all type Alire.Roots.Optional.States;
Table : Alire.Utils.Tables.Table;
Index_Outcome : Alire.Outcome;
Indexes : constant Alire.Features.Index.Index_On_Disk_Set :=
Alire.Features.Index.Find_All
(Alire.Config.Edit.Indexes_Directory, Index_Outcome);
Root : constant Alire.Roots.Optional.Root :=
Alire.Roots.Optional.Search_Root (Alire.Directories.Current);
begin
if Args.Count /= 0 then
Reportaise_Wrong_Arguments (Cmd.Name & " doesn't take arguments");
end if;

Trace.Always ("Alr version: " & Alire.Version.Current);
Trace.Always ("Alire Library version: " & Alire.Version.Current);
Trace.Always ("alr status is " & Bootstrap.Status_Line);
Trace.Always ("config folder is " & Paths.Alr_Config_Folder);
Trace.Always ("source folder is " & Paths.Alr_Source_Folder);

Trace.Always
("interaction flags are:"
& " force:" & Alire.Force'Img
& " not-interactive:" & CLIC.User_Input.Not_Interactive'Img);

case Cmd.Optional_Root.Status is
when Outside =>
Trace.Always ("alr root is empty");
when Broken =>
Trace.Always ("alr root has invalid metadata: "
& TTY.Error (Cmd.Optional_Root.Message));
when Valid =>
Trace.Always ("alr root is " & Cmd.Root.Release.Milestone.Image);
end case;

Table.Append ("APPLICATION").Append ("").New_Row;
Table.Append ("alr version:").Append (Alire.Version.Current).New_Row;
Table.Append ("libalire version:")
.Append (Alire.Version.Current).New_Row;
Table.Append ("compilation date:")
.Append (GNAT.Source_Info.Compilation_ISO_Date & " "
& GNAT.Source_Info.Compilation_Time).New_Row;
Table.Append ("compiler version:").Append (GNAT_Version.Version).New_Row;

Table.Append ("").New_Row;
Table.Append ("CONFIGURATION").New_Row;
Table.Append ("config folder:").Append (Paths.Alr_Config_Folder).New_Row;
Table.Append ("force flag:").Append (Alire.Force'Image).New_Row;
Table.Append ("non-interactive flag:")
.Append (CLIC.User_Input.Not_Interactive'Image).New_Row;
Table.Append ("community index branch:")
.Append (Alire.Index.Community_Branch).New_Row;
Table.Append ("indexes folder:")
.Append (Alire.Config.Edit.Indexes_Directory).New_Row;
Table.Append ("indexes metadata:")
.Append (if Index_Outcome.Success
then "OK"
else "ERROR: " & Index_Outcome.Message).New_Row;
for Index of Indexes loop
Table.Append ("index #" & Utils.Trim (Index.Priority'Image) & ":")
.Append ("(" & Index.Name & ") " & Index.Origin).New_Row;
end loop;
Table.Append ("toolchain assistant:")
.Append (if Alire.Toolchains.Assistant_Enabled
then "enabled"
else "disabled").New_Row;
declare
Guard : Folder_Guard (Enter_Working_Folder) with Unreferenced;
I : Positive := 1;
begin
Trace.Always ("alr root detection has settled on path: " &
OS_Lib.Current_Folder);
Trace.Always ("alr is finding" & Files.Locate_Any_GPR_File'Img &
" GPR project files");
Trace.Always
("alr session state is [" & Cmd.Optional_Root.Status'Img & "]");
for Tool of Alire.Toolchains.Tools loop
Table
.Append ("tool #" & Utils.Trim (I'Image)
& " " & Tool.As_String & ":")
.Append (if Alire.Toolchains.Tool_Is_Configured (Tool)
then Alire.Toolchains.Tool_Milestone (Tool).Image
else "not configured").New_Row;
I := I + 1;
end loop;
end;

Log ("alr compiled on [" &
GNAT.Source_Info.Compilation_ISO_Date & " " &
GNAT.Source_Info.Compilation_Time & "] with GNAT version [" &
GNAT_Version.Version & "]",
Always);

Trace.Always ("platform fingerprint: " & Version.Fingerprint);
Put ("platform properties:");
Table.Append ("").New_Row;
Table.Append ("WORKSPACE").New_Row;

Table.Append ("root status:")
.Append (Root.Status'Image).New_Row;
Table.Append ("root release:")
.Append (case Root.Status is
when Valid => Root.Value.Release.Milestone.Image,
when others => "N/A").New_Row;
Table.Append ("root load error:")
.Append (case Root.Status is
when Broken => Cmd.Optional_Root.Message,
when Valid => "none",
when Outside => "N/A").New_Row;
Table.Append ("root folder:")
.Append (case Root.Status is
when Outside => "N/A",
when Broken => "N/A",
when Valid => Root.Value.Path).New_Row;
Table.Append ("current folder:").Append (Alire.Directories.Current)
.New_Row;

Table.Append ("").New_Row;
Table.Append ("SYSTEM").New_Row;
for Prop of Platform.Properties loop
Put (" " & Prop.Image);
Table.Append (Prop.Key & ":").Append (Prop.Image).New_Row;
end loop;
New_Line;
Trace.Always ("community index required branch: "
& Alire.Index.Community_Branch);

Table.Print (Level => Always);
exception
when E : others =>
Alire.Log_Exception (E);
Trace.Error ("Unexpected error during information gathering");
Trace.Error ("Gathered information up to the error is:");
Table.Print (Level => Always);
raise;
end Execute;

----------------------
Expand Down
2 changes: 1 addition & 1 deletion src/alr/alr-commands.adb
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ package body Alr.Commands is
-- user for its preference at this time.

if Cmd not in Commands.Toolchain.Command'Class and then
Conf.Get (Conf.Keys.Toolchain_Assistant, Default => True)
Alire.Toolchains.Assistant_Enabled
then
Cmd.Requires_Full_Index;
Alire.Toolchains.Assistant (Conf.Global);
Expand Down
3 changes: 1 addition & 2 deletions src/alr/alr-main.adb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ with Alire;
with Alire_Early_Elaboration; pragma Elaborate_All (Alire_Early_Elaboration);
with Alire.Root;

with Alr.Bootstrap;
with Alr.Commands;
with Alr.Last_Chance_Handler;
with Alr.Platform.Init;
Expand All @@ -23,7 +22,7 @@ begin

Alire.Root.Set_Platform_Properties (Alr.Platform.Properties);

Trace.Detail ("alr build is " & Bootstrap.Status_Line);
Trace.Debug ("alr platform configured");

Commands.Execute;
exception
Expand Down
2 changes: 1 addition & 1 deletion testsuite/drivers/alr.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class CalledProcessError(Exception):

def distro_is_known():
p = run_alr('version')
return not re.match('.*platform properties:.*DISTRO_UNKNOWN.*',
return not re.match('.*distribution:.*DISTRO_UNKNOWN.*',
p.out, flags=re.S)


Expand Down
7 changes: 3 additions & 4 deletions testsuite/tests/misc/force-switch/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@

import re

assert_match('.*interaction flags are:.*force:TRUE.*',
run_alr('version', '--force').out,
flags=re.S)
assert_match('.*force flag:[\s]+TRUE.*',
run_alr('version', '--force').out)

assert_match('.*interaction flags are:.*force:TRUE.*',
assert_match('.*force flag:[\s]+TRUE',
run_alr('version', '-f').out,
flags=re.S)

Expand Down
3 changes: 2 additions & 1 deletion testsuite/tests/toolchain/directories/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@

# Identify config location
p = run_alr("version")
config_dir = re.search("config folder is ([^\n.]*)", p.out).group(1)
config_dir = re.search("config folder:([^\n]*)", p.out).group(1).strip()
config_dir = config_dir.replace("\\", "/")
cache_dir = os.path.join(config_dir, "cache")

# The 'contents` function we use to compare these strings normalizes all paths
# to forward slashes, so we do the same with the config_dir

Expand Down
24 changes: 24 additions & 0 deletions testsuite/tests/version/inside-outside/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
Verify that `alr version` works without error without, with and with broken
manifest
"""

from drivers.alr import run_alr, init_local_crate, alr_manifest
from drivers.asserts import assert_eq, assert_match

# Run in several situations with minimal double-check

p = run_alr("version")
assert_match(".*root status:.*OUTSIDE", p.out)

init_local_crate()
p = run_alr("version")
assert_match(".*root status:.*VALID", p.out)

# break the manifest
with open(alr_manifest(), "a") as manifest:
manifest.write("not valid TOML methinks...")
p = run_alr("version")
assert_match(".*root status:.*BROKEN", p.out)

print('SUCCESS')
3 changes: 3 additions & 0 deletions testsuite/tests/version/inside-outside/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
driver: python-script
indexes:
basic_index: {}

0 comments on commit 40af47f

Please sign in to comment.