Skip to content

Commit

Permalink
Bugfix: exception when trying to select a tool without the assistant …
Browse files Browse the repository at this point in the history
…while the configured one is missing (#1551)

* Fix exception when trying to select a toolchain

This problem arised only if trying to select a toolchain with --select <tool>
while the configured tool was missing on disk.

* Test for fix
  • Loading branch information
mosteo authored Jan 30, 2024
1 parent c25dd54 commit a9a8fb1
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/alire/alire-solutions-diffs.adb
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,10 @@ package body Alire.Solutions.Diffs is
and then Toolchains.Tool_Is_Configured (GNAT_Crate)
and then Toolchains.Tool_Milestone (GNAT_Crate).Crate
= GNAT_External_Crate
and then not Toolchains.Tool_Release (GNAT_Crate).Satisfies (Dep)
and then
(Toolchains.Tool_Is_Missing (GNAT_Crate)
or else
not Toolchains.Tool_Release (GNAT_Crate).Satisfies (Dep))
then
Trace.Log (Prefix, Level);
Trace.Log (Prefix & Icon (Missing)
Expand Down
39 changes: 39 additions & 0 deletions src/alire/alire-toolchains.adb
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,34 @@ package body Alire.Toolchains is
Put_Info (Release.Milestone.TTY_Image & " installed successfully.");
end Deploy;

--------------------
-- Deploy_Missing --
--------------------

procedure Deploy_Missing is
begin
for Tool of Tools loop
if Tool_Is_Configured (Tool) and then Tool_Is_Missing (Tool) then
declare
Mil : constant Milestones.Milestone := Tool_Milestone (Tool);
begin
Put_Warning ("Tool " & Mil.TTY_Image
& " is missing, redeploying...");
if Index.Exists (Mil.Crate, Mil.Version) then
Deploy (Index.Find (Mil.Crate, Mil.Version));
else
Raise_Checked_Error
(Errors.Wrap
("A configured tool is missing on disk and unavailable "
& "in the loaded index.",
" Run " & TTY.Terminal ("alr toolchain --select")
& " to select another toolchain"));
end if;
end;
end if;
end loop;
end Deploy_Missing;

------------
-- Remove --
------------
Expand Down Expand Up @@ -725,4 +753,15 @@ package body Alire.Toolchains is
raise Constraint_Error with "Not installed: " & Target.TTY_Image;
end Release;

---------------------
-- Tool_Is_Missing --
---------------------

function Tool_Is_Missing (Crate : Crate_Name) return Boolean is
begin
return not (for some Release of Available (Detect_Externals =>
Tool_Is_External (Crate))
=> Release.Milestone = Tool_Milestone (Crate));
end Tool_Is_Missing;

end Alire.Toolchains;
7 changes: 7 additions & 0 deletions src/alire/alire-toolchains.ads
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ package Alire.Toolchains is
-- Use the stored config to check if the tool is external without having to
-- detect it. Defaults to True if unset or tool is not configured.

function Tool_Is_Missing (Crate : Crate_Name) return Boolean
with Pre => Tool_Is_Configured (Crate);
-- Says is the configured tool is not ready for use and must be downloaded

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

function Tool_Release (Crate : Crate_Name) return Releases.Release;
Expand Down Expand Up @@ -132,6 +136,9 @@ package Alire.Toolchains is
Location : Any_Path := Path);
-- Deploy a release in the specified location

procedure Deploy_Missing;
-- Deploy any configured tool that is not found where expected on disk

procedure Remove
(Release : Releases.Release;
Confirm : Boolean := not CLIC.User_Input.Not_Interactive)
Expand Down
1 change: 1 addition & 0 deletions src/alr/alr-commands-toolchain.adb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ package body Alr.Commands.Toolchain is
-- command-line, will impose an origin compatibility constraint

if Toolchains.Tool_Is_Configured (Tool)
and then not Toolchains.Tool_Is_Missing (Tool)
and then not
(for some P of Pending =>
Toolchains.Tool_Release (Tool).Provides (P) or else
Expand Down
18 changes: 18 additions & 0 deletions testsuite/tests/toolchain/select-while-missing/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""
Check a particular error in which selecting a compiler via `alr toolchain
--select <compiler>` fails if the previously configured compiler is missing on
disk.
"""

from drivers.alr import run_alr

# Configure a valid compiler
run_alr("toolchain", "--select", "gnat_native", "gprbuild")

# Configure an invalid compiler
run_alr("config", "--global", "--set", "toolchain.use.gnat", "gnat_nono=1.2.3")

# This must succeed
run_alr("toolchain", "--select", "gnat_native=1.0")

print("SUCCESS")
4 changes: 4 additions & 0 deletions testsuite/tests/toolchain/select-while-missing/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
driver: python-script
build_mode: both
indexes:
gnat_toolchain_index: {}

0 comments on commit a9a8fb1

Please sign in to comment.