From 74196dabc3807c185b8d51b7ad23ce57be2c928f Mon Sep 17 00:00:00 2001 From: Alejandro R Mosteo Date: Mon, 4 Mar 2024 11:40:31 +0100 Subject: [PATCH 01/17] Document more configuration details (#1611) --- doc/configuration.md | 33 +++++++++++++++++++++++-------- doc/getting-started.md | 44 ++++++++++++++++++++++++++++-------------- 2 files changed, 55 insertions(+), 22 deletions(-) diff --git a/doc/configuration.md b/doc/configuration.md index f28839ead..e7f6ac930 100644 --- a/doc/configuration.md +++ b/doc/configuration.md @@ -14,7 +14,7 @@ "10.1" or "true". Extra type checking is used for built-in options (see below). Specific config options: - + - `--list` List configuration options - `--show-origin` Show origin of configuration values in `--list` - `--get` Print value of a configuration option @@ -22,17 +22,17 @@ - `--unset` Unset a configuration option - `--global` Set and Unset global configuration instead of the local one - `--builtins-doc` Print Markdown list of built-in configuration options - + Examples: - `alr config --global --set my_option option_value` - - Will set a configuration option with the key `my_option` and the string + + Will set a configuration option with the key `my_option` and the string value `option_value` in the global configuration file. - `alr config --get my_option` - - Will print the value configuration option `my_option` if it is defined, + + Will print the value configuration option `my_option` if it is defined, otherwise the command fails. @@ -62,6 +62,23 @@ The built-ins also have a short description to document their type and usage. ## Built-ins list -Here is the list of `Alire` built-in configuration options. You can also get -this from `alr` with `alr help config`. +You can get the list of options recognized by `alr` with `alr help config`, +including their default values and a short explanation of their effects. + +## Relocating your configuration + +By default, `alr` stores its global configuration at `/.config/alire`. You can use any other location by setting in the +environment the variable `ALR_CONFIG=`, or by +using the global `-c` switch: `alr -c `. + +Using a pristine default configuration can be useful to isolate the source of +errors by ensuring that a misconfiguration is not at play. + +## Inspecting your configuration +These commands may help you in identifying Alire configuration and environment: +- `alr config --list` will show all configuration options in effect. +- `alr version` will print many relevant bits of information about the current + `alr` environment. +- `alr --version` will just print the version number and exit. \ No newline at end of file diff --git a/doc/getting-started.md b/doc/getting-started.md index f8d248a03..0c0709e55 100644 --- a/doc/getting-started.md +++ b/doc/getting-started.md @@ -10,14 +10,14 @@ repository](https://github.com/alire-project/alire/releases). On Linux, `Alire` is simply provided in an archive. Once the archive is extracted you have to add `alr` in the environment `PATH` . -This may be done for the duration of a terminal session by running the command below: +This may be done for the duration of a terminal session by running the command below: ```bash $ export PATH="/bin/:$PATH" ``` Those wanting to keep this path permanently in their `PATH` environment may do so by pasting the above command into the `.profile` file of their user's account. -Alire provides GNAT toolchains hosted on x86-64 for Linux. If those toolchains do not -work for you, or if you are on another host architecture like ARM, you have the option +Alire provides GNAT toolchains hosted on x86-64 for Linux. If those toolchains do not +work for you, or if you are on another host architecture like ARM, you have the option to look at the GNAT toolchains from the Linux distribution. ## `alr` on Windows @@ -25,15 +25,23 @@ to look at the GNAT toolchains from the Linux distribution. On Windows an installer is provided. The installer will create a shortcut to start `PowerShell` with `Alire` in the environment `PATH`. -The first time you run `alr` the program will ask if you want to install -[msys2](https://www.msys2.org/). This is recommended as `alr` will use `msys2` +The first time you run `alr`, the program +will ask if you want to install +[msys2](https://www.msys2.org/) (except in the cases listed below). This is recommended as `alr` will use `msys2` to automatically install required tools such as `git` or `make` that you would otherwise have to install manually. `msys2` will also provide external libraries required by some projects in the Alire index, allowing you to build more projects out of the box. -Alire provides GNAT toolchains hosted on x86-64 for Windows. Those toolchains -should work for all cases, if not, let us know. +`msys2` will not be installed +- when running `alr config`, to allow uninterrupted configuration, and configuration + of `msys2` location (see `alr help config`), or +- when you already have a msys2 installation in your PATH (more precisely, if `pacman` + is found in your PATH.) + - In this case, `alr` will reuse your existing installation. + +Alire provides GNAT toolchains hosted on x86-64 for Windows. Those toolchains +should work for all cases; if not, let us know. ## `alr` on macOS @@ -44,14 +52,14 @@ Once the archive is extracted you have to add `alr` in the environment `PATH`: $ export PATH="/bin/:$PATH" ``` -If you try to run it on recent versions of macOS, you will get a popup saying -`“alr” cannot be opened because the developer cannot be verified.` and inviting +If you try to run it on recent versions of macOS, you will get a popup saying +`“alr” cannot be opened because the developer cannot be verified.` and inviting you to move it to the bin. The way round this is to remove the quarantine attribute, ```console $ xattr -d com.apple.quarantine bin/alr ``` -Alire provides GNAT toolchains hosted on x86-64 for macOS. If those toolchains do not +Alire provides GNAT toolchains hosted on x86-64 for macOS. If those toolchains do not work for you, or if you are on another host architecture like the Apple M1, you have the option to look at the GNAT toolchains from the community. @@ -276,10 +284,18 @@ to print the build environment: ## Troubleshooting -By default `alr` is quite terse and will hide the output of subprocesses, -mostly reporting in case of failure. If you hit any problem, increasing -verbosity (`-v` or even `-vv`) is usually enough to get an idea of the root of -the problem. Additionally, `-d` will show tracebacks of exceptions. +If you hit any problem, increasing verbosity (`-v` or even `-vv`) is usually +enough to get an idea of the root of the problem. Additionally, `-d` will show +tracebacks of exceptions. + +Subprocess output is shown by default (you can silence it, and anything else +not an error) with `-q`, which enables quiet mode. Any subprocess that exist +abnormally will be reported, including its invocation arguments. + +If you suspect your configuration may be the source of some problem, please +check our section on [Configuration](configuration.md), and in particular how +to use a [default pristine +configuration](configuration.md#Relocating-your-configuration) ## Running tests From a65f0360b3d7410e0f015969b38ba08e0fa14f4f Mon Sep 17 00:00:00 2001 From: Alejandro R Mosteo Date: Mon, 4 Mar 2024 11:40:53 +0100 Subject: [PATCH 02/17] Don't try to obtain the parent dir of '/' in tmp cleanup (#1609) --- src/alire/alire-directories.adb | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/alire/alire-directories.adb b/src/alire/alire-directories.adb index 8deea106d..fffdb9c07 100644 --- a/src/alire/alire-directories.adb +++ b/src/alire/alire-directories.adb @@ -1,5 +1,6 @@ with AAA.Directories; +with Ada.Directories.Hierarchical_File_Names; with Ada.Numerics.Discrete_Random; with Ada.Real_Time; with Ada.Unchecked_Conversion; @@ -749,11 +750,21 @@ package body Alire.Directories is -- Remove temp dir if empty to keep things tidy, and avoid modifying -- lots of tests, but only when within <>/alire/tmp - if Ada.Directories.Simple_Name (Parent (Parent (This.Filename))) = - Paths.Working_Folder_Inside_Root - then - AAA.Directories.Remove_Folder_If_Empty (Parent (This.Filename)); - end if; + begin + if not Adirs.Hierarchical_File_Names.Is_Root_Directory_Name + (Parent (This.Filename)) + and then + Adirs.Simple_Name (Parent (Parent (This.Filename))) = + Paths.Working_Folder_Inside_Root + then + AAA.Directories.Remove_Folder_If_Empty (Parent (This.Filename)); + end if; + exception + when Use_Error => + -- May be raised by Adirs.Containing_Directory + Trace.Debug ("Failed to identify location of temp file: " + & This.Filename); + end; exception when E : others => From dc46eb61582d0ab82bdfdba089809f6c2b7058f7 Mon Sep 17 00:00:00 2001 From: Alejandro R Mosteo Date: Mon, 4 Mar 2024 11:41:15 +0100 Subject: [PATCH 03/17] Override distro via config key (#1610) --- src/alire/alire-config-builtins.ads | 16 ++++++++- src/alire/alire-config-checks.adb | 20 +++++++++++ src/alire/alire-config-checks.ads | 9 +++++ src/alire/alire-platforms-current.ads | 36 ++++++++++++++++--- src/alire/alire-warnings.adb | 14 ++++++++ src/alire/alire-warnings.ads | 9 +++++ .../tests/config/distro-override/test.py | 23 ++++++++++++ .../tests/config/distro-override/test.yaml | 3 ++ 8 files changed, 124 insertions(+), 6 deletions(-) create mode 100644 src/alire/alire-config-checks.adb create mode 100644 src/alire/alire-config-checks.ads create mode 100644 testsuite/tests/config/distro-override/test.py create mode 100644 testsuite/tests/config/distro-override/test.yaml diff --git a/src/alire/alire-config-builtins.ads b/src/alire/alire-config-builtins.ads index b77adaaba..745d0573b 100644 --- a/src/alire/alire-config-builtins.ads +++ b/src/alire/alire-config-builtins.ads @@ -1,3 +1,5 @@ +with Alire.Config.Checks; + package Alire.Config.Builtins is subtype Builtin is Builtin_Option; @@ -32,12 +34,24 @@ package Alire.Config.Builtins is & "location inside the global cache. When false, " & "dependencies are sandboxed in each workspace."); + -- DISTRIBUTION + Distribution_Disable_Detection : constant Builtin := New_Builtin (Key => "distribution.disable_detection", Def => False, Help => "If true, Alire will report an unknown distribution and will not" - & " attempt to use the system package manager."); + & " attempt to use the system package manager. Takes precedence over " + & " distribution.override."); + + Distribution_Override : constant Builtin := New_Builtin + (Key => "distribution.override", + Kind => Cfg_String, + Check => Checks.Valid_Distro'Access, + Def => "", + Help => + "Distribution name to be used instead of autodetection. No effect if " + & "distribution.disable_detection is True."); -- EDITOR diff --git a/src/alire/alire-config-checks.adb b/src/alire/alire-config-checks.adb new file mode 100644 index 000000000..b86edbfdc --- /dev/null +++ b/src/alire/alire-config-checks.adb @@ -0,0 +1,20 @@ +with AAA.Enum_Tools; + +with Alire.Platforms; + +package body Alire.Config.Checks is + + function Is_Valid is + new AAA.Enum_Tools.Is_Valid (Alire.Platforms.Known_Distributions); + + ------------------ + -- Valid_Distro -- + ------------------ + + function Valid_Distro (Key : CLIC.Config.Config_Key; + Value : TOML.TOML_Value) + return Boolean + is (Value.Kind in TOML.TOML_String + and then Is_Valid (Value.As_String)); + +end Alire.Config.Checks; diff --git a/src/alire/alire-config-checks.ads b/src/alire/alire-config-checks.ads new file mode 100644 index 000000000..a5f971ec3 --- /dev/null +++ b/src/alire/alire-config-checks.ads @@ -0,0 +1,9 @@ +with TOML; + +package Alire.Config.Checks is + + function Valid_Distro (Key : CLIC.Config.Config_Key; + Value : TOML.TOML_Value) + return Boolean; + +end Alire.Config.Checks; diff --git a/src/alire/alire-platforms-current.ads b/src/alire/alire-platforms-current.ads index 897f93d39..1327c369a 100644 --- a/src/alire/alire-platforms-current.ads +++ b/src/alire/alire-platforms-current.ads @@ -1,8 +1,12 @@ +private with AAA.Enum_Tools; + +private with Alire.Config.Builtins; limited with Alire.Environment; private with Alire.OS_Lib.Subprocess; private with Alire.Platforms.Common; with Alire.Properties; private with Alire.Properties.Platform; +private with Alire.Warnings; private with System; @@ -50,8 +54,9 @@ package Alire.Platforms.Current is Disable_Distribution_Detection : Boolean := False with Atomic; function Distribution return Platforms.Distributions; - -- Cooked distribution that may return Unknown if detection was disabled - -- via config. + -- Cooked distribution that may return Unknown if detection was + -- disabled via config, or a different distribution if config key + -- distribution.override is set. function Distribution_Is_Known return Boolean is (Platforms."/=" (Distribution, Platforms.Distribution_Unknown)); @@ -70,14 +75,35 @@ package Alire.Platforms.Current is private + function Is_Valid_Distro is + new AAA.Enum_Tools.Is_Valid (Platforms.Known_Distributions); + + function Return_With_Warning is + new Warnings.Warn_With_Result (Platforms.Distributions); + ------------------ -- Distribution -- ------------------ function Distribution return Platforms.Distributions - is (if Disable_Distribution_Detection - then Platforms.Distribution_Unknown - else Detected_Distribution); + is ( + -- Disabled detection + if Disable_Distribution_Detection then + Platforms.Distribution_Unknown + + -- Overridden detection + elsif Config.Builtins.Distribution_Override.Get /= "" then + (if Is_Valid_Distro (Config.Builtins.Distribution_Override.Get) then + Distributions'Value (Config.Builtins.Distribution_Override.Get) + else + Return_With_Warning + ("Invalid distribution override: " + & Config.Builtins.Distribution_Override.Get, + Result => Platforms.Distribution_Unknown)) + + -- Regular detection + else + Detected_Distribution); ----------------------- -- Host_Architecture -- diff --git a/src/alire/alire-warnings.adb b/src/alire/alire-warnings.adb index 63209d40a..e203bc419 100644 --- a/src/alire/alire-warnings.adb +++ b/src/alire/alire-warnings.adb @@ -26,4 +26,18 @@ package body Alire.Warnings is function Already_Warned (Id : Warning_Id) return Boolean is (Already_Emitted.Contains (String (Id))); + ---------------------- + -- Warn_With_Result -- + ---------------------- + + function Warn_With_Result (Text : String; + Result : Returned; + Level : Trace.Levels := Trace.Warning) + return Returned + is + begin + Trace.Log (Text, Level); + return Result; + end Warn_With_Result; + end Alire.Warnings; diff --git a/src/alire/alire-warnings.ads b/src/alire/alire-warnings.ads index 9b9b5779d..904665cee 100644 --- a/src/alire/alire-warnings.ads +++ b/src/alire/alire-warnings.ads @@ -14,6 +14,15 @@ package Alire.Warnings with Preelaborate is function Already_Warned (Id : Warning_Id) return Boolean; -- Says if a warning has been already emitted in the current run + generic + type Returned (<>) is private; + function Warn_With_Result (Text : String; + Result : Returned; + Level : Trace.Levels := Trace.Warning) + return Returned; + -- Return Result after printing Text; for use in expressions. See instances + -- in Alire.Warnings.Typed. + ------------------ -- Defined Ids -- ------------------ diff --git a/testsuite/tests/config/distro-override/test.py b/testsuite/tests/config/distro-override/test.py new file mode 100644 index 000000000..30be498c5 --- /dev/null +++ b/testsuite/tests/config/distro-override/test.py @@ -0,0 +1,23 @@ +""" +Verify that distro overridding works as intended +""" + +from drivers.alr import run_alr, distro_is_known +from drivers.asserts import assert_match + +# Overriding distro detection. We force Debian as our tests run in Ubuntu and +# many other distros so it is only giving a false positive on Debian. +run_alr("config", "--global", + "--set", "distribution.override", "debian") + +assert_match(".*distribution:[^\n]*DEBIAN", + run_alr("version").out) + +# Disabling distro detection takes precedence +run_alr("config", "--global", + "--set", "distribution.disable_detection", "true") + +assert_match(".*distribution:[^\n]*DISTRIBUTION_UNKNOWN", + run_alr("version").out) + +print('SUCCESS') diff --git a/testsuite/tests/config/distro-override/test.yaml b/testsuite/tests/config/distro-override/test.yaml new file mode 100644 index 000000000..872fc1274 --- /dev/null +++ b/testsuite/tests/config/distro-override/test.yaml @@ -0,0 +1,3 @@ +driver: python-script +indexes: + basic_index: {} From 6238ab1adfa2e26d9c3354532f567ef2a5033aa4 Mon Sep 17 00:00:00 2001 From: Alejandro R Mosteo Date: Thu, 7 Mar 2024 12:21:54 +0100 Subject: [PATCH 04/17] 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 7c6cf32c9..89b84aac9 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 bb6520a75..45c6d2150 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 e90503fcd..ed1994a8e 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 6967b80b7..fe397871a 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 a4d0c5fdf..b01d18595 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 000000000..b9a49de37 --- /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 000000000..8185c03b5 --- /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 6edcb087b..1fac692ee 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.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 808d97e20..cc6d305c2 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 74c555642..671e951c1 100644 --- a/testsuite/tests/toolchain/select-dontmix/test.py +++ b/testsuite/tests/toolchain/select-dontmix/test.py @@ -62,9 +62,4 @@ 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') From 155b6a467cfac94d8f7fa3e8e6c5e741400e0181 Mon Sep 17 00:00:00 2001 From: Jeremy Grosser Date: Fri, 8 Mar 2024 01:33:33 -0800 Subject: [PATCH 05/17] Remove .md extension from internal documentation links (#893) (#1616) --- doc/catalog-format-spec.md | 2 +- doc/getting-started.md | 4 ++-- doc/policies.md | 2 +- doc/publishing.md | 6 +++--- doc/user-changes.md | 14 +++++++------- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/doc/catalog-format-spec.md b/doc/catalog-format-spec.md index fb065179b..196aa5ca3 100644 --- a/doc/catalog-format-spec.md +++ b/doc/catalog-format-spec.md @@ -1169,7 +1169,7 @@ project My_Crate is Dependencies in Alire are used also to deal with compiler versions and cross-compilers. Also related is the information on toolchains available in the -[Toolchain management](./toolchains.md) document or via `alr help toolchains`. +[Toolchain management](toolchains) document or via `alr help toolchains`. ### Excluding compiler versions diff --git a/doc/getting-started.md b/doc/getting-started.md index 0c0709e55..b9a3b831c 100644 --- a/doc/getting-started.md +++ b/doc/getting-started.md @@ -293,9 +293,9 @@ not an error) with `-q`, which enables quiet mode. Any subprocess that exist abnormally will be reported, including its invocation arguments. If you suspect your configuration may be the source of some problem, please -check our section on [Configuration](configuration.md), and in particular how +check our section on [Configuration](configuration), and in particular how to use a [default pristine -configuration](configuration.md#Relocating-your-configuration) +configuration](configuration#Relocating-your-configuration) ## Running tests diff --git a/doc/policies.md b/doc/policies.md index c42f85f36..c326d70a2 100644 --- a/doc/policies.md +++ b/doc/policies.md @@ -60,7 +60,7 @@ major/minor/patch/build version changes), but not modified. - Tests, demos, examples, etc., can be provided in nested crates so they can be conveniently used locally when needed without causing extra build load on clients. See the documentation on - [local pins](catalog-format-spec.md#using-pins-for-crate-testing) for + [local pins](catalog-format-spec#using-pins-for-crate-testing) for details. - The manifests of these nested crates need not to be published to the diff --git a/doc/publishing.md b/doc/publishing.md index 0e68f6871..108f73465 100644 --- a/doc/publishing.md +++ b/doc/publishing.md @@ -57,7 +57,7 @@ crate and version it contains. A file contains the description of a release, with other metadata. The complete specification of such TOML files is available in this -[document](catalog-format-spec.md). +[document](catalog-format-spec). ## New crates and releases @@ -88,7 +88,7 @@ release of `alr`. Each crate is "owned" by a list of maintainers, provided with the `maintainers-logins` property of the crate file. After the initial submission, -which will be manually approved (see the [policies](policies.md) for details), +which will be manually approved (see the [policies](policies) for details), the maintainers of a crate are the only people allowed to submit new releases or metadata modifications to the corresponding crate. @@ -100,7 +100,7 @@ Other checks your submission will go through are: ## Best practices -See the section on [best practices](policies.md#best-practices) for crates +See the section on [best practices](policies#best-practices) for crates before publishing your first release. ## Detailed steps diff --git a/doc/user-changes.md b/doc/user-changes.md index 89b84aac9..de4f4900e 100644 --- a/doc/user-changes.md +++ b/doc/user-changes.md @@ -153,8 +153,8 @@ be reviewed and merged manually. This can now be done with `alr publish PR [#1406](https://github.com/alire-project/alire/pull/1406) -A pending submission can be closed with `alr publish --cancel - --reason `. +A pending submission can be closed with +`alr publish --cancel --reason `. ### Track user's index submissions with `alr publish --status` @@ -697,8 +697,8 @@ crate_1.var2 = true crate_2.var1 = "Debug" ``` -Check more examples and details in the catalog specification section ["Using -configuration"](https://github.com/mosteo/alire/blob/master/doc/catalog-format-spec.md#using-crate-configuration). +Check more examples and details in the catalog specification section +[Using configuration](catalog-format-spec#using-crate-configuration). ## Release `1.0` @@ -823,7 +823,7 @@ to be submitted to the community index via pull request. An upload link is provided for convenience that can be used to create this pull request. Complete information about this feature is available in the updated -[Publishing](publishing.md) page. +[Publishing](publishing) page. Other features of the assistant are that, in the local mode, a branch or tag can be specified to pinpoint a commit, and that the test build of the crate can @@ -847,8 +847,8 @@ files, executables, maintainers, etc.). The manifest internal format has been simplified by eliminating the possibility of multiple releases from its contents, which removes some nesting, and removing or making optional some fields that only make sense at the time of -publishing a crate to some index. Check the [catalog-format-spec.md] file for -details. +publishing a crate to some index. Check the [catalog-format-spec](catalog-format-spec) +file for details. The `alire` directory continues to exist, and it is used to store the source code of dependencies, local configuration and backup files. It can be safely From ef276cced948f345c48d2bc42b6d87b2e6e71c73 Mon Sep 17 00:00:00 2001 From: Fabien Chouteau Date: Sat, 9 Mar 2024 14:16:05 +0100 Subject: [PATCH 06/17] New `alr settings` command to replace `alr config` (#1617) This change is introduced to tackle the confusion between the configuration of the Alire commands and operations, and the configuration of crates. `alr config` is still available and should work as before with the exception of a deprecation warning message. --- doc/configuration.md | 84 ------- doc/getting-started.md | 11 +- doc/settings.md | 84 +++++++ doc/user-changes.md | 11 + src/alire/alire-platforms-current.ads | 4 +- src/alire/alire-toml_index.adb | 4 +- src/alire/alire.adb | 12 +- src/alire/alire.ads | 2 +- src/alr/alr-commands-config.adb | 226 +---------------- src/alr/alr-commands-config.ads | 36 +-- src/alr/alr-commands-settings.adb | 235 ++++++++++++++++++ src/alr/alr-commands-settings.ads | 49 ++++ src/alr/alr-commands-topics-aliases.ads | 4 +- src/alr/alr-commands.adb | 6 +- .../config/shared-deps-profiles/test.py | 2 +- testsuite/drivers/alr.py | 18 +- testsuite/drivers/builds.py | 4 +- testsuite/drivers/driver/docker_nested.py | 4 +- testsuite/drivers/driver/python_script.py | 2 +- testsuite/drivers/helpers.py | 2 +- testsuite/tests/alias/basic/test.py | 2 +- .../tests/build_profile/last_profile/test.py | 8 +- .../misc/failed-auto-update/test.py | 6 +- testsuite/tests/index/auto-update/test.py | 2 +- testsuite/tests/index/branch-mismatch/test.py | 2 +- .../tests/index/local-index-not-found/test.py | 2 +- .../tests/index/old-compat-version/test.py | 2 +- .../tests/init/interactive-inputs/test.py | 2 +- .../tests/init/user-input-validation/test.py | 6 +- .../tests/install/default-location/test.py | 2 +- testsuite/tests/misc/git-ungit/test.py | 2 +- .../publish/submit-request-cancel/test.py | 4 +- .../tests/{config => settings}/basics/test.py | 42 ++-- .../{config => settings}/basics/test.yaml | 0 .../cache-relocation/test.py | 12 +- .../cache-relocation/test.yaml | 0 .../community-disable/test.py | 0 .../community-disable/test.yaml | 0 .../distro-disable/test.py | 2 +- .../distro-disable/test.yaml | 0 .../distro-override/test.py | 4 +- .../distro-override/test.yaml | 0 .../early-loading/test.py | 6 +- .../early-loading/test.yaml | 0 .../my_index/he/hello/hello-1.0.0.toml | 0 .../my_index/he/hello/hello-1.0.1.toml | 0 .../my_index/index.toml | 0 .../my_index/li/libhello/libhello-1.0.0.toml | 0 .../missing-config-default/test.py | 0 .../missing-config-default/test.yaml | 0 .../relative_config_path/test.py | 2 +- .../relative_config_path/test.yaml | 0 .../{config => settings}/shared-deps/test.py | 0 .../shared-deps/test.yaml | 0 .../tests/solver/compiler-selected/test.py | 2 +- .../tests/toolchain/select-defaults/test.py | 2 +- .../toolchain/select-while-missing/test.py | 2 +- testsuite/tests/workflows/edit/test.py | 6 +- 58 files changed, 496 insertions(+), 424 deletions(-) delete mode 100644 doc/configuration.md create mode 100644 doc/settings.md create mode 100644 src/alr/alr-commands-settings.adb create mode 100644 src/alr/alr-commands-settings.ads rename testsuite/tests/{config => settings}/basics/test.py (68%) rename testsuite/tests/{config => settings}/basics/test.yaml (100%) rename testsuite/tests/{config => settings}/cache-relocation/test.py (65%) rename testsuite/tests/{config => settings}/cache-relocation/test.yaml (100%) rename testsuite/tests/{config => settings}/community-disable/test.py (100%) rename testsuite/tests/{config => settings}/community-disable/test.yaml (100%) rename testsuite/tests/{config => settings}/distro-disable/test.py (88%) rename testsuite/tests/{config => settings}/distro-disable/test.yaml (100%) rename testsuite/tests/{config => settings}/distro-override/test.py (91%) rename testsuite/tests/{config => settings}/distro-override/test.yaml (100%) rename testsuite/tests/{config => settings}/early-loading/test.py (77%) rename testsuite/tests/{config => settings}/early-loading/test.yaml (100%) rename testsuite/tests/{config => settings}/missing-config-default/my_index/he/hello/hello-1.0.0.toml (100%) rename testsuite/tests/{config => settings}/missing-config-default/my_index/he/hello/hello-1.0.1.toml (100%) rename testsuite/tests/{config => settings}/missing-config-default/my_index/index.toml (100%) rename testsuite/tests/{config => settings}/missing-config-default/my_index/li/libhello/libhello-1.0.0.toml (100%) rename testsuite/tests/{config => settings}/missing-config-default/test.py (100%) rename testsuite/tests/{config => settings}/missing-config-default/test.yaml (100%) rename testsuite/tests/{config => settings}/relative_config_path/test.py (88%) rename testsuite/tests/{config => settings}/relative_config_path/test.yaml (100%) rename testsuite/tests/{config => settings}/shared-deps/test.py (100%) rename testsuite/tests/{config => settings}/shared-deps/test.yaml (100%) diff --git a/doc/configuration.md b/doc/configuration.md deleted file mode 100644 index e7f6ac930..000000000 --- a/doc/configuration.md +++ /dev/null @@ -1,84 +0,0 @@ -# Configuration - -`alr` provides a generic mechanism to `list`, `get`, `set` or -`unset` configuration options, either in a local or global context. - - Option names (keys) can use lowercase and uppercase alphanumeric characters - from the Latin alphabet. Underscores and dashes can also be used except as - the first or last character. Dot '.' is used to specify sub-categories, e.g. - 'user.name' or 'user.email'. - - Option values can be integers, floats, Booleans (true or false), or strings. The - type detection is automatic, e.g. 10 is integer, 10.1 is float, true is - Boolean. You can force a value to be a string by using double-quotes, e.g. - "10.1" or "true". Extra type checking is used for built-in options (see below). - - Specific config options: - - - `--list` List configuration options - - `--show-origin` Show origin of configuration values in `--list` - - `--get` Print value of a configuration option - - `--set` Set a configuration option - - `--unset` Unset a configuration option - - `--global` Set and Unset global configuration instead of the local one - - `--builtins-doc` Print Markdown list of built-in configuration options - - Examples: - - - `alr config --global --set my_option option_value` - - Will set a configuration option with the key `my_option` and the string - value `option_value` in the global configuration file. - - - `alr config --get my_option` - - Will print the value configuration option `my_option` if it is defined, - otherwise the command fails. - - -## Custom configuration options - -The `alr config` command allows you to set and get any combination of -configuration option `key` and `value`. You can use this feature to store your -own project related configuration, or implement tools that integrate in an -`Alire` context. However, be careful when naming custom configuration options -because `Alire` may use the same `key` in the future. We recommend using a -distinctive sub-category name, for instance: `my_project.my_config_option`. - -## Built-in configuration options - -The options used by `Alire` are pre-defined and documented. We call these -options `built-ins`. - -A built-in option has a pre-defined type that is checked when setting or -loading a configuration file. For instance: - - - `alr config --global --set user.email "This is not an email address"` - -will fail because the value tentatively assigned to `user.email` is not an -email address. - -The built-ins also have a short description to document their type and usage. - -## Built-ins list - -You can get the list of options recognized by `alr` with `alr help config`, -including their default values and a short explanation of their effects. - -## Relocating your configuration - -By default, `alr` stores its global configuration at `/.config/alire`. You can use any other location by setting in the -environment the variable `ALR_CONFIG=`, or by -using the global `-c` switch: `alr -c `. - -Using a pristine default configuration can be useful to isolate the source of -errors by ensuring that a misconfiguration is not at play. - -## Inspecting your configuration - -These commands may help you in identifying Alire configuration and environment: -- `alr config --list` will show all configuration options in effect. -- `alr version` will print many relevant bits of information about the current - `alr` environment. -- `alr --version` will just print the version number and exit. \ No newline at end of file diff --git a/doc/getting-started.md b/doc/getting-started.md index b9a3b831c..3044bdc6d 100644 --- a/doc/getting-started.md +++ b/doc/getting-started.md @@ -34,8 +34,8 @@ libraries required by some projects in the Alire index, allowing you to build more projects out of the box. `msys2` will not be installed -- when running `alr config`, to allow uninterrupted configuration, and configuration - of `msys2` location (see `alr help config`), or +- when running `alr settings`, to allow uninterrupted configuration, and setting + of `msys2` location (see `alr help settings`), or - when you already have a msys2 installation in your PATH (more precisely, if `pacman` is found in your PATH.) - In this case, `alr` will reuse your existing installation. @@ -292,10 +292,9 @@ Subprocess output is shown by default (you can silence it, and anything else not an error) with `-q`, which enables quiet mode. Any subprocess that exist abnormally will be reported, including its invocation arguments. -If you suspect your configuration may be the source of some problem, please -check our section on [Configuration](configuration), and in particular how -to use a [default pristine -configuration](configuration#Relocating-your-configuration) +If you suspect your settings may be the source of some problem, please check +our section on [Settings](setting), and in particular how to use a [default +pristine settings](settings#Relocating-your-settings) ## Running tests diff --git a/doc/settings.md b/doc/settings.md new file mode 100644 index 000000000..262950539 --- /dev/null +++ b/doc/settings.md @@ -0,0 +1,84 @@ +# Settings + +`alr` provides a generic mechanism to `list`, `get`, `set` or +`unset` settings options, either in a local or global context. + + Option names (keys) can use lowercase and uppercase alphanumeric characters + from the Latin alphabet. Underscores and dashes can also be used except as + the first or last character. Dot '.' is used to specify sub-categories, e.g. + 'user.name' or 'user.email'. + + Option values can be integers, floats, Booleans (true or false), or strings. The + type detection is automatic, e.g. 10 is integer, 10.1 is float, true is + Boolean. You can force a value to be a string by using double-quotes, e.g. + "10.1" or "true". Extra type checking is used for built-in options (see below). + + Specific settings options: + + - `--list` List settings options + - `--show-origin` Show origin of settings values in `--list` + - `--get` Print value of a setting option + - `--set` Set a setting option + - `--unset` Unset a setting option + - `--global `Set and Unset global settings instead of the local one + - `--builtins-doc` Print Markdown list of built-in settings + + Examples: + + - `alr settings --global --set my_option option_value` + + Will set a setting option with the key `my_option` and the string + value `option_value` in the global settings file. + + - `alr settings --get my_option` + + Will print the value setting option `my_option` if it is defined, + otherwise the command fails. + + +## Custom settings options + +The `alr settings` command allows you to set and get any combination of option +`key` and `value`. You can use this feature to store your own project related +settings, or implement tools that integrate in an `Alire` context. However, be +careful when naming custom settings options because `Alire` may use the same +`key` in the future. We recommend using a distinctive sub-category name, for +instance: `my_project.my_option`. + +## Built-in settings options + +The options used by `Alire` are pre-defined and documented. We call these +options `built-ins`. + +A built-in option has a pre-defined type that is checked when setting or +loading. For instance: + + - `alr settings --global --set user.email "This is not an email address"` + +will fail because the value tentatively assigned to `user.email` is not an +email address. + +The built-ins also have a short description to document their type and usage. + +## Built-ins list + +You can get the list of options recognized by `alr` with `alr help settings`, +including their default values and a short explanation of their effects. + +## Relocating your settings + +By default, `alr` stores its global settings at `/.config/alire`. +You can use any other location by setting in the environment the variable +`ALR_CONFIG=`, or by using the global `-c` +switch: `alr -c `. + +Using pristine default settings can be useful to isolate the source of errors +by ensuring that a misconfiguration is not at play. + +## Inspecting your settings + +These commands may help you in identifying Alire settings and environment: +- `alr settings --list` will show all settings options in effect. +- `alr version` will print many relevant bits of information about the current + `alr` environment. +- `alr --version` will just print the version number and exit. diff --git a/doc/user-changes.md b/doc/user-changes.md index de4f4900e..4e83940f1 100644 --- a/doc/user-changes.md +++ b/doc/user-changes.md @@ -6,6 +6,17 @@ stay on top of `alr` new features. ## Release `2.0-dev` +### + +PR [1617](https://github.com/alire-project/alire/pull/1617) + +The `alr settings` command replaces the `alr config` command. This change is +introduced to tackle the confusion between the configuration of the Alire +commands and operations, and the configuration of crates. + +`alr config` is still available and should work as before with the exception of +a deprecation warning message. + ### Deprecation of `toolchain --install/--uninstall/--install-dir` PR [#1614](https://github.com/alire-project/alire/pull/1614) diff --git a/src/alire/alire-platforms-current.ads b/src/alire/alire-platforms-current.ads index 1327c369a..913b311ab 100644 --- a/src/alire/alire-platforms-current.ads +++ b/src/alire/alire-platforms-current.ads @@ -40,8 +40,8 @@ package Alire.Platforms.Current is procedure Initialize; -- Do any initialization that is necessary for this platform. This is - -- called as soon as we know the user is not running `alr config`, as we - -- want to allow the opportunity to configure things without triggering + -- called as soon as we know the user is not running `alr settings`, as + -- we want to allow the opportunity to configure things without triggering -- this initialization. -------------------------------- diff --git a/src/alire/alire-toml_index.adb b/src/alire/alire-toml_index.adb index 969b19fda..54de246b2 100644 --- a/src/alire/alire-toml_index.adb +++ b/src/alire/alire-toml_index.adb @@ -130,7 +130,7 @@ package body Alire.TOML_Index is & TTY.Emph (Alire.Index.Branch_Kind) & "' but your community index branch is '" & TTY.Emph (Local) & "'", - Disable_Config => Config.Builtins.Warning_Old_Index.Key); + Disable_Setting => Config.Builtins.Warning_Old_Index.Key); Suggest_Update := True; end if; end Compare_Branches; @@ -189,7 +189,7 @@ package body Alire.TOML_Index is & "' version (" & Loading_Index_Version.Image & ") is older than the newest supported by alr (" & Alire.Index.Version.Image & ")", - Disable_Config => + Disable_Setting => Config.Builtins.Warning_Old_Index.Key); Suggest_Update := True; elsif not Alire.Index.Valid_Versions.Contains (Loading_Index_Version) diff --git a/src/alire/alire.adb b/src/alire/alire.adb index c205b615b..88857118b 100644 --- a/src/alire/alire.adb +++ b/src/alire/alire.adb @@ -117,9 +117,9 @@ package body Alire is -- Put_Warning -- ----------------- - procedure Put_Warning (Text : String; - Level : Trace.Levels := Warning; - Disable_Config : String := "") + procedure Put_Warning (Text : String; + Level : Trace.Levels := Warning; + Disable_Setting : String := "") is Prefix : constant String := (if Level = Warning @@ -128,10 +128,10 @@ package body Alire is "Warning: ")); begin Trace.Log (Prefix & Text, Level); - if Disable_Config /= "" then + if Disable_Setting /= "" then Trace.Log (Prefix - & "You can disable this warning with configuration key '" - & TTY.Emph (Disable_Config) & "'", + & "You can disable this warning with settings key '" + & TTY.Emph (Disable_Setting) & "'", Level); end if; end Put_Warning; diff --git a/src/alire/alire.ads b/src/alire/alire.ads index 857141962..2bccc8017 100644 --- a/src/alire/alire.ads +++ b/src/alire/alire.ads @@ -287,7 +287,7 @@ package Alire with Preelaborate is procedure Put_Warning (Text : String; Level : Trace.Levels := Warning; - Disable_Config : String := ""); + Disable_Setting : String := ""); -- Prepend Text with a yellow "⚠", or "Warning: " if no color/tty. If -- Disable_setting /= "", append a line informing about how to disable -- this warning. diff --git a/src/alr/alr-commands-config.adb b/src/alr/alr-commands-config.adb index ec395ab15..c2a20253b 100644 --- a/src/alr/alr-commands-config.adb +++ b/src/alr/alr-commands-config.adb @@ -1,9 +1,4 @@ -with Alire.Config; -with Alire.Config.Edit; -with Alire.Root; - -with CLIC.Config.Info; -with CLIC.Config.Edit; +with Alire.Warnings; package body Alr.Commands.Config is @@ -15,221 +10,12 @@ package body Alr.Commands.Config is procedure Execute (Cmd : in out Command; Args : AAA.Strings.Vector) is - Enabled : Natural := 0; - - Lvl : constant Alire.Config.Level := (if Cmd.Global - then Alire.Config.Global - else Alire.Config.Local); begin - - -- Check no multi-action - Enabled := Enabled + (if Cmd.List then 1 else 0); - Enabled := Enabled + (if Cmd.Get then 1 else 0); - Enabled := Enabled + (if Cmd.Set then 1 else 0); - Enabled := Enabled + (if Cmd.Unset then 1 else 0); - Enabled := Enabled + (if Cmd.Builtins_Doc then 1 else 0); - - if Enabled > 1 then - Reportaise_Wrong_Arguments ("Specify at most one subcommand"); - end if; - - if Enabled = 0 then - -- The default command is --list - Cmd.List := True; - end if; - - if Cmd.Show_Origin and then not Cmd.List then - Reportaise_Wrong_Arguments - ("--show-origin only valid with --list"); - end if; - - if Cmd.Builtins_Doc then - Alire.Config.Edit.Print_Builtins_Doc; - return; - end if; - - if not Cmd.Global and then not Alire.Root.Current.Is_Valid then - Reportaise_Command_Failed - ("Not in an Alire project directory." & - " Use --global to edit the global configuration."); - end if; - - if Cmd.List then - case Args.Count is - when 0 => - Trace.Always - (CLIC.Config.Info.List - (Alire.Config.DB.all, - Filter => ".*", - Show_Origin => Cmd.Show_Origin).Flatten (ASCII.LF)); - when 1 => - Trace.Always - (CLIC.Config.Info.List - (Alire.Config.DB.all, - Filter => Args.First_Element, - Show_Origin => Cmd.Show_Origin).Flatten (ASCII.LF)); - when others => - Reportaise_Wrong_Arguments - ("List expects at most one argument"); - end case; - - elsif Cmd.Get then - if Args.Count /= 1 then - Reportaise_Wrong_Arguments ("Unset expects one argument"); - end if; - - if not CLIC.Config.Is_Valid_Config_Key (Args.First_Element) then - Reportaise_Wrong_Arguments ("Invalid configuration key '" & - Args.First_Element & "'"); - end if; - - if Alire.Config.DB.Defined (Args.First_Element) then - Trace.Always (Alire.Config.DB.Get_As_String (Args.First_Element)); - else - Reportaise_Command_Failed ("Configuration key '" & - Args.First_Element & - "' is not defined"); - end if; - elsif Cmd.Set then - if Args.Count /= 2 then - Reportaise_Wrong_Arguments ("Set expects two arguments"); - end if; - - declare - Key : constant String := Args.Element (1); - Val : constant String := Args.Element (2); - begin - - if not CLIC.Config.Is_Valid_Config_Key (Key) then - Reportaise_Wrong_Arguments ("Invalid configuration key '" & - Key & "'"); - end if; - - -- Check explicitly for booleans to store the proper TOML type - -- regardless of the capitalization used by the user. - if Is_Boolean (Val) then - Alire.Config.Edit.Set_Boolean - (Lvl, - Key, Boolean'Value (Val), - Check => Alire.Config.Edit.Valid_Builtin'Access); - else - Alire.Config.Edit.Set - (Lvl, - Key, Val, - Check => Alire.Config.Edit.Valid_Builtin'Access); - end if; - end; - - elsif Cmd.Unset then - if Args.Count /= 1 then - Reportaise_Wrong_Arguments ("Unset expects one argument"); - end if; - - declare - Key : constant String := Args.Element (1); - begin - if not CLIC.Config.Is_Valid_Config_Key (Key) then - Reportaise_Wrong_Arguments ("Invalid configuration key '" & - Key & "'"); - end if; - - if not CLIC.Config.Edit.Unset - (Alire.Config.Edit.Filepath (Lvl), Key) - then - Reportaise_Command_Failed ("Cannot unset config key"); - end if; - end; - end if; + Alire.Warnings.Warn_Once ("`alr " & Command_Name & "` is " & + CLIC.TTY.Error ("deprecated") & ". " & + "Please use `alr " & Settings.Command_Name & + "` instead."); + Parent (Cmd).Execute (Args); end Execute; - ---------------------- - -- Long_Description -- - ---------------------- - - overriding - function Long_Description (Cmd : Command) - return AAA.Strings.Vector is - (AAA.Strings.Empty_Vector - .Append ("Provides a command line interface to the Alire configuration" & - " option files.") - .New_Line - .Append ("Option names (keys) can use lowercase and uppercase" & - " alphanumeric characters") - .Append ("from the Latin alphabet. Underscores and dashes can also be" & - " used except as") - .Append ("first or last character. Dot '.' is used to specify" & - " sub-categories, e.g.") - .Append ("'user.name' or 'user.email'.") - .New_Line - - .Append ("Option values can be integers, float, Boolean (true or" & - " false) or strings. The") - .Append ("type detection is automatic, e.g. 10 is integer, 10.1 is" & - " float, true is") - .Append ("Boolean. You can force a value to be set a string by using" & - " double-quotes, e.g.") - .Append ("""10.1"" or ""true"". Extra type checking is used for" & - " built-in options (see below).") - .New_Line - .Append ("Built-in configuration options:") - .New_Line - .Append (Alire.Config.Edit.Builtins_Info)); - - -------------------- - -- Setup_Switches -- - -------------------- - - overriding - procedure Setup_Switches - (Cmd : in out Command; - Config : in out CLIC.Subcommand.Switches_Configuration) - is - use CLIC.Subcommand; - begin - Define_Switch - (Config => Config, - Output => Cmd.List'Access, - Long_Switch => "--list", - Help => "List configuration options"); - - Define_Switch - (Config => Config, - Output => Cmd.Show_Origin'Access, - Long_Switch => "--show-origin", - Help => "Show origin of configuration values in --list"); - - Define_Switch - (Config => Config, - Output => Cmd.Get'Access, - Long_Switch => "--get", - Help => "Print value of a configuration option"); - - Define_Switch - (Config => Config, - Output => Cmd.Set'Access, - Long_Switch => "--set", - Help => "Set a configuration option"); - - Define_Switch - (Config => Config, - Output => Cmd.Unset'Access, - Long_Switch => "--unset", - Help => "Unset a configuration option"); - - Define_Switch - (Config => Config, - Output => Cmd.Global'Access, - Long_Switch => "--global", - Help => "Set and Unset global configuration instead" & - " of the local one"); - - Define_Switch - (Config => Config, - Output => Cmd.Builtins_Doc'Access, - Long_Switch => "--builtins-doc", - Help => - "Print Markdown list of built-in configuration options"); - - end Setup_Switches; - end Alr.Commands.Config; diff --git a/src/alr/alr-commands-config.ads b/src/alr/alr-commands-config.ads index 32d3101c5..9ebbb83ba 100644 --- a/src/alr/alr-commands-config.ads +++ b/src/alr/alr-commands-config.ads @@ -1,8 +1,10 @@ with AAA.Strings; +with Alr.Commands.Settings; package Alr.Commands.Config is - type Command is new Commands.Command with private; + subtype Parent is Alr.Commands.Settings.Command; + type Command is new Parent with private; Command_Name : constant String := "config"; @@ -15,35 +17,21 @@ package Alr.Commands.Config is Args : AAA.Strings.Vector); overriding - function Long_Description (Cmd : Command) - return AAA.Strings.Vector; - - overriding - procedure Setup_Switches - (Cmd : in out Command; - Config : in out CLIC.Subcommand.Switches_Configuration); + function Short_Description (Cmd : Command) return String + is (CLIC.TTY.Error ("Deprecated command") & ". " & + "Please use `alr " & Settings.Command_Name & "` instead."); overriding - function Short_Description (Cmd : Command) return String - is ("List, Get, Set or Unset configuration options"); + function Long_Description (Cmd : Command) + return AAA.Strings.Vector + is (AAA.Strings.Empty_Vector); overriding - function Usage_Custom_Parameters (Cmd : Command) return String is - ("[--list] [--show-origin] [key_regex] |" & - " --get |" & - " --set |" & - " --unset "); + function Usage_Custom_Parameters (Cmd : Command) return String + is (""); private - type Command is new Commands.Command with record - Show_Origin : aliased Boolean := False; - List : aliased Boolean := False; - Get : aliased Boolean := False; - Set : aliased Boolean := False; - Unset : aliased Boolean := False; - Global : aliased Boolean := False; - Builtins_Doc : aliased Boolean := False; - end record; + type Command is new Parent with null record; end Alr.Commands.Config; diff --git a/src/alr/alr-commands-settings.adb b/src/alr/alr-commands-settings.adb new file mode 100644 index 000000000..932bd8027 --- /dev/null +++ b/src/alr/alr-commands-settings.adb @@ -0,0 +1,235 @@ +with Alire.Config; +with Alire.Config.Edit; +with Alire.Root; + +with CLIC.Config.Info; +with CLIC.Config.Edit; + +package body Alr.Commands.Settings is + + ------------- + -- Execute -- + ------------- + + overriding + procedure Execute (Cmd : in out Command; + Args : AAA.Strings.Vector) + is + Enabled : Natural := 0; + + Lvl : constant Alire.Config.Level := (if Cmd.Global + then Alire.Config.Global + else Alire.Config.Local); + begin + + -- Check no multi-action + Enabled := Enabled + (if Cmd.List then 1 else 0); + Enabled := Enabled + (if Cmd.Get then 1 else 0); + Enabled := Enabled + (if Cmd.Set then 1 else 0); + Enabled := Enabled + (if Cmd.Unset then 1 else 0); + Enabled := Enabled + (if Cmd.Builtins_Doc then 1 else 0); + + if Enabled > 1 then + Reportaise_Wrong_Arguments ("Specify at most one subcommand"); + end if; + + if Enabled = 0 then + -- The default command is --list + Cmd.List := True; + end if; + + if Cmd.Show_Origin and then not Cmd.List then + Reportaise_Wrong_Arguments + ("--show-origin only valid with --list"); + end if; + + if Cmd.Builtins_Doc then + Alire.Config.Edit.Print_Builtins_Doc; + return; + end if; + + if not Cmd.Global and then not Alire.Root.Current.Is_Valid then + Reportaise_Command_Failed + ("Not in an Alire project directory." & + " Use --global to edit the global settings."); + end if; + + if Cmd.List then + case Args.Count is + when 0 => + Trace.Always + (CLIC.Config.Info.List + (Alire.Config.DB.all, + Filter => ".*", + Show_Origin => Cmd.Show_Origin).Flatten (ASCII.LF)); + when 1 => + Trace.Always + (CLIC.Config.Info.List + (Alire.Config.DB.all, + Filter => Args.First_Element, + Show_Origin => Cmd.Show_Origin).Flatten (ASCII.LF)); + when others => + Reportaise_Wrong_Arguments + ("List expects at most one argument"); + end case; + + elsif Cmd.Get then + if Args.Count /= 1 then + Reportaise_Wrong_Arguments ("Unset expects one argument"); + end if; + + if not CLIC.Config.Is_Valid_Config_Key (Args.First_Element) then + Reportaise_Wrong_Arguments ("Invalid setting key '" & + Args.First_Element & "'"); + end if; + + if Alire.Config.DB.Defined (Args.First_Element) then + Trace.Always (Alire.Config.DB.Get_As_String (Args.First_Element)); + else + Reportaise_Command_Failed ("Setting key '" & + Args.First_Element & + "' is not defined"); + end if; + elsif Cmd.Set then + if Args.Count /= 2 then + Reportaise_Wrong_Arguments ("Set expects two arguments"); + end if; + + declare + Key : constant String := Args.Element (1); + Val : constant String := Args.Element (2); + begin + + if not CLIC.Config.Is_Valid_Config_Key (Key) then + Reportaise_Wrong_Arguments ("Invalid setting key '" & + Key & "'"); + end if; + + -- Check explicitly for booleans to store the proper TOML type + -- regardless of the capitalization used by the user. + if Is_Boolean (Val) then + Alire.Config.Edit.Set_Boolean + (Lvl, + Key, Boolean'Value (Val), + Check => Alire.Config.Edit.Valid_Builtin'Access); + else + Alire.Config.Edit.Set + (Lvl, + Key, Val, + Check => Alire.Config.Edit.Valid_Builtin'Access); + end if; + end; + + elsif Cmd.Unset then + if Args.Count /= 1 then + Reportaise_Wrong_Arguments ("Unset expects one argument"); + end if; + + declare + Key : constant String := Args.Element (1); + begin + if not CLIC.Config.Is_Valid_Config_Key (Key) then + Reportaise_Wrong_Arguments ("Invalid setting key '" & + Key & "'"); + end if; + + if not CLIC.Config.Edit.Unset + (Alire.Config.Edit.Filepath (Lvl), Key) + then + Reportaise_Command_Failed ("Cannot unset setting key"); + end if; + end; + end if; + end Execute; + + ---------------------- + -- Long_Description -- + ---------------------- + + overriding + function Long_Description (Cmd : Command) + return AAA.Strings.Vector is + (AAA.Strings.Empty_Vector + .Append ("Provides a command line interface to the Alire settings" & + " files.") + .New_Line + .Append ("Settings names (keys) can use lowercase and uppercase" & + " alphanumeric characters") + .Append ("from the Latin alphabet. Underscores and dashes can also be" & + " used except as") + .Append ("first or last character. Dot '.' is used to specify" & + " sub-categories, e.g.") + .Append ("'user.name' or 'user.email'.") + .New_Line + + .Append ("Option values can be integers, float, Boolean (true or" & + " false) or strings. The") + .Append ("type detection is automatic, e.g. 10 is integer, 10.1 is" & + " float, true is") + .Append ("Boolean. You can force a value to be set a string by using" & + " double-quotes, e.g.") + .Append ("""10.1"" or ""true"". Extra type checking is used for" & + " built-in options (see below).") + .New_Line + .Append ("Built-in settings:") + .New_Line + .Append (Alire.Config.Edit.Builtins_Info)); + + -------------------- + -- Setup_Switches -- + -------------------- + + overriding + procedure Setup_Switches + (Cmd : in out Command; + Config : in out CLIC.Subcommand.Switches_Configuration) + is + use CLIC.Subcommand; + begin + Define_Switch + (Config => Config, + Output => Cmd.List'Access, + Long_Switch => "--list", + Help => "List settings options"); + + Define_Switch + (Config => Config, + Output => Cmd.Show_Origin'Access, + Long_Switch => "--show-origin", + Help => "Show origin of settings values in --list"); + + Define_Switch + (Config => Config, + Output => Cmd.Get'Access, + Long_Switch => "--get", + Help => "Print value of a setting option"); + + Define_Switch + (Config => Config, + Output => Cmd.Set'Access, + Long_Switch => "--set", + Help => "Set a setting option"); + + Define_Switch + (Config => Config, + Output => Cmd.Unset'Access, + Long_Switch => "--unset", + Help => "Unset a setting option"); + + Define_Switch + (Config => Config, + Output => Cmd.Global'Access, + Long_Switch => "--global", + Help => "Set and Unset global settings instead" & + " of the local one"); + + Define_Switch + (Config => Config, + Output => Cmd.Builtins_Doc'Access, + Long_Switch => "--builtins-doc", + Help => + "Print Markdown list of built-in settings"); + + end Setup_Switches; + +end Alr.Commands.Settings; diff --git a/src/alr/alr-commands-settings.ads b/src/alr/alr-commands-settings.ads new file mode 100644 index 000000000..b42a7e19f --- /dev/null +++ b/src/alr/alr-commands-settings.ads @@ -0,0 +1,49 @@ +with AAA.Strings; + +package Alr.Commands.Settings is + + type Command is new Commands.Command with private; + + Command_Name : constant String := "settings"; + + overriding + function Name (Cmd : Command) return CLIC.Subcommand.Identifier + is (Command_Name); + + overriding + procedure Execute (Cmd : in out Command; + Args : AAA.Strings.Vector); + + overriding + function Long_Description (Cmd : Command) + return AAA.Strings.Vector; + + overriding + procedure Setup_Switches + (Cmd : in out Command; + Config : in out CLIC.Subcommand.Switches_Configuration); + + overriding + function Short_Description (Cmd : Command) return String + is ("List, Get, Set or Unset Alire settings options"); + + overriding + function Usage_Custom_Parameters (Cmd : Command) return String is + ("[--list] [--show-origin] [key_regex] |" & + " --get |" & + " --set |" & + " --unset "); + +private + + type Command is new Commands.Command with record + Show_Origin : aliased Boolean := False; + List : aliased Boolean := False; + Get : aliased Boolean := False; + Set : aliased Boolean := False; + Unset : aliased Boolean := False; + Global : aliased Boolean := False; + Builtins_Doc : aliased Boolean := False; + end record; + +end Alr.Commands.Settings; diff --git a/src/alr/alr-commands-topics-aliases.ads b/src/alr/alr-commands-topics-aliases.ads index a572b944f..e9c481753 100644 --- a/src/alr/alr-commands-topics-aliases.ads +++ b/src/alr/alr-commands-topics-aliases.ads @@ -18,10 +18,10 @@ package Alr.Commands.Topics.Aliases is function Content (This : Topic) return AAA.Strings.Vector is (AAA.Strings.Empty_Vector .Append ("Command aliases can be defined in local or global ") - .Append ("configuration.") + .Append ("settings.") .New_Line .Append ("For example the following command:") - .Append ("""$ alr config --set --global alias.graph 'show --graph'""") + .Append ("""$ alr settings --set --global alias.graph 'show --graph'""") .Append ("Defines a global alias for the 'show' command with a ") .Append ("'--graph' switch.") .New_Line diff --git a/src/alr/alr-commands.adb b/src/alr/alr-commands.adb index 5ad5b79ad..96a77f623 100644 --- a/src/alr/alr-commands.adb +++ b/src/alr/alr-commands.adb @@ -36,6 +36,7 @@ with Alr.Commands.Printenv; with Alr.Commands.Publish; with Alr.Commands.Run; with Alr.Commands.Search; +with Alr.Commands.Settings; with Alr.Commands.Show; with Alr.Commands.Test; with Alr.Commands.Toolchain; @@ -523,12 +524,14 @@ package body Alr.Commands is begin if Sub_Cmd.What_Command /= Config.Command_Name + and then + Sub_Cmd.What_Command /= Settings.Command_Name then Alire.Platforms.Current.Initialize; Trace.Debug ("Platform-specific initialization done."); else Trace.Debug - ("Platform-specific initialization skipped (alr config)."); + ("Platform-specific initialization skipped (alr settings)."); end if; exception when Sub_Cmd.Error_No_Command => @@ -661,6 +664,7 @@ begin -- Commands -- Sub_Cmd.Register ("General", new Sub_Cmd.Builtin_Help); + Sub_Cmd.Register ("General", new Settings.Command); Sub_Cmd.Register ("General", new Config.Command); Sub_Cmd.Register ("General", new Install.Command); Sub_Cmd.Register ("General", new Toolchain.Command); diff --git a/testsuite/deprecated/config/shared-deps-profiles/test.py b/testsuite/deprecated/config/shared-deps-profiles/test.py index fde5a9aab..b742050f5 100644 --- a/testsuite/deprecated/config/shared-deps-profiles/test.py +++ b/testsuite/deprecated/config/shared-deps-profiles/test.py @@ -11,7 +11,7 @@ # Enable sharing of dependencies os.mkdir(deps_dir) -run_alr("config", "--global", "--set", "dependencies.dir", +run_alr("settings", "--global", "--set", "dependencies.dir", os.path.abspath(deps_dir)) # Create a crate with a dependency diff --git a/testsuite/drivers/alr.py b/testsuite/drivers/alr.py index b01d18595..809e968fc 100644 --- a/testsuite/drivers/alr.py +++ b/testsuite/drivers/alr.py @@ -49,18 +49,18 @@ def prepare_env(config_dir, env): if platform.system() == "Windows": # Disable msys inadvertent installation - run_alr("-c", config_dir, "config", "--global", + run_alr("-c", config_dir, "settings", "--global", "--set", "msys2.do_not_install", "true") # And configure the one set up in the environment so it is used by # tests that need it. - run_alr("-c", config_dir, "config", "--global", + run_alr("-c", config_dir, "settings", "--global", "--set", "msys2.install_dir", os.path.join(os.environ.get("LocalAppData"), "alire", "msys64")) # Disable autoconfig of the community index, to prevent unintended use of # it in tests, besides the overload of fetching it - run_alr("-c", config_dir, "config", "--global", + run_alr("-c", config_dir, "settings", "--global", "--set", "index.auto_community", "false") # Disable selection of toolchain to preserve older behavior. Tests that @@ -69,21 +69,21 @@ def prepare_env(config_dir, env): # Disable warning on old index, to avoid having to update index versions # when they're still compatible. - run_alr("-c", config_dir, "config", "--global", + run_alr("-c", config_dir, "settings", "--global", "--set", "warning.old_index", "false") # Disable shared dependencies (keep old pre-2.0 behavior) not to break lots # of tests. The post-2.0 behavior will have its own tests. - run_alr("-c", config_dir, "config", "--global", + run_alr("-c", config_dir, "settings", "--global", "--set", "dependencies.shared", "false") # Disable index auto-updates, which is not expected by most tests - run_alr("-c", config_dir, "config", "--global", + run_alr("-c", config_dir, "settings", "--global", "--set", "index.auto_update", "0") # If distro detection is disabled via environment, configure so in alr if "ALIRE_TESTSUITE_DISABLE_DISTRO" in env: - run_alr("-c", config_dir, "config", "--global", + run_alr("-c", config_dir, "settings", "--global", "--set", "distribution.disable_detection", "true") @@ -614,5 +614,5 @@ 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 + run_alr("settings", "--global", "--unset", "toolchain.use.gnat") + run_alr("settings", "--global", "--unset", "toolchain.external.gnat") diff --git a/testsuite/drivers/builds.py b/testsuite/drivers/builds.py index bfbb5fbc5..09424b508 100644 --- a/testsuite/drivers/builds.py +++ b/testsuite/drivers/builds.py @@ -20,7 +20,7 @@ def enable_shared() -> None: """ Enable shared builds """ - run_alr("config", "--global", "--set", "dependencies.shared", "true") + run_alr("settings", "--global", "--set", "dependencies.shared", "true") def are_shared() -> bool: @@ -28,7 +28,7 @@ def are_shared() -> bool: Return True if shared builds are enabled """ try: - return run_alr("config", "--global", "--get", + return run_alr("settings", "--global", "--get", "dependencies.shared").out.strip().lower() == "true" except: return False diff --git a/testsuite/drivers/driver/docker_nested.py b/testsuite/drivers/driver/docker_nested.py index cce50544e..642552e0f 100644 --- a/testsuite/drivers/driver/docker_nested.py +++ b/testsuite/drivers/driver/docker_nested.py @@ -43,7 +43,7 @@ def main(): os.environ["ALR_PATH"] = "/usr/bin/alr" # Must match docker volume mount # Disable autoconfig of the community index, to prevent unintended use - run_alr("config", "--global", "--set", "index.auto_community", "false") + run_alr("settings", "--global", "--set", "index.auto_community", "false") # Disable selection of toolchain. Tests that # require a configured compiler will have to set it up explicitly. @@ -51,7 +51,7 @@ def main(): # Disable warning on old index, to avoid having to update index versions # when they're still compatible. - run_alr("config", "--global", "--set", "warning.old_index", "false") + run_alr("settings", "--global", "--set", "warning.old_index", "false") # indexes to use if 'indexes' in test_env: diff --git a/testsuite/drivers/driver/python_script.py b/testsuite/drivers/driver/python_script.py index 8e4e25a65..1b30d8d5f 100644 --- a/testsuite/drivers/driver/python_script.py +++ b/testsuite/drivers/driver/python_script.py @@ -169,7 +169,7 @@ def run(self): # Activate shared builds. Using "-c" is needed as the environment # still isn't activated at the driver script level. run_alr("-c", pristine_env["ALR_CONFIG"], - "config", "--global", "--set", + "settings", "--global", "--set", "dependencies.shared", "true") p = self.run_script(copy.deepcopy(pristine_env)) self.check_result(p) diff --git a/testsuite/drivers/helpers.py b/testsuite/drivers/helpers.py index 4446697ff..b61403216 100644 --- a/testsuite/drivers/helpers.py +++ b/testsuite/drivers/helpers.py @@ -292,4 +292,4 @@ def __exit__(self, exc_type, exc_val, exc_tb): # Release the file lock import fcntl fcntl.flock(self.lock_file.fileno(), fcntl.LOCK_UN) - self.lock_file.close() \ No newline at end of file + self.lock_file.close() diff --git a/testsuite/tests/alias/basic/test.py b/testsuite/tests/alias/basic/test.py index 163a8041c..e19e72a1b 100644 --- a/testsuite/tests/alias/basic/test.py +++ b/testsuite/tests/alias/basic/test.py @@ -15,7 +15,7 @@ os.chdir(glob('hello*')[0]) # Define an alias locally -run_alr('config', '--set', 'alias.my_alias', 'exec -- echo Test an alias') +run_alr('settings', '--set', 'alias.my_alias', 'exec -- echo Test an alias') # Use the alias p = run_alr('my_alias', diff --git a/testsuite/tests/build_profile/last_profile/test.py b/testsuite/tests/build_profile/last_profile/test.py index b4d40154e..92f74fc35 100644 --- a/testsuite/tests/build_profile/last_profile/test.py +++ b/testsuite/tests/build_profile/last_profile/test.py @@ -11,19 +11,19 @@ run_alr("build") assert_match(".*last_build_profile=xxx=DEVELOPMENT.*", - run_alr("config").out) + run_alr("settings").out) # Check explicit profile in command line run_alr("build", "--release") assert_match(".*last_build_profile=xxx=RELEASE.*", - run_alr("config").out) + run_alr("settings").out) # Check implicit profile when build is indirect is last that was used: run_alr("run") # Causes a build with the last used profile assert_match(".*last_build_profile=xxx=RELEASE.*", - run_alr("config").out) + run_alr("settings").out) # Check explicit profile requested in the manifest @@ -33,6 +33,6 @@ run_alr("build") assert_match(".*last_build_profile=xxx=VALIDATION.*", - run_alr("config").out) + run_alr("settings").out) print('SUCCESS') diff --git a/testsuite/tests/dockerized/misc/failed-auto-update/test.py b/testsuite/tests/dockerized/misc/failed-auto-update/test.py index cb75457e7..bed898b0a 100644 --- a/testsuite/tests/dockerized/misc/failed-auto-update/test.py +++ b/testsuite/tests/dockerized/misc/failed-auto-update/test.py @@ -19,11 +19,11 @@ run_alr("show", "libhello") # Enable autoupdate -run_alr("config", "--global", "--set", "index.auto_update", "1") +run_alr("settings", "--global", "--set", "index.auto_update", "1") # Ensure next `alr show` will trigger an update -run_alr("config", "--global", "--unset", "index.last_update") -run_alr("config", "--global", "--set", "index.auto_update_asked", "true") +run_alr("settings", "--global", "--unset", "index.last_update") +run_alr("settings", "--global", "--set", "index.auto_update_asked", "true") # Prepare a copy of `unshare` that can be run as regular user run(["cp", "/usr/bin/unshare", "/tmp"]).check_returncode() diff --git a/testsuite/tests/index/auto-update/test.py b/testsuite/tests/index/auto-update/test.py index 525191e4e..1d5889de1 100644 --- a/testsuite/tests/index/auto-update/test.py +++ b/testsuite/tests/index/auto-update/test.py @@ -16,7 +16,7 @@ # Auto updates are disabled by default by the python harness, to maintain # compatibility of older tests. We disable the disabling now. -run_alr("config", "--global", "--unset", "index.auto_update") +run_alr("settings", "--global", "--unset", "index.auto_update") # This was set to 0 to disable updates # After using the index, the user will have been asked diff --git a/testsuite/tests/index/branch-mismatch/test.py b/testsuite/tests/index/branch-mismatch/test.py index 8d3145aab..ac61a8537 100644 --- a/testsuite/tests/index/branch-mismatch/test.py +++ b/testsuite/tests/index/branch-mismatch/test.py @@ -25,7 +25,7 @@ os.chdir(start) # Enable the warning we are trying to test -run_alr("config", "--global", "--set", "warning.old_index", "true") +run_alr("settings", "--global", "--set", "warning.old_index", "true") # Run the test. No alr version should use 'master' for the community index. # This produces a warning only, because the index version is valid. diff --git a/testsuite/tests/index/local-index-not-found/test.py b/testsuite/tests/index/local-index-not-found/test.py index 3997eebb2..4add3de68 100644 --- a/testsuite/tests/index/local-index-not-found/test.py +++ b/testsuite/tests/index/local-index-not-found/test.py @@ -17,7 +17,7 @@ # Delete old configuration and indexes, but disable msys2 installation or # installation will be reattempted. rm('alr-config', recursive=True) - run_alr("config", "--global", "--set", "msys2.do_not_install", "true") + run_alr("settings", "--global", "--set", "msys2.do_not_install", "true") prepare_indexes('alr-config', '.', {'bad_index': {'dir': d, 'in_fixtures': False}}) diff --git a/testsuite/tests/index/old-compat-version/test.py b/testsuite/tests/index/old-compat-version/test.py index c69accbc6..d65e3f8cc 100644 --- a/testsuite/tests/index/old-compat-version/test.py +++ b/testsuite/tests/index/old-compat-version/test.py @@ -9,7 +9,7 @@ import os # Enable the warning we are trying to test -run_alr("config", "--global", "--set", "warning.old_index", "true") +run_alr("settings", "--global", "--set", "warning.old_index", "true") # Run a command that loads the index. This produces a warning only, because the # index version is old but valid. diff --git a/testsuite/tests/init/interactive-inputs/test.py b/testsuite/tests/init/interactive-inputs/test.py index e874729e6..f453aa128 100644 --- a/testsuite/tests/init/interactive-inputs/test.py +++ b/testsuite/tests/init/interactive-inputs/test.py @@ -41,7 +41,7 @@ def check(descr: str = "", name: str = ""): shutil.rmtree("xxx") # Unset the user information so it is re-asked next time - run_alr('config', '--global', '--unset', 'user.name') + run_alr('settings', '--global', '--unset', 'user.name') # Other fields are not being set because they use the defaults so don't # require unsetting. diff --git a/testsuite/tests/init/user-input-validation/test.py b/testsuite/tests/init/user-input-validation/test.py index 07cbbd233..3fb5f99d9 100644 --- a/testsuite/tests/init/user-input-validation/test.py +++ b/testsuite/tests/init/user-input-validation/test.py @@ -10,9 +10,9 @@ # Preconfigure needed fields name = "Äł O'Reilly O\"Raro" -run_alr("config", "--global", "--set", "user.email", "abc@de.com") -run_alr("config", "--global", "--set", "user.github_login", "abcde") -run_alr("config", "--global", "--set", "user.name", name) +run_alr("settings", "--global", "--set", "user.email", "abc@de.com") +run_alr("settings", "--global", "--set", "user.github_login", "abcde") +run_alr("settings", "--global", "--set", "user.name", name) # Create crate run_alr("init", "--bin", "xxx") diff --git a/testsuite/tests/install/default-location/test.py b/testsuite/tests/install/default-location/test.py index f5b0350bb..9239a6952 100644 --- a/testsuite/tests/install/default-location/test.py +++ b/testsuite/tests/install/default-location/test.py @@ -17,7 +17,7 @@ # Disable msys2 as the home change doesn't sit well with it and we don't need it here. # This is a workaround because trying to disable it via config doesn't work on 1st run: -# run_alr("config", "--global", "--set", "msys2.do_not_install", "true") +# run_alr("settings", "--global", "--set", "msys2.do_not_install", "true") if on_windows(): os.makedirs(os.path.join(os.environ["USERPROFILE"], ".cache", "alire", "msys64")) diff --git a/testsuite/tests/misc/git-ungit/test.py b/testsuite/tests/misc/git-ungit/test.py index 4054d27cd..ff59ce4c0 100644 --- a/testsuite/tests/misc/git-ungit/test.py +++ b/testsuite/tests/misc/git-ungit/test.py @@ -37,7 +37,7 @@ if not wanted: # Enable for next round - run_alr("config", "--global", "--set", + run_alr("settings", "--global", "--set", "dependencies.git.keep_repository", "true") # Cleanup for next round diff --git a/testsuite/tests/publish/submit-request-cancel/test.py b/testsuite/tests/publish/submit-request-cancel/test.py index 548de0685..4931be90b 100644 --- a/testsuite/tests/publish/submit-request-cancel/test.py +++ b/testsuite/tests/publish/submit-request-cancel/test.py @@ -35,11 +35,11 @@ print("SKIP: GH_USERNAME not set") sys.exit(0) else: - run_alr("config", "--global", "--set", + run_alr("settings", "--global", "--set", "user.github_login", os.environ["GH_USERNAME"]) # Configure the testing remote index -run_alr("config", "--global", "--set", "index.repository_name", "test-index") +run_alr("settings", "--global", "--set", "index.repository_name", "test-index") # Clone a simple crate not already in the index with a local remote subprocess.run(["gh", "repo", "clone", diff --git a/testsuite/tests/config/basics/test.py b/testsuite/tests/settings/basics/test.py similarity index 68% rename from testsuite/tests/config/basics/test.py rename to testsuite/tests/settings/basics/test.py index a8dcd7baf..8c57e87d9 100644 --- a/testsuite/tests/config/basics/test.py +++ b/testsuite/tests/settings/basics/test.py @@ -1,5 +1,5 @@ """ -Check basic features of the alr config command +Check basic features of the alr settings command """ import os @@ -9,19 +9,19 @@ from drivers.alr import run_alr def invalid_key(*args): - print("Running: alr config %s" % " ".join([item for item in args])) + print("Running: alr settings %s" % " ".join([item for item in args])) - p = run_alr('config', *args, complain_on_error=False, quiet=False) + p = run_alr('settings', *args, complain_on_error=False, quiet=False) assert p.status != 0, "command should fail" - assert "Invalid configuration key" in p.out, \ + assert "Invalid setting key" in p.out, \ "Missing error message in: '%s" % p.out def invalid_builtin(*args): - print("Running: alr config %s" % " ".join([item for item in args])) + print("Running: alr settings %s" % " ".join([item for item in args])) - p = run_alr('config', *args, complain_on_error=False, quiet=False) + p = run_alr('settings', *args, complain_on_error=False, quiet=False) assert p.status != 0, "command should fail" @@ -30,9 +30,9 @@ def invalid_builtin(*args): def check_value(key, expected_value, local=True): if local: - get = run_alr('config', '--get', key) + get = run_alr('settings', '--get', key) else: - get = run_alr('config', '--global', '--get', key) + get = run_alr('settings', '--global', '--get', key) assert get.out == expected_value + "\n", "Got '%s'" % get.out def set_get_unset(key, value, image=None): @@ -41,24 +41,24 @@ def set_get_unset(key, value, image=None): image = value # The key should not be defined - get1 = run_alr('config', '--global', '--get', key, complain_on_error=False) + get1 = run_alr('settings', '--global', '--get', key, complain_on_error=False) assert get1.status != 0, 'Should not be defined' # Define it - run_alr('config', '--global', '--set', key, value) + run_alr('settings', '--global', '--set', key, value) # Check that it is defined check_value(key, image, local=False) # Unset it - run_alr('config', '--global', '--unset', key) + run_alr('settings', '--global', '--unset', key) # Check that is it not defined anymore - get3 = run_alr('config', '--global', '--get', key, complain_on_error=False) + get3 = run_alr('settings', '--global', '--get', key, complain_on_error=False) assert get3.status != 0, 'Should not be defined' ####################### -# invalid config keys # +# invalid settings keys # ####################### invalid_key('--get', '--global', '.test') invalid_key('--get', '--global', '_test.') @@ -86,12 +86,12 @@ def set_get_unset(key, value, image=None): set_get_unset('test.bool', 'true') set_get_unset('test.float', '0.2', image='2.00000000000000E-01') -################ -# Local config # -################ +################## +# Local settings # +################## # Check that local operations (default) fail if not in a crate context -p = run_alr('config', '--set', 'test.local', '42', complain_on_error=False) +p = run_alr('settings', '--set', 'test.local', '42', complain_on_error=False) assert p.status != 0, 'Should fail' # Get a create to have local context @@ -99,14 +99,14 @@ def set_get_unset(key, value, image=None): os.chdir(glob('hello*')[0]) # Local operation should now work -run_alr('config', '--set', 'test.local', '42') +run_alr('settings', '--set', 'test.local', '42') # Set a local and check its value -run_alr('config', '--set', 'test.override', '"is_local"') +run_alr('settings', '--set', 'test.override', '"is_local"') check_value('test.override', 'is_local') # Set a global and check that the local value is still returned -run_alr('config', '--set', '--global', 'test.override', '"is_global"') +run_alr('settings', '--set', '--global', 'test.override', '"is_global"') check_value('test.override', 'is_local') # Leave the crate context (local keys are not available anymore) @@ -116,6 +116,6 @@ def set_get_unset(key, value, image=None): check_value('test.override', 'is_global', local=False) # Remove the global key -run_alr('config', '--unset', '--global', 'test.override') +run_alr('settings', '--unset', '--global', 'test.override') print('SUCCESS') diff --git a/testsuite/tests/config/basics/test.yaml b/testsuite/tests/settings/basics/test.yaml similarity index 100% rename from testsuite/tests/config/basics/test.yaml rename to testsuite/tests/settings/basics/test.yaml diff --git a/testsuite/tests/config/cache-relocation/test.py b/testsuite/tests/settings/cache-relocation/test.py similarity index 65% rename from testsuite/tests/config/cache-relocation/test.py rename to testsuite/tests/settings/cache-relocation/test.py index a6e4c63e4..d8868c22f 100644 --- a/testsuite/tests/config/cache-relocation/test.py +++ b/testsuite/tests/settings/cache-relocation/test.py @@ -12,15 +12,15 @@ drive = "" # Default cache location (inside test config dir) -assert_match(r".*cache folder:[^\n]*config__cache-relocation/alr-config/cache", +assert_match(r".*cache folder:[^\n]*settings__cache-relocation/alr-config/cache", run_alr("version").out.replace("\\", "/")) # Check toolchain location inside cache location -assert_match(r".*toolchain folder:[^\n]*config__cache-relocation/alr-config/cache/toolchains", +assert_match(r".*toolchain folder:[^\n]*settings__cache-relocation/alr-config/cache/toolchains", run_alr("version").out.replace("\\", "/")) -# Override via config (takes precedence) -run_alr("config", "--global", "--set", "cache.dir", f"{drive}/relocated-to-root") +# Override via settings (takes precedence) +run_alr("settings", "--global", "--set", "cache.dir", f"{drive}/relocated-to-root") assert_match(r".*cache folder:[^\n]*/relocated-to-root", run_alr("version").out.replace("\\", "/")) @@ -28,8 +28,8 @@ assert_match(r".*toolchain folder:[^\n]*/relocated-to-root/toolchains", run_alr("version").out.replace("\\", "/")) -# Check toolchain override via config (takes precedence over cache override) -run_alr("config", "--global", "--set", "toolchain.dir", f"{drive}/relocated-toolchains") +# Check toolchain override via settings (takes precedence over cache override) +run_alr("settings", "--global", "--set", "toolchain.dir", f"{drive}/relocated-toolchains") assert_match(r".*toolchain folder:[^\n]*/relocated-toolchains", run_alr("version").out.replace("\\", "/")) diff --git a/testsuite/tests/config/cache-relocation/test.yaml b/testsuite/tests/settings/cache-relocation/test.yaml similarity index 100% rename from testsuite/tests/config/cache-relocation/test.yaml rename to testsuite/tests/settings/cache-relocation/test.yaml diff --git a/testsuite/tests/config/community-disable/test.py b/testsuite/tests/settings/community-disable/test.py similarity index 100% rename from testsuite/tests/config/community-disable/test.py rename to testsuite/tests/settings/community-disable/test.py diff --git a/testsuite/tests/config/community-disable/test.yaml b/testsuite/tests/settings/community-disable/test.yaml similarity index 100% rename from testsuite/tests/config/community-disable/test.yaml rename to testsuite/tests/settings/community-disable/test.yaml diff --git a/testsuite/tests/config/distro-disable/test.py b/testsuite/tests/settings/distro-disable/test.py similarity index 88% rename from testsuite/tests/config/distro-disable/test.py rename to testsuite/tests/settings/distro-disable/test.py index ecc1278da..1e45faa25 100644 --- a/testsuite/tests/config/distro-disable/test.py +++ b/testsuite/tests/settings/distro-disable/test.py @@ -4,7 +4,7 @@ from drivers.alr import run_alr, distro_is_known -run_alr("config", "--global", +run_alr("settings", "--global", "--set", "distribution.disable_detection", "true") assert not distro_is_known(), "Unexpected distro detection" diff --git a/testsuite/tests/config/distro-disable/test.yaml b/testsuite/tests/settings/distro-disable/test.yaml similarity index 100% rename from testsuite/tests/config/distro-disable/test.yaml rename to testsuite/tests/settings/distro-disable/test.yaml diff --git a/testsuite/tests/config/distro-override/test.py b/testsuite/tests/settings/distro-override/test.py similarity index 91% rename from testsuite/tests/config/distro-override/test.py rename to testsuite/tests/settings/distro-override/test.py index 30be498c5..afb328377 100644 --- a/testsuite/tests/config/distro-override/test.py +++ b/testsuite/tests/settings/distro-override/test.py @@ -7,14 +7,14 @@ # Overriding distro detection. We force Debian as our tests run in Ubuntu and # many other distros so it is only giving a false positive on Debian. -run_alr("config", "--global", +run_alr("settings", "--global", "--set", "distribution.override", "debian") assert_match(".*distribution:[^\n]*DEBIAN", run_alr("version").out) # Disabling distro detection takes precedence -run_alr("config", "--global", +run_alr("settings", "--global", "--set", "distribution.disable_detection", "true") assert_match(".*distribution:[^\n]*DISTRIBUTION_UNKNOWN", diff --git a/testsuite/tests/config/distro-override/test.yaml b/testsuite/tests/settings/distro-override/test.yaml similarity index 100% rename from testsuite/tests/config/distro-override/test.yaml rename to testsuite/tests/settings/distro-override/test.yaml diff --git a/testsuite/tests/config/early-loading/test.py b/testsuite/tests/settings/early-loading/test.py similarity index 77% rename from testsuite/tests/config/early-loading/test.py rename to testsuite/tests/settings/early-loading/test.py index 40f45b3b8..fbbeffb26 100644 --- a/testsuite/tests/config/early-loading/test.py +++ b/testsuite/tests/settings/early-loading/test.py @@ -17,13 +17,13 @@ # Verify proper loading with both short and long config options assert_eq(expected, - run_alr("-c", custom_config, "config", "--global").out) + run_alr("-c", custom_config, "settings", "--global").out) assert_eq(expected, - run_alr(f"--config={custom_config}", "config", "--global").out) + run_alr(f"--config={custom_config}", "settings", "--global").out) # Verify also when using environment variable os.environ["ALR_CONFIG"] = os.path.abspath(custom_config) assert_eq(expected, - run_alr("config", "--global").out) + run_alr("settings", "--global").out) print('SUCCESS') diff --git a/testsuite/tests/config/early-loading/test.yaml b/testsuite/tests/settings/early-loading/test.yaml similarity index 100% rename from testsuite/tests/config/early-loading/test.yaml rename to testsuite/tests/settings/early-loading/test.yaml diff --git a/testsuite/tests/config/missing-config-default/my_index/he/hello/hello-1.0.0.toml b/testsuite/tests/settings/missing-config-default/my_index/he/hello/hello-1.0.0.toml similarity index 100% rename from testsuite/tests/config/missing-config-default/my_index/he/hello/hello-1.0.0.toml rename to testsuite/tests/settings/missing-config-default/my_index/he/hello/hello-1.0.0.toml diff --git a/testsuite/tests/config/missing-config-default/my_index/he/hello/hello-1.0.1.toml b/testsuite/tests/settings/missing-config-default/my_index/he/hello/hello-1.0.1.toml similarity index 100% rename from testsuite/tests/config/missing-config-default/my_index/he/hello/hello-1.0.1.toml rename to testsuite/tests/settings/missing-config-default/my_index/he/hello/hello-1.0.1.toml diff --git a/testsuite/tests/config/missing-config-default/my_index/index.toml b/testsuite/tests/settings/missing-config-default/my_index/index.toml similarity index 100% rename from testsuite/tests/config/missing-config-default/my_index/index.toml rename to testsuite/tests/settings/missing-config-default/my_index/index.toml diff --git a/testsuite/tests/config/missing-config-default/my_index/li/libhello/libhello-1.0.0.toml b/testsuite/tests/settings/missing-config-default/my_index/li/libhello/libhello-1.0.0.toml similarity index 100% rename from testsuite/tests/config/missing-config-default/my_index/li/libhello/libhello-1.0.0.toml rename to testsuite/tests/settings/missing-config-default/my_index/li/libhello/libhello-1.0.0.toml diff --git a/testsuite/tests/config/missing-config-default/test.py b/testsuite/tests/settings/missing-config-default/test.py similarity index 100% rename from testsuite/tests/config/missing-config-default/test.py rename to testsuite/tests/settings/missing-config-default/test.py diff --git a/testsuite/tests/config/missing-config-default/test.yaml b/testsuite/tests/settings/missing-config-default/test.yaml similarity index 100% rename from testsuite/tests/config/missing-config-default/test.yaml rename to testsuite/tests/settings/missing-config-default/test.yaml diff --git a/testsuite/tests/config/relative_config_path/test.py b/testsuite/tests/settings/relative_config_path/test.py similarity index 88% rename from testsuite/tests/config/relative_config_path/test.py rename to testsuite/tests/settings/relative_config_path/test.py index 9e79fe2e8..efb4e7a0a 100644 --- a/testsuite/tests/config/relative_config_path/test.py +++ b/testsuite/tests/settings/relative_config_path/test.py @@ -10,7 +10,7 @@ from drivers.asserts import assert_eq from drivers.helpers import lines_of -run_alr("--config=.", "config", "--global", +run_alr("--config=.", "settings", "--global", "--set", "some_config_key", "true") diff --git a/testsuite/tests/config/relative_config_path/test.yaml b/testsuite/tests/settings/relative_config_path/test.yaml similarity index 100% rename from testsuite/tests/config/relative_config_path/test.yaml rename to testsuite/tests/settings/relative_config_path/test.yaml diff --git a/testsuite/tests/config/shared-deps/test.py b/testsuite/tests/settings/shared-deps/test.py similarity index 100% rename from testsuite/tests/config/shared-deps/test.py rename to testsuite/tests/settings/shared-deps/test.py diff --git a/testsuite/tests/config/shared-deps/test.yaml b/testsuite/tests/settings/shared-deps/test.yaml similarity index 100% rename from testsuite/tests/config/shared-deps/test.yaml rename to testsuite/tests/settings/shared-deps/test.yaml diff --git a/testsuite/tests/solver/compiler-selected/test.py b/testsuite/tests/solver/compiler-selected/test.py index 52b0527a9..70a10ccf4 100644 --- a/testsuite/tests/solver/compiler-selected/test.py +++ b/testsuite/tests/solver/compiler-selected/test.py @@ -20,7 +20,7 @@ match_solution("gnat=8888.0.0 (gnat_native)", escape=True) # Selecting another default will cause a corresponding change in the solution -run_alr("config", "--set", "toolchain.use.gnat", "gnat_cross_2=1") +run_alr("settings", "--set", "toolchain.use.gnat", "gnat_cross_2=1") run_alr("update") match_solution("gnat=1.0.0 (gnat_cross_2)", escape=True) diff --git a/testsuite/tests/toolchain/select-defaults/test.py b/testsuite/tests/toolchain/select-defaults/test.py index fadefe8dc..f0c03873d 100644 --- a/testsuite/tests/toolchain/select-defaults/test.py +++ b/testsuite/tests/toolchain/select-defaults/test.py @@ -10,7 +10,7 @@ init_local_crate() # Re-config as if it was the first time running alr -run_alr("config", "--global", "--set", "toolchain.assistant", "true") +run_alr("settings", "--global", "--set", "toolchain.assistant", "true") # A command requiring a workspace will trigger the assistant p = run_alr("show", quiet=False) diff --git a/testsuite/tests/toolchain/select-while-missing/test.py b/testsuite/tests/toolchain/select-while-missing/test.py index 66fe36263..2ce31dc1f 100644 --- a/testsuite/tests/toolchain/select-while-missing/test.py +++ b/testsuite/tests/toolchain/select-while-missing/test.py @@ -10,7 +10,7 @@ run_alr("toolchain", "--select", "gnat_native", "gprbuild") # Configure an invalid compiler -run_alr("config", "--global", "--set", "toolchain.use.gnat", "gnat_nono=1.2.3") +run_alr("settings", "--global", "--set", "toolchain.use.gnat", "gnat_nono=1.2.3") # This must succeed run_alr("toolchain", "--select", "gnat_native=1.0") diff --git a/testsuite/tests/workflows/edit/test.py b/testsuite/tests/workflows/edit/test.py index 8f7bf6a6c..b7c8f89fc 100644 --- a/testsuite/tests/workflows/edit/test.py +++ b/testsuite/tests/workflows/edit/test.py @@ -14,7 +14,7 @@ os.chdir(glob('libhello*')[0]) # Set GNATstudio as prefered editor -run_alr('config', '--set', 'editor.cmd', 'gnatstudio -P ${GPR_FILE}') +run_alr('settings', '--set', 'editor.cmd', 'gnatstudio -P ${GPR_FILE}') gs = shutil.which('gnatstudio') @@ -30,13 +30,13 @@ assert_match(".*Please specify a project file with --project=.*", p.out) # Set an editor that doesn't exist (different than GNAT Studio) -run_alr('config', '--set', 'editor.cmd', 'doesnt_exist arg1 ab${GPR_FILE}ab arg3') +run_alr('settings', '--set', 'editor.cmd', 'doesnt_exist arg1 ab${GPR_FILE}ab arg3') p = run_alr('edit', '--project=project1.gpr', complain_on_error=False) assert_match("ERROR: 'doesnt_exist' not available or not in PATH.*", p.out) print(p.out) # Use echo as an editor to check command line args -run_alr('config', '--set', 'editor.cmd', 'echo arg1 ab${GPR_FILE}ab arg3') +run_alr('settings', '--set', 'editor.cmd', 'echo arg1 ab${GPR_FILE}ab arg3') p = run_alr('edit', '--project=project1.gpr') assert_match("arg1 abproject1.gprab arg3", p.out) From d302de27ee38234d27e3e2255683968be5d91f25 Mon Sep 17 00:00:00 2001 From: Manuel Date: Sat, 9 Mar 2024 14:44:34 +0100 Subject: [PATCH 07/17] Clarify remark about `--force` in `alr install --help` (#1618) Since it affects the place where the argument can be used, the user has to be aware of that. --- src/alr/alr-commands-install.adb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/alr/alr-commands-install.adb b/src/alr/alr-commands-install.adb index 6b84f4693..974885a6e 100644 --- a/src/alr/alr-commands-install.adb +++ b/src/alr/alr-commands-install.adb @@ -122,8 +122,8 @@ package body Alr.Commands.Install is & "templates, should be able to coexist in a same installation prefix" & " without issue.") .New_Line - .Append ("You can use the --force to reinstall already installed " - & "releases.") + .Append ("You can use the --force global option to reinstall " + & "already installed releases.") ); -------------------- From fe485e3a5c22eaa5e7cb85344430b223b396403c Mon Sep 17 00:00:00 2001 From: Francesc Rocher Date: Sat, 9 Mar 2024 14:47:22 +0100 Subject: [PATCH 08/17] Handle config switch missing argument exceptions (#1619) Both 'alr -c' and 'alr --config' throw exceptions because a required parameter is missing. This fix handle missing parameter of config switch in the same way as, for example, 'alr -C' and 'alr --chdir': an error message informs the user that a required parameter is missing. --- src/alire/alire_early_elaboration.adb | 23 +++++++++++++++++-- .../tests/config/missing-config-path/test.py | 18 +++++++++++++++ .../config/missing-config-path/test.yaml | 3 +++ 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 testsuite/tests/config/missing-config-path/test.py create mode 100644 testsuite/tests/config/missing-config-path/test.yaml diff --git a/src/alire/alire_early_elaboration.adb b/src/alire/alire_early_elaboration.adb index b09b78582..94765f2e5 100644 --- a/src/alire/alire_early_elaboration.adb +++ b/src/alire/alire_early_elaboration.adb @@ -71,6 +71,17 @@ package body Alire_Early_Elaboration is procedure Check_Switches is + ------------------------- + -- Config_Switch_Error -- + ------------------------- + + procedure Config_Switch_Error (Switch : String) is + begin + GNAT.IO.Put_Line + ("ERROR: Switch " & Switch & " requires argument (global)."); + Early_Error ("try ""alr --help"" for more information."); + end Config_Switch_Error; + --------------------- -- Set_Config_Path -- --------------------- @@ -78,7 +89,9 @@ package body Alire_Early_Elaboration is procedure Set_Config_Path (Path : String) is package Adirs renames Ada.Directories; begin - if not Adirs.Exists (Path) then + if Path = "" then + Config_Switch_Error ("--config"); + elsif not Adirs.Exists (Path) then Early_Error ("Invalid non-existing configuration path: " & Path); elsif Adirs.Kind (Path) not in Adirs.Directory then @@ -107,11 +120,13 @@ package body Alire_Early_Elaboration is end if; end Check_Long_Switch; + Option : Character; begin loop -- We use the simpler Getopt form to avoid built-in help and other -- shenanigans. - case Getopt ("* d? --debug? q v c= --config=") is + Option := Getopt ("* d? --debug? q v c= --config="); + case Option is when ASCII.NUL => exit; when '*' => @@ -148,6 +163,10 @@ package body Alire_Early_Elaboration is end case; end loop; exception + when GNAT.Command_Line.Invalid_Parameter => + if Option = 'c' then + Config_Switch_Error ("-c"); + end if; when Exit_From_Command_Line => -- Something unexpected happened but it will be properly dealt -- with later on, in the regular command-line parser. diff --git a/testsuite/tests/config/missing-config-path/test.py b/testsuite/tests/config/missing-config-path/test.py new file mode 100644 index 000000000..0047db813 --- /dev/null +++ b/testsuite/tests/config/missing-config-path/test.py @@ -0,0 +1,18 @@ +""" +Verify that errors are properly handled when no config path is given +""" + +from drivers.alr import run_alr +from drivers.asserts import assert_match + +import re + +p = run_alr("--config", complain_on_error=False) +assert p.status != 0, "command should fail" +assert_match("ERROR: Switch --config requires argument.*", p.out, flags=re.S) + +p = run_alr("-c", complain_on_error=False) +assert p.status != 0, "command should fail" +assert_match("ERROR: Switch -c requires argument.*", p.out, flags=re.S) + +print('SUCCESS') diff --git a/testsuite/tests/config/missing-config-path/test.yaml b/testsuite/tests/config/missing-config-path/test.yaml new file mode 100644 index 000000000..872fc1274 --- /dev/null +++ b/testsuite/tests/config/missing-config-path/test.yaml @@ -0,0 +1,3 @@ +driver: python-script +indexes: + basic_index: {} From 3245eeb6bf116205e78e1c7bfad484d0d37aa30c Mon Sep 17 00:00:00 2001 From: Francesc Rocher Date: Sat, 9 Mar 2024 19:24:55 +0100 Subject: [PATCH 09/17] Missing dependencies in testsuite documentation. (#1620) * Missing dependencies in testsuite documentation. Required package 'pexpect' is not installed as a dependency of 'e3-testsuite', so is has to be explicitly installed. Neither 'e3-testsuite' nor 'e3-core' depend on it: $ pip show e3-testsuite e3-core Name: e3-testsuite Version: 26.0 Summary: E3 testsuite Home-page: Author: AdaCore Author-email: info@adacore.com License: GPLv3 Location: /home/ada/opt/alire/venv/lib/python3.10/site-packages Requires: e3-core Required-by: --- Name: e3-core Version: 22.4.0 Summary: E3 core. Tools and library for building and testing software Home-page: https://github.com/AdaCore/e3-core Author: AdaCore Author-email: info@adacore.com License: GPLv3 Location: /home/ada/opt/alire/venv/lib/python3.10/site-packages Requires: colorama, ld, packaging, psutil, python-dateutil, pyyaml, requests, requests-cache, requests-toolbelt, setuptools, stevedore, tqdm Required-by: e3-testsuite * Install pip dependencies using requirements.txt --- testsuite/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/README.md b/testsuite/README.md index 933fef077..96534f133 100644 --- a/testsuite/README.md +++ b/testsuite/README.md @@ -28,7 +28,7 @@ $ virtualenv my-virtual-env $ source my-virtual-env/bin/activate # Install e3-testsuite and all its dependencies -$ pip install e3-testsuite +$ pip install -r requirements.txt # You should now be able to run the testsuite (make sure you built alr and # made it available with your PATH): From d57b71c67e8e151ef0ba008a797d3e80267c3439 Mon Sep 17 00:00:00 2001 From: Alejandro R Mosteo Date: Mon, 11 Mar 2024 12:34:16 +0100 Subject: [PATCH 10/17] Refactor `Alire.Config.*` as `Alire.Settings.*` (#1622) * Refactor `Alire.Config.*` as `Alire.Settings.*` * Refactor Windows-only files --- RELEASING.md | 1 + src/alire/alire-builds.adb | 8 ++-- src/alire/alire-config-edit-early_load.adb | 14 ------- src/alire/alire-crate_configuration.adb | 6 +-- src/alire/alire-index.ads | 9 +++-- src/alire/alire-index_on_disk-loading.adb | 16 ++++---- src/alire/alire-index_on_disk-updates.adb | 18 ++++----- src/alire/alire-index_on_disk-updates.ads | 6 +-- src/alire/alire-origins-deployers-git.adb | 4 +- src/alire/alire-paths-vault.ads | 4 +- src/alire/alire-platforms-current.ads | 11 +++--- src/alire/alire-platforms-folders.ads | 2 +- src/alire/alire-publish.adb | 8 ++-- src/alire/alire-releases.adb | 6 +-- src/alire/alire-roots.adb | 2 +- src/alire/alire-selftest.adb | 24 ++++++------ ...iltins.ads => alire-settings-builtins.ads} | 6 +-- ...g-checks.adb => alire-settings-checks.adb} | 4 +- ...g-checks.ads => alire-settings-checks.ads} | 4 +- src/alire/alire-settings-edit-early_load.adb | 14 +++++++ ...ads => alire-settings-edit-early_load.ads} | 6 +-- ...onfig-edit.adb => alire-settings-edit.adb} | 16 ++++---- ...onfig-edit.ads => alire-settings-edit.ads} | 12 +++--- .../{alire-config.adb => alire-settings.adb} | 14 +++---- .../{alire-config.ads => alire-settings.ads} | 12 +++--- src/alire/alire-solutions.adb | 4 +- src/alire/alire-toml_index.adb | 8 ++-- src/alire/alire-toolchains.adb | 39 ++++++++++--------- src/alire/alire-toolchains.ads | 22 ++++++----- .../alire-utils-user_input-query_config.adb | 10 ++--- src/alire/alire_early_elaboration.adb | 6 +-- .../alire-platforms-current__windows.adb | 20 +++++----- ...ds => alire-settings-builtins-windows.ads} | 10 ++--- src/alr/alr-commands-clean.adb | 4 +- src/alr/alr-commands-edit.adb | 12 +++--- src/alr/alr-commands-get.adb | 6 +-- src/alr/alr-commands-index.adb | 10 ++--- src/alr/alr-commands-init.adb | 4 +- src/alr/alr-commands-settings.adb | 33 ++++++++-------- src/alr/alr-commands-toolchain.adb | 25 ++++++------ src/alr/alr-commands-version.adb | 10 ++--- src/alr/alr-commands.adb | 16 ++++---- 42 files changed, 239 insertions(+), 227 deletions(-) delete mode 100644 src/alire/alire-config-edit-early_load.adb rename src/alire/{alire-config-builtins.ads => alire-settings-builtins.ads} (98%) rename src/alire/{alire-config-checks.adb => alire-settings-checks.adb} (87%) rename src/alire/{alire-config-checks.ads => alire-settings-checks.ads} (73%) create mode 100644 src/alire/alire-settings-edit-early_load.adb rename src/alire/{alire-config-edit-early_load.ads => alire-settings-edit-early_load.ads} (55%) rename src/alire/{alire-config-edit.adb => alire-settings-edit.adb} (96%) rename src/alire/{alire-config-edit.ads => alire-settings-edit.ads} (91%) rename src/alire/{alire-config.adb => alire-settings.adb} (94%) rename src/alire/{alire-config.ads => alire-settings.ads} (94%) rename src/alire/os_windows/{alire-config-builtins-windows.ads => alire-settings-builtins-windows.ads} (85%) diff --git a/RELEASING.md b/RELEASING.md index 198b74d3c..e58d31f84 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -1,6 +1,7 @@ ## Checklist for releasing a new version 1. [ ] Update version in `Alire.Version`. +1. [ ] Run local-only tests (`/testsuite/run-dev-sh`) 1. [ ] Create test release in own fork. - To verify builds succeed. - As the Windows build can rarely fail, this provides a backup .exe diff --git a/src/alire/alire-builds.adb b/src/alire/alire-builds.adb index f632b95f1..22b0c9710 100644 --- a/src/alire/alire-builds.adb +++ b/src/alire/alire-builds.adb @@ -1,7 +1,7 @@ with AAA.Strings; -with Alire.Config.Builtins; -with Alire.Config.Edit; +with Alire.Settings.Builtins; +with Alire.Settings.Edit; with Alire.Directories; with Alire.Flags; with Alire.Paths.Vault; @@ -18,7 +18,7 @@ package body Alire.Builds is ---------------------------- function Sandboxed_Dependencies return Boolean - is (not Config.Builtins.Dependencies_Shared.Get); + is (not Settings.Builtins.Dependencies_Shared.Get); ---------- -- Sync -- @@ -83,7 +83,7 @@ package body Alire.Builds is ---------- function Path return Absolute_Path - is (Config.Edit.Cache_Path + is (Settings.Edit.Cache_Path / Paths.Build_Folder_Inside_Working_Folder); ---------- diff --git a/src/alire/alire-config-edit-early_load.adb b/src/alire/alire-config-edit-early_load.adb deleted file mode 100644 index e0df70e51..000000000 --- a/src/alire/alire-config-edit-early_load.adb +++ /dev/null @@ -1,14 +0,0 @@ -package body Alire.Config.Edit.Early_Load is - - ----------------- - -- Load_Config -- - ----------------- - - procedure Load_Config is - begin - Alire.Config.Edit.Load_Config; - end Load_Config; - -begin - Load_Config; -end Alire.Config.Edit.Early_Load; diff --git a/src/alire/alire-crate_configuration.adb b/src/alire/alire-crate_configuration.adb index e96776531..c886c523b 100644 --- a/src/alire/alire-crate_configuration.adb +++ b/src/alire/alire-crate_configuration.adb @@ -11,7 +11,7 @@ with Alire.Solutions; with Alire.Roots; with Alire.Origins; with Alire.Warnings; -with Alire.Config.Edit; +with Alire.Settings.Edit; with Alire.Properties.Build_Profiles; with Alire.Properties.Build_Switches; @@ -955,7 +955,7 @@ package body Alire.Crate_Configuration is ------------------------- function Last_Build_Profiles return Profile_Maps.Map is - Str : constant String := Config.DB.Get ("last_build_profile", ""); + Str : constant String := Settings.DB.Get ("last_build_profile", ""); Profiles : Parsed_Profiles; begin Profiles := Parse_Profiles (Str, Accept_Wildcards => False); @@ -1059,7 +1059,7 @@ package body Alire.Crate_Configuration is (String'(Key (I).As_String & Profile_Assign & Element (I)'Image)); end loop; - Config.Edit.Set_Locally ("last_build_profile", + Settings.Edit.Set_Locally ("last_build_profile", Profiles.Flatten (Profile_Split)); end Save_Last_Build_Profiles; diff --git a/src/alire/alire-index.ads b/src/alire/alire-index.ads index c9a706275..2e581d033 100644 --- a/src/alire/alire-index.ads +++ b/src/alire/alire-index.ads @@ -2,7 +2,7 @@ private with Alire_Early_Elaboration; pragma Elaborate_All (Alire_Early_Elaboration); pragma Unreferenced (Alire_Early_Elaboration); -with Alire.Config.Builtins; +with Alire.Settings.Builtins; with Alire.Crates.Containers; with Alire.Dependencies; with Alire.Origins; @@ -16,12 +16,13 @@ with Semantic_Versioning.Extended; package Alire.Index is - Community_Host : constant String := Config.Builtins.Index_Host.Get; + Community_Host : constant String := Settings.Builtins.Index_Host.Get; - Community_Organization : constant String := Config.Builtins.Index_Owner.Get; + Community_Organization : constant String := + Settings.Builtins.Index_Owner.Get; Community_Repo_Name : constant String - := Config.Builtins.Index_Repository_Name.Get; + := Settings.Builtins.Index_Repository_Name.Get; Community_Repo : constant URL := "git+" & Community_Host diff --git a/src/alire/alire-index_on_disk-loading.adb b/src/alire/alire-index_on_disk-loading.adb index 1051bac15..e9ff9ad9d 100644 --- a/src/alire/alire-index_on_disk-loading.adb +++ b/src/alire/alire-index_on_disk-loading.adb @@ -1,8 +1,8 @@ with Ada.Directories; with Ada.Text_IO; -with Alire.Config.Builtins; -with Alire.Config.Edit; +with Alire.Settings.Builtins; +with Alire.Settings.Edit; with Alire.Containers; with Alire.Index; with Alire.Index_On_Disk.Updates; @@ -189,7 +189,7 @@ package body Alire.Index_On_Disk.Loading is Result : Outcome with Warnings => Off; -- Spurious warning to be silenced in Debian stable/Ubuntu LTS GNATs. Indexes : constant Set := - Find_All (Config.Edit.Indexes_Directory, + Find_All (Settings.Edit.Indexes_Directory, Result, Cached => False); use Sets; @@ -205,15 +205,15 @@ package body Alire.Index_On_Disk.Loading is return Add (Origin => Alire.Index.Community_Repo & "#" & Alire.Index.Community_Branch, Name => Alire.Index.Community_Name, - Under => Config.Edit.Indexes_Directory, + Under => Settings.Edit.Indexes_Directory, Before => Before); end Actually_Add; begin - if not Config.Builtins.Index_Auto_Community.Get then + if not Settings.Builtins.Index_Auto_Community.Get then Warnings.Warn_Once ("Not configuring the community index, disabled via " - & Config.Builtins.Index_Auto_Community.Key); + & Settings.Builtins.Index_Auto_Community.Key); return Outcome_Success; end if; @@ -257,7 +257,7 @@ package body Alire.Index_On_Disk.Loading is ------------------ function Default_Path return Absolute_Path - is (Config.Edit.Indexes_Directory); + is (Settings.Edit.Indexes_Directory); ----------- -- Setup -- @@ -420,7 +420,7 @@ package body Alire.Index_On_Disk.Loading is if From.Is_Empty and then Path = "" then Load (Crate, Detect_Externals, Strict, From, - Config.Edit.Indexes_Directory); + Settings.Edit.Indexes_Directory); return; elsif Path /= "" then Setup (Path); diff --git a/src/alire/alire-index_on_disk-updates.adb b/src/alire/alire-index_on_disk-updates.adb index c22ec9594..29a0b9803 100644 --- a/src/alire/alire-index_on_disk-updates.adb +++ b/src/alire/alire-index_on_disk-updates.adb @@ -1,14 +1,14 @@ with Ada.Calendar; -with Alire.Config.Builtins; +with Alire.Settings.Builtins; with Alire.Index_On_Disk.Loading; with CLIC.User_Input; package body Alire.Index_On_Disk.Updates is - package Builtins renames Config.Builtins; - subtype Int is Config.Config_Int; + package Builtins renames Settings.Builtins; + subtype Int is Settings.Config_Int; Epoch : constant Ada.Calendar.Time := Ada.Calendar.Time_Of (Year => 2017, @@ -21,7 +21,7 @@ package body Alire.Index_On_Disk.Updates is ----------------- procedure Auto_Update - (Under : Absolute_Path := Config.Edit.Indexes_Directory) + (Under : Absolute_Path := Settings.Edit.Indexes_Directory) is Wait : constant Int := Builtins.Index_Auto_Update.Get; @@ -52,13 +52,13 @@ package body Alire.Index_On_Disk.Updates is Valid => (Yes | No => True, others => False), Default => Yes) = Yes then - Builtins.Index_Auto_Update_Asked.Set (Config.Global, True); + Builtins.Index_Auto_Update_Asked.Set (Settings.Global, True); return True; else Put_Info ("Understood, Alire will not perform automatic updates."); Trace.Debug ("Index auto-refresh disabled by user"); - Builtins.Index_Auto_Update.Set (Config.Global, 0); - Builtins.Index_Auto_Update_Asked.Set (Config.Global, True); + Builtins.Index_Auto_Update.Set (Settings.Global, 0); + Builtins.Index_Auto_Update_Asked.Set (Settings.Global, True); return False; end if; end User_Approves; @@ -122,7 +122,7 @@ package body Alire.Index_On_Disk.Updates is ---------------- function Update_All - (Under : Absolute_Path := Config.Edit.Indexes_Directory) return Outcome + (Under : Absolute_Path := Settings.Edit.Indexes_Directory) return Outcome is Result : Outcome; Indexes : constant Loading.Set := Loading.Find_All (Under, Result); @@ -163,7 +163,7 @@ package body Alire.Index_On_Disk.Updates is use Ada.Calendar; begin Trace.Debug ("Index auto-refresh timestamp updated"); - Builtins.Index_Last_Update.Set (Config.Global, + Builtins.Index_Last_Update.Set (Settings.Global, Int (Clock - Epoch)); end Reset_Update_Time; diff --git a/src/alire/alire-index_on_disk-updates.ads b/src/alire/alire-index_on_disk-updates.ads index ceac9389a..ed2f70b6f 100644 --- a/src/alire/alire-index_on_disk-updates.ads +++ b/src/alire/alire-index_on_disk-updates.ads @@ -1,13 +1,13 @@ -with Alire.Config.Edit; +with Alire.Settings.Edit; package Alire.Index_On_Disk.Updates is procedure Auto_Update - (Under : Absolute_Path := Config.Edit.Indexes_Directory); + (Under : Absolute_Path := Settings.Edit.Indexes_Directory); -- Check last update timestamp and update if necessary function Update_All - (Under : Absolute_Path := Config.Edit.Indexes_Directory) return Outcome; + (Under : Absolute_Path := Settings.Edit.Indexes_Directory) return Outcome; -- Find and update all indexes at given location procedure Reset_Update_Time; diff --git a/src/alire/alire-origins-deployers-git.adb b/src/alire/alire-origins-deployers-git.adb index e3a4d1d57..2fc62c453 100644 --- a/src/alire/alire-origins-deployers-git.adb +++ b/src/alire/alire-origins-deployers-git.adb @@ -1,4 +1,4 @@ -with Alire.Config.Builtins; +with Alire.Settings.Builtins; with Alire.Directories; with Alire.VCSs.Git; @@ -15,7 +15,7 @@ package body Alire.Origins.Deployers.Git is begin VCSs.Git.Handler.Clone (This.Base.URL_With_Commit, Folder).Assert; - if Config.Builtins.Dependencies_Git_Keep_Repository.Get then + if Settings.Builtins.Dependencies_Git_Keep_Repository.Get then Trace.Debug ("Keeping git repo from " & This.Base.TTY_URL_With_Commit & " at " & TTY.URL (Folder)); diff --git a/src/alire/alire-paths-vault.ads b/src/alire/alire-paths-vault.ads index 23d4f3170..0c6b1eeb4 100644 --- a/src/alire/alire-paths-vault.ads +++ b/src/alire/alire-paths-vault.ads @@ -1,4 +1,4 @@ -with Alire.Config.Edit; +with Alire.Settings.Edit; package Alire.Paths.Vault is @@ -10,7 +10,7 @@ package Alire.Paths.Vault is -- are run there (see Alire.Builds). function Path return Absolute_Path - is (Config.Edit.Cache_Path + is (Settings.Edit.Cache_Path / Release_Folder_Inside_Working_Folder); end Alire.Paths.Vault; diff --git a/src/alire/alire-platforms-current.ads b/src/alire/alire-platforms-current.ads index 913b311ab..bc632742b 100644 --- a/src/alire/alire-platforms-current.ads +++ b/src/alire/alire-platforms-current.ads @@ -1,6 +1,6 @@ private with AAA.Enum_Tools; -private with Alire.Config.Builtins; +private with Alire.Settings.Builtins; limited with Alire.Environment; private with Alire.OS_Lib.Subprocess; private with Alire.Platforms.Common; @@ -92,13 +92,14 @@ private Platforms.Distribution_Unknown -- Overridden detection - elsif Config.Builtins.Distribution_Override.Get /= "" then - (if Is_Valid_Distro (Config.Builtins.Distribution_Override.Get) then - Distributions'Value (Config.Builtins.Distribution_Override.Get) + elsif Settings.Builtins.Distribution_Override.Get /= "" then + (if Is_Valid_Distro (Settings.Builtins.Distribution_Override.Get) then + Distributions'Value + (Settings.Builtins.Distribution_Override.Get) else Return_With_Warning ("Invalid distribution override: " - & Config.Builtins.Distribution_Override.Get, + & Settings.Builtins.Distribution_Override.Get, Result => Platforms.Distribution_Unknown)) -- Regular detection diff --git a/src/alire/alire-platforms-folders.ads b/src/alire/alire-platforms-folders.ads index 456866be4..f330cf743 100644 --- a/src/alire/alire-platforms-folders.ads +++ b/src/alire/alire-platforms-folders.ads @@ -3,7 +3,7 @@ package Alire.Platforms.Folders is -- This spec must be fulfilled by bodies for each different OS we support -- IMPORTANT NOTE: these are not intended to be used directly in most - -- cases; instead, use the ones in Alire.Config.Edit that take into + -- cases; instead, use the ones in Alire.Settings.Edit that take into -- account user overriding of the config location. function Config return Absolute_Path; diff --git a/src/alire/alire-publish.adb b/src/alire/alire-publish.adb index a0aa7d4e8..0edcc4b2f 100644 --- a/src/alire/alire-publish.adb +++ b/src/alire/alire-publish.adb @@ -3,7 +3,7 @@ with Ada.Text_IO; with AAA.Strings; -with Alire.Config.Builtins; +with Alire.Settings.Builtins; with Alire.Crates; with Alire.Environment; with Alire.Errors; @@ -578,12 +578,12 @@ package body Alire.Publish is then raise Early_Stop; end if; - elsif not Config.Builtins.User_Github_Login.Is_Empty then + elsif not Settings.Builtins.User_Github_Login.Is_Empty then Put_Info ("Please upload this file to " & TTY.URL (Index.Community_Host & "/" - & Config.Builtins.User_Github_Login.Get & "/" + & Settings.Builtins.User_Github_Login.Get & "/" & Index.Community_Repo_Name & "/upload/" & Index.Community_Branch & "/" @@ -810,7 +810,7 @@ package body Alire.Publish is -- User has an account - if Config.Builtins.User_Github_Login.Is_Empty then + if Settings.Builtins.User_Github_Login.Is_Empty then Put_Info ("Publishing to the community index" & " requires a GitHub account."); else diff --git a/src/alire/alire-releases.adb b/src/alire/alire-releases.adb index 95aa11ef5..1858480fe 100644 --- a/src/alire/alire-releases.adb +++ b/src/alire/alire-releases.adb @@ -1,7 +1,7 @@ with Ada.Directories; with Ada.Text_IO; -with Alire.Config.Builtins; +with Alire.Settings.Builtins; with Alire.Crates; with Alire.Directories; with Alire.Defaults; @@ -85,7 +85,7 @@ package body Alire.Releases is Newline : constant String := ASCII.LF & " "; begin for Dep of This.Flat_Dependencies loop - if Config.Builtins.Warning_Caret.Get + if Settings.Builtins.Warning_Caret.Get and then AAA.Strings.Contains (Dep.Versions.Image, "^0") then @@ -98,7 +98,7 @@ package body Alire.Releases is & "The suspicious dependency is: " & TTY.Version (Dep.Image) & Newline & "You can disable this warning by setting the option " - & TTY.Emph (Config.Builtins.Warning_Caret.Key) & " to false.", + & TTY.Emph (Settings.Builtins.Warning_Caret.Key) & " to false.", Warnings.Caret_Or_Tilde); return True; end if; diff --git a/src/alire/alire-roots.adb b/src/alire/alire-roots.adb index 0f4d1a295..be9ea1d43 100644 --- a/src/alire/alire-roots.adb +++ b/src/alire/alire-roots.adb @@ -669,7 +669,7 @@ package body Alire.Roots is Guard : Directories.Guard (Directories.Enter (Path (This))) with Unreferenced; -- At some point inside the configuration generation process the config - -- is loaded and Config.Edit.Filepath requires being inside the root, + -- is loaded and Settings.Edit.Filepath requires being inside the root, -- which can't be directly used because of circularities. begin This.Load_Configuration; diff --git a/src/alire/alire-selftest.adb b/src/alire/alire-selftest.adb index cdaf422a2..a6ae87802 100644 --- a/src/alire/alire-selftest.adb +++ b/src/alire/alire-selftest.adb @@ -1,4 +1,4 @@ -with Alire.Config.Edit; +with Alire.Settings.Edit; with Alire.Utils.Regex; with Alire.VCSs.Git; @@ -13,28 +13,28 @@ package body Alire.Selftest is Key : constant String := "test_key"; Val : constant String := "nominal"; begin - Config.Edit.Set_Globally (Key, Val); - pragma Assert (Config.DB.Defined (Key)); - pragma Assert (Config.DB.Get (Key, "snafu") = Val); + Settings.Edit.Set_Globally (Key, Val); + pragma Assert (Settings.DB.Defined (Key)); + pragma Assert (Settings.DB.Get (Key, "snafu") = Val); -- Check typed storing -- Raw storing of integer - Config.Edit.Set_Globally (Key, "777"); - pragma Assert (Integer (Config.DB.Get (Key, 0)) = 777); + Settings.Edit.Set_Globally (Key, "777"); + pragma Assert (Integer (Settings.DB.Get (Key, 0)) = 777); -- Raw storing of boolean - Config.Edit.Set_Globally (Key, "true"); - pragma Assert (Config.DB.Get (Key, False) = True); + Settings.Edit.Set_Globally (Key, "true"); + pragma Assert (Settings.DB.Get (Key, False) = True); -- Typed storing of boolean - Config.Edit.Set_Boolean (Config.Global, Key, False); - pragma Assert (Config.DB.Get (Key, True) = False); + Settings.Edit.Set_Boolean (Settings.Global, Key, False); + pragma Assert (Settings.DB.Get (Key, True) = False); -- Raw storing of boolean with wrong type - Config.Edit.Set_Globally (Key, "True"); + Settings.Edit.Set_Globally (Key, "True"); -- This causes a string to be stored, as in TOML only "true" is bool - pragma Assert (Config.DB.Get (Key, "False") = "True"); + pragma Assert (Settings.DB.Get (Key, "False") = "True"); end Check_Config_Changes; diff --git a/src/alire/alire-config-builtins.ads b/src/alire/alire-settings-builtins.ads similarity index 98% rename from src/alire/alire-config-builtins.ads rename to src/alire/alire-settings-builtins.ads index 745d0573b..d4c87f6a2 100644 --- a/src/alire/alire-config-builtins.ads +++ b/src/alire/alire-settings-builtins.ads @@ -1,6 +1,6 @@ -with Alire.Config.Checks; +with Alire.Settings.Checks; -package Alire.Config.Builtins is +package Alire.Settings.Builtins is subtype Builtin is Builtin_Option; @@ -205,4 +205,4 @@ package Alire.Config.Builtins is "using a compatible index with a lower version than the newest" & " known."); -end Alire.Config.Builtins; +end Alire.Settings.Builtins; diff --git a/src/alire/alire-config-checks.adb b/src/alire/alire-settings-checks.adb similarity index 87% rename from src/alire/alire-config-checks.adb rename to src/alire/alire-settings-checks.adb index b86edbfdc..e8fb2413f 100644 --- a/src/alire/alire-config-checks.adb +++ b/src/alire/alire-settings-checks.adb @@ -2,7 +2,7 @@ with AAA.Enum_Tools; with Alire.Platforms; -package body Alire.Config.Checks is +package body Alire.Settings.Checks is function Is_Valid is new AAA.Enum_Tools.Is_Valid (Alire.Platforms.Known_Distributions); @@ -17,4 +17,4 @@ package body Alire.Config.Checks is is (Value.Kind in TOML.TOML_String and then Is_Valid (Value.As_String)); -end Alire.Config.Checks; +end Alire.Settings.Checks; diff --git a/src/alire/alire-config-checks.ads b/src/alire/alire-settings-checks.ads similarity index 73% rename from src/alire/alire-config-checks.ads rename to src/alire/alire-settings-checks.ads index a5f971ec3..a25a48cb7 100644 --- a/src/alire/alire-config-checks.ads +++ b/src/alire/alire-settings-checks.ads @@ -1,9 +1,9 @@ with TOML; -package Alire.Config.Checks is +package Alire.Settings.Checks is function Valid_Distro (Key : CLIC.Config.Config_Key; Value : TOML.TOML_Value) return Boolean; -end Alire.Config.Checks; +end Alire.Settings.Checks; diff --git a/src/alire/alire-settings-edit-early_load.adb b/src/alire/alire-settings-edit-early_load.adb new file mode 100644 index 000000000..de3ed9139 --- /dev/null +++ b/src/alire/alire-settings-edit-early_load.adb @@ -0,0 +1,14 @@ +package body Alire.Settings.Edit.Early_Load is + + ------------------- + -- Load_Settings -- + ------------------- + + procedure Load_Settings is + begin + Alire.Settings.Edit.Load_Config; + end Load_Settings; + +begin + Load_Settings; +end Alire.Settings.Edit.Early_Load; diff --git a/src/alire/alire-config-edit-early_load.ads b/src/alire/alire-settings-edit-early_load.ads similarity index 55% rename from src/alire/alire-config-edit-early_load.ads rename to src/alire/alire-settings-edit-early_load.ads index 73656602e..4c6cafe52 100644 --- a/src/alire/alire-config-edit-early_load.ads +++ b/src/alire/alire-settings-edit-early_load.ads @@ -1,7 +1,7 @@ -package Alire.Config.Edit.Early_Load with Elaborate_Body is +package Alire.Settings.Edit.Early_Load with Elaborate_Body is - procedure Load_Config; + procedure Load_Settings; -- For internal use of Alire_Early_Elaboration, DO NOT CALL otherwise. -- This should be hidden but that would require a non-trivial refactoring. -end Alire.Config.Edit.Early_Load; +end Alire.Settings.Edit.Early_Load; diff --git a/src/alire/alire-config-edit.adb b/src/alire/alire-settings-edit.adb similarity index 96% rename from src/alire/alire-config-edit.adb rename to src/alire/alire-settings-edit.adb index b7a846fbd..3303e53fb 100644 --- a/src/alire/alire-config-edit.adb +++ b/src/alire/alire-settings-edit.adb @@ -1,16 +1,16 @@ with Ada.Text_IO; -with Alire.Config.Builtins; with Alire.Environment; with Alire.Paths; with Alire.Platforms.Folders; with Alire.Platforms.Current; +with Alire.Settings.Builtins; with Alire.Utils; with CLIC.Config.Edit; with CLIC.Config.Load; -package body Alire.Config.Edit is +package body Alire.Settings.Edit is use Ada.Strings.Unbounded; use AAA.Strings; @@ -57,7 +57,7 @@ package body Alire.Config.Edit is -- Set -- --------- - procedure Set (Level : Config.Level; + procedure Set (Level : Settings.Level; Key : CLIC.Config.Config_Key; Value : String; Check : CLIC.Config.Check_Import := null) @@ -73,7 +73,7 @@ package body Alire.Config.Edit is -- Unset -- ----------- - procedure Unset (Level : Config.Level; + procedure Unset (Level : Settings.Level; Key : CLIC.Config.Config_Key) is begin @@ -92,7 +92,7 @@ package body Alire.Config.Edit is -- Set_Boolean -- ----------------- - procedure Set_Boolean (Level : Config.Level; + procedure Set_Boolean (Level : Settings.Level; Key : CLIC.Config.Config_Key; Value : Boolean; Check : CLIC.Config.Check_Import := null) @@ -114,7 +114,7 @@ package body Alire.Config.Edit is begin case Lvl is when Global => - return Alire.Config.Edit.Path / "config.toml"; + return Alire.Settings.Edit.Path / "config.toml"; when Local => declare Candidate : constant String := @@ -154,7 +154,7 @@ package body Alire.Config.Edit is -- Set variables elsewhere Platforms.Current.Disable_Distribution_Detection := - Config.Builtins.Distribution_Disable_Detection.Get; + Settings.Builtins.Distribution_Disable_Detection.Get; if Platforms.Current.Disable_Distribution_Detection then Trace.Debug ("Distribution detection disabled by configuration"); end if; @@ -318,4 +318,4 @@ package body Alire.Config.Edit is end loop; end Print_Builtins_Doc; -end Alire.Config.Edit; +end Alire.Settings.Edit; diff --git a/src/alire/alire-config-edit.ads b/src/alire/alire-settings-edit.ads similarity index 91% rename from src/alire/alire-config-edit.ads rename to src/alire/alire-settings-edit.ads index b1055b7e3..13959746a 100644 --- a/src/alire/alire-config-edit.ads +++ b/src/alire/alire-settings-edit.ads @@ -6,7 +6,7 @@ with CLIC.Config; with TOML; -package Alire.Config.Edit is +package Alire.Settings.Edit is -- Shortcuts that use the standard config locations. These interpret the -- value in string as a TOML type whenever possible. @@ -19,14 +19,14 @@ package Alire.Config.Edit is Value : String; Check : CLIC.Config.Check_Import := null); - procedure Set (Level : Config.Level; + procedure Set (Level : Settings.Level; Key : CLIC.Config.Config_Key; Value : String; Check : CLIC.Config.Check_Import := null); -- Typed alternatives - procedure Set_Boolean (Level : Config.Level; + procedure Set_Boolean (Level : Settings.Level; Key : CLIC.Config.Config_Key; Value : Boolean; Check : CLIC.Config.Check_Import := null); @@ -35,7 +35,7 @@ package Alire.Config.Edit is -- here all non-preelaborable things related to config loading. This -- way, querying stays preelaborable. - procedure Unset (Level : Config.Level; + procedure Unset (Level : Settings.Level; Key : CLIC.Config.Config_Key); -- Unset a key at a level; silently succeed even if the key was undefined. @@ -66,7 +66,7 @@ package Alire.Config.Edit is -- Return path of the configuration file corresponding to the given -- configuration level. - -- Support for built-in config variables. See Alire.Config.Builtins also. + -- Support for built-in config variables. See Alire.Settings.Builtins also. function Builtins_Info return AAA.Strings.Vector; -- Return a String_Vector with the documentation of builtin configuration @@ -88,4 +88,4 @@ private -- the program-wide configuration ready. This is done during startup from -- Alire_Early_Elaboration so config is available ASAP. -end Alire.Config.Edit; +end Alire.Settings.Edit; diff --git a/src/alire/alire-config.adb b/src/alire/alire-settings.adb similarity index 94% rename from src/alire/alire-config.adb rename to src/alire/alire-settings.adb index 5b5de1435..c5d21d5c6 100644 --- a/src/alire/alire-config.adb +++ b/src/alire/alire-settings.adb @@ -1,6 +1,6 @@ -with Alire.Config.Edit; +with Alire.Settings.Edit; -package body Alire.Config is +package body Alire.Settings is -------- -- DB -- @@ -61,7 +61,7 @@ package body Alire.Config is --------- procedure Set (This : Builtin_Option; - Level : Config.Level; + Level : Settings.Level; Value : String) is begin @@ -73,7 +73,7 @@ package body Alire.Config is --------- procedure Set (This : Builtin_Option; - Level : Config.Level; + Level : Settings.Level; Value : Boolean) is begin @@ -85,7 +85,7 @@ package body Alire.Config is --------- procedure Set (This : Builtin_Option; - Level : Config.Level; + Level : Settings.Level; Value : Config_Int) is begin @@ -97,7 +97,7 @@ package body Alire.Config is ----------- procedure Unset (This : Builtin_Option; - Level : Config.Level) + Level : Settings.Level) is begin Edit.Unset (Level, +This.Key); @@ -182,4 +182,4 @@ package body Alire.Config is Public => Public, Check => Check)); -end Alire.Config; +end Alire.Settings; diff --git a/src/alire/alire-config.ads b/src/alire/alire-settings.ads similarity index 94% rename from src/alire/alire-config.ads rename to src/alire/alire-settings.ads index 5082ea522..66597784a 100644 --- a/src/alire/alire-config.ads +++ b/src/alire/alire-settings.ads @@ -6,7 +6,7 @@ with Alire.OS_Lib; use Alire.OS_Lib.Operators; with CLIC.Config; -package Alire.Config is +package Alire.Settings is function DB return access constant CLIC.Config.Instance; @@ -49,19 +49,19 @@ package Alire.Config is procedure Set_Globally (This : Builtin_Option; Value : String); procedure Set (This : Builtin_Option; - Level : Config.Level; + Level : Settings.Level; Value : String); procedure Set (This : Builtin_Option; - Level : Config.Level; + Level : Settings.Level; Value : Boolean); procedure Set (This : Builtin_Option; - Level : Config.Level; + Level : Settings.Level; Value : Config_Int); procedure Unset (This : Builtin_Option; - Level : Config.Level); + Level : Settings.Level); function New_Builtin (Key : CLIC.Config.Config_Key; Kind : Builtin_Kind; @@ -115,4 +115,4 @@ private All_Builtins : Builtin_Maps.Map; -end Alire.Config; +end Alire.Settings; diff --git a/src/alire/alire-solutions.adb b/src/alire/alire-solutions.adb index e0ea1db4e..8e5228c40 100644 --- a/src/alire/alire-solutions.adb +++ b/src/alire/alire-solutions.adb @@ -1,6 +1,6 @@ with Ada.Containers; -with Alire.Config.Builtins; +with Alire.Settings.Builtins; with Alire.Crates; with Alire.Dependencies.Diffs; with Alire.Dependencies.Graphs; @@ -1402,7 +1402,7 @@ package body Alire.Solutions is -- Do nothing when deps are being removed. - if not Config.Builtins.Solver_Autonarrow.Get or else + if not Settings.Builtins.Solver_Autonarrow.Get or else not Diff.Removed.Is_Empty then return New_Deps; diff --git a/src/alire/alire-toml_index.adb b/src/alire/alire-toml_index.adb index 54de246b2..07c3aac60 100644 --- a/src/alire/alire-toml_index.adb +++ b/src/alire/alire-toml_index.adb @@ -1,6 +1,6 @@ with Ada.Directories; -with Alire.Config.Builtins; +with Alire.Settings.Builtins; with Alire.Crates; with Alire.Directories; with Alire.Loading; @@ -113,7 +113,7 @@ package body Alire.TOML_Index is use type Semantic_Versioning.Version; Warn_Of_Old_Compatible : constant Boolean := - Config.Builtins.Warning_Old_Index.Get; + Settings.Builtins.Warning_Old_Index.Get; ---------------------- -- Compare_Branches -- @@ -130,7 +130,7 @@ package body Alire.TOML_Index is & TTY.Emph (Alire.Index.Branch_Kind) & "' but your community index branch is '" & TTY.Emph (Local) & "'", - Disable_Setting => Config.Builtins.Warning_Old_Index.Key); + Disable_Setting => Settings.Builtins.Warning_Old_Index.Key); Suggest_Update := True; end if; end Compare_Branches; @@ -190,7 +190,7 @@ package body Alire.TOML_Index is & ") is older than the newest supported by alr (" & Alire.Index.Version.Image & ")", Disable_Setting => - Config.Builtins.Warning_Old_Index.Key); + Settings.Builtins.Warning_Old_Index.Key); Suggest_Update := True; elsif not Alire.Index.Valid_Versions.Contains (Loading_Index_Version) then diff --git a/src/alire/alire-toolchains.adb b/src/alire/alire-toolchains.adb index 45c6d2150..08a118e43 100644 --- a/src/alire/alire-toolchains.adb +++ b/src/alire/alire-toolchains.adb @@ -3,7 +3,7 @@ with AAA.Text_IO; with Ada.Containers.Indefinite_Vectors; with Ada.Directories; -with Alire.Config.Edit; +with Alire.Settings.Edit; with Alire.Directories; with Alire.Index; with Alire.Manifest; @@ -44,7 +44,7 @@ package body Alire.Toolchains is -- Assistant -- --------------- - procedure Assistant (Level : Config.Level; + procedure Assistant (Level : Settings.Level; Allow_Incompatible : Boolean := False; First_Run : Boolean := False) is package Release_Vectors is new @@ -403,14 +403,15 @@ package body Alire.Toolchains is -- Set_As_Default -- -------------------- - procedure Set_As_Default (Release : Releases.Release; Level : Config.Level) + procedure Set_As_Default (Release : Releases.Release; + Level : Settings.Level) is begin - Alire.Config.Edit.Set + Alire.Settings.Edit.Set (Level, Key => Tool_Key (Release.Name), Value => Release.Milestone.Image); - Alire.Config.Edit.Set_Boolean + Alire.Settings.Edit.Set_Boolean (Level, Key => Tool_Key (Release.Name, For_Is_External), Value => not Release.Origin.Is_Index_Provided); @@ -420,10 +421,11 @@ package body Alire.Toolchains is -- Set_Automatic_Assistant -- ----------------------------- - procedure Set_Automatic_Assistant (Enabled : Boolean; Level : Config.Level) + procedure Set_Automatic_Assistant (Enabled : Boolean; + Level : Settings.Level) is begin - Config.Builtins.Toolchain_Assistant.Set (Level, Enabled); + Settings.Builtins.Toolchain_Assistant.Set (Level, Enabled); end Set_Automatic_Assistant; ------------------------ @@ -431,7 +433,7 @@ package body Alire.Toolchains is ------------------------ function Tool_Is_Configured (Crate : Crate_Name) return Boolean - is (Config.DB.Defined (Tool_Key (Crate))); + is (Settings.DB.Defined (Tool_Key (Crate))); --------------------- -- Tool_Dependency -- @@ -467,12 +469,12 @@ package body Alire.Toolchains is ----------------- procedure Unconfigure (Crate : Crate_Name; - Level : Config.Level; + Level : Settings.Level; Fail_If_Unset : Boolean := True) is begin - if CLIC.Config.Defined (Config.DB.all, Tool_Key (Crate)) and then + if CLIC.Config.Defined (Settings.DB.all, Tool_Key (Crate)) and then not CLIC.Config.Edit.Unset - (Config.Edit.Filepath (Level), + (Settings.Edit.Filepath (Level), Tool_Key (Crate)) then declare @@ -490,12 +492,13 @@ package body Alire.Toolchains is -- Remove caching of external condition too for consistency - if CLIC.Config.Defined (Config.DB.all, Tool_Key (Crate, For_Is_External)) + if CLIC.Config.Defined (Settings.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), + (Settings.Edit.Filepath (Level), Tool_Key (Crate, For_Is_External))'Image); end if; end Unconfigure; @@ -605,9 +608,9 @@ package body Alire.Toolchains is ---------- function Path return Absolute_Path - is (if Config.Builtins.Toolchain_Dir.Get /= "" - then Config.Builtins.Toolchain_Dir.Get - else Config.Edit.Cache_Path / "toolchains"); + is (if Settings.Builtins.Toolchain_Dir.Get /= "" + then Settings.Builtins.Toolchain_Dir.Get + else Settings.Edit.Cache_Path / "toolchains"); ------------ -- Deploy -- @@ -717,9 +720,9 @@ package body Alire.Toolchains is -- So remove it at any level. We currently do not have a way to know -- from which level we have to remove this configuration. - Toolchains.Unconfigure (Release.Name, Config.Global, + Toolchains.Unconfigure (Release.Name, Settings.Global, Fail_If_Unset => False); - Toolchains.Unconfigure (Release.Name, Config.Local, + Toolchains.Unconfigure (Release.Name, Settings.Local, Fail_If_Unset => False); Invalidate_Available_Cache; diff --git a/src/alire/alire-toolchains.ads b/src/alire/alire-toolchains.ads index 31c9c0262..51b44f3e7 100644 --- a/src/alire/alire-toolchains.ads +++ b/src/alire/alire-toolchains.ads @@ -2,7 +2,7 @@ with Ada.Containers.Indefinite_Ordered_Sets; with AAA.Strings; -with Alire.Config.Builtins; +with Alire.Settings.Builtins; with Alire.Dependencies; with Alire.Errors; with Alire.Milestones; @@ -30,7 +30,7 @@ package Alire.Toolchains is function Any_Tool (Crate : Crate_Name) return Dependencies.Dependency; -- Returns a dependency on crate* - procedure Assistant (Level : Config.Level; + procedure Assistant (Level : Settings.Level; Allow_Incompatible : Boolean := False; First_Run : Boolean := False); -- Runs the interactive assistant to select the default toolchain. By @@ -43,12 +43,14 @@ package Alire.Toolchains is -- plain `gnat`. This way we need not to litter the callers with similar -- transformations, as we always want whatever gnat_XXX is used for "gnat". - procedure Set_Automatic_Assistant (Enabled : Boolean; Level : Config.Level); + procedure Set_Automatic_Assistant (Enabled : Boolean; + Level : Settings.Level); -- Enable/Disable the automatic assistant on next run function Assistant_Enabled return Boolean; - procedure Set_As_Default (Release : Releases.Release; Level : Config.Level); + procedure Set_As_Default (Release : Releases.Release; + Level : Settings.Level); -- Mark the given release as the default to be used. Does not check that it -- be already installed. @@ -83,7 +85,7 @@ package Alire.Toolchains is -- manually). procedure Unconfigure (Crate : Crate_Name; - Level : Config.Level; + Level : Settings.Level; Fail_If_Unset : Boolean := True); -- Set the crate as not configured. If not set and Fail_If_Unset, raise @@ -160,7 +162,7 @@ private ----------------------- function Assistant_Enabled return Boolean - is (Config.Builtins.Toolchain_Assistant.Get); + is (Settings.Builtins.Toolchain_Assistant.Get); ---------------------- -- Tool_Is_External -- @@ -168,7 +170,7 @@ private function Tool_Is_External (Crate : Crate_Name) return Boolean is (Boolean'Value - (Config.DB.Get_As_String -- because it could be stored as bool or string + (Settings.DB.Get_As_String -- because it could be stored as bool or str (Tool_Key (Crate, For_Is_External), "True"))); -------------- @@ -182,8 +184,8 @@ private then Tool_Key (GNAT_Crate, Kind) else CLIC.Config.Config_Key ((case Kind is - when For_Use => Config.Builtins.Toolchain_Use.Key, - when For_Is_External => Config.Builtins.Toolchain_External.Key) + when For_Use => Settings.Builtins.Toolchain_Use.Key, + when For_Is_External => Settings.Builtins.Toolchain_External.Key) & "." & Crate.As_String)); -------------------- @@ -191,6 +193,6 @@ private -------------------- -- Return the milestone stored by the user for this tool function Tool_Milestone (Crate : Crate_Name) return Milestones.Milestone - is (Milestones.New_Milestone (Config.DB.Get (Tool_Key (Crate), ""))); + is (Milestones.New_Milestone (Settings.DB.Get (Tool_Key (Crate), ""))); end Alire.Toolchains; diff --git a/src/alire/alire-utils-user_input-query_config.adb b/src/alire/alire-utils-user_input-query_config.adb index fed2561e1..50e110c3c 100644 --- a/src/alire/alire-utils-user_input-query_config.adb +++ b/src/alire/alire-utils-user_input-query_config.adb @@ -1,4 +1,4 @@ -with Alire.Config.Edit; +with Alire.Settings.Edit; with CLIC.User_Input; use CLIC.User_Input; package body Alire.Utils.User_Input.Query_Config is @@ -13,17 +13,17 @@ package body Alire.Utils.User_Input.Query_Config is Validation : String_Validation_Access) return String is - use Alire.Config; + use Alire.Settings; begin - if Config.DB.Defined (Config_Key) then - return Config.DB.Get (Config_Key, Default); + if Settings.DB.Defined (Config_Key) then + return Settings.DB.Get (Config_Key, Default); else declare Result : constant String := Query_String (Question, Default, Validation); begin if Result /= Default then - Alire.Config.Edit.Set_Globally (Config_Key, Result); + Alire.Settings.Edit.Set_Globally (Config_Key, Result); end if; return Result; diff --git a/src/alire/alire_early_elaboration.adb b/src/alire/alire_early_elaboration.adb index 94765f2e5..ae97124d0 100644 --- a/src/alire/alire_early_elaboration.adb +++ b/src/alire/alire_early_elaboration.adb @@ -2,7 +2,7 @@ with AAA.Strings; with Ada.Directories; -with Alire.Config.Edit.Early_Load; +with Alire.Settings.Edit.Early_Load; with GNAT.Command_Line; with GNAT.OS_Lib; @@ -98,7 +98,7 @@ package body Alire_Early_Elaboration is Early_Error ("Given configuration path is not a directory: " & Path); else - Alire.Config.Edit.Set_Path (Adirs.Full_Name (Path)); + Alire.Settings.Edit.Set_Path (Adirs.Full_Name (Path)); end if; end Set_Config_Path; @@ -199,7 +199,7 @@ package body Alire_Early_Elaboration is end if; -- Load config ASAP - Alire.Config.Edit.Early_Load.Load_Config; + Alire.Settings.Edit.Early_Load.Load_Settings; end Early_Switch_Detection; ------------------- diff --git a/src/alire/os_windows/alire-platforms-current__windows.adb b/src/alire/os_windows/alire-platforms-current__windows.adb index bc136d106..d4ccb3140 100644 --- a/src/alire/os_windows/alire-platforms-current__windows.adb +++ b/src/alire/os_windows/alire-platforms-current__windows.adb @@ -8,7 +8,7 @@ pragma Unreferenced (Alire_Early_Elaboration); with Alire.Environment; with Alire.OS_Lib; use Alire.OS_Lib; -with Alire.Config.Builtins.Windows; +with Alire.Settings.Builtins.Windows; with Alire.Errors; with GNATCOLL.VFS; @@ -154,7 +154,7 @@ package body Alire.Platforms.Current is use CLIC.User_Input; begin - if Config.Builtins.Windows.Msys2_Do_Not_Install.Get then + if Settings.Builtins.Windows.Msys2_Do_Not_Install.Get then -- User already requested that msys2 should not be installed @@ -189,7 +189,8 @@ package body Alire.Platforms.Current is Default => No) = Yes then -- Save user choice in the global config - Config.Builtins.Windows.Msys2_Do_Not_Install.Set_Globally ("true"); + Settings + .Builtins.Windows.Msys2_Do_Not_Install.Set_Globally ("true"); end if; -- We are not allowed to install @@ -244,10 +245,10 @@ package body Alire.Platforms.Current is end Download_File; Msys2_Installer : constant String := - Config.Builtins.Windows.Msys2_Installer.Get; + Settings.Builtins.Windows.Msys2_Installer.Get; Msys2_Installer_URL : constant String := - Config.Builtins.Windows.Msys2_Installer_URL.Get; + Settings.Builtins.Windows.Msys2_Installer_URL.Get; Result : Alire.Outcome; begin @@ -285,9 +286,10 @@ package body Alire.Platforms.Current is return Alire.Outcome_Failure ("Cannot setup msys2 environment"); end; - if Config.Builtins.Windows.Msys2_Install_Dir.Is_Empty then + if Settings.Builtins.Windows.Msys2_Install_Dir.Is_Empty then -- Save msys2 install dir in the global config - Config.Builtins.Windows.Msys2_Install_Dir.Set_Globally (Install_Dir); + Settings + .Builtins.Windows.Msys2_Install_Dir.Set_Globally (Install_Dir); end if; -- Load msys2 environment to attempt first full update according to @@ -295,7 +297,7 @@ package body Alire.Platforms.Current is -- https://www.msys2.org/wiki/MSYS2-installation/ declare Cfg_Install_Dir : constant String := - Config.Builtins.Windows.Msys2_Install_Dir.Get; + Settings.Builtins.Windows.Msys2_Install_Dir.Get; begin Set_Msys2_Env (Cfg_Install_Dir); end; @@ -367,7 +369,7 @@ package body Alire.Platforms.Current is Result : Alire.Outcome; Cfg_Install_Dir : constant String := - Config.Builtins.Windows.Msys2_Install_Dir.Get; + Settings.Builtins.Windows.Msys2_Install_Dir.Get; Pacman : constant String := Alire.OS_Lib.Subprocess.Locate_In_Path ("pacman"); diff --git a/src/alire/os_windows/alire-config-builtins-windows.ads b/src/alire/os_windows/alire-settings-builtins-windows.ads similarity index 85% rename from src/alire/os_windows/alire-config-builtins-windows.ads rename to src/alire/os_windows/alire-settings-builtins-windows.ads index ef3d2b422..f6a2d90a2 100644 --- a/src/alire/os_windows/alire-config-builtins-windows.ads +++ b/src/alire/os_windows/alire-settings-builtins-windows.ads @@ -1,8 +1,8 @@ -- Ensure config is loaded for some defaults below -with Alire.Config.Edit.Early_Load; -pragma Unreferenced (Alire.Config.Edit.Early_Load); +with Alire.Settings.Edit.Early_Load; +pragma Unreferenced (Alire.Settings.Edit.Early_Load); -package Alire.Config.Builtins.Windows is +package Alire.Settings.Builtins.Windows is Default_Msys2_Installer : constant String := "msys2-x86_64-20221216.exe"; Default_Msys2_Installer_URL : constant String := @@ -21,7 +21,7 @@ package Alire.Config.Builtins.Windows is Msys2_Install_Dir : constant Builtin := New_Builtin (Key => "msys2.install_dir", Kind => Cfg_Absolute_Path, - Def => Config.Edit.Cache_Path / "msys64", + Def => Settings.Edit.Cache_Path / "msys64", Help => "Directory where Alire will detect and/or install" & " msys2 system package manager. (Windows only)"); @@ -40,4 +40,4 @@ package Alire.Config.Builtins.Windows is Help => "URL of the executable msys2 installer. (Windows only)"); -end Alire.Config.Builtins.Windows; +end Alire.Settings.Builtins.Windows; diff --git a/src/alr/alr-commands-clean.adb b/src/alr/alr-commands-clean.adb index 33412006d..d22918736 100644 --- a/src/alr/alr-commands-clean.adb +++ b/src/alr/alr-commands-clean.adb @@ -1,6 +1,6 @@ with Ada.Directories; -with Alire.Config.Edit; +with Alire.Settings.Edit; with Alire.Directories; with Alire.Paths; with Alire.Platforms.Current; @@ -66,7 +66,7 @@ package body Alr.Commands.Clean is -- Configuration-wide cache, where interrupted binary downloads dwell... Alire.Directories.Traverse_Tree - (Start => Alire.Config.Edit.Path, + (Start => Alire.Settings.Edit.Path, Doing => Add_Target'Access, Recurse => True); diff --git a/src/alr/alr-commands-edit.adb b/src/alr/alr-commands-edit.adb index d0de9820a..36758d15a 100644 --- a/src/alr/alr-commands-edit.adb +++ b/src/alr/alr-commands-edit.adb @@ -1,7 +1,7 @@ with Ada.Containers; with Alire; use Alire; -with Alire.Config.Builtins; +with Alire.Settings.Builtins; with Alire.OS_Lib.Subprocess; with Alire.Platforms.Current; @@ -21,11 +21,11 @@ package body Alr.Commands.Edit is use Trace; begin if Cmd /= "" then - Config.Set_Globally (Config.Builtins.Editor_Cmd, Cmd); + Settings.Set_Globally (Settings.Builtins.Editor_Cmd, Cmd); Put_Info ("'" & TTY.Terminal (Cmd) & "' is now set as the editor command."); else - Config.Builtins.Editor_Cmd.Unset (Alire.Config.Global); + Settings.Builtins.Editor_Cmd.Unset (Alire.Settings.Global); Put_Info ("The editor command has been unset."); end if; @@ -64,7 +64,7 @@ package body Alr.Commands.Edit is use AAA.Strings; use CLIC.User_Input; - package Builtins renames Alire.Config.Builtins; + package Builtins renames Alire.Settings.Builtins; type Editor_Choice is (VScode, GNATstudio, Other); @@ -177,9 +177,9 @@ package body Alr.Commands.Edit is is use Ada.Containers; use GNAT.Strings; - use Alire.Config; + use Alire.Settings; - package Builtins renames Alire.Config.Builtins; + package Builtins renames Alire.Settings.Builtins; begin if Args.Count /= 0 then Reportaise_Wrong_Arguments (Cmd.Name & " doesn't take arguments"); diff --git a/src/alr/alr-commands-get.adb b/src/alr/alr-commands-get.adb index 3f1145d92..7ca2b122e 100644 --- a/src/alr/alr-commands-get.adb +++ b/src/alr/alr-commands-get.adb @@ -1,6 +1,6 @@ with Ada.Directories; -with Alire.Config.Builtins; +with Alire.Settings.Builtins; with Alire.Dependencies; with Alire.Directories; with Alire.Index; @@ -161,8 +161,8 @@ package body Alr.Commands.Get is Trace.Info ("Because --only was used, automatic dependency" & " retrieval is disabled in this workspace:" & " use `alr update` to apply dependency changes"); - Alire.Config.Builtins.Update_Manually_Only.Set (Alire.Config.Local, - True); + Alire.Settings.Builtins.Update_Manually_Only.Set + (Alire.Settings.Local, True); if not CLIC.User_Input.Not_Interactive then Alire.Roots.Print_Nested_Crates (Cmd.Root.Path); diff --git a/src/alr/alr-commands-index.adb b/src/alr/alr-commands-index.adb index a5a470e33..9f261746e 100644 --- a/src/alr/alr-commands-index.adb +++ b/src/alr/alr-commands-index.adb @@ -1,6 +1,6 @@ with AAA.Table_IO; -with Alire.Config.Edit; +with Alire.Settings.Edit; with Alire.Index; with Alire.Index_On_Disk.Loading; with Alire.Index_On_Disk.Updates; @@ -32,7 +32,7 @@ package body Alr.Commands.Index is Alire.Index_On_Disk.Loading.Add (Origin => Cmd.Add.all, Name => Cmd.Name.all, - Under => Alire.Config.Edit.Indexes_Directory, + Under => Alire.Settings.Edit.Indexes_Directory, Before => Before); begin Trace.Debug ("Index before ID = " & Before); @@ -50,7 +50,7 @@ package body Alr.Commands.Index is Result : Alire.Outcome; Indexes : constant Index_Load.Set := Index_Load.Find_All - (Alire.Config.Edit.Indexes_Directory, Result); + (Alire.Settings.Edit.Indexes_Directory, Result); Found : Boolean := False; begin if not Result.Success then @@ -153,7 +153,7 @@ package body Alr.Commands.Index is Result : Alire.Outcome; Indexes : constant Index_Load.Set := Index_Load.Find_All - (Alire.Config.Edit.Indexes_Directory, Result); + (Alire.Settings.Edit.Indexes_Directory, Result); Table : AAA.Table_IO.Table; Count : Natural := 0; @@ -301,7 +301,7 @@ package body Alr.Commands.Index is procedure Update_All is Result : constant Alire.Outcome := Index_Updates.Update_All - (Alire.Config.Edit.Indexes_Directory); + (Alire.Settings.Edit.Indexes_Directory); begin if not Result.Success then Reportaise_Command_Failed (Alire.Message (Result)); diff --git a/src/alr/alr-commands-init.adb b/src/alr/alr-commands-init.adb index f52354374..0895c203f 100644 --- a/src/alr/alr-commands-init.adb +++ b/src/alr/alr-commands-init.adb @@ -4,7 +4,7 @@ with Ada.Directories; with Ada.Wide_Wide_Text_IO; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; -with Alire.Config.Builtins; +with Alire.Settings.Builtins; with Alire.Roots.Optional; with Alire.Utils.User_Input.Query_Config; @@ -580,7 +580,7 @@ package body Alr.Commands.Init is procedure Execute (Cmd : in out Command; Args : AAA.Strings.Vector) is - use Alire.Config; + use Alire.Settings; Info : Crate_Init_Info; begin diff --git a/src/alr/alr-commands-settings.adb b/src/alr/alr-commands-settings.adb index 932bd8027..5043460dd 100644 --- a/src/alr/alr-commands-settings.adb +++ b/src/alr/alr-commands-settings.adb @@ -1,5 +1,5 @@ -with Alire.Config; -with Alire.Config.Edit; +with Alire.Settings; +with Alire.Settings.Edit; with Alire.Root; with CLIC.Config.Info; @@ -17,9 +17,9 @@ package body Alr.Commands.Settings is is Enabled : Natural := 0; - Lvl : constant Alire.Config.Level := (if Cmd.Global - then Alire.Config.Global - else Alire.Config.Local); + Lvl : constant Alire.Settings.Level := (if Cmd.Global + then Alire.Settings.Global + else Alire.Settings.Local); begin -- Check no multi-action @@ -44,7 +44,7 @@ package body Alr.Commands.Settings is end if; if Cmd.Builtins_Doc then - Alire.Config.Edit.Print_Builtins_Doc; + Alire.Settings.Edit.Print_Builtins_Doc; return; end if; @@ -59,13 +59,13 @@ package body Alr.Commands.Settings is when 0 => Trace.Always (CLIC.Config.Info.List - (Alire.Config.DB.all, + (Alire.Settings.DB.all, Filter => ".*", Show_Origin => Cmd.Show_Origin).Flatten (ASCII.LF)); when 1 => Trace.Always (CLIC.Config.Info.List - (Alire.Config.DB.all, + (Alire.Settings.DB.all, Filter => Args.First_Element, Show_Origin => Cmd.Show_Origin).Flatten (ASCII.LF)); when others => @@ -83,8 +83,9 @@ package body Alr.Commands.Settings is Args.First_Element & "'"); end if; - if Alire.Config.DB.Defined (Args.First_Element) then - Trace.Always (Alire.Config.DB.Get_As_String (Args.First_Element)); + if Alire.Settings.DB.Defined (Args.First_Element) then + Trace.Always + (Alire.Settings.DB.Get_As_String (Args.First_Element)); else Reportaise_Command_Failed ("Setting key '" & Args.First_Element & @@ -108,15 +109,15 @@ package body Alr.Commands.Settings is -- Check explicitly for booleans to store the proper TOML type -- regardless of the capitalization used by the user. if Is_Boolean (Val) then - Alire.Config.Edit.Set_Boolean + Alire.Settings.Edit.Set_Boolean (Lvl, Key, Boolean'Value (Val), - Check => Alire.Config.Edit.Valid_Builtin'Access); + Check => Alire.Settings.Edit.Valid_Builtin'Access); else - Alire.Config.Edit.Set + Alire.Settings.Edit.Set (Lvl, Key, Val, - Check => Alire.Config.Edit.Valid_Builtin'Access); + Check => Alire.Settings.Edit.Valid_Builtin'Access); end if; end; @@ -134,7 +135,7 @@ package body Alr.Commands.Settings is end if; if not CLIC.Config.Edit.Unset - (Alire.Config.Edit.Filepath (Lvl), Key) + (Alire.Settings.Edit.Filepath (Lvl), Key) then Reportaise_Command_Failed ("Cannot unset setting key"); end if; @@ -173,7 +174,7 @@ package body Alr.Commands.Settings is .New_Line .Append ("Built-in settings:") .New_Line - .Append (Alire.Config.Edit.Builtins_Info)); + .Append (Alire.Settings.Edit.Builtins_Info)); -------------------- -- Setup_Switches -- diff --git a/src/alr/alr-commands-toolchain.adb b/src/alr/alr-commands-toolchain.adb index ed1994a8e..b5f78188b 100644 --- a/src/alr/alr-commands-toolchain.adb +++ b/src/alr/alr-commands-toolchain.adb @@ -1,7 +1,7 @@ with AAA.Table_IO; -with Alire.Config.Edit; +with Alire.Settings.Edit; with Alire.Containers; with Alire.Dependencies; with Alire.Errors; @@ -237,8 +237,8 @@ package body Alr.Commands.Toolchain is Alire.Toolchains.Set_As_Default (Rel, Level => (if Cmd.Local - then Alire.Config.Local - else Alire.Config.Global)); + then Alire.Settings.Local + else Alire.Settings.Global)); Alire.Put_Info (Rel.Milestone.TTY_Image & " set as default in " & TTY.Emph (if Cmd.Local then "local" else "global") @@ -276,7 +276,7 @@ package body Alr.Commands.Toolchain is if Alire.Toolchains.Available.Is_Empty then Trace.Info ("Nothing installed in configuration prefix " - & TTY.URL (Alire.Config.Edit.Path)); + & TTY.URL (Alire.Settings.Edit.Path)); return; end if; @@ -344,10 +344,11 @@ package body Alr.Commands.Toolchain is -- Dispatch to subcommands if Cmd.Disable then - Alire.Toolchains.Set_Automatic_Assistant (False, - (if Cmd.Local - then Alire.Config.Local - else Alire.Config.Global)); + Alire.Toolchains.Set_Automatic_Assistant + (False, + (if Cmd.Local + then Alire.Settings.Local + else Alire.Settings.Global)); Alire.Put_Info ("Assistant disabled in " & TTY.Emph (if Cmd.Local then "local" else "global") @@ -367,8 +368,8 @@ package body Alr.Commands.Toolchain is if Args.Count = 0 then Alire.Toolchains.Assistant ((if Cmd.Local - then Alire.Config.Local - else Alire.Config.Global), + then Alire.Settings.Local + else Alire.Settings.Global), Allow_Incompatible => Alire.Force); else @@ -384,8 +385,8 @@ package body Alr.Commands.Toolchain is Alire.Toolchains.Set_Automatic_Assistant (False, (if Cmd.Local - then Alire.Config.Local - else Alire.Config.Global)); + then Alire.Settings.Local + else Alire.Settings.Global)); Trace.Detail ("Assistant disabled in " & TTY.Emph (if Cmd.Local then "local" else "global") diff --git a/src/alr/alr-commands-version.adb b/src/alr/alr-commands-version.adb index 16629f421..a0d731175 100644 --- a/src/alr/alr-commands-version.adb +++ b/src/alr/alr-commands-version.adb @@ -1,5 +1,5 @@ with Alire.Builds; -with Alire.Config.Edit; +with Alire.Settings.Edit; with Alire.Directories; with Alire.Index; with Alire.Index_On_Disk.Loading; @@ -41,7 +41,7 @@ package body Alr.Commands.Version is Index_Outcome : Alire.Outcome; Indexes : constant Alire.Index_On_Disk.Loading.Set := Alire.Index_On_Disk.Loading.Find_All - (Alire.Config.Edit.Indexes_Directory, Index_Outcome); + (Alire.Settings.Edit.Indexes_Directory, Index_Outcome); Root : Alire.Roots.Optional.Root := Alire.Roots.Optional.Search_Root (Alire.Directories.Current); @@ -72,9 +72,9 @@ package body Alr.Commands.Version is Table.Append ("").New_Row; Table.Append ("CONFIGURATION").New_Row; - Table.Append ("config folder:").Append (Alire.Config.Edit.Path).New_Row; + Table.Append ("config folder:").Append (Settings.Edit.Path).New_Row; Table.Append ("cache folder:") - .Append (Alire.Config.Edit.Cache_Path).New_Row; + .Append (Alire.Settings.Edit.Cache_Path).New_Row; Table.Append ("vault folder:").Append (Paths.Vault.Path).New_Row; Table.Append ("build folder:").Append (Build_Path).New_Row; Table.Append ("temp folder:") @@ -87,7 +87,7 @@ package body Alr.Commands.Version is Table.Append ("compatible index versions:") .Append (Alire.Index.Valid_Versions.Image).New_Row; Table.Append ("indexes folder:") - .Append (Alire.Config.Edit.Indexes_Directory).New_Row; + .Append (Alire.Settings.Edit.Indexes_Directory).New_Row; Table.Append ("indexes metadata:") .Append (if Index_Outcome.Success then "OK" diff --git a/src/alr/alr-commands.adb b/src/alr/alr-commands.adb index 96a77f623..3aa8afa67 100644 --- a/src/alr/alr-commands.adb +++ b/src/alr/alr-commands.adb @@ -8,8 +8,8 @@ with CLIC.User_Input; with Alire.Platforms; with Alire_Early_Elaboration; -with Alire.Config.Builtins; -with Alire.Config.Edit; +with Alire.Settings.Builtins; +with Alire.Settings.Edit; with Alire.Errors; with Alire.Index_On_Disk.Loading; with Alire.Index_On_Disk.Updates; @@ -207,7 +207,7 @@ package body Alr.Commands is procedure Create_Alire_Folders is use GNATCOLL.VFS; begin - Make_Dir (Create (+Alire.Config.Edit.Path)); + Make_Dir (Create (+Alire.Settings.Edit.Path)); end Create_Alire_Folders; -------------------------- @@ -302,9 +302,9 @@ package body Alr.Commands is Unchecked : Alire.Roots.Optional.Root renames Cmd.Optional_Root; Manual_Only : constant Boolean := - Alire.Config.Builtins.Update_Manually_Only.Get; + Alire.Settings.Builtins.Update_Manually_Only.Get; - package Conf renames Alire.Config; + package Conf renames Alire.Settings; begin -- If the root has been already loaded, then all following checks have @@ -498,11 +498,11 @@ package body Alr.Commands is then -- Just verify that early processing catched it pragma Assert - (Alire.Config.Edit.Path = + (Alire.Settings.Edit.Path = Ada.Directories.Full_Name (Command_Line_Config_Path.all), "Unexpected mismatch of config paths:" & Alire.New_Line - & "Early: " & Alire.Config.Edit.Path + & "Early: " & Alire.Settings.Edit.Path & Alire.New_Line & "Late : " & Command_Line_Config_Path.all); end if; @@ -543,7 +543,7 @@ package body Alr.Commands is Set_Builtin_Aliases; - Sub_Cmd.Load_Aliases (Alire.Config.DB.all); + Sub_Cmd.Load_Aliases (Alire.Settings.DB.all); Sub_Cmd.Execute; Log ("alr " & Sub_Cmd.What_Command & " done", Detail); From 2ec732a2e99e4fb2b248ef034df35a03d3dca273 Mon Sep 17 00:00:00 2001 From: Alejandro R Mosteo Date: Mon, 11 Mar 2024 12:49:39 +0100 Subject: [PATCH 11/17] More conventional location for settings in Windows (#1624) To avoid mixing top levels, also nest the cache too. --- src/alire/os_windows/alire-platforms-folders__windows.adb | 8 +++++--- testsuite/drivers/alr.py | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/alire/os_windows/alire-platforms-folders__windows.adb b/src/alire/os_windows/alire-platforms-folders__windows.adb index 2cd1d4d16..f2f2dc7bd 100644 --- a/src/alire/os_windows/alire-platforms-folders__windows.adb +++ b/src/alire/os_windows/alire-platforms-folders__windows.adb @@ -18,14 +18,16 @@ package body Alire.Platforms.Folders is ----------- function Cache return Absolute_Path - is (OS_Lib.Getenv ("LocalAppData", Home / ".local" / "share") - / "alire"); + is (OS_Lib.Getenv ("LocalAppData", Home / "AppData" / "Local") + / "alire" / "cache"); ------------ -- Config -- ------------ - function Config return Absolute_Path is (Home / ".config" / "alire"); + function Config return Absolute_Path + is (OS_Lib.Getenv ("LocalAppData", Home / "AppData" / "Local") + / "alire" / "settings"); ---------- -- Temp -- diff --git a/testsuite/drivers/alr.py b/testsuite/drivers/alr.py index 809e968fc..1a611a685 100644 --- a/testsuite/drivers/alr.py +++ b/testsuite/drivers/alr.py @@ -56,7 +56,8 @@ def prepare_env(config_dir, env): # tests that need it. run_alr("-c", config_dir, "settings", "--global", "--set", "msys2.install_dir", - os.path.join(os.environ.get("LocalAppData"), "alire", "msys64")) + os.path.join( + os.environ.get("LocalAppData"), "alire", "cache", "msys64")) # Disable autoconfig of the community index, to prevent unintended use of # it in tests, besides the overload of fetching it From da203b3282953f9c5d750610d59a7ed8f48d0629 Mon Sep 17 00:00:00 2001 From: Alejandro R Mosteo Date: Mon, 11 Mar 2024 14:24:46 +0100 Subject: [PATCH 12/17] Refactor `ALR_CONFIG` to `ALIRE_SETTINGS_DIR` (#1625) * Refactor `ALR_CONFIG` to `ALIRE_SETTINGS` * Code review --- doc/user-changes.md | 10 +++++- src/alire/alire-environment.ads | 8 +++++ src/alire/alire-features.ads | 27 +++++++++++++++ src/alire/alire-index_features.ads | 16 --------- src/alire/alire-origins.adb | 6 ++-- src/alire/alire-settings-edit.adb | 25 ++++++++++++-- src/alire/alire-version-semver.ads | 14 ++++++++ testsuite/drivers/alr.py | 34 +++++++++---------- testsuite/drivers/driver/python_script.py | 2 +- .../tests/build_profile/recursive/test.py | 4 --- .../index/origin-binary-explicit/test.py | 2 +- testsuite/tests/provides/metadata/test.py | 6 ++-- .../tests/publish/local-repo-branched/test.py | 2 -- .../tests/publish/local-repo-nonstd/test.py | 1 - testsuite/tests/publish/local-repo/test.py | 1 - .../tests/settings/early-loading/test.py | 2 +- .../toolchain/missing-tool-redeploy/test.py | 4 +-- 17 files changed, 109 insertions(+), 55 deletions(-) create mode 100644 src/alire/alire-features.ads delete mode 100644 src/alire/alire-index_features.ads create mode 100644 src/alire/alire-version-semver.ads diff --git a/doc/user-changes.md b/doc/user-changes.md index 4e83940f1..08bb3e8d2 100644 --- a/doc/user-changes.md +++ b/doc/user-changes.md @@ -6,7 +6,15 @@ stay on top of `alr` new features. ## Release `2.0-dev` -### +### `ALIRE_SETTINGS_DIR` replaces `ALR_CONFIG` + +PR [1625](https://github.com/alire-project/alire/pull/1625) + +This reflects the new nomenclature of Alire settings versus crate +configuration. Also, it better reflects that the effect is on the whole library +and not only the `alr` command-line tool. + +### `alr settings` replaces `alr config` PR [1617](https://github.com/alire-project/alire/pull/1617) diff --git a/src/alire/alire-environment.ads b/src/alire/alire-environment.ads index 9b5d6ed97..6e3d283cb 100644 --- a/src/alire/alire-environment.ads +++ b/src/alire/alire-environment.ads @@ -11,8 +11,16 @@ private with Ada.Containers.Generic_Array_Sort; package Alire.Environment with Preelaborate is + -- ANY NEW VARIABLES SHOULD USE "ALIRE" IF THIS IS SOMETHING AFFECTING THE + -- BASE LIBRARY. CONSIDER USING A SETTING INSTEAD, UNLESS AN ENVIRONMENT + -- VARIABLE MAKES ABSOLUTE SENSE. + Config : constant String := "ALR_CONFIG"; -- Folder where current alr will look for configuration + -- DEPRECATED on 3.0 + + Settings : constant String := "ALIRE_SETTINGS_DIR"; + -- Folder where Alire will look for configuration Testsuite : constant String := "ALR_TESTSUITE"; -- If defined, we are running under the testsuite harness diff --git a/src/alire/alire-features.ads b/src/alire/alire-features.ads new file mode 100644 index 000000000..0c97a29e4 --- /dev/null +++ b/src/alire/alire-features.ads @@ -0,0 +1,27 @@ +with Semantic_Versioning; + +package Alire.Features is + + -- For easier lockstep updates, we keep track of features that we will + -- enable in future index versions. + + subtype Min_Version is Semantic_Versioning.Version; + subtype On_Version is Min_Version; + + use type Min_Version; + + Env_Alr_Config_Deprecated : constant On_Version := +"3.0"; + -- We migrate ALR_CONFIG to ALIRE_SETTINGS_DIR, but allow the use of the + -- former with a warning during our next major release to ease transition. + + package Index is + + -- Features referring to the index version + + Explicit_Binary_Origin : constant Min_Version := +"1.3.0"; + -- Require that binary origins are explicitly marked as such instead of + -- relying on dynamic expressions. + + end Index; + +end Alire.Features; diff --git a/src/alire/alire-index_features.ads b/src/alire/alire-index_features.ads deleted file mode 100644 index 10f81cb1b..000000000 --- a/src/alire/alire-index_features.ads +++ /dev/null @@ -1,16 +0,0 @@ -with Semantic_Versioning; - -package Alire.Index_Features is - - -- For easier lockstep updates, we keep track of features that we will - -- enable in future index versions. - - subtype Min_Version is Semantic_Versioning.Version; - - use type Min_Version; - - Explicit_Binary_Origin : constant Min_Version := +"1.3.0"; - -- Require that binary origins are explicitly marked as such instead of - -- relying on dynamic expressions. - -end Alire.Index_Features; diff --git a/src/alire/alire-origins.adb b/src/alire/alire-origins.adb index cc4004105..d838ffd8f 100644 --- a/src/alire/alire-origins.adb +++ b/src/alire/alire-origins.adb @@ -2,7 +2,7 @@ with Ada.Directories; with AAA.Strings; -with Alire.Index_Features; +with Alire.Features; with Alire.Loading; with Alire.Platforms.Current; with Alire.Root; @@ -519,7 +519,7 @@ package body Alire.Origins is -- generated by ourselves for internal use (which always contains the -- binary property when needed). and then - From.Metadata.Version >= Index_Features.Explicit_Binary_Origin + From.Metadata.Version >= Features.Index.Explicit_Binary_Origin and then (not Table.Unwrap.Has (Keys.Binary) or else not Table.Unwrap.Get (Keys.Binary).As_Boolean) @@ -527,7 +527,7 @@ package body Alire.Origins is Raise_Checked_Error ("Dynamic origins must explicitly set the `binary=true` property" & " from index version " - & TTY.Bold (Index_Features.Explicit_Binary_Origin.Image) + & TTY.Bold (Features.Index.Explicit_Binary_Origin.Image) & " onwards."); end if; diff --git a/src/alire/alire-settings-edit.adb b/src/alire/alire-settings-edit.adb index 3303e53fb..4a7d35952 100644 --- a/src/alire/alire-settings-edit.adb +++ b/src/alire/alire-settings-edit.adb @@ -1,11 +1,14 @@ with Ada.Text_IO; with Alire.Environment; +with Alire.Features; with Alire.Paths; with Alire.Platforms.Folders; with Alire.Platforms.Current; with Alire.Settings.Builtins; with Alire.Utils; +with Alire.Version.Semver; +with Alire.Warnings; with CLIC.Config.Edit; with CLIC.Config.Load; @@ -167,12 +170,30 @@ package body Alire.Settings.Edit is ---------- function Path return Absolute_Path is + use type Version.Semver.Version; + Unset : constant String := "unset"; + Msg : constant String + := "Environment variable " & Environment.Config + & " is " & TTY.Error ("deprecated") & ". Use " + & Environment.Settings & " instead."; begin + -- Warn or fail depending on version + if OS_Lib.Getenv (Environment.Config, Unset) /= Unset then + if Version.Semver.Current < Features.Env_Alr_Config_Deprecated then + Warnings.Warn_Once (Msg, Level => Warning); + else + Raise_Checked_Error (Msg); + end if; + end if; + if Config_Path /= null then -- Case with switch (TODO) return Config_Path.all; else - return OS_Lib.Getenv (Environment.Config, - Default_Config_Path); + return OS_Lib.Getenv + (Environment.Settings, + Default => + OS_Lib.Getenv (Environment.Config, + Default_Config_Path)); end if; end Path; diff --git a/src/alire/alire-version-semver.ads b/src/alire/alire-version-semver.ads new file mode 100644 index 000000000..aeead5a9d --- /dev/null +++ b/src/alire/alire-version-semver.ads @@ -0,0 +1,14 @@ +with Semantic_Versioning; + +package Alire.Version.Semver is + + -- Convenience to be able to use the current version directly as a + -- comparable proper semantic version version. + + package Semver renames Semantic_Versioning; + + subtype Version is Semver.Version; + + Current : constant Version := Semver.New_Version (Alire.Version.Current); + +end Alire.Version.Semver; diff --git a/testsuite/drivers/alr.py b/testsuite/drivers/alr.py index 1a611a685..23528324a 100644 --- a/testsuite/drivers/alr.py +++ b/testsuite/drivers/alr.py @@ -28,7 +28,7 @@ def distro_is_known(): p.out, flags=re.S) -def prepare_env(config_dir, env): +def prepare_env(settings_dir, env): """ Prepare the environment to run "alr". @@ -41,50 +41,50 @@ def prepare_env(config_dir, env): env["GIT_CONFIG_GLOBAL"] = "/dev/null" env["GIT_CONFIG_SYSTEM"] = "/dev/null" - config_dir = os.path.abspath(config_dir) - mkdir(config_dir) - env['ALR_CONFIG'] = config_dir + settings_dir = os.path.abspath(settings_dir) + mkdir(settings_dir) + env['ALIRE_SETTINGS_DIR'] = settings_dir # We pass config location explicitly in the following calls since env is # not yet applied (it's just a dict to be passed later to subprocess) if platform.system() == "Windows": # Disable msys inadvertent installation - run_alr("-c", config_dir, "settings", "--global", + run_alr("-c", settings_dir, "settings", "--global", "--set", "msys2.do_not_install", "true") # And configure the one set up in the environment so it is used by # tests that need it. - run_alr("-c", config_dir, "settings", "--global", + run_alr("-c", settings_dir, "settings", "--global", "--set", "msys2.install_dir", os.path.join( os.environ.get("LocalAppData"), "alire", "cache", "msys64")) # Disable autoconfig of the community index, to prevent unintended use of # it in tests, besides the overload of fetching it - run_alr("-c", config_dir, "settings", "--global", + run_alr("-c", settings_dir, "settings", "--global", "--set", "index.auto_community", "false") # Disable selection of toolchain to preserve older behavior. Tests that # require a configured compiler will have to set it up explicitly. - run_alr("-c", config_dir, "toolchain", "--disable-assistant") + run_alr("-c", settings_dir, "toolchain", "--disable-assistant") # Disable warning on old index, to avoid having to update index versions # when they're still compatible. - run_alr("-c", config_dir, "settings", "--global", + run_alr("-c", settings_dir, "settings", "--global", "--set", "warning.old_index", "false") # Disable shared dependencies (keep old pre-2.0 behavior) not to break lots # of tests. The post-2.0 behavior will have its own tests. - run_alr("-c", config_dir, "settings", "--global", + run_alr("-c", settings_dir, "settings", "--global", "--set", "dependencies.shared", "false") # Disable index auto-updates, which is not expected by most tests - run_alr("-c", config_dir, "settings", "--global", + run_alr("-c", settings_dir, "settings", "--global", "--set", "index.auto_update", "0") # If distro detection is disabled via environment, configure so in alr if "ALIRE_TESTSUITE_DISABLE_DISTRO" in env: - run_alr("-c", config_dir, "settings", "--global", + run_alr("-c", settings_dir, "settings", "--global", "--set", "distribution.disable_detection", "true") @@ -572,25 +572,25 @@ def alr_publish(name, return p -def alr_config_dir() -> str: +def alr_settings_dir() -> str: """ Return the path to the alr configuration directory """ - return os.environ.get("ALR_CONFIG") + return os.environ.get("ALIRE_SETTINGS_DIR") def alr_vault_dir() -> str: """ Return the path to the vault for release pristine sources """ - return os.path.join(alr_config_dir(), "cache", "releases") + return os.path.join(alr_settings_dir(), "cache", "releases") def alr_builds_dir() -> str: """ Return the path to the builds directory """ - return os.path.join(alr_config_dir(), "cache", "builds") + return os.path.join(alr_settings_dir(), "cache", "builds") def crate_dirname(crate): @@ -616,4 +616,4 @@ def unselect_compiler(): assistant. """ run_alr("settings", "--global", "--unset", "toolchain.use.gnat") - run_alr("settings", "--global", "--unset", "toolchain.external.gnat") + run_alr("settings", "--global", "--unset", "toolchain.external.gnat") \ No newline at end of file diff --git a/testsuite/drivers/driver/python_script.py b/testsuite/drivers/driver/python_script.py index 1b30d8d5f..b08fdc1c9 100644 --- a/testsuite/drivers/driver/python_script.py +++ b/testsuite/drivers/driver/python_script.py @@ -168,7 +168,7 @@ def run(self): self.result.log.log += "Build mode: SHARED\n" # Activate shared builds. Using "-c" is needed as the environment # still isn't activated at the driver script level. - run_alr("-c", pristine_env["ALR_CONFIG"], + run_alr("-c", pristine_env["ALIRE_SETTINGS_DIR"], "settings", "--global", "--set", "dependencies.shared", "true") p = self.run_script(copy.deepcopy(pristine_env)) diff --git a/testsuite/tests/build_profile/recursive/test.py b/testsuite/tests/build_profile/recursive/test.py index 3f6448850..348b26934 100644 --- a/testsuite/tests/build_profile/recursive/test.py +++ b/testsuite/tests/build_profile/recursive/test.py @@ -2,15 +2,11 @@ Check build --profiles switch """ -from drivers import builds from drivers.alr import run_alr, init_local_crate, alr_pin, alr_manifest from drivers.helpers import lines_of, content_of import os -from drivers.asserts import assert_contents, assert_match - - def check_profile(profile: str, file: str): line = f' Build_Profile : Build_Profile_Kind := "{profile}";\n' assert line in lines_of(file), \ diff --git a/testsuite/tests/index/origin-binary-explicit/test.py b/testsuite/tests/index/origin-binary-explicit/test.py index 4164694d5..aba6878d2 100644 --- a/testsuite/tests/index/origin-binary-explicit/test.py +++ b/testsuite/tests/index/origin-binary-explicit/test.py @@ -6,7 +6,7 @@ from glob import glob import os from drivers import builds -from drivers.alr import alr_config_dir, alr_with, run_alr, init_local_crate +from drivers.alr import alr_settings_dir, alr_with, run_alr, init_local_crate from drivers.asserts import assert_match from drivers.helpers import contents diff --git a/testsuite/tests/provides/metadata/test.py b/testsuite/tests/provides/metadata/test.py index e82c28a1e..dd0035b81 100644 --- a/testsuite/tests/provides/metadata/test.py +++ b/testsuite/tests/provides/metadata/test.py @@ -4,10 +4,10 @@ import os -from drivers.alr import run_alr -from drivers.asserts import assert_eq, assert_match +from drivers.alr import run_alr, alr_settings_dir +from drivers.asserts import assert_eq -aliases_file = os.path.join(os.environ['ALR_CONFIG'], +aliases_file = os.path.join(alr_settings_dir(), "indexes", "providers.toml") # This is the file where crate aliases are stored diff --git a/testsuite/tests/publish/local-repo-branched/test.py b/testsuite/tests/publish/local-repo-branched/test.py index 00eb44f79..b2d09efcc 100644 --- a/testsuite/tests/publish/local-repo-branched/test.py +++ b/testsuite/tests/publish/local-repo-branched/test.py @@ -3,9 +3,7 @@ """ from drivers.alr import init_local_crate, run_alr -from drivers.asserts import assert_match from drivers.helpers import init_git_repo -from glob import glob from shutil import copyfile from subprocess import run diff --git a/testsuite/tests/publish/local-repo-nonstd/test.py b/testsuite/tests/publish/local-repo-nonstd/test.py index 759050dcd..355cd7fd4 100644 --- a/testsuite/tests/publish/local-repo-nonstd/test.py +++ b/testsuite/tests/publish/local-repo-nonstd/test.py @@ -5,7 +5,6 @@ from drivers.alr import init_local_crate, run_alr from drivers.asserts import assert_match from drivers.helpers import init_git_repo -from glob import glob from shutil import rmtree from subprocess import run diff --git a/testsuite/tests/publish/local-repo/test.py b/testsuite/tests/publish/local-repo/test.py index 009a73db2..41d27e43b 100644 --- a/testsuite/tests/publish/local-repo/test.py +++ b/testsuite/tests/publish/local-repo/test.py @@ -5,7 +5,6 @@ from drivers.alr import init_local_crate, run_alr from drivers.asserts import assert_match from drivers.helpers import init_git_repo -from glob import glob from shutil import rmtree from subprocess import run diff --git a/testsuite/tests/settings/early-loading/test.py b/testsuite/tests/settings/early-loading/test.py index fbbeffb26..c2f78c2c2 100644 --- a/testsuite/tests/settings/early-loading/test.py +++ b/testsuite/tests/settings/early-loading/test.py @@ -22,7 +22,7 @@ run_alr(f"--config={custom_config}", "settings", "--global").out) # Verify also when using environment variable -os.environ["ALR_CONFIG"] = os.path.abspath(custom_config) +os.environ["ALIRE_SETTINGS_DIR"] = os.path.abspath(custom_config) assert_eq(expected, run_alr("settings", "--global").out) diff --git a/testsuite/tests/toolchain/missing-tool-redeploy/test.py b/testsuite/tests/toolchain/missing-tool-redeploy/test.py index 4e368e7e9..0eed229ce 100644 --- a/testsuite/tests/toolchain/missing-tool-redeploy/test.py +++ b/testsuite/tests/toolchain/missing-tool-redeploy/test.py @@ -6,7 +6,7 @@ import os from shutil import rmtree -from drivers.alr import init_local_crate, run_alr +from drivers.alr import init_local_crate, run_alr, alr_settings_dir from drivers.asserts import assert_match # We can trigger a buggy situation by configuring a toolchain, removing @@ -16,7 +16,7 @@ init_local_crate() # Remove the tool manually through the filesystem -rmtree(os.path.join(os.environ["ALR_CONFIG"], "cache")) +rmtree(os.path.join(alr_settings_dir(), "cache")) # This should not fail. A message should warn of redeployments happening. p = run_alr("printenv", quiet=False) From c4f991c46b7c37520ed95458f9c0300fb36bcc30 Mon Sep 17 00:00:00 2001 From: Alejandro R Mosteo Date: Mon, 11 Mar 2024 16:04:56 +0100 Subject: [PATCH 13/17] `config.toml` --> `settings.toml` (#1626) * config.toml --> settings.toml * Prepend comment in `config.toml` about migration * Remove file touching --- src/alire/alire-directories.adb | 2 +- src/alire/alire-paths.ads | 3 + src/alire/alire-settings-edit.adb | 93 ++++++++++++++----- src/alire/alire-utils-text_files.adb | 28 ++++++ src/alire/alire-utils-text_files.ads | 9 ++ testsuite/tests/index/auto-update/test.py | 2 +- .../tests/settings/early-loading/test.py | 2 +- .../settings/relative_config_path/test.py | 2 +- .../tests/workflows/init-options/test.py | 6 +- 9 files changed, 116 insertions(+), 31 deletions(-) diff --git a/src/alire/alire-directories.adb b/src/alire/alire-directories.adb index fffdb9c07..5d7905394 100644 --- a/src/alire/alire-directories.adb +++ b/src/alire/alire-directories.adb @@ -87,7 +87,7 @@ package body Alire.Directories is else File & ".prev"); begin if Exists (File) then - if not Exists (Base_Dir) then + if Base_Dir /= "" and then not Exists (Base_Dir) then Create_Directory (Base_Dir); end if; diff --git a/src/alire/alire-paths.ads b/src/alire/alire-paths.ads index 1798089f0..5b4a06824 100644 --- a/src/alire/alire-paths.ads +++ b/src/alire/alire-paths.ads @@ -5,6 +5,9 @@ package Alire.Paths with Preelaborate is Crate_File_Name : constant String := "alire.toml"; -- Name of the manifest file in a regular workspace + Settings_File_Name : constant String := "settings.toml"; + -- Storage of Alire settings in workspace or global location + Build_Folder_Inside_Working_Folder : constant Relative_Path := "builds"; Cache_Folder_Inside_Working_Folder : constant Relative_Path := "cache"; diff --git a/src/alire/alire-settings-edit.adb b/src/alire/alire-settings-edit.adb index 4a7d35952..6ce00c709 100644 --- a/src/alire/alire-settings-edit.adb +++ b/src/alire/alire-settings-edit.adb @@ -1,3 +1,4 @@ +with Ada.Directories; with Ada.Text_IO; with Alire.Environment; @@ -6,7 +7,7 @@ with Alire.Paths; with Alire.Platforms.Folders; with Alire.Platforms.Current; with Alire.Settings.Builtins; -with Alire.Utils; +with Alire.Utils.Text_Files; with Alire.Version.Semver; with Alire.Warnings; @@ -19,8 +20,10 @@ package body Alire.Settings.Edit is use AAA.Strings; use TOML; + package Adirs renames Ada.Directories; + type String_Access is access String; - Config_Path : String_Access; + Settings_Path : String_Access; ----------------- -- Set_Locally -- @@ -114,25 +117,67 @@ package body Alire.Settings.Edit is -------------- function Filepath (Lvl : Level) return Absolute_Path is + + type Old_New is (Old, Current); + + -------------- + -- Location -- + -------------- + + function Location (Which : Old_New) return Absolute_Path is + File : constant String := + (case Which is + when Old => "config.toml", + when Current => Paths.Settings_File_Name); + begin + case Lvl is + when Global => + return Alire.Settings.Edit.Path / File; + when Local => + declare + Candidate : constant String := + Directories.Detect_Root_Path; + begin + if Candidate /= "" then + return Candidate / "alire" / File; + else + Raise_Checked_Error + ("Can only be used in an Alire directory"); + end if; + end; + end case; + end Location; + begin - case Lvl is - when Global => - return Alire.Settings.Edit.Path / "config.toml"; - when Local => - declare - Candidate : constant String := - Directories.Detect_Root_Path; - begin - if Candidate /= "" then - -- This file cannot have a .toml extension or the root - -- detection will not work. - return Candidate / "alire" / "config.toml"; - else - Raise_Checked_Error - ("Can only be used in an Alire directory"); - end if; - end; - end case; + -- Migrate file on the spot if necessary. This file is transparent to + -- users so we do not emit visible messages. + + if Directories.Is_File (Location (Old)) and then + not Directories.Is_File (Location (Current)) + then + Trace.Debug ("Migrating settings file: " + & Location (Old) & " --> " & Location (Current)); + Adirs.Copy_File (Source_Name => Location (Old), + Target_Name => Location (Current)); + + begin + -- Insert a comment in the old config.toml + Utils.Text_Files.Replace_Lines + (Location (Old), + Empty_Vector + & String'("# config.toml has been replaced by settings.toml" + & " after alr 2.0") + & "" + & Utils.Text_Files.Lines (Location (Old))); + exception + -- Ensure we don't break anything trying to leaving the clues + when E : others => + Log_Exception (E); + Trace.Debug ("Failed when leaving clue about settings.toml"); + end; + end if; + + return Location (Current); end Filepath; ----------------- @@ -186,8 +231,8 @@ package body Alire.Settings.Edit is end if; end if; - if Config_Path /= null then -- Case with switch (TODO) - return Config_Path.all; + if Settings_Path /= null then -- Case with switch (TODO) + return Settings_Path.all; else return OS_Lib.Getenv (Environment.Settings, @@ -215,10 +260,10 @@ package body Alire.Settings.Edit is procedure Set_Path (Path : Absolute_Path) is begin - if Config_Path /= null then + if Settings_Path /= null then raise Constraint_Error with "Custom path already set"; else - Config_Path := new String'(Path); + Settings_Path := new String'(Path); end if; end Set_Path; diff --git a/src/alire/alire-utils-text_files.adb b/src/alire/alire-utils-text_files.adb index a014b6aa9..b060d2338 100644 --- a/src/alire/alire-utils-text_files.adb +++ b/src/alire/alire-utils-text_files.adb @@ -20,6 +20,20 @@ package body Alire.Utils.Text_Files is F.Lines.Append (Lines); end Append_Lines; + ------------------- + -- Replace_Lines -- + ------------------- + + procedure Replace_Lines (File : Any_Path; + Lines : AAA.Strings.Vector; + Backup : Boolean := True; + Backup_Dir : Any_Path := "") + is + F : Text_Files.File := Load (File, Backup, Backup_Dir); + begin + F.Lines := Lines; + end Replace_Lines; + -------------- -- Finalize -- -------------- @@ -31,6 +45,8 @@ package body Alire.Utils.Text_Files is if This.Lines = This.Orig then Trace.Debug ("No changes to save in " & This.Name); return; + else + Trace.Debug ("Replacing contents of " & This.Name); end if; declare @@ -60,6 +76,18 @@ package body Alire.Utils.Text_Files is return access AAA.Strings.Vector is (This.Lines'Access); + ----------- + -- Lines -- + ----------- + + function Lines (Filename : Any_Path) + return AAA.Strings.Vector + is + F : constant File := Load (Filename); + begin + return F.Lines; + end Lines; + ------------ -- Create -- ------------ diff --git a/src/alire/alire-utils-text_files.ads b/src/alire/alire-utils-text_files.ads index d1de4d3ca..abf43f687 100644 --- a/src/alire/alire-utils-text_files.ads +++ b/src/alire/alire-utils-text_files.ads @@ -21,12 +21,21 @@ package Alire.Utils.Text_Files is function Lines (This : aliased in out File) return access AAA.Strings.Vector; + function Lines (Filename : Any_Path) + return AAA.Strings.Vector; + procedure Append_Lines (File : Any_Path; Lines : AAA.Strings.Vector; Backup : Boolean := True; Backup_Dir : Any_Path := ""); -- Add the given lines to the end of the file + procedure Replace_Lines (File : Any_Path; + Lines : AAA.Strings.Vector; + Backup : Boolean := True; + Backup_Dir : Any_Path := ""); + -- Replace contents of File with the new lines. + private type File (Length, Backup_Len : Natural) is diff --git a/testsuite/tests/index/auto-update/test.py b/testsuite/tests/index/auto-update/test.py index 1d5889de1..907fa2bb4 100644 --- a/testsuite/tests/index/auto-update/test.py +++ b/testsuite/tests/index/auto-update/test.py @@ -6,7 +6,7 @@ from drivers.alr import run_alr from drivers.helpers import content_of, lines_of -CONFIG_FILE = os.path.join("alr-config", "config.toml") +CONFIG_FILE = os.path.join("alr-config", "settings.toml") # First, we check no related configuration exists diff --git a/testsuite/tests/settings/early-loading/test.py b/testsuite/tests/settings/early-loading/test.py index c2f78c2c2..c3bdfa9cb 100644 --- a/testsuite/tests/settings/early-loading/test.py +++ b/testsuite/tests/settings/early-loading/test.py @@ -10,7 +10,7 @@ # Create a custom configuration dir + file custom_config = "custom_config" os.mkdir(custom_config) -with open(os.path.join(custom_config, "config.toml"), "w") as f: +with open(os.path.join(custom_config, "settings.toml"), "w") as f: f.write("test_value = 42\n") expected = "test_value=42\n" diff --git a/testsuite/tests/settings/relative_config_path/test.py b/testsuite/tests/settings/relative_config_path/test.py index efb4e7a0a..6f3d8ff6a 100644 --- a/testsuite/tests/settings/relative_config_path/test.py +++ b/testsuite/tests/settings/relative_config_path/test.py @@ -14,7 +14,7 @@ "--set", "some_config_key", "true") -assert_eq("some_config_key = true\n", lines_of ("config.toml")[0]) +assert_eq("some_config_key = true\n", lines_of ("settings.toml")[0]) print('SUCCESS') diff --git a/testsuite/tests/workflows/init-options/test.py b/testsuite/tests/workflows/init-options/test.py index 3e3e95f11..a56e3a988 100644 --- a/testsuite/tests/workflows/init-options/test.py +++ b/testsuite/tests/workflows/init-options/test.py @@ -26,7 +26,7 @@ 'xxx/alire.toml', 'xxx/alire/alire.lock', 'xxx/alire/build_hash_inputs', - 'xxx/alire/config.toml', + 'xxx/alire/settings.toml', 'xxx/config', 'xxx/config/xxx_config.ads', 'xxx/config/xxx_config.gpr', @@ -46,7 +46,7 @@ 'aaa/alire.toml', 'aaa/alire/alire.lock', 'aaa/alire/build_hash_inputs', - 'aaa/alire/config.toml', + 'aaa/alire/settings.toml', 'aaa/config', 'aaa/config/aaa_config.ads', 'aaa/config/aaa_config.gpr', @@ -89,7 +89,7 @@ './alire.toml', './alire/alire.lock', './alire/build_hash_inputs', - './alire/config.toml', + './alire/settings.toml', './config', './config/zzz_config.ads', './config/zzz_config.gpr', From ef83f192f1dee973a73fd3fdf35792650386865e Mon Sep 17 00:00:00 2001 From: Alejandro R Mosteo Date: Mon, 11 Mar 2024 16:41:10 +0100 Subject: [PATCH 14/17] Refactor `--config` as `--settings` (#1627) * Refactor `ALR_CONFIG` to `ALIRE_SETTINGS` * Replace --config with --settings * Code review * Post-merge fix --- src/alire/alire-features.ads | 3 +- src/alire/alire-settings-edit-early_load.adb | 2 +- src/alire/alire-settings-edit.adb | 20 ++--- src/alire/alire-settings-edit.ads | 2 +- src/alire/alire_early_elaboration.adb | 74 +++++++++++++++---- src/alr/alr-commands-version.adb | 3 +- src/alr/alr-commands.adb | 16 +++- testsuite/drivers/alr.py | 20 ++--- testsuite/drivers/driver/python_script.py | 2 +- .../tests/config/missing-config-path/test.py | 23 ++++-- .../tests/settings/early-loading/test.py | 4 +- .../settings/relative_config_path/test.py | 2 +- testsuite/tests/toolchain/directories/test.py | 2 +- 13 files changed, 122 insertions(+), 51 deletions(-) diff --git a/src/alire/alire-features.ads b/src/alire/alire-features.ads index 0c97a29e4..c55661baf 100644 --- a/src/alire/alire-features.ads +++ b/src/alire/alire-features.ads @@ -10,9 +10,10 @@ package Alire.Features is use type Min_Version; - Env_Alr_Config_Deprecated : constant On_Version := +"3.0"; + Config_Deprecated : constant On_Version := +"1.0"; -- We migrate ALR_CONFIG to ALIRE_SETTINGS_DIR, but allow the use of the -- former with a warning during our next major release to ease transition. + -- Likewise for the -c/--config switch package Index is diff --git a/src/alire/alire-settings-edit-early_load.adb b/src/alire/alire-settings-edit-early_load.adb index de3ed9139..5740c75f6 100644 --- a/src/alire/alire-settings-edit-early_load.adb +++ b/src/alire/alire-settings-edit-early_load.adb @@ -6,7 +6,7 @@ package body Alire.Settings.Edit.Early_Load is procedure Load_Settings is begin - Alire.Settings.Edit.Load_Config; + Alire.Settings.Edit.Load_Settings; end Load_Settings; begin diff --git a/src/alire/alire-settings-edit.adb b/src/alire/alire-settings-edit.adb index 6ce00c709..37bdc40bf 100644 --- a/src/alire/alire-settings-edit.adb +++ b/src/alire/alire-settings-edit.adb @@ -39,7 +39,7 @@ package body Alire.Settings.Edit is end if; -- Reload after change - Load_Config; + Load_Settings; end Set_Locally; ------------------ @@ -56,7 +56,7 @@ package body Alire.Settings.Edit is end if; -- Reload after change - Load_Config; + Load_Settings; end Set_Globally; --------- @@ -86,7 +86,7 @@ package body Alire.Settings.Edit is if CLIC.Config.Edit.Unset (Filepath (Level), Key, Quiet => True) then Trace.Debug ("Config key " & Key & " unset from " & Level'Image & "configuration at " & Filepath (Level)); - Load_Config; + Load_Settings; else Trace.Debug ("Config key " & Key & " requested to be unset at level " & Level'Image & " but it was already unset at " @@ -109,7 +109,7 @@ package body Alire.Settings.Edit is Assert (Set_Boolean_Impl (Filepath (Level), Key, Value, Check), "Cannot set config key '" & Key & "' at level " & Level'Image); -- Reload after change - Load_Config; + Load_Settings; end Set_Boolean; -------------- @@ -180,11 +180,11 @@ package body Alire.Settings.Edit is return Location (Current); end Filepath; - ----------------- - -- Load_Config -- - ----------------- + ------------------- + -- Load_Settings -- + ------------------- - procedure Load_Config is + procedure Load_Settings is begin DB_Instance.Clear; @@ -206,7 +206,7 @@ package body Alire.Settings.Edit is if Platforms.Current.Disable_Distribution_Detection then Trace.Debug ("Distribution detection disabled by configuration"); end if; - end Load_Config; + end Load_Settings; Default_Config_Path : constant Absolute_Path := Platforms.Folders.Config; @@ -224,7 +224,7 @@ package body Alire.Settings.Edit is begin -- Warn or fail depending on version if OS_Lib.Getenv (Environment.Config, Unset) /= Unset then - if Version.Semver.Current < Features.Env_Alr_Config_Deprecated then + if Version.Semver.Current < Features.Config_Deprecated then Warnings.Warn_Once (Msg, Level => Warning); else Raise_Checked_Error (Msg); diff --git a/src/alire/alire-settings-edit.ads b/src/alire/alire-settings-edit.ads index 13959746a..a80effcc0 100644 --- a/src/alire/alire-settings-edit.ads +++ b/src/alire/alire-settings-edit.ads @@ -82,7 +82,7 @@ package Alire.Settings.Edit is private - procedure Load_Config; + procedure Load_Settings; -- Clear and reload all configuration. Also set some values elsewhere -- used to break circularities. Bottom line, this procedure must leave -- the program-wide configuration ready. This is done during startup from diff --git a/src/alire/alire_early_elaboration.adb b/src/alire/alire_early_elaboration.adb index ae97124d0..d819982ca 100644 --- a/src/alire/alire_early_elaboration.adb +++ b/src/alire/alire_early_elaboration.adb @@ -2,7 +2,9 @@ with AAA.Strings; with Ada.Directories; +with Alire.Features; with Alire.Settings.Edit.Early_Load; +with Alire.Version.Semver; with GNAT.Command_Line; with GNAT.OS_Lib; @@ -71,26 +73,26 @@ package body Alire_Early_Elaboration is procedure Check_Switches is - ------------------------- - -- Config_Switch_Error -- - ------------------------- + --------------------------- + -- Settings_Switch_Error -- + --------------------------- - procedure Config_Switch_Error (Switch : String) is + procedure Settings_Switch_Error (Switch : String) is begin GNAT.IO.Put_Line ("ERROR: Switch " & Switch & " requires argument (global)."); Early_Error ("try ""alr --help"" for more information."); - end Config_Switch_Error; + end Settings_Switch_Error; --------------------- -- Set_Config_Path -- --------------------- - procedure Set_Config_Path (Path : String) is + procedure Set_Config_Path (Switch, Path : String) is package Adirs renames Ada.Directories; begin if Path = "" then - Config_Switch_Error ("--config"); + Settings_Switch_Error (Switch); elsif not Adirs.Exists (Path) then Early_Error ("Invalid non-existing configuration path: " & Path); @@ -102,6 +104,42 @@ package body Alire_Early_Elaboration is end if; end Set_Config_Path; + ----------------------------- + -- Check_Config_Deprecated -- + ----------------------------- + + use type Alire.Version.Semver.Version; + Config_Deprecated : constant Boolean + := Alire.Version.Semver.Current >= Alire.Features.Config_Deprecated; + + procedure Check_Config_Deprecated is + begin + if Config_Deprecated then + Early_Error + ("--config is deprecated, use --settings instead"); + end if; + end Check_Config_Deprecated; + + ---------------- + -- Check_Seen -- + ---------------- + + Settings_Seen : Boolean := False; + + procedure Check_Settings_Seen is + begin + if Settings_Seen then + Early_Error + ("Only one of -s, --settings" + & (if not Config_Deprecated + then ", -c, --config" + else "") + & " allowed"); + else + Settings_Seen := True; + end if; + end Check_Settings_Seen; + ----------------------- -- Check_Long_Switch -- ----------------------- @@ -116,16 +154,22 @@ package body Alire_Early_Elaboration is Switch_D := True; Add_Scopes (Tail (Switch, "=")); elsif Has_Prefix (Switch, "--config") then - Set_Config_Path (Tail (Switch, "=")); + Check_Config_Deprecated; + Check_Settings_Seen; + Set_Config_Path (Switch, Tail (Switch, "=")); + elsif Has_Prefix (Switch, "--settings") then + Check_Settings_Seen; + Set_Config_Path (Switch, Tail (Switch, "=")); end if; end Check_Long_Switch; Option : Character; + begin loop -- We use the simpler Getopt form to avoid built-in help and other -- shenanigans. - Option := Getopt ("* d? --debug? q v c= --config="); + Option := Getopt ("* d? --debug? q v c= --config= s= --settings="); case Option is when ASCII.NUL => exit; @@ -133,9 +177,13 @@ package body Alire_Early_Elaboration is if not Subcommand_Seen then Check_Long_Switch (Full_Switch); end if; - when 'c' => + when 'c' | 's' => if not Subcommand_Seen then - Set_Config_Path (Parameter); + Check_Settings_Seen; + if Option = 'c' then + Check_Config_Deprecated; + end if; + Set_Config_Path ("-" & Option, Parameter); end if; when 'd' => if not Subcommand_Seen then @@ -164,8 +212,8 @@ package body Alire_Early_Elaboration is end loop; exception when GNAT.Command_Line.Invalid_Parameter => - if Option = 'c' then - Config_Switch_Error ("-c"); + if Option in 'c' | 's' then + Settings_Switch_Error ("-" & Option); end if; when Exit_From_Command_Line => -- Something unexpected happened but it will be properly dealt diff --git a/src/alr/alr-commands-version.adb b/src/alr/alr-commands-version.adb index a0d731175..bd145df5e 100644 --- a/src/alr/alr-commands-version.adb +++ b/src/alr/alr-commands-version.adb @@ -72,7 +72,8 @@ package body Alr.Commands.Version is Table.Append ("").New_Row; Table.Append ("CONFIGURATION").New_Row; - Table.Append ("config folder:").Append (Settings.Edit.Path).New_Row; + Table.Append ("settings folder:") + .Append (Alire.Settings.Edit.Path).New_Row; Table.Append ("cache folder:") .Append (Alire.Settings.Edit.Cache_Path).New_Row; Table.Append ("vault folder:").Append (Paths.Vault.Path).New_Row; diff --git a/src/alr/alr-commands.adb b/src/alr/alr-commands.adb index 3aa8afa67..64d9155f5 100644 --- a/src/alr/alr-commands.adb +++ b/src/alr/alr-commands.adb @@ -11,6 +11,7 @@ with Alire_Early_Elaboration; with Alire.Settings.Builtins; with Alire.Settings.Edit; with Alire.Errors; +with Alire.Features; with Alire.Index_On_Disk.Loading; with Alire.Index_On_Disk.Updates; with Alire.Lockfiles; @@ -19,6 +20,7 @@ with Alire.Platforms.Current; with Alire.Root; with Alire.Solutions; with Alire.Toolchains; +with Alire.Version.Semver; with Alr.Commands.Action; with Alr.Commands.Build; @@ -137,12 +139,22 @@ package body Alr.Commands is procedure Set_Global_Switches (Config : in out CLIC.Subcommand.Switches_Configuration) is + use Alire; use CLIC.Subcommand; + use type Alire.Version.Semver.Version; begin + if Alire.Version.Semver.Current < Features.Config_Deprecated then + Define_Switch (Config, + Command_Line_Config_Path'Access, + "-c=", "--config=", + TTY.Error ("Deprecated") + & ". See -s/--settings switch"); + end if; + Define_Switch (Config, Command_Line_Config_Path'Access, - "-c=", "--config=", - "Override configuration folder location"); + "-s=", "--settings=", + "Override settings folder location"); Define_Switch (Config, Command_Line_Chdir_Target_Path'Access, diff --git a/testsuite/drivers/alr.py b/testsuite/drivers/alr.py index 23528324a..95da91404 100644 --- a/testsuite/drivers/alr.py +++ b/testsuite/drivers/alr.py @@ -44,47 +44,47 @@ def prepare_env(settings_dir, env): settings_dir = os.path.abspath(settings_dir) mkdir(settings_dir) env['ALIRE_SETTINGS_DIR'] = settings_dir - # We pass config location explicitly in the following calls since env is + # We pass settings location explicitly in the following calls since env is # not yet applied (it's just a dict to be passed later to subprocess) if platform.system() == "Windows": # Disable msys inadvertent installation - run_alr("-c", settings_dir, "settings", "--global", + run_alr("-s", settings_dir, "settings", "--global", "--set", "msys2.do_not_install", "true") # And configure the one set up in the environment so it is used by # tests that need it. - run_alr("-c", settings_dir, "settings", "--global", + run_alr("-s", settings_dir, "settings", "--global", "--set", "msys2.install_dir", os.path.join( os.environ.get("LocalAppData"), "alire", "cache", "msys64")) # Disable autoconfig of the community index, to prevent unintended use of # it in tests, besides the overload of fetching it - run_alr("-c", settings_dir, "settings", "--global", + run_alr(f"-s", settings_dir, "settings", "--global", "--set", "index.auto_community", "false") # Disable selection of toolchain to preserve older behavior. Tests that # require a configured compiler will have to set it up explicitly. - run_alr("-c", settings_dir, "toolchain", "--disable-assistant") + run_alr("-s", settings_dir, "toolchain", "--disable-assistant") # Disable warning on old index, to avoid having to update index versions # when they're still compatible. - run_alr("-c", settings_dir, "settings", "--global", + run_alr("-s", settings_dir, "settings", "--global", "--set", "warning.old_index", "false") # Disable shared dependencies (keep old pre-2.0 behavior) not to break lots # of tests. The post-2.0 behavior will have its own tests. - run_alr("-c", settings_dir, "settings", "--global", + run_alr("-s", settings_dir, "settings", "--global", "--set", "dependencies.shared", "false") # Disable index auto-updates, which is not expected by most tests - run_alr("-c", settings_dir, "settings", "--global", + run_alr("-s", settings_dir, "settings", "--global", "--set", "index.auto_update", "0") # If distro detection is disabled via environment, configure so in alr if "ALIRE_TESTSUITE_DISABLE_DISTRO" in env: - run_alr("-c", settings_dir, "settings", "--global", + run_alr("-s", settings_dir, "settings", "--global", "--set", "distribution.disable_detection", "true") @@ -616,4 +616,4 @@ def unselect_compiler(): assistant. """ run_alr("settings", "--global", "--unset", "toolchain.use.gnat") - run_alr("settings", "--global", "--unset", "toolchain.external.gnat") \ No newline at end of file + run_alr("settings", "--global", "--unset", "toolchain.external.gnat") diff --git a/testsuite/drivers/driver/python_script.py b/testsuite/drivers/driver/python_script.py index b08fdc1c9..08279299b 100644 --- a/testsuite/drivers/driver/python_script.py +++ b/testsuite/drivers/driver/python_script.py @@ -168,7 +168,7 @@ def run(self): self.result.log.log += "Build mode: SHARED\n" # Activate shared builds. Using "-c" is needed as the environment # still isn't activated at the driver script level. - run_alr("-c", pristine_env["ALIRE_SETTINGS_DIR"], + run_alr(f"--settings={pristine_env['ALIRE_SETTINGS_DIR']}", "settings", "--global", "--set", "dependencies.shared", "true") p = self.run_script(copy.deepcopy(pristine_env)) diff --git a/testsuite/tests/config/missing-config-path/test.py b/testsuite/tests/config/missing-config-path/test.py index 0047db813..e96524098 100644 --- a/testsuite/tests/config/missing-config-path/test.py +++ b/testsuite/tests/config/missing-config-path/test.py @@ -1,18 +1,27 @@ """ -Verify that errors are properly handled when no config path is given +Verify that errors are properly handled when no settings path is given """ +import os from drivers.alr import run_alr from drivers.asserts import assert_match import re -p = run_alr("--config", complain_on_error=False) -assert p.status != 0, "command should fail" -assert_match("ERROR: Switch --config requires argument.*", p.out, flags=re.S) +switch = "--settings" +short = "-s" -p = run_alr("-c", complain_on_error=False) -assert p.status != 0, "command should fail" -assert_match("ERROR: Switch -c requires argument.*", p.out, flags=re.S) +p = run_alr(switch, complain_on_error=False) +assert_match(f"ERROR: Switch {switch} requires argument.*", p.out, flags=re.S) + +p = run_alr(short, complain_on_error=False) +assert_match(f"ERROR: Switch {short} requires argument.*", p.out, flags=re.S) + +# Check also failure in case of duplication of switch +path = os.getcwd() +p = run_alr(f"{short}", path, f"{switch}={path}", "version", + complain_on_error=False) +assert_match(".*Only one of .* allowed", + p.out) print('SUCCESS') diff --git a/testsuite/tests/settings/early-loading/test.py b/testsuite/tests/settings/early-loading/test.py index c3bdfa9cb..263bfc1e9 100644 --- a/testsuite/tests/settings/early-loading/test.py +++ b/testsuite/tests/settings/early-loading/test.py @@ -17,9 +17,9 @@ # Verify proper loading with both short and long config options assert_eq(expected, - run_alr("-c", custom_config, "settings", "--global").out) + run_alr("-s", custom_config, "settings", "--global").out) assert_eq(expected, - run_alr(f"--config={custom_config}", "settings", "--global").out) + run_alr(f"--settings={custom_config}", "settings", "--global").out) # Verify also when using environment variable os.environ["ALIRE_SETTINGS_DIR"] = os.path.abspath(custom_config) diff --git a/testsuite/tests/settings/relative_config_path/test.py b/testsuite/tests/settings/relative_config_path/test.py index 6f3d8ff6a..a425515e2 100644 --- a/testsuite/tests/settings/relative_config_path/test.py +++ b/testsuite/tests/settings/relative_config_path/test.py @@ -10,7 +10,7 @@ from drivers.asserts import assert_eq from drivers.helpers import lines_of -run_alr("--config=.", "settings", "--global", +run_alr("--settings=.", "settings", "--global", "--set", "some_config_key", "true") diff --git a/testsuite/tests/toolchain/directories/test.py b/testsuite/tests/toolchain/directories/test.py index cc6d305c2..1d2954039 100644 --- a/testsuite/tests/toolchain/directories/test.py +++ b/testsuite/tests/toolchain/directories/test.py @@ -11,7 +11,7 @@ # Identify config location p = run_alr("version") -config_dir = re.search("config folder:([^\n]*)", p.out).group(1).strip() +config_dir = re.search("settings folder:([^\n]*)", p.out).group(1).strip() config_dir = config_dir.replace("\\", "/") cache_dir = os.path.join(config_dir, "cache") From 5d82a061439883644f9c49a334197d6cb083d063 Mon Sep 17 00:00:00 2001 From: Alejandro R Mosteo Date: Tue, 12 Mar 2024 12:36:14 +0100 Subject: [PATCH 15/17] Remainders of the config --> settings refactor (#1631) * Remainders of the config --> settings refactor * Fix Windows-only builtins --- UPGRADING.md | 23 ++++++++++++-- doc/settings.md | 4 +-- src/alire/alire-index_on_disk-updates.adb | 2 +- src/alire/alire-settings-builtins.ads | 24 +++++++-------- src/alire/alire-settings-edit.adb | 28 ++++++++--------- src/alire/alire-settings-edit.ads | 28 +++++++++-------- src/alire/alire-settings.adb | 30 +++++++++---------- src/alire/alire-settings.ads | 18 +++++------ .../alire-settings-builtins-windows.ads | 6 ++-- 9 files changed, 92 insertions(+), 71 deletions(-) diff --git a/UPGRADING.md b/UPGRADING.md index 1020de0bd..9f796b8be 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -3,6 +3,25 @@ There are no special preparations to be made in advance to upgrading. However, please check out the following information. +### Refactored features + +The following features have changed in version `2.0`, with the corresponding +replacements: + +- "Alire configuration" is now renamed to "Alire settings", to distinguish it + from a crate configuration. This entails a few changes: + - `ALR_CONFIG` environment variable is now `ALIRE_SETTINGS_DIR`. + - `alr config` is now `alr settings`. + - `alr -c|--config` is now `alr -s|--settings`. + +- Installation of toolchains for use outside of Alire control is no longer done + through `alr toolchain`, but through `alr install`: + - `alr toolchain --install|--uninstall|--install-dir` no longer exist. + - `alr toolchain --select` remains as the way to select a default toolchain + for use by Alire. + - `alr install` will create a standard prefix structure, with binaries found + at `/bin`. The default prefix location is `/.alire`. + ### Obsolete large folders Changes in default storage locations mean that the following folders, if @@ -33,9 +52,9 @@ If you want to have a fallback to be able to downgrade, you have two safe options: - Use the newer version with its own separate configuration storage. You can override - the default location by providing a new path in the `ALR_CONFIG` environment + the default location by providing a new path in the `ALIRE_SETTINGS_DIR` environment variable. - Keep a backup of your current configuration at the default location, which is `.config/alire` within your user's home. You can restore this folder in sync with - its older `alr` version. \ No newline at end of file + its older `alr` version. diff --git a/doc/settings.md b/doc/settings.md index 262950539..fb3e75ef9 100644 --- a/doc/settings.md +++ b/doc/settings.md @@ -69,8 +69,8 @@ including their default values and a short explanation of their effects. By default, `alr` stores its global settings at `/.config/alire`. You can use any other location by setting in the environment the variable -`ALR_CONFIG=`, or by using the global `-c` -switch: `alr -c `. +`ALIRE_SETTINGS_DIR=`, or by using the global `-s` +switch: `alr -s `. Using pristine default settings can be useful to isolate the source of errors by ensuring that a misconfiguration is not at play. diff --git a/src/alire/alire-index_on_disk-updates.adb b/src/alire/alire-index_on_disk-updates.adb index 29a0b9803..3fe21e272 100644 --- a/src/alire/alire-index_on_disk-updates.adb +++ b/src/alire/alire-index_on_disk-updates.adb @@ -8,7 +8,7 @@ with CLIC.User_Input; package body Alire.Index_On_Disk.Updates is package Builtins renames Settings.Builtins; - subtype Int is Settings.Config_Int; + subtype Int is Settings.Setting_Int; Epoch : constant Ada.Calendar.Time := Ada.Calendar.Time_Of (Year => 2017, diff --git a/src/alire/alire-settings-builtins.ads b/src/alire/alire-settings-builtins.ads index d4c87f6a2..70b144c8c 100644 --- a/src/alire/alire-settings-builtins.ads +++ b/src/alire/alire-settings-builtins.ads @@ -12,7 +12,7 @@ package Alire.Settings.Builtins is Cache_Dir : constant Builtin := New_Builtin (Key => "cache.dir", - Kind => Cfg_Absolute_Path, + Kind => Stn_Absolute_Path, Def => "", Help => "Directory where Alire will store its cache."); @@ -46,7 +46,7 @@ package Alire.Settings.Builtins is Distribution_Override : constant Builtin := New_Builtin (Key => "distribution.override", - Kind => Cfg_String, + Kind => Stn_String, Check => Checks.Valid_Distro'Access, Def => "", Help => @@ -57,7 +57,7 @@ package Alire.Settings.Builtins is Editor_Cmd : constant Builtin := New_Builtin (Key => "editor.cmd", - Kind => Cfg_String, + Kind => Stn_String, Def => "", Help => "Editor command and arguments for editing crate code (alr edit)." & @@ -76,7 +76,7 @@ package Alire.Settings.Builtins is Index_Auto_Update : constant Builtin := New_Builtin (Key => "index.auto_update", - Kind => Cfg_Int, + Kind => Stn_Int, Def => "24", -- hours Help => "Hours between automatic index refresh. Set to 0 to disable."); @@ -90,25 +90,25 @@ package Alire.Settings.Builtins is Index_Last_Update : constant Builtin := New_Builtin (Key => "index.last_update", Public => False, - Kind => Cfg_Int, + Kind => Stn_Int, Def => "0", -- seconds since epoch Help => "Timestamp of last index auto-refresh (seconds)"); Index_Host : constant Builtin := New_Builtin (Key => "index.host", - Kind => Cfg_String, + Kind => Stn_String, Def => "https://github.com", Help => "URL of the community index host"); Index_Owner : constant Builtin := New_Builtin (Key => "index.owner", - Kind => Cfg_String, + Kind => Stn_String, Def => "alire-project", Help => "Owner of the index repository (GitHub user/org)."); Index_Repository_Name : constant Builtin := New_Builtin (Key => "index.repository_name", - Kind => Cfg_String, + Kind => Stn_String, Def => "alire-index", Help => "Name of the index repository."); @@ -132,7 +132,7 @@ package Alire.Settings.Builtins is Toolchain_Dir : constant Builtin := New_Builtin (Key => "toolchain.dir", - Kind => Cfg_Absolute_Path, + Kind => Stn_Absolute_Path, Def => "", Help => "Directory where Alire will store its toolchains."); @@ -169,21 +169,21 @@ package Alire.Settings.Builtins is User_Email : constant Builtin := New_Builtin (Key => "user.email", - Kind => Cfg_Email, + Kind => Stn_Email, Help => "User email address. Used for the authors and" & " maintainers field of a new crate."); User_Name : constant Builtin := New_Builtin (Key => "user.name", - Kind => Cfg_String, + Kind => Stn_String, Help => "User full name. Used for the authors and " & "maintainers field of a new crate."); User_Github_Login : constant Builtin := New_Builtin (Key => "user.github_login", - Kind => Cfg_GitHub_Login, + Kind => Stn_GitHub_Login, Help => "User GitHub login/username. Used to for the maintainers-logins " & "field of a new crate."); diff --git a/src/alire/alire-settings-edit.adb b/src/alire/alire-settings-edit.adb index 37bdc40bf..0962c1345 100644 --- a/src/alire/alire-settings-edit.adb +++ b/src/alire/alire-settings-edit.adb @@ -35,7 +35,7 @@ package body Alire.Settings.Edit is is begin if not CLIC.Config.Edit.Set (Filepath (Local), Key, Value, Check) then - Raise_Checked_Error ("Cannot set local config key"); + Raise_Checked_Error ("Cannot set local settings key"); end if; -- Reload after change @@ -52,7 +52,7 @@ package body Alire.Settings.Edit is is begin if not CLIC.Config.Edit.Set (Filepath (Global), Key, Value, Check) then - Raise_Checked_Error ("Cannot set global config key"); + Raise_Checked_Error ("Cannot set global settings key"); end if; -- Reload after change @@ -84,11 +84,11 @@ package body Alire.Settings.Edit is is begin if CLIC.Config.Edit.Unset (Filepath (Level), Key, Quiet => True) then - Trace.Debug ("Config key " & Key & " unset from " & Level'Image + Trace.Debug ("Setting key " & Key & " unset from " & Level'Image & "configuration at " & Filepath (Level)); Load_Settings; else - Trace.Debug ("Config key " & Key & " requested to be unset at level " + Trace.Debug ("Setting key " & Key & " requested to be unset at level " & Level'Image & " but it was already unset at " & Filepath (Level)); end if; @@ -107,7 +107,7 @@ package body Alire.Settings.Edit is (Boolean, TOML_Boolean, Boolean'Image); begin Assert (Set_Boolean_Impl (Filepath (Level), Key, Value, Check), - "Cannot set config key '" & Key & "' at level " & Level'Image); + "Cannot set setting key '" & Key & "' at level " & Level'Image); -- Reload after change Load_Settings; end Set_Boolean; @@ -197,7 +197,7 @@ package body Alire.Settings.Edit is end if; end loop; - Config_Loaded := True; + Settings_Loaded := True; -- Set variables elsewhere @@ -290,18 +290,18 @@ package body Alire.Settings.Edit is -- Verify the type/specific constraints case Ent.Kind is - when Cfg_Int => + when Stn_Int => Result := Value.Kind = TOML_Integer; - when Cfg_Float => + when Stn_Float => Result := Value.Kind = TOML_Float; - when Cfg_Bool => + when Stn_Bool => Result := Value.Kind = TOML_Boolean; - when Cfg_String => + when Stn_String => Result := Value.Kind = TOML_String; - when Cfg_Absolute_Path => + when Stn_Absolute_Path => Result := Value.Kind = TOML_String and then Check_Absolute_Path (Value.As_String); - when Cfg_Existing_Absolute_Path => + when Stn_Existing_Absolute_Path => Result := Value.Kind = TOML_String and then Check_Absolute_Path (Value.As_String); if Result and then @@ -314,11 +314,11 @@ package body Alire.Settings.Edit is & "please create it beforehand or recheck it."); return False; end if; - when Cfg_Email => + when Stn_Email => Result := Value.Kind = TOML_String and then Alire.Utils.Could_Be_An_Email (Value.As_String, With_Name => False); - when Cfg_GitHub_Login => + when Stn_GitHub_Login => Result := Value.Kind = TOML_String and then Utils.Is_Valid_GitHub_Username (Value.As_String); end case; diff --git a/src/alire/alire-settings-edit.ads b/src/alire/alire-settings-edit.ads index a80effcc0..196a66c9f 100644 --- a/src/alire/alire-settings-edit.ads +++ b/src/alire/alire-settings-edit.ads @@ -8,7 +8,7 @@ with TOML; package Alire.Settings.Edit is - -- Shortcuts that use the standard config locations. These interpret the + -- Shortcuts that use the standard settings locations. These interpret the -- value in string as a TOML type whenever possible. procedure Set_Locally (Key : CLIC.Config.Config_Key; @@ -40,40 +40,42 @@ package Alire.Settings.Edit is -- Unset a key at a level; silently succeed even if the key was undefined. function Path return Absolute_Path; - -- The in-use global config folder path. + -- The in-use global settings folder path. -- In order of decreasing precedence: -- * A manually set path with Set_Path (below) - -- * An ALR_CONFIG env given folder + -- * An ALIRE_SETTINGS_DIR env given folder -- * Default per-platform path (see alire-platforms-*) function Cache_Path return Absolute_Path; -- The location for data that will be recreated if missing; its value in -- precedence order is: - -- 1) Config builtin 'cache.dir' + -- 1) Setting builtin 'cache.dir' -- 2) if Path above is overridden, Path/cache -- 3) Platforms.Folders.Cache procedure Set_Path (Path : Absolute_Path); - -- Override global config folder path + -- Override global settings folder path function Is_At_Default_Dir return Boolean; - -- Says if we are using the default config location (no -c or env override) + -- Says if we are using the default settings location (no -c or env + -- override). function Indexes_Directory return Absolute_Path is (Path / "indexes"); function Filepath (Lvl : Level) return Absolute_Path with Pre => Lvl /= Local or else Directories.Detect_Root_Path /= ""; - -- Return path of the configuration file corresponding to the given + -- Return path of the settings file corresponding to the given -- configuration level. - -- Support for built-in config variables. See Alire.Settings.Builtins also. + -- Support for built-in settings variables. See Alire.Settings.Builtins + -- also. function Builtins_Info return AAA.Strings.Vector; - -- Return a String_Vector with the documentation of builtin configuration + -- Return a String_Vector with the documentation of builtin settings -- options in text format. procedure Print_Builtins_Doc; - -- Print a Markdown documentation for the built-in configuration options + -- Print a Markdown documentation for the built-in settings options function Valid_Builtin (Key : CLIC.Config.Config_Key; Value : TOML.TOML_Value) @@ -83,9 +85,9 @@ package Alire.Settings.Edit is private procedure Load_Settings; - -- Clear and reload all configuration. Also set some values elsewhere + -- Clear and reload all settings. Also set some values elsewhere -- used to break circularities. Bottom line, this procedure must leave - -- the program-wide configuration ready. This is done during startup from - -- Alire_Early_Elaboration so config is available ASAP. + -- the program-wide settings ready. This is done during startup from + -- Alire_Early_Elaboration so settings are available ASAP. end Alire.Settings.Edit; diff --git a/src/alire/alire-settings.adb b/src/alire/alire-settings.adb index c5d21d5c6..41bad57f6 100644 --- a/src/alire/alire-settings.adb +++ b/src/alire/alire-settings.adb @@ -9,10 +9,10 @@ package body Alire.Settings is function DB return access constant CLIC.Config.Instance is begin - if Config_Loaded then + if Settings_Loaded then return DB_Instance'Access; else - raise Program_Error with "Attempt to use config database too early"; + raise Program_Error with "Attempt to use settings database too early"; end if; end DB; @@ -34,8 +34,8 @@ package body Alire.Settings is -- Get -- --------- - function Get (This : Builtin_Option) return Config_Int - is (Config_Int'Value + function Get (This : Builtin_Option) return Setting_Int + is (Setting_Int'Value (DB.Get_As_String (+This.Key, +This.Def))); ----------------- @@ -86,7 +86,7 @@ package body Alire.Settings is procedure Set (This : Builtin_Option; Level : Settings.Level; - Value : Config_Int) + Value : Setting_Int) is begin Edit.Set (Level, +This.Key, Value'Image, This.Check); @@ -109,14 +109,14 @@ package body Alire.Settings is function Image (Kind : Builtin_Kind) return String is (case Kind is - when Cfg_Int => "Integer", - when Cfg_Float => "Float", - when Cfg_Bool => "Boolean", - when Cfg_String => "String", - when Cfg_Absolute_Path => "Absolute path", - when Cfg_Existing_Absolute_Path => "Absolute path already existing", - when Cfg_Email => "Email address", - when Cfg_GitHub_Login => "GitHub login"); + when Stn_Int => "Integer", + when Stn_Float => "Float", + when Stn_Bool => "Boolean", + when Stn_String => "String", + when Stn_Absolute_Path => "Absolute path", + when Stn_Existing_Absolute_Path => "Absolute path already existing", + when Stn_Email => "Email address", + when Stn_GitHub_Login => "GitHub login"); ---------------- -- Is_Builtin -- @@ -137,7 +137,7 @@ package body Alire.Settings is return All_Builtins (Key).Kind; end if; - Raise_Checked_Error ("Kind is only valid for builtin config key"); + Raise_Checked_Error ("Kind is only valid for builtin setting key"); end Kind_Of_Builtin; ----------------- @@ -176,7 +176,7 @@ package body Alire.Settings is Check : CLIC.Config.Check_Import := null) return Builtin_Option is (New_Builtin (Key => Key, - Kind => Cfg_Bool, + Kind => Stn_Bool, Def => Def'Image, Help => Help, Public => Public, diff --git a/src/alire/alire-settings.ads b/src/alire/alire-settings.ads index 66597784a..b04fa9326 100644 --- a/src/alire/alire-settings.ads +++ b/src/alire/alire-settings.ads @@ -14,16 +14,16 @@ package Alire.Settings is -- Ordering is important, as Globals are loaded first and overridden by any -- Local definition loaded later. - subtype Config_Int is Long_Long_Integer; + subtype Setting_Int is Long_Long_Integer; --------------- -- Built-ins -- --------------- - type Builtin_Kind is (Cfg_Int, Cfg_Float, Cfg_Bool, - Cfg_String, Cfg_Absolute_Path, - Cfg_Existing_Absolute_Path, - Cfg_Email, Cfg_GitHub_Login); + type Builtin_Kind is (Stn_Int, Stn_Float, Stn_Bool, + Stn_String, Stn_Absolute_Path, + Stn_Existing_Absolute_Path, + Stn_Email, Stn_GitHub_Login); function Image (Kind : Builtin_Kind) return String; @@ -42,7 +42,7 @@ package Alire.Settings is function Get (This : Builtin_Option) return String; function Get (This : Builtin_Option) return Boolean; - function Get (This : Builtin_Option) return Config_Int; + function Get (This : Builtin_Option) return Setting_Int; procedure Set_Locally (This : Builtin_Option; Value : String); @@ -58,7 +58,7 @@ package Alire.Settings is procedure Set (This : Builtin_Option; Level : Settings.Level; - Value : Config_Int); + Value : Setting_Int); procedure Unset (This : Builtin_Option; Level : Settings.Level); @@ -82,10 +82,10 @@ package Alire.Settings is private - Config_Loaded : Boolean := False; + Settings_Loaded : Boolean := False; DB_Instance : aliased CLIC.Config.Instance; - -- The Alire user configuration database + -- The Alire user settings database type Builtin_Option is tagged record Key : Ada.Strings.Unbounded.Unbounded_String; diff --git a/src/alire/os_windows/alire-settings-builtins-windows.ads b/src/alire/os_windows/alire-settings-builtins-windows.ads index f6a2d90a2..19d4f4c86 100644 --- a/src/alire/os_windows/alire-settings-builtins-windows.ads +++ b/src/alire/os_windows/alire-settings-builtins-windows.ads @@ -20,7 +20,7 @@ package Alire.Settings.Builtins.Windows is Msys2_Install_Dir : constant Builtin := New_Builtin (Key => "msys2.install_dir", - Kind => Cfg_Absolute_Path, + Kind => Stn_Absolute_Path, Def => Settings.Edit.Cache_Path / "msys64", Help => "Directory where Alire will detect and/or install" & @@ -28,14 +28,14 @@ package Alire.Settings.Builtins.Windows is Msys2_Installer : constant Builtin := New_Builtin (Key => "msys2.installer", - Kind => Cfg_String, + Kind => Stn_String, Def => Default_Msys2_Installer, Help => "Filename of the executable msys2 installer. (Windows only)"); Msys2_Installer_URL : constant Builtin := New_Builtin (Key => "msys2.installer_url", - Kind => Cfg_String, + Kind => Stn_String, Def => Default_Msys2_Installer_URL, Help => "URL of the executable msys2 installer. (Windows only)"); From 845766d9bc9907cb984d57a3428682b1802115bb Mon Sep 17 00:00:00 2001 From: Alejandro R Mosteo Date: Tue, 12 Mar 2024 17:02:02 +0100 Subject: [PATCH 16/17] Classify builds by release milestone (#1632) --- .github/workflows/ci-windows.yml | 19 +++++++++++-------- src/alire/alire-builds.adb | 5 ++--- testsuite/drivers/asserts.py | 1 + testsuite/drivers/builds.py | 16 +++++----------- .../dockerized/misc/default-cache/test.py | 2 +- testsuite/tests/pin/downgrade/test.py | 2 +- testsuite/tests/settings/shared-deps/test.py | 4 ++-- 7 files changed, 23 insertions(+), 26 deletions(-) diff --git a/.github/workflows/ci-windows.yml b/.github/workflows/ci-windows.yml index e6adc0598..d0258d925 100644 --- a/.github/workflows/ci-windows.yml +++ b/.github/workflows/ci-windows.yml @@ -12,7 +12,10 @@ on: workflow_dispatch: env: - ALIRE_OS: "windows" + ALIRE_OS: windows + MINGW64_PATH: C:\Users\runneradmin\AppData\Local\alire\cache\msys64\mingw64\bin + MSYS2_PATH: C:\Users\runneradmin\AppData\Local\alire\cache\msys64\usr\bin + PACMAN: C:\Users\runneradmin\AppData\Local\alire\cache\msys64\usr\bin\pacman --noconfirm jobs: @@ -35,11 +38,11 @@ jobs: - name: Build alr run: gprbuild -j0 -p -P alr_env - - name: alr first run to install msys2 - run: ./bin/alr --non-interactive help get + - name: Display built alr and trigger install of msys2 + run: ./bin/alr version - name: install tar from msys2 (Git tar in Actions VM does not seem to work) - run: C:\Users\runneradmin\AppData\Local\alire\msys64\usr\bin\pacman --noconfirm -S tar + run: ${{env.PACMAN}} -S tar - name: Install Python 3.x (required for the testsuite) uses: actions/setup-python@v2 @@ -57,17 +60,17 @@ jobs: run: gprinstall -p -P alr_env --prefix=${{ runner.temp }}/alr_install - name: Install qt-installer-framework in msys2 - run: C:\Users\runneradmin\AppData\Local\alire\msys64\usr\bin\pacman --noconfirm -S mingw64/mingw-w64-x86_64-qt-installer-framework + run: ${{env.PACMAN}} -S mingw64/mingw-w64-x86_64-qt-installer-framework - name: Add msys2 /mingw64/bin to the path (for qt-installer-framework) - run: echo 'C:\Users\runneradmin\AppData\Local\alire\msys64\mingw64\bin' >> $GITHUB_PATH + run: echo '${{env.MINGW64_PATH}}' >> $GITHUB_PATH shell: bash - name: Install zip in msys2 - run: C:\Users\runneradmin\AppData\Local\alire\msys64\usr\bin\pacman --noconfirm -S zip + run: ${{env.PACMAN}} --noconfirm -S zip - name: Add msys2 /usr/bin to the path (for zip) - run: echo 'C:\Users\runneradmin\AppData\Local\alire\msys64\usr\bin' >> $GITHUB_PATH + run: echo '${{env.MSYS2_PATH}}' >> $GITHUB_PATH shell: bash - name: Run installer build script diff --git a/src/alire/alire-builds.adb b/src/alire/alire-builds.adb index 22b0c9710..f15ea0041 100644 --- a/src/alire/alire-builds.adb +++ b/src/alire/alire-builds.adb @@ -97,9 +97,8 @@ package body Alire.Builds is is Base : constant Absolute_Path := Builds.Path - / (Release.Deployment_Folder - & "_" - & Root.Build_Hash (Release.Name)); + / Release.Deployment_Folder + / Root.Build_Hash (Release.Name); begin if Subdir and then Release.Origin.Is_Monorepo then return Base / Release.Origin.Subdir; diff --git a/testsuite/drivers/asserts.py b/testsuite/drivers/asserts.py index fd96d4cb0..7947044c4 100644 --- a/testsuite/drivers/asserts.py +++ b/testsuite/drivers/asserts.py @@ -7,6 +7,7 @@ import os import re import difflib +import sys from drivers.alr import run_alr from drivers.helpers import contents, lines_of diff --git a/testsuite/drivers/builds.py b/testsuite/drivers/builds.py index 09424b508..f83448a04 100644 --- a/testsuite/drivers/builds.py +++ b/testsuite/drivers/builds.py @@ -34,27 +34,21 @@ def are_shared() -> bool: return False -def clear_builds_dir() -> None: - """ - Clear the shared build directory - """ - rmtree(path()) - - def find_dir(crate_name: str) -> str: """ - Find the build dir of a crate in the shared build directory + Find the build dir of a crate in the shared build directory. It always uses + forward slashes in the returned folder path. """ - if len(found := glob(f"{path()}/{crate_name}_*")) != 1: + if len(found := glob(f"{path()}/{crate_name}*/*")) != 1: raise AssertionError(f"Unexpected number of dirs for crate {crate_name}: {found}") - return glob(f"{path()}/{crate_name}_*")[0] + return glob(f"{path()}/{crate_name}*/*")[0].replace(os.sep, "/") def find_hash(crate_name: str) -> str: """ Find the hash of a crate in the shared build directory """ - return find_dir(crate_name).split("_")[-1] + return find_dir(crate_name).split("/")[-1] def hash_input(crate_name: str, as_lines: bool=False) -> str: diff --git a/testsuite/tests/dockerized/misc/default-cache/test.py b/testsuite/tests/dockerized/misc/default-cache/test.py index 34fe7d49e..8f0045482 100644 --- a/testsuite/tests/dockerized/misc/default-cache/test.py +++ b/testsuite/tests/dockerized/misc/default-cache/test.py @@ -49,7 +49,7 @@ # procedures) hash = "0774083df8ff003084c32cabdec6090a58b41c6be317cec0475df5eacbca0d23" assert \ - os.path.isdir(f"{base}/builds/crate_real_1.0.0_filesystem_{hash}"), \ + os.path.isdir(f"{base}/builds/crate_real_1.0.0_filesystem/{hash}"), \ f"Shared build not found at the expected location: f{contents(base)}" print('SUCCESS') diff --git a/testsuite/tests/pin/downgrade/test.py b/testsuite/tests/pin/downgrade/test.py index 5255dbee3..348b9488c 100644 --- a/testsuite/tests/pin/downgrade/test.py +++ b/testsuite/tests/pin/downgrade/test.py @@ -27,7 +27,7 @@ def check_child(version, output, pinned): # Verify dependency folders if builds.are_shared(): run_alr('update') # force hash computation - assert builds.find_dir('libchild_' + version + '_filesystem') + assert builds.find_dir('libchild_' + version) else: assert os.path.exists('alire/cache/dependencies/libchild_' + version + '_filesystem') diff --git a/testsuite/tests/settings/shared-deps/test.py b/testsuite/tests/settings/shared-deps/test.py index 84291e547..b13d0ad24 100644 --- a/testsuite/tests/settings/shared-deps/test.py +++ b/testsuite/tests/settings/shared-deps/test.py @@ -41,12 +41,12 @@ def check_in(file : str, expected : str) -> bool: # because no build has been attempted yet, hence a sync has not been performed. # And, since there's no sync yet, neither the build dir exists: -assert len(glob.glob(os.path.join(build_dir, "hello_1.0.1_filesystem_*"))) == 0, \ +assert len(glob.glob(os.path.join(build_dir, "hello_1.0.1_filesystem/*"))) == 0, \ "Build dir should not exist yet" # Do a build, and now the sync should have happened and the build dir be filled run_alr("build") -base = builds.find_dir("hello_1.0.1_filesystem") +base = builds.find_dir("hello") # There's too much object files and the like, check a few critical files: files = contents(base) # This returns "normalized" paths (with '/' separators) From cb3114c05c8394561c6115e73d0c9e982cf2a927 Mon Sep 17 00:00:00 2001 From: Alejandro R Mosteo Date: Tue, 12 Mar 2024 17:35:07 +0100 Subject: [PATCH 17/17] Don't say unknown crate for abstract crates in `alr get` (#1633) * Inform about providers in `alr get` * Test for the change --- src/alr/alr-commands-get.adb | 14 +++++++++++-- src/alr/alr-commands-show.adb | 26 +++---------------------- src/alr/alr-common.adb | 27 ++++++++++++++++++++++++++ src/alr/alr-common.ads | 10 ++++++++++ testsuite/tests/get/provides/test.py | 26 +++++++++++++++++++++++++ testsuite/tests/get/provides/test.yaml | 4 ++++ 6 files changed, 82 insertions(+), 25 deletions(-) create mode 100644 src/alr/alr-common.adb create mode 100644 src/alr/alr-common.ads create mode 100644 testsuite/tests/get/provides/test.py create mode 100644 testsuite/tests/get/provides/test.yaml diff --git a/src/alr/alr-commands-get.adb b/src/alr/alr-commands-get.adb index 7ca2b122e..cc040e5cc 100644 --- a/src/alr/alr-commands-get.adb +++ b/src/alr/alr-commands-get.adb @@ -12,6 +12,8 @@ with Alire.Solutions.Diffs; with Alire.Solver; with Alire.Utils.Switches; +with Alr.Common; + with CLIC.User_Input; with Semantic_Versioning.Extended; @@ -341,8 +343,16 @@ package body Alr.Commands.Get is Cmd.Auto_Update_Index; if not Alire.Index.Exists (Allowed.Crate) then - Reportaise_Command_Failed - ("Crate [" & Args (1) & "] does not exist in the index."); + -- Even if the crate does not exist, it may be an abstract crate + -- provided by some others (e.g. gnat -> gnat_native), so inform + -- about it rather than saying it doesn't exist. + if Common.Show_Providers (Allowed) then + return; + else + Reportaise_Command_Failed + ("Crate [" & Allowed.Crate.As_String + & "] does not exist in the index."); + end if; end if; Check_Unavailable_External (Allowed.Crate); diff --git a/src/alr/alr-commands-show.adb b/src/alr/alr-commands-show.adb index b18c55964..e52f38722 100644 --- a/src/alr/alr-commands-show.adb +++ b/src/alr/alr-commands-show.adb @@ -11,7 +11,8 @@ with Alire.Roots.Optional; with Alire.Solutions; with Alire.Solver; with Alire.Utils.Tables; -with Alire.Utils.TTY; + +with Alr.Common; with Semantic_Versioning.Extended; @@ -248,27 +249,6 @@ package body Alr.Commands.Show is (Name, Versions).TTY_Image); end Report_Jekyll; - -------------------- - -- Show_Providers -- - -------------------- - - function Show_Providers (Dep : Alire.Dependencies.Dependency) return Boolean - is - use Alire; - begin - if Index.All_Crate_Aliases.Contains (Dep.Crate) then - Trace.Info ("Crate " & Utils.TTY.Name (Dep.Crate) & " is abstract and" - & " provided by:"); - for Provider of Index.All_Crate_Aliases.all (Dep.Crate) loop - Trace.Info (" " & Utils.TTY.Name (Provider)); - end loop; - - return True; - else - return False; - end if; - end Show_Providers; - ------------- -- Execute -- ------------- @@ -310,7 +290,7 @@ package body Alr.Commands.Show is -- Even if the crate does not exist, it may be an abstract crate -- provided by some others (e.g. gnat_native -> gnat). - if Show_Providers (Allowed) then + if Common.Show_Providers (Allowed) then return; else raise Alire.Query_Unsuccessful; diff --git a/src/alr/alr-common.adb b/src/alr/alr-common.adb new file mode 100644 index 000000000..7bb8b738b --- /dev/null +++ b/src/alr/alr-common.adb @@ -0,0 +1,27 @@ +with Alire.Index; +with Alire.Utils.TTY; + +package body Alr.Common is + + -------------------- + -- Show_Providers -- + -------------------- + + function Show_Providers (Dep : Alire.Dependencies.Dependency) return Boolean + is + use Alire; + begin + if Index.All_Crate_Aliases.Contains (Dep.Crate) then + Trace.Always ("Crate " & Utils.TTY.Name (Dep.Crate) + & " is abstract and provided by:"); + for Provider of Index.All_Crate_Aliases.all (Dep.Crate) loop + Trace.Always (" " & Utils.TTY.Name (Provider)); + end loop; + + return True; + else + return False; + end if; + end Show_Providers; + +end Alr.Common; diff --git a/src/alr/alr-common.ads b/src/alr/alr-common.ads new file mode 100644 index 000000000..b657e8653 --- /dev/null +++ b/src/alr/alr-common.ads @@ -0,0 +1,10 @@ +with Alire.Dependencies; + +package Alr.Common is + + -- Some reusable bits across commands + + function Show_Providers (Dep : Alire.Dependencies.Dependency) + return Boolean; + +end Alr.Common; diff --git a/testsuite/tests/get/provides/test.py b/testsuite/tests/get/provides/test.py new file mode 100644 index 000000000..86e835e84 --- /dev/null +++ b/testsuite/tests/get/provides/test.py @@ -0,0 +1,26 @@ +""" +Test the output of `alr get` for an abstract crate +""" + +from drivers.alr import run_alr +from drivers.asserts import assert_eq + +# gnat does not contain releases but several other crates provide it, so rather +# than saying that the crate doesn't exist, show its providers: + +assert_eq("""Crate gnat is abstract and provided by: + gnat_cross_1 + gnat_cross_2 + gnat_external + gnat_native +""", + run_alr("get", "gnat", "--dirname").out) + +# Check the error for a truly unknown crate: + +assert_eq("""\ +ERROR: Crate [unobtanium] does not exist in the index. +""", + run_alr("get", "unobtanium", "--dirname", complain_on_error=False).out) + +print('SUCCESS') diff --git a/testsuite/tests/get/provides/test.yaml b/testsuite/tests/get/provides/test.yaml new file mode 100644 index 000000000..8185c03b5 --- /dev/null +++ b/testsuite/tests/get/provides/test.yaml @@ -0,0 +1,4 @@ +driver: python-script +indexes: + toolchain_index: + in_fixtures: true