Skip to content

Commit

Permalink
Simpler error on alr with for unknown crates (#1489)
Browse files Browse the repository at this point in the history
  • Loading branch information
mosteo authored Nov 6, 2023
1 parent 1ce9a22 commit fe20941
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
18 changes: 15 additions & 3 deletions src/alire/alire-roots-editable.adb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
with Alire.Conditional;
with Alire.Dependencies.Diffs;
with Alire.Directories;
with Alire.Index;
with Alire.Manifest;
with Alire.Origins;
with Alire.Roots.Optional;
Expand Down Expand Up @@ -78,8 +79,9 @@ package body Alire.Roots.Editable is
-- Add_Dependency --
--------------------

procedure Add_Dependency (This : in out Root;
Dep : Dependencies.Dependency)
procedure Add_Dependency (This : in out Root;
Dep : Dependencies.Dependency;
Allow_Unknown : Boolean := Alire.Force)
is

--------------------
Expand Down Expand Up @@ -125,6 +127,14 @@ package body Alire.Roots.Editable is

begin

-- Reject if unknown

if not Allow_Unknown and then not Index.Exists (Dep.Crate) then
Alire.Recoverable_Error
("Cannot add crate '" & Alire.Utils.TTY.Name (Dep.Crate)
& "' not found in index.");
end if;

-- Do not add if already a direct dependency

if Release (This.Edit).Depends_On (Dep.Crate, This.Edit.Environment) then
Expand Down Expand Up @@ -287,7 +297,9 @@ package body Alire.Roots.Editable is
(Crate,
(if Pin_Root.Is_Valid and then not Pin_Is_Parent_Crate
then Pin_Root.Updatable_Dependency.Versions
else Semver.Extended.Any)));
else Semver.Extended.Any)),
Allow_Unknown => True);
-- Pins to local paths are more likely not to be indexed
end if;

-- Remove any previous pin for this crate
Expand Down
7 changes: 4 additions & 3 deletions src/alire/alire-roots-editable.ads
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ package Alire.Roots.Editable is
-- created, we need to reload the manifest. The solution remains
-- untouched (use Update to recompute a fresh solution).

procedure Add_Dependency (This : in out Root;
Dep : Dependencies.Dependency);
procedure Add_Dependency (This : in out Root;
Dep : Dependencies.Dependency;
Allow_Unknown : Boolean := Alire.Force);
-- Add a dependency, or raise Checked_Error is Dep is already among direct
-- dependencies.
-- dependencies. Recoverable error if Dep is unknown, unless Allow_Unknown.

procedure Remove_Dependency (This : in out Root;
Crate : Crate_Name;
Expand Down
12 changes: 10 additions & 2 deletions testsuite/tests/with/changes-info/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
p.out, flags=re.S)

###############################################################################
# Check adding a missing crate
p = run_alr('with', 'unobtanium', quiet=False)
# Check adding a missing crate (with forcing)
p = run_alr('with', 'unobtanium', quiet=False, force=True)
assert_match(".*" +
re.escape("""Requested changes:
Expand All @@ -40,6 +40,14 @@
+! unobtanium * (new,missing:unknown)""") + ".*",
p.out, flags=re.S)

# Remove the missing crate for following tests
run_alr("with", "--del", "unobtanium")

# Check adding without forcing for simpler error message
p = run_alr('with', 'unobtanium', force=False, complain_on_error=False)
assert_match(".*Cannot add crate 'unobtanium' not found in index",
p.out)

###############################################################################
# Check adding a pinned dir (the dir must exist)
os.mkdir("local_crate")
Expand Down

0 comments on commit fe20941

Please sign in to comment.