Skip to content

Commit

Permalink
fix: compiler autoselection on 1st run alr get --build (#1706)
Browse files Browse the repository at this point in the history
  • Loading branch information
mosteo committed Jul 5, 2024
1 parent 3bcddc2 commit da80fec
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/alire/alire-roots-optional.adb
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,15 @@ package body Alire.Roots.Optional is
Reference'(Ptr => This.Data.Value'Unrestricted_Access);
end Value;

-------------
-- Discard --
-------------

procedure Discard (This : in out Root) is
begin
This.Data := (Status => Outside);
end Discard;

---------------------
-- Outcome_Failure --
---------------------
Expand Down
3 changes: 3 additions & 0 deletions src/alire/alire-roots-optional.ads
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ package Alire.Roots.Optional is
function Value (This : in out Root) return Reference with
Pre => This.Is_Valid;

procedure Discard (This : in out Root);
-- Sets the root to Outside

function Brokenness (This : Root) return String with
Pre => This.Is_Broken;

Expand Down
18 changes: 14 additions & 4 deletions src/alr/alr-commands-get.adb
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,24 @@ package body Alr.Commands.Get is
Build_OK := True;

else
-- Require the workspace to ensure the same checks as in a
-- manual `get` followed by `cd` and `build` are performed.

Cmd.Optional_Root.Discard;
-- It will be reloaded next. This is needed or otherwise the
-- following call would do nothing (it would see a proper root
-- already available so it would just return).

Cmd.Requires_Workspace;

-- Build in release mode for a `get --build`
Cmd.Root.Set_Build_Profile
(Crate => Cmd.Root.Name,
Profile => Alire.Utils.Switches.Release);
(Crate => Cmd.Root.Name,
Profile => Alire.Utils.Switches.Release);

Build_OK := Cmd.Root.Build
(Cmd_Args => AAA.Strings.Empty_Vector,
Saved_Profiles => False);
(Cmd_Args => AAA.Strings.Empty_Vector,
Saved_Profiles => False);
end if;
else
Build_OK := True;
Expand Down
8 changes: 8 additions & 0 deletions testsuite/drivers/alr.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,3 +617,11 @@ def unselect_compiler():
"""
run_alr("settings", "--global", "--unset", "toolchain.use.gnat")
run_alr("settings", "--global", "--unset", "toolchain.external.gnat")


def set_default_user_settings():
"""
Set the default alr settings that are undone by the testsuite defaults
"""
run_alr("settings", "--global", "--set", "index.auto_community", "true")
run_alr("settings", "--global", "--set", "toolchain.assistant", "true")
26 changes: 26 additions & 0 deletions testsuite/tests/dockerized/get/build/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""
Check the `alr get --build` combo on 1st run with no available compiler. We
test under a pristine environment to avoid re-occurrence of issue #1671, which
only happens when no compiler has been selected yet, and none is available in
the environment.
"""

import subprocess
from drivers.alr import run_alr, set_default_user_settings

# First undo any testsuite compiler and index setup
set_default_user_settings()

# Remove gnat from path so no compiler is available
subprocess.run(['sudo', 'mv', '/usr/bin/gnat', '/usr/bin/gnat.bak']).check_returncode()
try:
assert subprocess.run(['gnat', '--version']).returncode == 0, "Unexpected GNAT found"
except FileNotFoundError:
pass

# Should succeed, issue in #1671 was that no compiler was available nor
# selected automatically as should have been the case.
p = run_alr('get', '--build', 'hello')


print('SUCCESS')
5 changes: 5 additions & 0 deletions testsuite/tests/dockerized/get/build/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
driver: docker-wrapper
control:
- [SKIP, "skip_docker", "Docker disabled"]
- [SKIP, "skip_network", "Network disabled"]
# To exactly reproduce the issue we use the community index here

0 comments on commit da80fec

Please sign in to comment.