From 6238ab1adfa2e26d9c3354532f567ef2a5033aa4 Mon Sep 17 00:00:00 2001 From: Alejandro R Mosteo Date: Thu, 7 Mar 2024 12:21:54 +0100 Subject: [PATCH] Remove `toolchain --install/--uninstall/--install-dir` (#1614) * Remove --[un]install, --install-dir * Patch tests * User changes * review of --install et al. removal * Fix test broken by new crate hash --- doc/user-changes.md | 21 +++ src/alire/alire-toolchains.adb | 22 +++ src/alr/alr-commands-toolchain.adb | 135 ++---------------- src/alr/alr-commands-toolchain.ads | 22 +-- testsuite/drivers/alr.py | 10 +- .../fixtures/crates/gnat_cross_1_bin.tgz | Bin 0 -> 180 bytes testsuite/fixtures/crates/gnat_native_bin.tgz | Bin 0 -> 173 bytes .../gnat_cross_1/gnat_cross_1-9999.0.0.toml | 4 +- .../gn/gnat_native/gnat_native-8888.0.0.toml | 4 +- .../dockerized/misc/default-cache/test.py | 2 +- .../tests/printenv/compiler-indirect/test.py | 2 +- .../tests/solver/compiler-installed/test.py | 20 ++- .../tests/solver/compiler-priorities/test.py | 26 +--- .../{custom_install_dir => alr-get}/test.py | 25 ++-- .../{custom_install_dir => alr-get}/test.yaml | 0 testsuite/tests/toolchain/alr-install/test.py | 39 +++++ .../tests/toolchain/alr-install/test.yaml | 4 + testsuite/tests/toolchain/basic/test.py | 46 +----- testsuite/tests/toolchain/directories/test.py | 7 +- .../tests/toolchain/select-dontmix/test.py | 5 - 20 files changed, 157 insertions(+), 237 deletions(-) create mode 100644 testsuite/fixtures/crates/gnat_cross_1_bin.tgz create mode 100644 testsuite/fixtures/crates/gnat_native_bin.tgz rename testsuite/tests/toolchain/{custom_install_dir => alr-get}/test.py (67%) rename testsuite/tests/toolchain/{custom_install_dir => alr-get}/test.yaml (100%) create mode 100644 testsuite/tests/toolchain/alr-install/test.py create mode 100644 testsuite/tests/toolchain/alr-install/test.yaml diff --git a/doc/user-changes.md b/doc/user-changes.md index 7c6cf32c..89b84aac 100644 --- a/doc/user-changes.md +++ b/doc/user-changes.md @@ -6,6 +6,27 @@ stay on top of `alr` new features. ## Release `2.0-dev` +### Deprecation of `toolchain --install/--uninstall/--install-dir` + +PR [#1614](https://github.com/alire-project/alire/pull/1614) + +Toolchain selection for use by Alire is still done by using +`alr toolchain --select`. + +For the installation of toolchains outside of Alire management (i.e., for +direct use with other tools, but not with Alire), the recommended +method now is to use `alr install`, e.g.: +``` +# Install to the default location, /.alire/bin +$ alr install gnat_native gprbuild + +# Install elsewhere +$ alr install --prefix=/path/to/installation gnat_native gprbuild +``` + +Removal of managed toolchains can be done by simply removing their folders +inside the toolchain cache (reported by `alr version`). + ### Cache and toolchain storage location overridding PR [#1593](https://github.com/alire-project/alire/pull/1593) diff --git a/src/alire/alire-toolchains.adb b/src/alire/alire-toolchains.adb index bb6520a7..45c6d215 100644 --- a/src/alire/alire-toolchains.adb +++ b/src/alire/alire-toolchains.adb @@ -487,6 +487,17 @@ package body Alire.Toolchains is end if; end; end if; + + -- Remove caching of external condition too for consistency + + if CLIC.Config.Defined (Config.DB.all, Tool_Key (Crate, For_Is_External)) + then + Trace.Debug + ("Unsetting " & Tool_Key (Crate, For_Is_External) & ": " + & CLIC.Config.Edit.Unset + (Config.Edit.Filepath (Level), + Tool_Key (Crate, For_Is_External))'Image); + end if; end Unconfigure; Available_Cached : Releases.Containers.Release_Set; @@ -569,6 +580,8 @@ package body Alire.Toolchains is Root.Platform_Properties) loop if not Release.Origin.Is_Index_Provided then + Trace.Debug ("Detected external toolchain release: " + & Release.Milestone.TTY_Image); Result.Include (Release); end if; end loop; @@ -579,6 +592,11 @@ package body Alire.Toolchains is Available_Cached := Result; Directories.Force_Delete (Dirty_Cache_Flag); + Trace.Debug ("Detected available tools:"); + for Rel of Result loop + Trace.Debug (" Tool: " & Rel.Milestone.TTY_Image); + end loop; + return Result; end Available; @@ -608,6 +626,10 @@ package body Alire.Toolchains is Trace.Detail ("Skipping installation of already available release: " & Release.Milestone.TTY_Image); return; + elsif Release.Origin.Kind in Origins.External then + Trace.Debug ("Skipping installation of external tool release: " + & Release.Milestone.TTY_Image); + return; end if; -- Deploy at the install location diff --git a/src/alr/alr-commands-toolchain.adb b/src/alr/alr-commands-toolchain.adb index e90503fc..ed1994a8 100644 --- a/src/alr/alr-commands-toolchain.adb +++ b/src/alr/alr-commands-toolchain.adb @@ -1,6 +1,4 @@ -with GNAT.Strings; use GNAT.Strings; - with AAA.Table_IO; with Alire.Config.Edit; @@ -39,19 +37,6 @@ package body Alr.Commands.Toolchain is Long_Switch => "--disable-assistant", Help => "Disable autorun of selection assistant"); - Define_Switch - (Config, - Cmd.Install'Access, - Switch => "-i", - Long_Switch => "--install", - Help => "Install one or more toolchain component"); - - Define_Switch - (Config, - Cmd.Install_Dir'Access, - Long_Switch => "--install-dir=", - Help => "Toolchain component(s) installation directory"); - Define_Switch (Config, Cmd.Local'Access, @@ -64,14 +49,7 @@ package body Alr.Commands.Toolchain is Cmd.S_Select'Access, Switch => "", Long_Switch => "--select", - Help => "Run the toolchain selection assistant"); - - Define_Switch - (Config, - Cmd.Uninstall'Access, - Switch => "-u", - Long_Switch => "--uninstall", - Help => "Uninstall one or more toolchain component"); + Help => "Select a toolchain or run the interactive assistant"); end Setup_Switches; ------------- @@ -243,27 +221,16 @@ package body Alr.Commands.Toolchain is -- And perform the actual installation - if Cmd.Install_Dir.all /= "" then - if Rel.Origin.Is_Index_Provided then - Toolchains.Deploy (Rel, Cmd.Install_Dir.all); - else - Reportaise_Command_Failed - ("Releases with external origins cannot be installed at " - & "specific locations; origin for " - & Rel.Milestone.TTY_Image & " is: " & Rel.Origin.Kind'Image); - end if; + if Rel.Origin.Is_Index_Provided then + Toolchains.Deploy (Rel); + elsif Rel.Origin.Is_System then + Origins.Deployers.Deploy (Rel).Assert; + elsif Rel.Origin.Kind = External then + Put_Info ("External tool needs no installation: " + & Rel.Milestone.TTY_Image); else - if Rel.Origin.Is_Index_Provided then - Toolchains.Deploy (Rel); - elsif Rel.Origin.Is_System then - Origins.Deployers.Deploy (Rel).Assert; - elsif Rel.Origin.Kind = External then - Put_Info ("External tool needs no installation: " - & Rel.Milestone.TTY_Image); - else - Raise_Checked_Error ("Unexpected release origin: " - & Rel.Origin.Kind'Image); - end if; + Raise_Checked_Error ("Unexpected release origin: " + & Rel.Origin.Kind'Image); end if; if Set_As_Default then @@ -347,53 +314,6 @@ package body Alr.Commands.Toolchain is Table.Print; end List; - --------------- - -- Uninstall -- - --------------- - - procedure Uninstall (Cmd : in out Command; Target : String) is - - ------------------ - -- Find_Version -- - ------------------ - - function Find_Version return String is - -- Obtain all installed releases for the crate; we will proceed if - -- only one exists. - Available : constant Alire.Releases.Containers.Release_Set := - Alire.Toolchains.Available.Satisfying - (Alire.Dependencies.New_Dependency - (Crate => Alire.To_Name (Target), - Versions => Semantic_Versioning.Extended.Any)); - begin - if Available.Is_Empty then - Reportaise_Command_Failed - ("Requested crate has no installed releases: " - & Alire.Utils.TTY.Name (Alire.To_Name (Target))); - elsif Available.Length not in 1 then - Reportaise_Command_Failed - ("Requested crate has several installed releases, " - & "please provide an exact target version"); - end if; - - return Available.First_Element.Milestone.Version.Image; - end Find_Version; - - begin - - -- If no version was given, find if only one is installed - - if not AAA.Strings.Contains (Target, "=") then - Uninstall (Cmd, Target & "=" & Find_Version); - return; - end if; - - -- Otherwise we proceed with a complete milestone - - Alire.Toolchains.Remove (Alire.Milestones.New_Milestone (Target)); - - end Uninstall; - ------------- -- Execute -- ------------- @@ -411,20 +331,7 @@ package body Alr.Commands.Toolchain is -- Validation - if Alire.Utils.Count_True - ((Cmd.Install, Cmd.S_Select, Cmd.Uninstall)) > 1 - then - Reportaise_Wrong_Arguments - ("The provided switches cannot be used simultaneously"); - end if; - - if (Cmd.Install or else Cmd.Uninstall) and then Args.Is_Empty then - Reportaise_Wrong_Arguments ("No release specified"); - end if; - - if not Args.Is_Empty and then - not (Cmd.Install or else Cmd.Uninstall or else Cmd.S_Select) - then + if not Args.Is_Empty and then not Cmd.S_Select then Reportaise_Wrong_Arguments ("Specify the action to perform with the crate"); end if; @@ -434,11 +341,6 @@ package body Alr.Commands.Toolchain is ("--local requires --select or --disable-assistant"); end if; - if Cmd.Install_Dir.all /= "" and then not Cmd.Install then - Reportaise_Wrong_Arguments - ("--install-dir is only compatible with --install action"); - end if; - -- Dispatch to subcommands if Cmd.Disable then @@ -491,21 +393,6 @@ package body Alr.Commands.Toolchain is & "command line."); end if; - elsif Cmd.Uninstall then - for Elt of Args loop - Uninstall (Cmd, Elt); - end loop; - - elsif Cmd.Install then - - Cmd.Auto_Update_Index; - - Alire.Toolchains.Detect_Externals; - - for Elt of Args loop - Install (Cmd, Elt, Name_Sets.Empty_Set, Set_As_Default => False); - end loop; - elsif not Cmd.Disable then -- When no command is specified, print the list Cmd.List; diff --git a/src/alr/alr-commands-toolchain.ads b/src/alr/alr-commands-toolchain.ads index 6967b80b..fe397871 100644 --- a/src/alr/alr-commands-toolchain.ads +++ b/src/alr/alr-commands-toolchain.ads @@ -1,7 +1,5 @@ with AAA.Strings; -private with GNAT.Strings; - package Alr.Commands.Toolchain is -- Installation of binary toolchain crates into the ${ALR_CONFIG}/cache @@ -22,9 +20,9 @@ package Alr.Commands.Toolchain is return AAA.Strings.Vector is (AAA.Strings.Empty_Vector .Append - ("Download toolchain elements, like" & " " & TTY.Emph ("GNAT") - & " and " & TTY.Emph ("gprbuild") & ", in the shared cache of the" - & " active configuration.") + ("Download and select toolchain elements, like" & " " + & TTY.Emph ("GNAT") & " and " & TTY.Emph ("gprbuild") + & ", for use by Alire.") .New_Line .Append ("Run it without arguments to get a list of downloaded tools.") @@ -38,10 +36,6 @@ package Alr.Commands.Toolchain is & " argument will skip the assistant and set the release as the" & " default.") .New_Line - .Append - ("Specify --install/--uninstall and one or more crates name with" - & " optional version set to make available or remove a tool.") - .New_Line .Append ("Run `" & TTY.Terminal ("alr help toolchains") & "` for further " & "information about toolchain management and use.") @@ -54,22 +48,18 @@ package Alr.Commands.Toolchain is overriding function Short_Description (Cmd : Command) return String - is ("Manage Alire-provided toolchains"); + is ("Select Alire's preferred toolchain"); overriding function Usage_Custom_Parameters (Cmd : Command) return String - is ("[-u|--uninstall] [-i|--install crate[version set]] |" - & " --select [--local] [releases] [--disable-assistant]"); + is ("--select [--local] [releases] [--disable-assistant]"); private type Command is new Commands.Command with record - Disable : aliased Boolean := False; - Install : aliased Boolean := False; - Install_Dir : aliased GNAT.Strings.String_Access := null; + Disable : aliased Boolean := False; -- Disable assistant Local : aliased Boolean := False; S_Select : aliased Boolean := False; - Uninstall : aliased Boolean := False; end record; end Alr.Commands.Toolchain; diff --git a/testsuite/drivers/alr.py b/testsuite/drivers/alr.py index a4d0c5fd..b01d1859 100644 --- a/testsuite/drivers/alr.py +++ b/testsuite/drivers/alr.py @@ -607,4 +607,12 @@ def external_compiler_version() -> str: p = run_alr("toolchain") # Capture version - return re.search("gnat_external ([0-9.]+)", p.out, re.MULTILINE).group(1) \ No newline at end of file + return re.search("gnat_external ([0-9.]+)", p.out, re.MULTILINE).group(1) + +def unselect_compiler(): + """ + Leave compiler configuration as if "None" was selected by the user in the + assistant. + """ + run_alr("config", "--global", "--unset", "toolchain.use.gnat") + run_alr("config", "--global", "--unset", "toolchain.external.gnat") \ No newline at end of file diff --git a/testsuite/fixtures/crates/gnat_cross_1_bin.tgz b/testsuite/fixtures/crates/gnat_cross_1_bin.tgz new file mode 100644 index 0000000000000000000000000000000000000000..71bd83f67b5caf73a3a52111c4189ba770b89b43 GIT binary patch literal 180 zcmb2|=3oE==C_wGay1!<9Q$Z{YTkmfW$D#28wFN!vzos6c)8m_C&+{O<^SE58)R?r z-46?^oIZE= 1 and \ - re.search(config_path_re(crate), paths[0]), \ + re.search(config_path_re(crate, dir), paths[0]), \ "Unexpected contents: " + str(paths) except: print(f"erroneous regex was: {config_path_re(crate)}") print(f"erroneous path was: {paths[0]}") raise +# Ensure destinations exist +os.makedirs(install_dir) +os.makedirs(install_dir_2) + # First we test installation of one component -run_alr("toolchain", "--install", "gnat_native", "--install-dir", install_dir) +os.chdir(install_dir) +run_alr("get", "gnat_native") check_content("gnat_native", install_dir) # We now test installation of two components -run_alr("toolchain", "--install", "gnat_native", "gnat_cross_1", - "--install-dir", install_dir_2) +os.chdir(install_dir_2) +run_alr("get", "gnat_native") +run_alr("get", "gnat_cross_1") check_content("gnat_native", install_dir_2) check_content("gnat_cross_1", install_dir_2) + print('SUCCESS') diff --git a/testsuite/tests/toolchain/custom_install_dir/test.yaml b/testsuite/tests/toolchain/alr-get/test.yaml similarity index 100% rename from testsuite/tests/toolchain/custom_install_dir/test.yaml rename to testsuite/tests/toolchain/alr-get/test.yaml diff --git a/testsuite/tests/toolchain/alr-install/test.py b/testsuite/tests/toolchain/alr-install/test.py new file mode 100644 index 00000000..b9a49de3 --- /dev/null +++ b/testsuite/tests/toolchain/alr-install/test.py @@ -0,0 +1,39 @@ +""" +Check folders when installing binary compiler crates at a custom location +through `alr install` +""" + +import os + +from drivers.alr import run_alr +from drivers.helpers import contents + +install_dir_1 = os.path.join (os.getcwd(), "custom_install_").replace("\\", "/") + "1" +install_dir_2 = os.path.join (os.getcwd(), "custom_install_").replace("\\", "/") + "2" + + +def check_content(file, dir): + paths = contents(dir) + assert os.path.isfile(os.path.join(dir, "bin", file)), \ + "Unexpected contents: " + str(paths) + + +# Ensure destinations exist +os.makedirs(install_dir_1) +os.makedirs(install_dir_2) + +# First we test installation of one component +os.chdir(install_dir_1) +run_alr("install", "gnat_native", f"--prefix={install_dir_1}") +check_content("gnat_native.exe", install_dir_1) + +# We now test installation of two components +os.chdir(install_dir_2) +run_alr("install", "gnat_native", f"--prefix={install_dir_2}") +run_alr("install", "gnat_cross_1", f"--prefix={install_dir_2}") + +check_content("gnat_native.exe", install_dir_2) +check_content("gnat_cross_1.exe", install_dir_2) + + +print('SUCCESS') diff --git a/testsuite/tests/toolchain/alr-install/test.yaml b/testsuite/tests/toolchain/alr-install/test.yaml new file mode 100644 index 00000000..8185c03b --- /dev/null +++ b/testsuite/tests/toolchain/alr-install/test.yaml @@ -0,0 +1,4 @@ +driver: python-script +indexes: + toolchain_index: + in_fixtures: true diff --git a/testsuite/tests/toolchain/basic/test.py b/testsuite/tests/toolchain/basic/test.py index 6edcb087..1fac692e 100644 --- a/testsuite/tests/toolchain/basic/test.py +++ b/testsuite/tests/toolchain/basic/test.py @@ -1,5 +1,5 @@ """ -Check basic use: manual install, uninstall, and listing of toolchains +Check basic use: manual install and listing of toolchains """ import re @@ -8,61 +8,27 @@ from drivers.alr import run_alr from drivers.asserts import assert_eq, assert_match # Install a precise version of gnat -run_alr("toolchain", "--install", "gnat_native=7777") +run_alr("toolchain", "--select", "gnat_native=7777") -# Verify that it appears as available +# Verify that it appears as default p = run_alr("toolchain") -assert_match(".*gnat_native.*" + re.escape("7777.0.0") + ".*Available", +assert_match(".*gnat_native.*" + re.escape("7777.0.0") + ".*Default", p.out) # Also that the external compiler is detected and always available assert_match(".*gnat_external.*Available", p.out) -# Also that the external compiler cannot be uninstalled (and short switch) -p = run_alr("toolchain", "-u", "gnat_external", complain_on_error=False) -assert_match(".*Only regular releases deployed through Alire can be removed.*", - p.out) - -# Verify that it can be uninstalled -run_alr("toolchain", "--uninstall", "gnat_native=7777") -p = run_alr("toolchain") -assert "gnat_native" not in p.out, "Unexpected output" - # Repeat install but without giving a version, and one should be autoidentified # as the newest available version -p = run_alr("toolchain", "-i", "gnat_native", quiet=False) # Test short switch +p = run_alr("toolchain", "--select", "gnat_native", quiet=False) assert_match(".*Requested crate resolved as gnat_native=8888.0.0.*", p.out) # Verify that we can explicitly install a second version for the same target -run_alr("toolchain", "--install", "gnat_native=7777") +run_alr("toolchain", "--select", "gnat_native=7777") p = run_alr("toolchain") assert_match(".*gnat_native.*" + re.escape("7777.0.0") + ".*Available", p.out) -# Verify that uninstalling without specifying version isn't allowed when there -# are two matching crates installed. -p = run_alr("toolchain", "--uninstall", "gnat_native", - complain_on_error=False) -assert_match(".*Requested crate has several installed releases.*", - p.out) - -# Uninstall successfully by giving a version -run_alr("toolchain", "--uninstall", "gnat_native=8888") -# Now we can uninstall without specifying the version of the remaining release -run_alr("toolchain", "--uninstall", "gnat_native") - - -# Verify that two components can be installed at once -run_alr("toolchain", "--install", "gnat_native", "gnat_cross_1") -p = run_alr("toolchain") -assert_match(".*gnat_native.*" + re.escape("8888.0.0") + ".*Available", - p.out) -assert_match(".*gnat_cross_1.*" + re.escape("9999.0.0") + ".*Available", - p.out) - -# Uninstall both components -run_alr("toolchain", "--uninstall", "gnat_native", "gnat_cross_1") - print('SUCCESS') diff --git a/testsuite/tests/toolchain/directories/test.py b/testsuite/tests/toolchain/directories/test.py index 808d97e2..cc6d305c 100644 --- a/testsuite/tests/toolchain/directories/test.py +++ b/testsuite/tests/toolchain/directories/test.py @@ -37,14 +37,9 @@ def check_content(crate): # First we test manual installation -run_alr("toolchain", "--install", "gnat_native") +run_alr("toolchain", "--select", "gnat_native") check_content("gnat_native") -# Uninstall the compiler and verify absence -run_alr("toolchain", "--uninstall", "gnat_native", quiet=False) -paths = contents(cache_dir, "gnat_native") -assert len(paths) == 0, "Unexpected contents: " + str(paths) - # Require the external compiler and verify no trace appears in install folder # nor in local folder init_local_crate("xxx") diff --git a/testsuite/tests/toolchain/select-dontmix/test.py b/testsuite/tests/toolchain/select-dontmix/test.py index 74c55564..671e951c 100644 --- a/testsuite/tests/toolchain/select-dontmix/test.py +++ b/testsuite/tests/toolchain/select-dontmix/test.py @@ -62,9 +62,4 @@ assert_match(".*gnat_native 8888.0.0 Default.*", p.out) assert_match(".*gnat_external [\d\s.]+ Available.*", p.out) # The external compiler must be still detected as available, even if unselected -# Finally, note that installing without selecting is not affected by checks, -# as these are not setting the default toolchain to be used, but merely making -# available these tools as alternatives. -run_alr("toolchain", "--install", "gnat_external", "gprbuild=8888") - print('SUCCESS') -- 2.39.5