diff --git a/src/alire/alire-roots-editable.adb b/src/alire/alire-roots-editable.adb index 81c11b4d0..a5749f5fb 100644 --- a/src/alire/alire-roots-editable.adb +++ b/src/alire/alire-roots-editable.adb @@ -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; @@ -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 -------------------- @@ -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 @@ -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 diff --git a/src/alire/alire-roots-editable.ads b/src/alire/alire-roots-editable.ads index cf1b45e53..8fea2cfb1 100644 --- a/src/alire/alire-roots-editable.ads +++ b/src/alire/alire-roots-editable.ads @@ -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; diff --git a/testsuite/tests/with/changes-info/test.py b/testsuite/tests/with/changes-info/test.py index fc5514387..ad6bc8b15 100644 --- a/testsuite/tests/with/changes-info/test.py +++ b/testsuite/tests/with/changes-info/test.py @@ -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: @@ -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")