Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config.toml --> settings.toml #1626

Merged
merged 5 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 59 additions & 23 deletions src/alire/alire-config-edit.adb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
with Ada.Directories;
with Ada.Text_IO;

with Alire.Config.Builtins;
Expand All @@ -16,8 +17,10 @@ package body Alire.Config.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 --
Expand Down Expand Up @@ -111,25 +114,58 @@ package body Alire.Config.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.Config.Edit.Path / File;
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" / 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.Config.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));

-- Leave an explanation just in case
mosteo marked this conversation as resolved.
Show resolved Hide resolved
Directories.Touch
(Directories.Parent (Location (Old))
/ "config-toml-is-settings-toml-after-alr-2_0");
end if;

return Location (Current);
end Filepath;

-----------------
Expand Down Expand Up @@ -168,8 +204,8 @@ package body Alire.Config.Edit is

function Path return Absolute_Path is
begin
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.Config,
Default_Config_Path);
Expand All @@ -194,10 +230,10 @@ package body Alire.Config.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;

Expand Down
3 changes: 3 additions & 0 deletions src/alire/alire-paths.ads
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/index/auto-update/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

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 @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/settings/relative_config_path/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
6 changes: 3 additions & 3 deletions testsuite/tests/workflows/init-options/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
Loading