Skip to content

Commit

Permalink
Fixes for Windows brokenness
Browse files Browse the repository at this point in the history
  • Loading branch information
mosteo committed Feb 22, 2024
1 parent 058e787 commit 7218070
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 21 deletions.
14 changes: 10 additions & 4 deletions src/alire/alire-os_lib.ads
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,19 @@ package Alire.OS_Lib with Preelaborate is

subtype Native_Path_Like is String
with Dynamic_Predicate =>
(for all Char of Native_Path_Like => Char /= Forbidden_Dir_Separator);
(for all Char of Native_Path_Like => Char /= Forbidden_Dir_Separator)
or else raise Ada.Assertions.Assertion_Error
with "Not a native-path-like: " & Native_Path_Like;

subtype Portable_Path_Like is String
with Dynamic_Predicate =>
(for all Char of Portable_Path_Like => Char /= '\');
(for all Char of Portable_Path_Like => Char /= '\')
or else raise Ada.Assertions.Assertion_Error
with "Not a portable-path-like: " & Portable_Path_Like;

function To_Portable (Path : Native_Path_Like) return Portable_Path_Like;
function To_Portable (Path : Any_Path) return Portable_Path_Like;
-- Path is Any_Path and not Native_Path_Like because some Windows native
-- programs return mixed style paths such as "C:/blah/blah".

function To_Native (Path : Portable_Path_Like) return Native_Path_Like;

Expand All @@ -57,7 +63,7 @@ private
-- To_Portable_Like --
----------------------

function To_Portable (Path : Native_Path_Like)
function To_Portable (Path : Any_Path)
return Portable_Path_Like
is (case GNATCOLL.OS.Constants.OS is
when MacOS | Unix => Path,
Expand Down
13 changes: 5 additions & 8 deletions src/alire/alire-publish.adb
Original file line number Diff line number Diff line change
Expand Up @@ -630,12 +630,10 @@ package body Alire.Publish is
With_Extension => False);
Git : constant VCSs.Git.VCS := VCSs.Git.Handler;
Is_Repo : constant Boolean := Git.Is_Repository (Base_Path (Context));
Archive : constant Relative_Path :=
Target_Dir
/ (Milestone
& (if Is_Repo
then ".tgz"
else ".tbz2"));
Archive : constant Relative_Path := Target_Dir / (Milestone & ".tgz");
-- We used to use tbz2 for locally tar'ed files, but that has an implicit
-- dependency on bzip2 that we are not managing yet, so for now we err on
-- the safe side of built-in tar gzip capabilities.

-----------------
-- Git_Archive --
Expand Down Expand Up @@ -668,7 +666,7 @@ package body Alire.Publish is
OS_Lib.Subprocess.Checked_Spawn
("tar",
Empty_Vector
& "cfj"
& "cfz"
& Archive -- Destination file at alire/archives/crate-version.tbz2

& String'("--exclude=./alire")
Expand Down Expand Up @@ -1096,7 +1094,6 @@ package body Alire.Publish is
then Ada.Directories.Full_Name (Path)
else Ada.Directories.Full_Name (Root.Value.Path));
begin

if not Git.Is_Repository (Root_Path) then
Git_Error ("no git repository found", Root_Path);
end if;
Expand Down
3 changes: 2 additions & 1 deletion src/alire/alire-utils-tools.ads
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ package Alire.Utils.Tools is
-- Check if a required executable tool is available in PATH.
-- If not, try to install it. If unable and Fail, abort, otherwise return

function Is_BSD_Tar return Boolean;
function Is_BSD_Tar return Boolean
with Pre => Available (Tar);
-- Say if the tar in PATH is the bsdtar variant, which lacks some features

end Alire.Utils.Tools;
4 changes: 3 additions & 1 deletion src/alire/alire-vfs.ads
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ private
-----------------

function To_Portable (Path : Relative_Path) return Portable_Path
is (Portable_Path (OS_Lib.To_Portable (Path)));
is (Portable_Path
(OS_Lib.To_Portable
(Path)));

---------------
-- To_Native --
Expand Down
5 changes: 4 additions & 1 deletion src/alire/alire.ads
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
with Ada.Assertions;
with Ada.Exceptions;
with Ada.Strings.Unbounded;
private with Ada.Strings.UTF_Encoding.Wide_Wide_Strings;
Expand Down Expand Up @@ -144,7 +145,9 @@ package Alire with Preelaborate is
-- Filenames with full path

subtype Absolute_Path is Any_Path
with Dynamic_Predicate => Check_Absolute_Path (Absolute_Path);
with Dynamic_Predicate => Check_Absolute_Path (Absolute_Path)
or else raise Ada.Assertions.Assertion_Error
with "Path is not absolute: " & Absolute_Path;

function Absolute_Path_Image (Path : Absolute_Path) return String;
-- Needed for later instantiations
Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/monorepo/subdir-in-tar/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# generated location as the "online" location, and this works because we are
# forcing.
p = run(["alr", "-q", "-f", "-n", "publish", "--skip-build", "--skip-submit", "--tar"],
input=f"file:{os.getcwd()}/alire/archives/xxx-0.1.0-dev.tbz2\n".encode())
input=f"file:{os.getcwd()}/alire/archives/xxx-0.1.0-dev.tgz\n".encode())
p.check_returncode()

# Add improper subdir to manifest
Expand Down
6 changes: 3 additions & 3 deletions testsuite/tests/publish/tarball-plaindir-nonstd/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
# forcing.
p = run(["alr", "-q", "-f", "-n", "publish", "--skip-build", "--skip-submit", "--tar",
"--manifest", "xxx.toml"],
input=f"file:{os.getcwd()}/alire/archives/xxx-0.1.0-dev.tbz2\n".encode())
input=f"file:{os.getcwd()}/alire/archives/xxx-0.1.0-dev.tgz\n".encode())
p.check_returncode()

# Verify the generated file does not contain the alire folder
p = run(["tar", "tf", "alire/archives/xxx-0.1.0-dev.tbz2"],
p = run(["tar", "tf", os.path.join("alire", "archives", "xxx-0.1.0-dev.tgz")],
capture_output=True)
p.check_returncode()
assert p.returncode == 0, "tar failed: " + p.stderr.decode()
assert "xxx-0.0.0/alire/" not in p.stdout.decode(), \
"Unexpected contents in tarball: " + p.stdout.decode()

Expand Down
4 changes: 2 additions & 2 deletions testsuite/tests/publish/tarball-plaindir/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
# generated location as the "online" location, and this works because we are
# forcing.
p = run(["alr", "-q", "-f", "-n", "publish", "--skip-build", "--skip-submit", "--tar"],
input=f"file:{os.getcwd()}/alire/archives/xxx-0.1.0-dev.tbz2\n".encode())
input=f"file:{os.getcwd()}/alire/archives/xxx-0.1.0-dev.tgz\n".encode())
p.check_returncode()

# Verify the generated file does not contain the alire folder
p = run(["tar", "tf", "alire/archives/xxx-0.1.0-dev.tbz2"],
p = run(["tar", "tf", "alire/archives/xxx-0.1.0-dev.tgz"],
capture_output=True)
p.check_returncode()
assert "xxx-0.0.0/alire/" not in p.stdout.decode(), \
Expand Down

0 comments on commit 7218070

Please sign in to comment.