From 3984cd59ee963e0d4cfe61cb48c2d38a279d305f Mon Sep 17 00:00:00 2001 From: "Alejandro R. Mosteo" Date: Sun, 23 Jun 2024 19:39:33 +0200 Subject: [PATCH] fix: compiler autoselection on 1st run alr get --build --- src/alire/alire-roots-optional.adb | 9 +++++++ src/alire/alire-roots-optional.ads | 3 +++ src/alr/alr-commands-get.adb | 18 ++++++++++--- testsuite/drivers/alr.py | 8 ++++++ testsuite/tests/dockerized/get/build/test.py | 26 +++++++++++++++++++ .../tests/dockerized/get/build/test.yaml | 5 ++++ 6 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 testsuite/tests/dockerized/get/build/test.py create mode 100644 testsuite/tests/dockerized/get/build/test.yaml diff --git a/src/alire/alire-roots-optional.adb b/src/alire/alire-roots-optional.adb index 84d27ba78..a233028a3 100644 --- a/src/alire/alire-roots-optional.adb +++ b/src/alire/alire-roots-optional.adb @@ -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 -- --------------------- diff --git a/src/alire/alire-roots-optional.ads b/src/alire/alire-roots-optional.ads index ee811233e..862d01cbc 100644 --- a/src/alire/alire-roots-optional.ads +++ b/src/alire/alire-roots-optional.ads @@ -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; diff --git a/src/alr/alr-commands-get.adb b/src/alr/alr-commands-get.adb index cc040e5cc..5423414bf 100644 --- a/src/alr/alr-commands-get.adb +++ b/src/alr/alr-commands-get.adb @@ -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; diff --git a/testsuite/drivers/alr.py b/testsuite/drivers/alr.py index 95da91404..18f52109b 100644 --- a/testsuite/drivers/alr.py +++ b/testsuite/drivers/alr.py @@ -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") diff --git a/testsuite/tests/dockerized/get/build/test.py b/testsuite/tests/dockerized/get/build/test.py new file mode 100644 index 000000000..ab916bd06 --- /dev/null +++ b/testsuite/tests/dockerized/get/build/test.py @@ -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') diff --git a/testsuite/tests/dockerized/get/build/test.yaml b/testsuite/tests/dockerized/get/build/test.yaml new file mode 100644 index 000000000..f508caebb --- /dev/null +++ b/testsuite/tests/dockerized/get/build/test.yaml @@ -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