Skip to content

Commit

Permalink
Warn when adding a ^0.x dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
mosteo committed Jan 28, 2021
1 parent c849f0d commit 2bb0872
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 2 deletions.
16 changes: 16 additions & 0 deletions src/alire/alire-releases.adb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,22 @@ package body Alire.Releases is
(New_Label (Description,
Defaults.Description)));

-----------------------
-- Flat_Dependencies --
-----------------------

function Flat_Dependencies
(R : Release;
P : Alire.Properties.Vector := Alire.Properties.No_Properties)
return Alire.Dependencies.Containers.List
is
function Enumerate is new Conditional.For_Dependencies.Enumerate
(Alire.Dependencies.Containers.List,
Alire.Dependencies.Containers.Append);
begin
return Enumerate (R.Dependencies.Evaluate (P));
end Flat_Dependencies;

---------------
-- Extending --
---------------
Expand Down
11 changes: 10 additions & 1 deletion src/alire/alire-releases.ads
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ with Ada.Containers.Indefinite_Ordered_Maps;
with Ada.Tags;

with Alire.Conditional;
with Alire.Dependencies;
with Alire.Dependencies.Containers;
with Alire.Interfaces;
with Alire.Manifest;
with Alire.Milestones;
Expand Down Expand Up @@ -158,6 +158,15 @@ package Alire.Releases is
return Conditional.Dependencies;
-- Retrieve only the dependencies that apply on platform P

function Flat_Dependencies
(R : Release;
P : Alire.Properties.Vector := Alire.Properties.No_Properties)
return Alire.Dependencies.Containers.List;
-- Remove any and/or nodes and return dependencies as a simple list. This
-- is useful whenever you need to inspect all direct dependencies, no
-- matter how they will be solved. If P is not empty, this function
-- also works for platform-dependent dependencies only.

function Property (R : Release;
Key : Alire.Properties.Labeled.Labels)
return String;
Expand Down
1 change: 1 addition & 0 deletions src/alire/alire-roots.adb
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ package body Alire.Roots is
Solution => This.Solution,
Deps_Dir => This.Dependencies_Dir);
end if;

end Sync_Solution_And_Deps;

-------------------------------------------
Expand Down
24 changes: 24 additions & 0 deletions src/alire/alire-warnings.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
with Alire.Utils;

package body Alire.Warnings is

Already_Emitted : Utils.String_Set;

---------------
-- Warn_Once --
---------------

procedure Warn_Once (Text : String;
ID : String := "";
Level : Trace.Levels := Trace.Warning)
is
begin
if ID = "" then
Warn_Once (Text, Text, Level);
elsif not Already_Emitted.Contains (ID) then
Already_Emitted.Include (ID);
Trace.Log (Text, Level);
end if;
end Warn_Once;

end Alire.Warnings;
10 changes: 10 additions & 0 deletions src/alire/alire-warnings.ads
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package Alire.Warnings with Preelaborate is

procedure Warn_Once (Text : String;
ID : String := "";
Level : Trace.Levels := Trace.Warning);
-- Emit a warning just once. If it has been already seen, do not warn
-- again. ID is used to determine if a warning has already been emitted
-- or, when not given, the actual warning text.

end Alire.Warnings;
33 changes: 32 additions & 1 deletion src/alire/alire-workspace.adb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,37 @@ with Alire.Paths;
with Alire.Properties.Actions.Executor;
with Alire.Roots;
with Alire.Solutions.Diffs;
with Alire.Workspace;
with Alire.Utils.TTY;
with Alire.Warnings;

package body Alire.Workspace is

use type Conditional.Dependencies;

-------------------------
-- Check_Caret_Warning --
-------------------------
-- Warn of ^0.x dependencies that probably should be ~0.x
procedure Check_Caret_Warning (Root : Roots.Root) is
use Alire.Utils;
Warning_Id : constant String := "caret or tilde";
begin
for Dep of Root.Release.Flat_Dependencies loop
if Utils.Contains (Dep.Versions.Image, "^0") then
Warnings.Warn_Once
("Possible tilde instead of caret intended for a 0.x version.",
Warning_Id & "1");
Warnings.Warn_Once
("Alire interprets caret and tilde the same way "
& "for both pre/post-1 versions.",
Warning_Id & "2");
Warnings.Warn_Once
("The suspicious dependency is: " & TTY.Version (Dep.Image),
Warning_Id & "3");
end if;
end loop;
end Check_Caret_Warning;

-------------------------
-- Deploy_Dependencies --
-------------------------
Expand Down Expand Up @@ -125,6 +150,12 @@ package body Alire.Workspace is

Solution.Print_Hints (Root.Environment);

-- Check that the solution does not contain suspicious dependencies,
-- taking advantage that this procedure is called whenever a change
-- to dependencies is happening.

Check_Caret_Warning (Root);

end Deploy_Dependencies;

--------------------
Expand Down

0 comments on commit 2bb0872

Please sign in to comment.