Skip to content

Commit

Permalink
Merge remote-tracking branch 'alire/master' into fix/config-toml
Browse files Browse the repository at this point in the history
  • Loading branch information
mosteo committed Mar 11, 2024
2 parents cdb6dd0 + da203b3 commit 5f8ddb8
Show file tree
Hide file tree
Showing 17 changed files with 109 additions and 55 deletions.
10 changes: 9 additions & 1 deletion doc/user-changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 8 additions & 0 deletions src/alire/alire-environment.ads
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions src/alire/alire-features.ads
Original file line number Diff line number Diff line change
@@ -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;
16 changes: 0 additions & 16 deletions src/alire/alire-index_features.ads

This file was deleted.

6 changes: 3 additions & 3 deletions src/alire/alire-origins.adb
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -519,15 +519,15 @@ 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)
then
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;

Expand Down
25 changes: 23 additions & 2 deletions src/alire/alire-settings-edit.adb
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
14 changes: 14 additions & 0 deletions src/alire/alire-version-semver.ads
Original file line number Diff line number Diff line change
@@ -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;
34 changes: 17 additions & 17 deletions testsuite/drivers/alr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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".
Expand All @@ -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")


Expand Down Expand Up @@ -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):
Expand All @@ -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")
2 changes: 1 addition & 1 deletion testsuite/drivers/driver/python_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 0 additions & 4 deletions testsuite/tests/build_profile/recursive/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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), \
Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/index/origin-binary-explicit/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions testsuite/tests/provides/metadata/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 0 additions & 2 deletions testsuite/tests/publish/local-repo-branched/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion testsuite/tests/publish/local-repo-nonstd/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion testsuite/tests/publish/local-repo/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/settings/early-loading/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions testsuite/tests/toolchain/missing-tool-redeploy/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 5f8ddb8

Please sign in to comment.