From 89ae47cb1a9e0ff884f633ab7f9e0776a4edade5 Mon Sep 17 00:00:00 2001 From: Alejandro R Mosteo Date: Wed, 15 Nov 2023 14:47:52 +0100 Subject: [PATCH] New warning when external GNAT selected but another compiler version is needed (#1500) * New warning for externally selected gnat * New test --- src/alire/alire-solutions-diffs.adb | 32 +++++++++++++++++++ src/alire/alire-solver.adb | 4 ++- .../gp/gprbuild/gprbuild-external.toml | 11 +++++++ .../solver/unsatisfying-external/test.py | 25 +++++++++++++++ .../solver/unsatisfying-external/test.yaml | 4 +++ 5 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 testsuite/fixtures/compiler_only_index/gp/gprbuild/gprbuild-external.toml create mode 100644 testsuite/tests/solver/unsatisfying-external/test.py create mode 100644 testsuite/tests/solver/unsatisfying-external/test.yaml diff --git a/src/alire/alire-solutions-diffs.adb b/src/alire/alire-solutions-diffs.adb index ed854037..377fdd64 100644 --- a/src/alire/alire-solutions-diffs.adb +++ b/src/alire/alire-solutions-diffs.adb @@ -1,4 +1,5 @@ with Alire.Origins; +with Alire.Toolchains; with Alire.Utils.Tables; with Alire.User_Pins; with Alire.Utils.TTY; @@ -389,6 +390,35 @@ package body Alire.Solutions.Diffs is is Table : Utils.Tables.Table; Changed : Boolean := False; + + procedure Warn_Unsatisfiable_GNAT_External is + begin + for Dep of This.Latter.All_Dependencies loop + if Dep.Crate = GNAT_Crate + and then not Dep.Is_Solved + 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) + then + Trace.Log (Prefix, Level); + Trace.Log (Prefix & Icon (Missing) + & " The explicitly configured external compiler " + & Toolchains.Tool_Milestone (GNAT_Crate).TTY_Image); + Trace.Log (Prefix + & " cannot satisfy dependency in solution " + & Dep.As_Dependency.TTY_Image, + Log_Level); + Trace.Log (Prefix + & " You can select a different compiler for the " + & "workspace with"); + Trace.Log (Prefix & " " + & TTY.Terminal ("alr toolchain --local --select"), + Log_Level); + end if; + end loop; + end Warn_Unsatisfiable_GNAT_External; + begin -- Start with an empty line to separate from previous output @@ -439,6 +469,8 @@ package body Alire.Solutions.Diffs is if Changed then Table.Print (Level); + + Warn_Unsatisfiable_GNAT_External; else Trace.Log (Prefix & "No changes between former and new solution.", Level); diff --git a/src/alire/alire-solver.adb b/src/alire/alire-solver.adb index 867b82a4..7adb6ac3 100644 --- a/src/alire/alire-solver.adb +++ b/src/alire/alire-solver.adb @@ -886,7 +886,9 @@ package body Alire.Solver is Check_Version_Pin; - elsif Index.Exists (Dep.Crate, Index_Query_Options) or else + elsif Index.Exists (Dep.Crate, Index_Query_Options) + or else Index.All_Crate_Aliases.Contains (Dep.Crate) + or else not Index.Releases_Satisfying (Dep, Props, Index_Query_Options).Is_Empty then diff --git a/testsuite/fixtures/compiler_only_index/gp/gprbuild/gprbuild-external.toml b/testsuite/fixtures/compiler_only_index/gp/gprbuild/gprbuild-external.toml new file mode 100644 index 00000000..dfc7bb3a --- /dev/null +++ b/testsuite/fixtures/compiler_only_index/gp/gprbuild/gprbuild-external.toml @@ -0,0 +1,11 @@ +description = "Fake gprbuild external" +name = "gprbuild" + +maintainers = ["alejandro@mosteo.com"] +maintainers-logins = ["mosteo"] + +[[external]] +kind = "version-output" +# We look for make instead, that should be always installed. +version-command = ["make", "--version"] +version-regexp = ".*Make ([\\d\\.]+).*" diff --git a/testsuite/tests/solver/unsatisfying-external/test.py b/testsuite/tests/solver/unsatisfying-external/test.py new file mode 100644 index 00000000..922165a7 --- /dev/null +++ b/testsuite/tests/solver/unsatisfying-external/test.py @@ -0,0 +1,25 @@ +""" +When an external compiler is explicitly configured, no other compiler will be +attempted to be added to the solution. This may be counterintuitive, so we emit +an special warning in this case. +""" + +from drivers.alr import run_alr, init_local_crate +from drivers.asserts import assert_match + + +init_local_crate() + +# Select the external compiler +run_alr("toolchain", "--select", "gnat_external", "gprbuild") + +# Add a different version to the solution +p = run_alr("with", "gnat^9999", force=True, quiet=False) + +# Check that the warning is emitted +assert_match(".*The explicitly configured external compiler gnat_external=.*" + "cannot satisfy dependency in solution gnat\^9999", + p.out) + + +print("SUCCESS") diff --git a/testsuite/tests/solver/unsatisfying-external/test.yaml b/testsuite/tests/solver/unsatisfying-external/test.yaml new file mode 100644 index 00000000..88f74696 --- /dev/null +++ b/testsuite/tests/solver/unsatisfying-external/test.yaml @@ -0,0 +1,4 @@ +driver: python-script +build_mode: both +indexes: + compiler_only_index: {} \ No newline at end of file -- 2.39.5