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

implement -C/--chdir flag #1479

Merged
merged 4 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
15 changes: 15 additions & 0 deletions src/alr/alr-commands.adb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ package body Alr.Commands is

Command_Line_Config_Path : aliased GNAT.OS_Lib.String_Access;

Command_Line_Chdir_Target_Path : aliased GNAT.OS_Lib.String_Access;

-- Following aliased booleans are used by GNAT.Command_Line processing:

Log_Quiet : Boolean renames Alire_Early_Elaboration.Switch_Q;
Expand Down Expand Up @@ -143,6 +145,11 @@ package body Alr.Commands is
"-c=", "--config=",
"Override configuration folder location");

Define_Switch (Config,
Command_Line_Chdir_Target_Path'Access,
"-C=", "--chdir=",
"Run `alr` in the given directory");

Define_Switch (Config,
Alire.Force'Access,
"-f", "--force",
Expand Down Expand Up @@ -498,6 +505,14 @@ package body Alr.Commands is
end;
end if;

-- chdir(2) if necessary.

if Command_Line_Chdir_Target_Path /= null and then
Command_Line_Chdir_Target_Path.all /= ""
then
Ada.Directories.Set_Directory (Command_Line_Chdir_Target_Path.all);
end if;

Create_Alire_Folders;

begin
Expand Down
20 changes: 20 additions & 0 deletions testsuite/tests/init/with-chdir/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""
Test "executable" only appears in --bin initializations
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quite common to forget to update this description ;-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching that - fixed in cba2c11, which also tests -C behavior on a non-existent directory. Thanks!


import os.path

from drivers.alr import run_alr
from drivers.asserts import assert_match
from drivers.helpers import content_of

test_dir = os.getcwd()

# Binary crate
run_alr("init", "--bin", "xxx")
assert_match(".*executables = \[", content_of("xxx/alire.toml"))

# Check that it builds and runs
run_alr("--chdir=xxx", "run")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, it would be good to have a check after this one that when the target directory doesn't exist, alr exits with error.


print('SUCCESS')
4 changes: 4 additions & 0 deletions testsuite/tests/init/with-chdir/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
driver: python-script
indexes:
basic_index: # needed to avoid cloning the community index
in_fixtures: true
Loading