From 0db9ca8c78370ebf7772023ad72c3fcff3c2b40b Mon Sep 17 00:00:00 2001 From: Alejandro R Mosteo Date: Fri, 19 Jun 2020 21:09:09 +0200 Subject: [PATCH] Detect and use Alire metadata found in pinned directory (#450) * Detect crate at linked dir and use its deps/paths If a path given to with/pin --use contains a loadable alire workspace (i.e., for a crate manually initialized, or retrieved with `get`), the release found there will be used to retrieve additional dependencies, and its project paths will also be used. * `with` directory with autodetection of crate When adding a dependency as a pinned dir, and the target dir is a regular Alire crate, we can autodetect the crate we are adding as dependency. In that case the command becomes `alr with --use `. This can also be useful in the future for remote URLs that will also provide the crate being retrieved. * Refactor --url to --use --- doc/user-changes.md | 13 +++++ src/alire/alire-dependencies-states.adb | 29 +++++++++++ src/alire/alire-dependencies-states.ads | 52 ++++++++++++++++--- src/alire/alire-roots.adb | 51 ++++++++++++++++++ src/alire/alire-roots.ads | 5 ++ src/alire/alire-solutions.adb | 2 +- src/alire/alire-solutions.ads | 3 +- src/alire/alire-solver.adb | 6 ++- src/alire/alire-workspace.adb | 20 ++++--- src/alr/alr-commands-pin.adb | 5 ++ src/alr/alr-commands-user_input.adb | 20 +++++++ src/alr/alr-commands-user_input.ads | 6 +++ src/alr/alr-commands-withing.adb | 52 +++++++++++++++---- testsuite/tests/pin/dir-crate/test.py | 38 ++++++++++++++ testsuite/tests/pin/dir-crate/test.yaml | 4 ++ testsuite/tests/pin/dir-mismatch/test.py | 32 ++++++++++++ testsuite/tests/pin/dir-mismatch/test.yaml | 4 ++ .../with/pin-dir-crate-autodetect/test.py | 36 +++++++++++++ .../with/pin-dir-crate-autodetect/test.yaml | 4 ++ testsuite/tests/with/pin-dir-crate/test.py | 31 +++++++++++ testsuite/tests/with/pin-dir-crate/test.yaml | 4 ++ testsuite/tests/with/pin-dir-mismatch/test.py | 29 +++++++++++ .../tests/with/pin-dir-mismatch/test.yaml | 4 ++ 23 files changed, 424 insertions(+), 26 deletions(-) create mode 100644 testsuite/tests/pin/dir-crate/test.py create mode 100644 testsuite/tests/pin/dir-crate/test.yaml create mode 100644 testsuite/tests/pin/dir-mismatch/test.py create mode 100644 testsuite/tests/pin/dir-mismatch/test.yaml create mode 100644 testsuite/tests/with/pin-dir-crate-autodetect/test.py create mode 100644 testsuite/tests/with/pin-dir-crate-autodetect/test.yaml create mode 100644 testsuite/tests/with/pin-dir-crate/test.py create mode 100644 testsuite/tests/with/pin-dir-crate/test.yaml create mode 100644 testsuite/tests/with/pin-dir-mismatch/test.py create mode 100644 testsuite/tests/with/pin-dir-mismatch/test.yaml diff --git a/doc/user-changes.md b/doc/user-changes.md index 8192e3bf..19719a7e 100644 --- a/doc/user-changes.md +++ b/doc/user-changes.md @@ -4,6 +4,19 @@ This document is a development diary summarizing changes in `alr` that notably affect the user experience. It is intended as a one-stop point for users to stay on top of `alr` new features. +### Use crate metadata when pinning to a directory + +PR [#450](https://github.com/alire-project/alire/pull/450). + +When pinning a dependency to a directory (`alr pin|with --url`), detect +if the target contains Alire metadata (as usual, in an `alire` subdir). In that +case, use it to determine further dependencies and project file scopes. Also, +the target dependency name is verified. + +For such a target directory, a shortcut `with` command is available since the +crate name can be determined from the metadata: `alr with --url +/path/to/target` (note the absence of a crate name). + ### Allow working with incomplete solutions PR [#447](https://github.com/alire-project/alire/pull/447). diff --git a/src/alire/alire-dependencies-states.adb b/src/alire/alire-dependencies-states.adb index b7e199a8..c2e4aed3 100644 --- a/src/alire/alire-dependencies-states.adb +++ b/src/alire/alire-dependencies-states.adb @@ -1,7 +1,34 @@ +with Alire.Roots; + with Alire.Crates.With_Releases; package body Alire.Dependencies.States is + ---------------------- + -- Optional_Release -- + ---------------------- + + function Optional_Release (Crate : Crate_Name; + Workspace : Any_Path) + return Containers.Release_H + is + Opt_Root : constant Roots.Root := Roots.Detect_Root (Workspace); + begin + if Opt_Root.Is_Valid then + if Opt_Root.Release.Name = Crate then + return Containers.To_Release_H (Opt_Root.Release); + else + Raise_Checked_Error ("crate mismatch: expected " + & Crate.TTY_Image + & " but found " + & Opt_Root.Release.Name.TTY_Image + & " at " & TTY.URL (Workspace)); + end if; + else + return Containers.Release_Holders.Empty_Holder; + end if; + end Optional_Release; + use TOML; package Keys is @@ -56,6 +83,8 @@ package body Alire.Dependencies.States is (From.Descend (Value => From.Checked_Pop (Keys.Link, TOML_Table), Context => Keys.Link))); + Data.Opt_Rel := Optional_Release (From_TOML.Crate, + Data.Target.Element.Path); when Missed => null; diff --git a/src/alire/alire-dependencies-states.ads b/src/alire/alire-dependencies-states.ads index 9d37f372..b7cc6c5b 100644 --- a/src/alire/alire-dependencies-states.ads +++ b/src/alire/alire-dependencies-states.ads @@ -71,6 +71,10 @@ package Alire.Dependencies.States is function As_Dependency (This : State) return Dependencies.Dependency; -- Upcast for convenience, equivalent to Dependencies.Dependency (This) + function Has_Release (This : State) return Boolean; + -- Says if a release can be retrieved for this state (a solved dependency, + -- or a linked crate folder with alire context). + -- Simple status identification function Is_Direct (This : State) return Boolean; @@ -98,7 +102,7 @@ package Alire.Dependencies.States is with Pre => This.Is_Pinned; function Release (This : State) return Releases.Release - with Pre => This.Is_Solved; + with Pre => This.Has_Release; function Transitivity (This : State) return Transitivities; @@ -120,6 +124,16 @@ private use type Semantic_Versioning.Extended.Version_Set; + -- Helper functions + + function Optional_Release (Crate : Crate_Name; + Workspace : Any_Path) + return Containers.Release_H; + -- Detect if Workspace is a valid Alire crate for the given Crate, in which + -- case the returned release will be valid. Otherwise it will be empty. If + -- the crate found does not match Crate in name, a Checked_Error will be + -- raised. + -- Base overridings overriding @@ -150,8 +164,11 @@ private type Fulfilment_Data (Fulfillment : Fulfilments := Missed) is record case Fulfillment is - when Linked => Target : Link_Holder; - when Solved => Release : Containers.Release_H; + when Linked => + Target : Link_Holder; + Opt_Rel : Containers.Release_H; -- This might not be filled-in + when Solved => + Release : Containers.Release_H; -- This is always valid when others => null; end case; end record; @@ -205,6 +222,14 @@ private function Fulfilment (This : State) return Fulfilments is (This.Fulfilled.Fulfillment); + ----------------- + -- Has_Release -- + ----------------- + + function Has_Release (This : State) return Boolean + is (This.Is_Solved or else + (This.Is_Linked and then not This.Fulfilled.Opt_Rel.Is_Empty)); + ------------- -- Hinting -- ------------- @@ -230,6 +255,9 @@ private & Utils.To_Lower_Case (This.Fulfilled.Fulfillment'Img) & (if This.Fulfilled.Fulfillment = Linked then ",target=" & This.Fulfilled.Target.Get.Path + & (if This.Has_Release + then ",release" + else "") else "") & (if This.Pinning.Pinned then ",pin=" & This.Pinning.Version.Image @@ -278,7 +306,9 @@ private is (Base.As_Dependency with Name_Len => Base.Name_Len, Fulfilled => (Fulfillment => Linked, - Target => To_Holder (Link)), + Target => To_Holder (Link), + Opt_Rel => Optional_Release (Base.Crate, + Link.Path)), Pinning => Base.Pinning, Transitivity => Base.Transitivity); @@ -363,7 +393,12 @@ private ------------- function Release (This : State) return Releases.Release - is (This.Fulfilled.Release.Element); + is (if This.Is_Solved then + This.Fulfilled.Release.Element + elsif This.Is_Linked then + This.Fulfilled.Opt_Rel.Element + else raise Program_Error + with "dependency has no release: " & This.Crate.TTY_Image); ------------- -- Setting -- @@ -388,8 +423,8 @@ private is (Base.As_Dependency with Name_Len => Base.Name_Len, Fulfilled => (Fulfillment => Solved, - Release => Containers.Release_Holders - .To_Holder (Using)), + Release => Containers.Release_Holders + .To_Holder (Using)), Pinning => Base.Pinning, Transitivity => Base.Transitivity); @@ -419,6 +454,9 @@ private & (if This.Fulfilled.Fulfillment = Linked then "," & TTY.Emph ("target") & "=" & TTY.URL (This.Fulfilled.Target.Get.Path) + & (if This.Has_Release + then "," & TTY.OK ("release") + else "") else "") & (if This.Pinning.Pinned then "," & TTY.Emph ("pin") diff --git a/src/alire/alire-roots.adb b/src/alire/alire-roots.adb index e5fc94f8..8f46b5be 100644 --- a/src/alire/alire-roots.adb +++ b/src/alire/alire-roots.adb @@ -1,5 +1,56 @@ +with Ada.Directories; + +with Alire.Directories; +with Alire.Root; +with Alire.TOML_Index; + +with GNAT.OS_Lib; + package body Alire.Roots is + ----------------- + -- Detect_Root -- + ----------------- + + function Detect_Root (Path : Any_Path) return Root is + use GNAT.OS_Lib; + Alire_Path : constant Any_Path := + Path / Alire.Paths.Working_Folder_Inside_Root; + begin + if not Is_Directory (Alire_Path) then + Trace.Debug ("No alire folder while detecting root at " & Path); + return New_Invalid_Root.With_Reason ("No alire metadata directory"); + end if; + + declare + Crate_File : constant String := Directories.Find_Single_File + (Path => Alire_Path, + Extension => ".toml"); + begin + if Crate_File /= "" then + declare + Release : constant Releases.Release := + TOML_Index.Load_Release_From_File (Crate_File); + begin + -- Crate loaded properly, we can return a valid root here + Trace.Debug ("Valid root found at " & Path); + return New_Root (R => Release, + Path => Ada.Directories.Full_Name (Path), + Env => Alire.Root.Platform_Properties); + end; + else + Trace.Debug ("No crate file found at " & Alire_Path); + return New_Invalid_Root.With_Reason ("no crate file found"); + end if; + exception + when E : others => + Trace.Debug ("Crate detection failed while loading toml file:"); + Log_Exception (E); + return New_Invalid_Root.With_Reason + ("toml file found but not loadable: " & Crate_File); + end; + end Detect_Root; + ------------------- -- Project_Paths -- ------------------- diff --git a/src/alire/alire-roots.ads b/src/alire/alire-roots.ads index 22a79e07..ee0a6552 100644 --- a/src/alire/alire-roots.ads +++ b/src/alire/alire-roots.ads @@ -41,6 +41,11 @@ package Alire.Roots is -- Valid roots -- ----------------- + function Detect_Root (Path : Any_Path) return Root; + -- Attempt to detect a root at the given path. The root will be valid if + -- path/alire exists, path/alire/*.toml is unique and loadable as a crate + -- containing a single release. + -- See Alire.Directories.Detect_Root_Path to use with the following function New_Root (Name : Crate_Name; diff --git a/src/alire/alire-solutions.adb b/src/alire/alire-solutions.adb index 6e989eab..4b74bee2 100644 --- a/src/alire/alire-solutions.adb +++ b/src/alire/alire-solutions.adb @@ -472,7 +472,7 @@ package body Alire.Solutions is begin return Result : Release_Map do for Dep of This.Dependencies loop - if Dep.Is_Solved then + if Dep.Has_Release then Result.Insert (Dep.Crate, Dep.Release); end if; end loop; diff --git a/src/alire/alire-solutions.ads b/src/alire/alire-solutions.ads index 030034f0..daa8c824 100644 --- a/src/alire/alire-solutions.ads +++ b/src/alire/alire-solutions.ads @@ -224,7 +224,8 @@ package Alire.Solutions is -- return all pinned dependencies as plain dependencies for a exact version function Releases (This : Solution) return Release_Map; - -- Returns the proper releases in the solution (regular and detected) + -- Returns the proper releases in the solution (regular and detected + -- externals). This also includes releases found at a linked folder. function Required (This : Solution) return State_Map'Class; -- Returns all dependencies required to fulfill this solution, diff --git a/src/alire/alire-solver.adb b/src/alire/alire-solver.adb index be5838e8..9bb05230 100644 --- a/src/alire/alire-solver.adb +++ b/src/alire/alire-solver.adb @@ -359,7 +359,11 @@ package body Alire.Solver is Tree'(Expanded and Target and Remaining).Image_One_Line); Expand (Expanded => Expanded and Dep, - Target => Remaining, + Target => Remaining and + (if Current.State (Dep.Crate).Has_Release + then Current.State (Dep.Crate) + .Release.Dependencies (Props) + else Empty), Remaining => Empty, Solution => Solution.Linking (Dep.Crate, diff --git a/src/alire/alire-workspace.adb b/src/alire/alire-workspace.adb index d2336638..3937e681 100644 --- a/src/alire/alire-workspace.adb +++ b/src/alire/alire-workspace.adb @@ -45,7 +45,7 @@ package body Alire.Workspace is -- dependents don't need to wait for their deployment). for Dep of Solution.Required loop - if not Dep.Is_Solved then + if not Dep.Has_Release then Deployed.Include (Dep.Crate); end if; end loop; @@ -67,15 +67,21 @@ package body Alire.Workspace is for Rel of Pending loop -- In the 1st step of each round we identify releases that - -- don't have undeployed dependencies. Until we track who - -- introduces what dependency, we fall back to enumerating - -- all dependencies of a release on platform. + -- don't have undeployed dependencies. We also identify + -- releases that need not to be deployed (e.g. linked ones). - if (for some Dep of Enum (Rel.Dependencies (Env)) => - not Deployed.Contains (Dep.Crate)) + if not Solution.State (Rel.Name).Is_Solved then + Trace.Debug ("Round" & Round'Img & ": NOOP " & + Rel.Milestone.Image); + + To_Remove.Include (Rel); + + elsif (for some Dep of Enum (Rel.Dependencies (Env)) => + not Deployed.Contains (Dep.Crate)) then Trace.Debug ("Round" & Round'Img & ": SKIP not-ready " & Rel.Milestone.Image); + else Trace.Debug ("Round" & Round'Img & ": CHECKOUT ready " & Rel.Milestone.Image); @@ -96,7 +102,7 @@ package body Alire.Workspace is if To_Remove.Is_Empty then raise Program_Error - with "No release checked-out in round" & Round'Img; + with "No release checked out in round" & Round'Img; else for Rel of To_Remove loop Pending.Exclude (Rel.Name); diff --git a/src/alr/alr-commands-pin.adb b/src/alr/alr-commands-pin.adb index bed9c55c..4350b610 100644 --- a/src/alr/alr-commands-pin.adb +++ b/src/alr/alr-commands-pin.adb @@ -191,6 +191,11 @@ package body Alr.Commands.Pin is Platform.Properties, Old_Sol); + -- Report crate detection at target destination + + User_Input.Report_Pinned_Crate_Detection (+Argument (1), + New_Sol); + else -- Change a single pin diff --git a/src/alr/alr-commands-user_input.adb b/src/alr/alr-commands-user_input.adb index 2c4ddf5e..0894c1ec 100644 --- a/src/alr/alr-commands-user_input.adb +++ b/src/alr/alr-commands-user_input.adb @@ -37,4 +37,24 @@ package body Alr.Commands.User_Input is else No)) = Yes; end Confirm_Solution_Changes; + ----------------------------------- + -- Report_Pinned_Crate_Detection -- + ----------------------------------- + + procedure Report_Pinned_Crate_Detection + (Crate : Alire.Crate_Name; + Solution : Alire.Solutions.Solution) + is + begin + if Solution.State (Crate).Has_Release then + Trace.Info + ("Alire crate detected at given destination: " + & Solution.State (Crate).Release + .Milestone.TTY_Image); + else + Trace.Warning ("No crate detected at destination;" + & " using it as a raw GNAT project."); + end if; + end Report_Pinned_Crate_Detection; + end Alr.Commands.User_Input; diff --git a/src/alr/alr-commands-user_input.ads b/src/alr/alr-commands-user_input.ads index ea43075d..f0d7e7f1 100644 --- a/src/alr/alr-commands-user_input.ads +++ b/src/alr/alr-commands-user_input.ads @@ -13,4 +13,10 @@ package Alr.Commands.User_Input is -- True when the user answers positively. Defaults to Yes when the new -- solution is complete, or when Alire.Force. + procedure Report_Pinned_Crate_Detection + (Crate : Alire.Crate_Name; + Solution : Alire.Solutions.Solution); + -- When pinning a directory, report if the target already contains an + -- initialized crate or not. For reuse from several commands. + end Alr.Commands.User_Input; diff --git a/src/alr/alr-commands-withing.adb b/src/alr/alr-commands-withing.adb index 6eeb9cfc..1dd2568b 100644 --- a/src/alr/alr-commands-withing.adb +++ b/src/alr/alr-commands-withing.adb @@ -73,17 +73,13 @@ package body Alr.Commands.Withing is -- Add_Softlink -- ------------------ - procedure Add_Softlink (Cmd : Command) is + procedure Add_Softlink (Dep_Spec : String; + Path : String) is Requested : constant Alire.Milestones.Allowed_Milestones := - Alire.Milestones.Crate_Versions (Argument (1)); + Alire.Milestones.Crate_Versions (Dep_Spec); New_Dep : constant Alire.Dependencies.Dependency := Alire.Dependencies.From_Milestones (Requested); begin - if Num_Arguments /= 1 then - Reportaise_Wrong_Arguments - ("Exactly one crate needed for external pinning."); - end if; - declare use Alire; use type Conditional.Dependencies; @@ -94,9 +90,23 @@ package body Alr.Commands.Withing is Old_Solution .Depending_On (New_Dep) .Linking (Crate => New_Dep.Crate, - Path => Cmd.URL.all); + Path => Path); begin + -- Prevent double-add + + if Old_Solution.Depends_On (New_Dep.Crate) then + Reportaise_Wrong_Arguments + ("Not adding " & New_Dep.Crate.TTY_Image & " because " + & Old_Solution.Dependency (New_Dep.Crate).TTY_Image + & " is already a dependency"); + end if; + + -- Report crate detection at target destination + + User_Input.Report_Pinned_Crate_Detection (New_Dep.Crate, + New_Solution); + -- If we made here there were no errors adding the dependency -- and storing the softlink. We can proceed to confirming the -- replacement. @@ -110,6 +120,25 @@ package body Alr.Commands.Withing is end; end Add_Softlink; + --------------------- + -- Detect_Softlink -- + --------------------- + + procedure Detect_Softlink (Path : String) is + Root : constant Alire.Roots.Root := Alire.Roots.Detect_Root (Path); + begin + if Root.Is_Valid then + -- Add a dependency on ^(detected version) (i.e., safely upgradable) + Add_Softlink + (Dep_Spec => Root.Release.Name_Str + & "^" & Root.Release.Version.Image, + Path => Path); + else + Reportaise_Command_Failed + ("cannot add target: " & Root.Invalid_Reason); + end if; + end Detect_Softlink; + --------- -- Del -- --------- @@ -417,7 +446,12 @@ package body Alr.Commands.Withing is -- Must be Add, but it could be regular or softlink if Cmd.URL.all /= "" then - Add_Softlink (Cmd); + if Num_Arguments = 1 then + Add_Softlink (Dep_Spec => Argument (1), + Path => Cmd.URL.all); + else + Detect_Softlink (Cmd.URL.all); + end if; else Requires_Full_Index; Add; diff --git a/testsuite/tests/pin/dir-crate/test.py b/testsuite/tests/pin/dir-crate/test.py new file mode 100644 index 00000000..22c461b7 --- /dev/null +++ b/testsuite/tests/pin/dir-crate/test.py @@ -0,0 +1,38 @@ +""" +Detect that a given folder to pin contains a crate and use its info +""" + +import os +import re + +from drivers.alr import run_alr +from drivers.asserts import assert_match +from drivers.helpers import path_separator +from glob import glob + +# Retrieve a crate +run_alr('get', 'hello=1') +target = glob('hello*')[0] + +# Initialize a workspace +run_alr('init', '--bin', 'xxx') +os.chdir('xxx') + +# Add dependency as regular crate; this has missing dependencies so we have to +# force. This brings in hello=4. +run_alr('with', 'hello', '--force') + +# Pin the hello crate as local dir dependency. The version in the folder is +# different to the one we had in the solution, so this should cause a downgrade +# but with complete solution. Now hello=1 --> libhello=1.1. +run_alr('pin', 'hello', '--use', '..' + path_separator() + target) + +# Verify that hello dependencies are detected and used, and are the ones +# corresponding to the linked dir versions. +p = run_alr('with', '--solve') +assert_match('''.*Dependencies \(solution\): + hello=1\.0\.0 .* + libhello=1\.1\.0 .*''', # we skip non-relevant details + p.out, flags=re.S) + +print('SUCCESS') diff --git a/testsuite/tests/pin/dir-crate/test.yaml b/testsuite/tests/pin/dir-crate/test.yaml new file mode 100644 index 00000000..e0a82ba8 --- /dev/null +++ b/testsuite/tests/pin/dir-crate/test.yaml @@ -0,0 +1,4 @@ +driver: python-script +indexes: + solver_index: + in_fixtures: true diff --git a/testsuite/tests/pin/dir-mismatch/test.py b/testsuite/tests/pin/dir-mismatch/test.py new file mode 100644 index 00000000..31a9bd2c --- /dev/null +++ b/testsuite/tests/pin/dir-mismatch/test.py @@ -0,0 +1,32 @@ +""" +Detect that a given folder to pin contains an unexpected crate +""" + +import os +import re + +from drivers.alr import run_alr +from drivers.asserts import assert_match +from drivers.helpers import path_separator +from glob import glob + +# Retrieve a crate +run_alr('get', 'hello=1') +target = glob('hello*')[0] + +# Initialize a workspace +run_alr('init', '--bin', 'xxx') +os.chdir('xxx') + +# Add a dependency as pinned dir without metadata; this should succeed +run_alr('with', 'nothello', '--use', '..') + +# Try to repin to a dir with valid crate metadata +p = run_alr('with', 'nothello', '--use', '..' + path_separator() + target, + complain_on_error=False) + +# Expected error +assert_match('.*crate mismatch: expected nothello but found hello at.*', p.out) +# skip test-specific path + +print('SUCCESS') diff --git a/testsuite/tests/pin/dir-mismatch/test.yaml b/testsuite/tests/pin/dir-mismatch/test.yaml new file mode 100644 index 00000000..e0a82ba8 --- /dev/null +++ b/testsuite/tests/pin/dir-mismatch/test.yaml @@ -0,0 +1,4 @@ +driver: python-script +indexes: + solver_index: + in_fixtures: true diff --git a/testsuite/tests/with/pin-dir-crate-autodetect/test.py b/testsuite/tests/with/pin-dir-crate-autodetect/test.py new file mode 100644 index 00000000..6b8beb73 --- /dev/null +++ b/testsuite/tests/with/pin-dir-crate-autodetect/test.py @@ -0,0 +1,36 @@ +""" +Test that `alr with --url` without explicit crate autodetects the target crate +and correctly adds the pinned dependency +""" + +import os +import re + +from drivers.alr import run_alr +from drivers.asserts import assert_match +from drivers.helpers import path_separator +from glob import glob + +# Retrieve a crate +run_alr('get', 'hello=1') +target = glob('hello*')[0] + +# Initialize a workspace +run_alr('init', '--bin', 'xxx') +os.chdir('xxx') + +# Add the directory as pinned crate, with autodetection (no crate given, +# inferred from the crate metadata found at target). +run_alr('with', '--use', '..' + path_separator() + target) + +# Verify that hello^1 is a new dependency and also that hello dependencies are +# in the solution. +p = run_alr('with', '--solve') +assert_match('''Dependencies \(direct\): + hello\^1\.0\.0 +.*Dependencies \(solution\): + hello=1\.0\.0 .* + libhello=1\.1\.0 .*''', # we skip non-relevant details + p.out, flags=re.S) + +print('SUCCESS') diff --git a/testsuite/tests/with/pin-dir-crate-autodetect/test.yaml b/testsuite/tests/with/pin-dir-crate-autodetect/test.yaml new file mode 100644 index 00000000..e0a82ba8 --- /dev/null +++ b/testsuite/tests/with/pin-dir-crate-autodetect/test.yaml @@ -0,0 +1,4 @@ +driver: python-script +indexes: + solver_index: + in_fixtures: true diff --git a/testsuite/tests/with/pin-dir-crate/test.py b/testsuite/tests/with/pin-dir-crate/test.py new file mode 100644 index 00000000..15522c6d --- /dev/null +++ b/testsuite/tests/with/pin-dir-crate/test.py @@ -0,0 +1,31 @@ +""" +Detect that a given folder to pin contains a crate and use its info +""" + +import os +import re + +from drivers.alr import run_alr +from drivers.asserts import assert_match +from drivers.helpers import path_separator +from glob import glob + +# Retrieve a crate +run_alr('get', 'hello=1') +target = glob('hello*')[0] + +# Initialize a workspace +run_alr('init', '--bin', 'xxx') +os.chdir('xxx') + +# Pin the hello crate as local dir dependency +run_alr('with', 'hello', '--use', '..' + path_separator() + target) + +# Verify that hello dependencies are detected and used +p = run_alr('with', '--solve') +assert_match('''.*Dependencies \(solution\): + hello=1\.0\.0 .* + libhello=1\.1\.0 .*''', # we skip non-relevant details + p.out, flags=re.S) + +print('SUCCESS') diff --git a/testsuite/tests/with/pin-dir-crate/test.yaml b/testsuite/tests/with/pin-dir-crate/test.yaml new file mode 100644 index 00000000..e0a82ba8 --- /dev/null +++ b/testsuite/tests/with/pin-dir-crate/test.yaml @@ -0,0 +1,4 @@ +driver: python-script +indexes: + solver_index: + in_fixtures: true diff --git a/testsuite/tests/with/pin-dir-mismatch/test.py b/testsuite/tests/with/pin-dir-mismatch/test.py new file mode 100644 index 00000000..9b75e33d --- /dev/null +++ b/testsuite/tests/with/pin-dir-mismatch/test.py @@ -0,0 +1,29 @@ +""" +Detect that a given folder to pin contains an unexpected crate +""" + +import os +import re + +from drivers.alr import run_alr +from drivers.asserts import assert_match +from drivers.helpers import path_separator +from glob import glob + +# Retrieve a crate +run_alr('get', 'hello=1') +target = glob('hello*')[0] + +# Initialize a workspace +run_alr('init', '--bin', 'xxx') +os.chdir('xxx') + +# Try to pin the hello crate as local dir dependency +p = run_alr('with', 'nothello', '--use', '..' + path_separator() + target, + complain_on_error=False) + +# Expected error +assert_match('.*crate mismatch: expected nothello but found hello at.*', p.out) +# skip test-specific path + +print('SUCCESS') diff --git a/testsuite/tests/with/pin-dir-mismatch/test.yaml b/testsuite/tests/with/pin-dir-mismatch/test.yaml new file mode 100644 index 00000000..e0a82ba8 --- /dev/null +++ b/testsuite/tests/with/pin-dir-mismatch/test.yaml @@ -0,0 +1,4 @@ +driver: python-script +indexes: + solver_index: + in_fixtures: true -- 2.39.5