Skip to content

Commit

Permalink
Alire.Config.Edit: fix for --config with relative path (#848)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabien-Chouteau authored Sep 14, 2021
1 parent 954135a commit b923985
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/alire/alire-config-edit.adb
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand 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";
Expand Down
4 changes: 2 additions & 2 deletions src/alire/alire-config-edit.ads
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
12 changes: 10 additions & 2 deletions src/alr/alr-commands.adb
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 20 additions & 0 deletions testsuite/tests/config/relative_config_path/test.py
Original file line number Diff line number Diff line change
@@ -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')
3 changes: 3 additions & 0 deletions testsuite/tests/config/relative_config_path/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
driver: python-script
indexes:
basic_index: {}

0 comments on commit b923985

Please sign in to comment.