From b923985324431f867ae576e9dd3676fa743fac2f Mon Sep 17 00:00:00 2001 From: Fabien Chouteau Date: Tue, 14 Sep 2021 15:58:16 +0200 Subject: [PATCH] Alire.Config.Edit: fix for --config with relative path (#848) --- src/alire/alire-config-edit.adb | 4 ++-- src/alire/alire-config-edit.ads | 4 ++-- src/alr/alr-commands.adb | 12 +++++++++-- .../tests/config/relative_config_path/test.py | 20 +++++++++++++++++++ .../config/relative_config_path/test.yaml | 3 +++ 5 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 testsuite/tests/config/relative_config_path/test.py create mode 100644 testsuite/tests/config/relative_config_path/test.yaml diff --git a/src/alire/alire-config-edit.adb b/src/alire/alire-config-edit.adb index eed6293b5..b6c138e3f 100644 --- a/src/alire/alire-config-edit.adb +++ b/src/alire/alire-config-edit.adb @@ -393,7 +393,7 @@ package body Alire.Config.Edit is -- Path -- ---------- - function Path return String is + function Path return Absolute_Path is begin if Config_Path /= null then -- Case with switch (TODO) return Config_Path.all; @@ -407,7 +407,7 @@ package body Alire.Config.Edit is -- Set_Path -- -------------- - procedure Set_Path (Path : String) is + procedure Set_Path (Path : Absolute_Path) is begin if Config_Path /= null then raise Constraint_Error with "Custom path already set"; diff --git a/src/alire/alire-config-edit.ads b/src/alire/alire-config-edit.ads index 1750008a0..49f25d902 100644 --- a/src/alire/alire-config-edit.ads +++ b/src/alire/alire-config-edit.ads @@ -17,14 +17,14 @@ package Alire.Config.Edit is -- here all non-preelaborable things related to config loading. This -- way, querying stays preelaborable. - function Path return String; + function Path return Absolute_Path; -- The in-use global config folder path. -- In order of decreasing precedence: -- * A manually set path with Set_Path (below) -- * An ALR_CONFIG env given folder -- * Default per-platform path (see alire-platforms-*) - procedure Set_Path (Path : String); + procedure Set_Path (Path : Absolute_Path); -- Override global config folder path function Indexes_Directory return Absolute_Path is (Path / "indexes"); diff --git a/src/alr/alr-commands.adb b/src/alr/alr-commands.adb index 8724ec62d..3592c8f52 100644 --- a/src/alr/alr-commands.adb +++ b/src/alr/alr-commands.adb @@ -388,10 +388,18 @@ package body Alr.Commands is -- Also use a fancier busy spinner end if; - if Command_Line_Config_Path /= null and then + if Command_Line_Config_Path /= null and then Command_Line_Config_Path.all /= "" then - Alire.Config.Edit.Set_Path (Command_Line_Config_Path.all); + if not Alire.Check_Absolute_Path (Command_Line_Config_Path.all) then + -- Make an absolute path from user relative path + Alire.Config.Edit.Set_Path + (Ada.Directories.Full_Name (Command_Line_Config_Path.all)); + else + + -- Use absolute path from user + Alire.Config.Edit.Set_Path (Command_Line_Config_Path.all); + end if; end if; Create_Alire_Folders; diff --git a/testsuite/tests/config/relative_config_path/test.py b/testsuite/tests/config/relative_config_path/test.py new file mode 100644 index 000000000..41af1784f --- /dev/null +++ b/testsuite/tests/config/relative_config_path/test.py @@ -0,0 +1,20 @@ +""" +Verify that using a relative path for Alire config dir is ok +""" + +import os + +from glob import glob + +from drivers.alr import run_alr +from drivers.asserts import assert_eq +from drivers.helpers import lines_of + +run_alr("--config", ".", "config", "--global", + "--set", "some_config_key", "true") + + +assert_eq("some_config_key = true\n", lines_of ("config.toml")[0]) + + +print('SUCCESS') diff --git a/testsuite/tests/config/relative_config_path/test.yaml b/testsuite/tests/config/relative_config_path/test.yaml new file mode 100644 index 000000000..872fc1274 --- /dev/null +++ b/testsuite/tests/config/relative_config_path/test.yaml @@ -0,0 +1,3 @@ +driver: python-script +indexes: + basic_index: {}