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 aec0e3cb5..6ce00c709 100644 --- a/src/alire/alire-settings-edit.adb +++ b/src/alire/alire-settings-edit.adb @@ -2,11 +2,14 @@ with Ada.Directories; 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.Text_Files; +with Alire.Version.Semver; +with Alire.Warnings; with CLIC.Config.Edit; with CLIC.Config.Load; @@ -212,12 +215,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 Settings_Path /= null then -- Case with switch (TODO) return Settings_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 087fef0c1..c3bdfa9cb 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)