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

Fix early error on Windows with msys2 disabled #1747

Merged
merged 3 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 8 additions & 1 deletion src/alire/alire-platforms-common.ads
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ private package Alire.Platforms.Common is
---------------------

function Unix_Home_Folder return String
is (OS_Lib.Getenv ("HOME", Default => "/tmp"));
is (if OS_Lib.Getenv ("HOME", "unset") = "unset" and then
GNAT.OS_Lib.Directory_Separator = '\'
then
raise Checked_Error with
"$HOME is not set, you might be running an"
& " `alr` built for a non-Windows OS"
else
OS_Lib.Getenv ("HOME", Default => "/tmp"));

----------------------
-- Unix_Temp_Folder --
Expand Down
15 changes: 14 additions & 1 deletion src/alire/os_windows/alire-platforms-current__windows.adb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,20 @@ package body Alire.Platforms.Current is
return Detect_Msys2_Root;

when others =>
return OS_Lib.Getenv ("HOMEDRIVE");
declare
Root : constant String := OS_Lib.Getenv ("HOMEDRIVE", "C:\");
begin
if Root'Length not in 2 | 3 then
Raise_Checked_Error
("$HOMEDRIVE is not a proper drive: " & Root);
end if;

if Root (Root'Last) not in '/' | '\' then
return Root & '\';
else
return Root;
end if;
end;

end case;
end Distribution_Root;
Expand Down
15 changes: 14 additions & 1 deletion src/alire/os_windows/alire-platforms-folders__windows.adb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ with Ada.Directories;

with Alire.OS_Lib;

with GNAT.OS_Lib;

package body Alire.Platforms.Folders is

use OS_Lib.Operators;
Expand All @@ -11,7 +13,18 @@ package body Alire.Platforms.Folders is
----------

function Home return Absolute_Path
is (OS_Lib.Getenv ("USERPROFILE"));
is
begin
if OS_Lib.Getenv ("USERPROFILE", "unset") = "unset" and then
GNAT.OS_Lib.Directory_Separator = '/'
then
Raise_Checked_Error
("$USERPROFILE not set "
& "(might you be running an `alr` built for Windows?)");
else
return OS_Lib.Getenv ("USERPROFILE");
end if;
end Home;

-----------
-- Cache --
Expand Down
15 changes: 14 additions & 1 deletion testsuite/tests/settings/distro-disable/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,24 @@
Verify that disabling distro detection works as intended
"""

from drivers.alr import run_alr, distro_is_known
from drivers.alr import run_alr, distro_is_known, init_local_crate, alr_with, alr_manifest

run_alr("settings", "--global",
"--set", "distribution.disable_detection", "true")

# Inspect output of `alr version`
assert not distro_is_known(), "Unexpected distro detection"

# Ensure that basic environment can be printed for crates that use
# $DISTRIB_ROOT

init_local_crate()
# Append usage of DISTRIB_ROOT to the manifest
with open(alr_manifest(), "a") as f:
f.write("""
[environment]
PATH.append = "${DISTRIB_ROOT}"
""")
run_alr("printenv")

print('SUCCESS')
2 changes: 1 addition & 1 deletion testsuite/tests/settings/distro-disable/test.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
driver: python-script
indexes:
basic_index: {}
compiler_only_index: {}
Loading