Skip to content

Commit

Permalink
Clearer identification of missing dependencies (#1588)
Browse files Browse the repository at this point in the history
When a complete solution is printed (`alr show|with --solve`), the "external"
section is now named "missing" (which is what it actually meant).

When a diff is show that contains missing dependencies, a new section is
appended containing separately all missing dependencies, labeled as such:
```
$ alr -f with hello unobtanium
Requested changes:

   ✓ hello      ^1.0.2 (add)
   ✓ unobtanium *      (add)

Changes to dependency solution:

   New solution is incomplete.
   +        hello      1.0.2 (new)
   Missing:
   +❗      unobtanium *     (new,missing:unknown)
```
  • Loading branch information
mosteo authored Feb 26, 2024
1 parent a30e568 commit 7084a58
Show file tree
Hide file tree
Showing 19 changed files with 184 additions and 113 deletions.
17 changes: 17 additions & 0 deletions src/alire/alire-dependencies-states.ads
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ package Alire.Dependencies.States is
-- From the POV of users, pinning to version or linking to dir is a pin

function Is_Solved (This : State) return Boolean;
-- With a regular release from the index

function Is_Fulfilled (This : State) return Boolean;
-- Either solved or linked

function Is_Unfulfilled (This : State) return Boolean;
-- Neither solved nor linked

-- Case-specific info

Expand Down Expand Up @@ -333,6 +340,16 @@ private
function Is_Direct (This : State) return Boolean
is (This.Transitivity = Direct);

function Is_Fulfilled (This : State) return Boolean
is (case This.Fulfilment is
when Solved | Linked => True,
when Hinted | Missed => False);

function Is_Unfulfilled (This : State) return Boolean
is (case This.Fulfilment is
when Solved | Linked => False,
when Hinted | Missed => True);

function Is_Hinted (This : State) return Boolean
is (This.Fulfilled.Fulfillment = Hinted);

Expand Down
120 changes: 84 additions & 36 deletions src/alire/alire-solutions-diffs.adb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package body Alire.Solutions.Diffs is
type Changes is
(Added, -- A new release
Removed, -- A removed dependency of any kind
Hinted, -- An undetected external dependency
Upgraded, -- An upgraded release
Downgraded, -- A downgraded release
Pinned, -- A release being pinned
Expand All @@ -27,6 +26,8 @@ package body Alire.Solutions.Diffs is
Info -- General info icon
);

Missing_Flag : constant String := "missing";

----------
-- Icon --
----------
Expand All @@ -36,7 +37,6 @@ package body Alire.Solutions.Diffs is
(case Change is
when Added => TTY.OK (U ("+")),
when Removed => TTY.Emph (U ("")),
when Hinted => TTY.Warn (U ("🔎")), -- alts: 💡🔍🔎
when Upgraded => TTY.OK (U ("")),
when Downgraded => TTY.Warn (U ("")),
when Pinned => TTY.OK (U ("📌")), -- alts: ⊙📍📌
Expand All @@ -49,7 +49,6 @@ package body Alire.Solutions.Diffs is
(case Change is
when Added => U ("+"),
when Removed => U ("-"),
when Hinted => U ("~"),
when Upgraded => U ("^"),
when Downgraded => U ("v"),
when Pinned => U ("·"),
Expand Down Expand Up @@ -151,12 +150,8 @@ package body Alire.Solutions.Diffs is
use type Alire.User_Pins.Pin;

begin
-- New hint
if Gains_State (Hinted) then
Add_Change (Chg, Icon (Hinted), TTY.Warn ("external"));

-- Changed linked dir
elsif Has_Latter and then Latter.Is_Linked and then
if Has_Latter and then Latter.Is_Linked and then
(not Has_Former or else not Former.Is_Linked or else
Former.Link /= Latter.Link)
then
Expand All @@ -166,7 +161,7 @@ package body Alire.Solutions.Diffs is
-- New unsolvable
elsif Gains_State (Missed) then
Add_Change (Chg, Icon (Missing),
TTY.Error ("missing") & ":"
TTY.Error (Missing_Flag) & ":"
& TTY.Warn (To_Lower_Case (Latter.Reason'Image)));

-- From hint to proper release
Expand Down Expand Up @@ -237,7 +232,12 @@ package body Alire.Solutions.Diffs is

procedure Provider_Change is
begin
if Has_Latter and then Latter.Is_Provided then
if Has_Latter and then Latter.Is_Provided
and then
(not Has_Former or else
(Former.Has_Release and Then
Former.Release.Name_Str /= Latter.Release.Name_Str))
then
Add_Change (Chg, "", TTY.Italic (Latter.Release.Name.As_String));
end if;
end Provider_Change;
Expand Down Expand Up @@ -317,11 +317,14 @@ package body Alire.Solutions.Diffs is
subtype Report_Kinds is Origins.Kinds with Static_Predicate =>
Report_Kinds in Binary_Archive | External | System;
begin
-- For "special" releases, show extra info: binaries that can
-- be very large, or releases that are not from sources (so
-- harder to audit, intrinsically shared, ...)
-- For "special" releases, show extra info: binaries that can be very
-- large, or releases that are not from sources (so harder to audit,
-- intrinsically shared, ...), but only if they were going to be
-- shown already.

if not Has_Latter or else not Latter.Has_Release then
if not Has_Latter or else not Latter.Has_Release or else
Chg.Detail.Is_Empty
then
return;
end if;

Expand All @@ -341,6 +344,26 @@ package body Alire.Solutions.Diffs is
end;
end Releases_Without_Sources;

----------------------
-- Missing_Releases --
----------------------

procedure Missing_Releases is
begin
if not Contains (Chg.Detail.Flatten, Missing_Flag) and then
Has_Latter and then
Latter.Is_Unfulfilled
then
Add_Change (Chg, Icon (Missing),
TTY.Error (Missing_Flag)
& (if Latter.Is_Missing -- Has a reason
then ":"
& TTY.Warn (To_Lower_Case (Latter.Reason'Image))
else "" -- hinted don't have a reason
));
end if;
end Missing_Releases;

begin

-- Go through possible changes and add each marker
Expand All @@ -360,8 +383,10 @@ package body Alire.Solutions.Diffs is
Determine_Relevant_Version;

Releases_Without_Sources;
-- This one must go after the rest, as it only appends info if the
-- release was going to be shown anyway.

-- Final fill-in for no changes
-- Final fill-in for no changes and missing (always reported)

if Length (Chg.Icon) = 0 then
Add_Change (Chg, Icon (Unchanged), "");
Expand All @@ -371,6 +396,8 @@ package body Alire.Solutions.Diffs is
Add_Change (Chg, "", "unchanged");
end if;

Missing_Releases;

return Chg;

end Find_Changes;
Expand Down Expand Up @@ -454,6 +481,9 @@ package body Alire.Solutions.Diffs is
end loop;
end Warn_Unsatisfiable_GNAT_External;

type Passes is (Fulfilled, Missing);
Missing_Header_Added : Boolean := False;

begin

-- Start with an empty line to separate from previous output
Expand All @@ -468,38 +498,56 @@ package body Alire.Solutions.Diffs is
Level);
end if;

-- Detailed changes otherwise
-- Detailed changes, showing separately missing dependencies

for Crate of This.Former.Crates.Union (This.Latter.Crates) loop
declare
Changes : constant Crate_Changes := Find_Changes (This, Crate);
begin
for Pass in Passes'Range loop
for Crate of This.Former.Crates.Union (This.Latter.Crates) loop
declare
Changes : constant Crate_Changes := Find_Changes (This, Crate);
begin

if not Changed_Only or else
Changes.Detail.Flatten /= "unchanged"
then
Changed := Changed or True;
if not Changed_Only or else
Changes.Detail.Flatten /= "unchanged" or else
Pass = Missing -- Always show missing ones to raise awareness
then

-- Show icon of change
if (Pass = Fulfilled and then
not Contains (Changes.Detail.Flatten, Missing_Flag))
or else
(Pass = Missing and then
Contains (Changes.Detail.Flatten, Missing_Flag))
then
Changed := Changed or True;

Table.Append (Prefix & (+Changes.Icon));
-- Header for missing section on first missing

-- Always show crate name
if Pass = Missing and then not Missing_Header_Added then
Missing_Header_Added := True;
Table.Append (Prefix & TTY.Warn ("Missing:")).New_Row;
end if;

Table.Append (Utils.TTY.Name (Crate));
-- Show icon of change

-- Show most precise version available
Table.Append (Prefix & (+Changes.Icon));

Table.Append (+Changes.Best_Version);
-- Always show crate name

-- Show an explanation of the change depending on
-- status changes.
Table.Append (Utils.TTY.Name (Crate));

Table.Append ("(" & Changes.Detail.Flatten (",") & ")");
-- Show most precise version available

Table.New_Row;
end if;
end;
Table.Append (+Changes.Best_Version);

-- Show an explanation of the change depending on
-- status changes.

Table.Append ("(" & Changes.Detail.Flatten (",") & ")");

Table.New_Row;
end if;
end if;
end;
end loop;
end loop;

if Changed then
Expand Down
Loading

0 comments on commit 7084a58

Please sign in to comment.