From 26f5bb6c81b2fea0e3b2daf6d2d8a7395adf81f5 Mon Sep 17 00:00:00 2001 From: "Alejandro R. Mosteo" Date: Mon, 30 Sep 2024 21:14:02 +0200 Subject: [PATCH 1/3] Fix: consider 'provides' during pinning --- src/alire/alire-dependencies-states.adb | 11 +++++++++++ src/alire/alire-roots.adb | 6 ++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/alire/alire-dependencies-states.adb b/src/alire/alire-dependencies-states.adb index 159f429a7..34ff68a02 100644 --- a/src/alire/alire-dependencies-states.adb +++ b/src/alire/alire-dependencies-states.adb @@ -52,7 +52,18 @@ package body Alire.Dependencies.States is begin if Opt_Root.Is_Valid then if Opt_Root.Value.Release.Name = Crate then + + -- Simple case in which the release corresponds with the crate return To_Holder (Opt_Root.Value.Release); + + elsif Opt_Root.Value.Release.Provides (Crate) then + + -- But also, the release may be providing the crate instead + Trace.Debug ("Created optional release " + & Opt_Root.Value.Release.Milestone.Image + & " providing crate " & Crate.As_String); + return To_Holder (Opt_Root.Value.Release); + else Raise_Checked_Error ("crate mismatch: expected " & Crate.TTY_Image diff --git a/src/alire/alire-roots.adb b/src/alire/alire-roots.adb index fae9448b8..76e967352 100644 --- a/src/alire/alire-roots.adb +++ b/src/alire/alire-roots.adb @@ -104,7 +104,7 @@ package body Alire.Roots is end Build_Prepare; ----------- - -- Build -- + -- noteBuild -- ----------- function Build (This : in out Root; @@ -1060,7 +1060,9 @@ package body Alire.Roots is if Target.Is_Valid then Trace.Debug ("Crate found at pin location " & Pin.Relative_Path); - if Target.Value.Name /= Crate then + if Target.Value.Name /= Crate and then + not Target.Value.Release.Element.Provides (Crate) + then Raise_Checked_Error ("Mismatched crates for pin linking to " & TTY.URL (Pin.Path) & ": expected " & From 3a0f69c1d263f2749b3b406dda18f228b29d8995 Mon Sep 17 00:00:00 2001 From: "Alejandro R. Mosteo" Date: Wed, 2 Oct 2024 13:27:55 +0200 Subject: [PATCH 2/3] Test --- .../tests/pin/crate-with-provides/test.py | 40 +++++++++++++++++++ .../tests/pin/crate-with-provides/test.yaml | 4 ++ 2 files changed, 44 insertions(+) create mode 100644 testsuite/tests/pin/crate-with-provides/test.py create mode 100644 testsuite/tests/pin/crate-with-provides/test.yaml diff --git a/testsuite/tests/pin/crate-with-provides/test.py b/testsuite/tests/pin/crate-with-provides/test.py new file mode 100644 index 000000000..c5e63c803 --- /dev/null +++ b/testsuite/tests/pin/crate-with-provides/test.py @@ -0,0 +1,40 @@ +""" +Verify that we can link-pin a crate that has "provides" in a variety of ways. +""" + +import os +from drivers.alr import run_alr, init_local_crate, alr_manifest +from drivers.asserts import assert_eq, assert_match, match_solution + +# Create the target crate +init_local_crate(name="mylib") +# Update its manifest +with open(alr_manifest(), "a") as f: + f.write('provides=["coollib=1.0.0"]') +os.chdir("..") + +tests = [ + ["with", "--use=../mylib"], + ["with", "coollib", "--use=../mylib"], +] + +matches = [ + "mylib=0.1.0-dev (pinned) (origin: ../mylib)", + "coollib=0.1.0-dev (mylib) (pinned) (origin: ../mylib)" +] + +for target, test, id in zip(matches, tests, range(len(tests))): + # Create a new dependent crate + init_local_crate(f"myapp{id}") + run_alr(*test) + match_solution(target, escape=True) + os.chdir("..") + +# For the final test we need an extra step to force-add the dependency before +# pinning. +init_local_crate("myapp_final") +run_alr("--force", "with", "coollib") # Force because not in index +run_alr("pin", "coollib", "--use=../mylib") +match_solution(matches[-1], escape=True) + +print("SUCCESS") diff --git a/testsuite/tests/pin/crate-with-provides/test.yaml b/testsuite/tests/pin/crate-with-provides/test.yaml new file mode 100644 index 000000000..702010525 --- /dev/null +++ b/testsuite/tests/pin/crate-with-provides/test.yaml @@ -0,0 +1,4 @@ +driver: python-script +build_mode: both +indexes: + compiler_only_index: {} From 6b3da0b26c7cd5ac95c8224dec7c4f50a6a617fb Mon Sep 17 00:00:00 2001 From: Alejandro R Mosteo Date: Mon, 7 Oct 2024 11:30:03 +0200 Subject: [PATCH 3/3] Fix unwanted edition in alire-roots.adb --- src/alire/alire-roots.adb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/alire/alire-roots.adb b/src/alire/alire-roots.adb index 76e967352..27f3d3052 100644 --- a/src/alire/alire-roots.adb +++ b/src/alire/alire-roots.adb @@ -104,7 +104,7 @@ package body Alire.Roots is end Build_Prepare; ----------- - -- noteBuild -- + -- Build -- ----------- function Build (This : in out Root;