Skip to content

Commit

Permalink
Fixes detected by testsuite
Browse files Browse the repository at this point in the history
  • Loading branch information
mosteo committed Jul 24, 2020
1 parent d9eca17 commit 3cb3d3f
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 35 deletions.
2 changes: 1 addition & 1 deletion scripts/python/separate-origins.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def migrate(path):

# Visit all nested TOML files. We do not check for proper placement.
for file in glob.iglob(os.path.join(path, '**/*.toml'), recursive=True):
if "/index.toml" not in file and "external" not in file:
if "/index.toml" not in file and "-external.toml" not in file:
fix_manifest(file)

# Finalize by updating the index version
Expand Down
3 changes: 1 addition & 2 deletions src/alire/alire-origins-tweaks.adb
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,10 @@ package body Alire.Origins.Tweaks is

function Fix_VCS return Origin is
use Ada.Directories;
use Utils;
URL : constant String := This.URL; -- Doesn't include @commit
begin
-- Check for "xxx+file://" or return as-is:
if not Starts_With (URL, Prefix_File) then
if URI.Scheme (URL) not in URI.File_Schemes then
return This;
end if;

Expand Down
50 changes: 35 additions & 15 deletions src/alire/alire-origins.adb
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,20 @@ package body Alire.Origins is
Context => Keys.Origin);
URL : constant String :=
Table.Checked_Pop (Keys.URL, TOML_String).As_String;
VCS_URL : constant String := Utils.Tail (URL, '+');
VCS_URL : constant String :=
(if Utils.Contains (URL, "file:")
then Utils.Tail (URL, ':') -- Remove file: that confuses git
else Utils.Tail (URL, '+')); -- remove prefix vcs+
Scheme : constant URI.Schemes := URI.Scheme (URL);
Hashed : constant Boolean := Table.Unwrap.Has (Keys.Hashes);
begin
case Scheme is
when External =>
This := New_External (URI.Path (URL));

when URI.File_Schemes =>
if URI.Local_Path (URL) = "" then
From.Checked_Error ("empty path given in local origin: " & URL);
From.Checked_Error ("empty path given in local origin");
end if;
This := New_Filesystem (URI.Local_Path (URL));

Expand Down Expand Up @@ -247,24 +254,36 @@ package body Alire.Origins is
& Keys.Archive_Name & "'");
end;

when System =>
This := New_System (URI.Path (URL));

when Unknown =>
From.Checked_Error ("unsupported scheme in URL: " & URL);
end case;

-- Check hashes existence appropriateness

if This.Kind = Source_Archive or else
(This.Kind = Filesystem and then
GNAT.OS_Lib.Is_Regular_File (This.Path))
then
return Add_Hashes (Table);
elsif Table.Unwrap.Has (Keys.Hashes) then
return Table.Failure
("hashes cannot be provided for origins of kind "
& Utils.To_Mixed_Case (This.Kind'Img));
end if;
case This.Kind is
when Filesystem =>
if Hashed then
return Add_Hashes (Table);
end if;
-- Hashes are mandatory only for source archives. This is checked
-- on deployment, since at this moment we do not have the proper
-- absolute patch

when Source_Archive =>
return Add_Hashes (Table); -- mandatory

when others =>
if Hashed then
return Table.Failure
("hashes cannot be provided for origins of kind "
& Utils.To_Mixed_Case (This.Kind'Img));
end if;
end case;

return Outcome_Success;
return Table.Report_Extra_Keys;
end From_TOML;

---------------------
Expand Down Expand Up @@ -315,8 +334,9 @@ package body Alire.Origins is
Table.Set (Keys.URL, +("file:" & This.Path));

when VCS_Kinds =>
Table.Set (Keys.URL, +(Prefixes (This.Kind).all &
This.URL & "#" & This.Commit));
Table.Set (Keys.URL, +(Prefixes (This.Kind).all & This.URL));
Table.Set (Keys.Commit, +This.Commit);

when External =>
Table.Set (Keys.URL,
+(Prefixes (This.Kind).all & (+This.Data.Description)));
Expand Down
21 changes: 16 additions & 5 deletions src/alire/alire-uri.ads
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ package Alire.URI with Preelaborate is
(None,
-- For URLs without scheme (to be interpreted as local paths)

External,
-- external: denotes a crate detected by some external definition

File,
-- A file: URI

Expand All @@ -41,6 +44,9 @@ package Alire.URI with Preelaborate is
HTTP,
-- Either http or https, since we don't differentiate treatment

System,
-- system:package is used to denote a native package from the platform

Unknown
-- Anything else
);
Expand Down Expand Up @@ -70,7 +76,8 @@ package Alire.URI with Preelaborate is
-- TODO: fix incorrectly emitted file:// paths in Origins so at least we
-- are not generating improper URIs.

function Remote_Path (This : URL) return String;
function Path (This : URL) return String;
-- The path as properly defined (without the authority, if any)

private

Expand All @@ -85,11 +92,11 @@ private
function Local_Path (This : URL) return String
is (U.Permissive_Path (This));

-----------------
-- Remote_Path --
-----------------
----------
-- Path --
----------

function Remote_Path (This : URL) return String
function Path (This : URL) return String
is (U.Extract (This, U.Path));

------------
Expand All @@ -99,6 +106,8 @@ private
function Scheme (This : URL) return Schemes
is (if U.Scheme (This) = "" then
None
elsif L (U.Scheme (This)) = "external" then
External
elsif L (U.Scheme (This)) = "file" then
File
elsif Utils.Starts_With (L (U.Scheme (This)), "git+") then
Expand All @@ -111,6 +120,8 @@ private
HTTP
elsif L (U.Scheme (This)) = "https" then
HTTP
elsif L (U.Scheme (This)) = "system" then
System
else
Unknown);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ maintainers-logins = ["mylogin"]
[origin]
url = "git+file:../../../crates/libhello_git"
commit = "ce78e7706c9d3f97605df48d8befca5407f8d328"
hashes = ["sha512:f9d5a85fec4db46d5a2859057658c01ee4fe1ab412dab80bcbb426102b5dcb147ab7e0744e781d045e5d2b50ec3cb4f0990c8ce66e52cda37c88833d0f814500"]
# hashes = ["sha512:f9d5a85fec4db46d5a2859057658c01ee4fe1ab412dab80bcbb426102b5dcb147ab7e0744e781d045e5d2b50ec3cb4f0990c8ce66e52cda37c88833d0f814500"]
# Hashes no longer accepted for git origins
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ maintainers-logins = ["mylogin"]
[origin]
url = "git+file:../../../crates/libhello_git"
commit = "ce78e7706c9d3f97605df48d8befca5407f8d328"
hashes = ["sha512:deadbeef"]
# hashes = ["sha512:deadbeef"]
# Hashes no longer accepted for vcs remotes
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
description = "Main program"
name = "main"
version = "1.0.0"
origin = "file://./../../../crates/noop_1.0-default.tgz"
licenses = []
maintainers = ["alejandro@mosteo.com"]
maintainers-logins = ["mylogin"]
origin-hashes = ["sha512:de676fbda9f16ba98fe1adc80e20dbd9b98a86352267825b55f1d719570adc0f92f1be2e96fd3df06aac4f6b5fee8686695e315be370cabe482edefc5a0570c5"]

[[depends-on]]
make = "*"

[origin]
url = "file:./../../../crates/noop_1.0-default.tgz"
hashes = ["sha512:de676fbda9f16ba98fe1adc80e20dbd9b98a86352267825b55f1d719570adc0f92f1be2e96fd3df06aac4f6b5fee8686695e315be370cabe482edefc5a0570c5"]
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
version = "0.2"
badkey = "sneaking around"
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
description = "A crate with a dependency"
name = "crate_master"
version = "1.0.0"
origin = "file://../../../crates/noop_1.0-default.tgz"
licenses = []
maintainers = ["somebody@somewhere.com"]
maintainers-logins = ["mylogin"]
origin-hashes = ["sha512:de676fbda9f16ba98fe1adc80e20dbd9b98a86352267825b55f1d719570adc0f92f1be2e96fd3df06aac4f6b5fee8686695e315be370cabe482edefc5a0570c5"]

[[depends-on]]
crate = "any"

[origin]
url = "file://../../../crates/noop_1.0-default.tgz"
hashes = ["sha512:de676fbda9f16ba98fe1adc80e20dbd9b98a86352267825b55f1d719570adc0f92f1be2e96fd3df06aac4f6b5fee8686695e315be370cabe482edefc5a0570c5"]
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
description = "Main program"
name = "main"
version = "1.0.0"
origin = "file://./../../../crates/noop_1.0-default.tgz"
licenses = []
maintainers = ["alejandro@mosteo.com"]
maintainers-logins = ["mylogin"]
origin-hashes = ["sha512:de676fbda9f16ba98fe1adc80e20dbd9b98a86352267825b55f1d719570adc0f92f1be2e96fd3df06aac4f6b5fee8686695e315be370cabe482edefc5a0570c5"]

[[depends-on]]
dialog = "*"
[[actions."case(os)".windows]]
type = "post-fetch"
command = ["bash", "-c", "uname && dialog --help"]

[origin]
url = "file://./../../../crates/noop_1.0-default.tgz"
hashes = ["sha512:de676fbda9f16ba98fe1adc80e20dbd9b98a86352267825b55f1d719570adc0f92f1be2e96fd3df06aac4f6b5fee8686695e315be370cabe482edefc5a0570c5"]
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ description = "This is the regular short description"
long-description = "This is the long crate description.\n\nThis can be a multiline string, and TOML parsers are free to use the platform end-of-line character during loading.\n"
name = "hello_world"
version = "0.1.0"
origin = "http://blah.com/pkg.zip"
licenses = []
maintainers = ["example@example.com"]
maintainers-logins = ["mylogin"]
origin-hashes = ["sha512:deadbeef"]

[origin]
url = "http://blah.com/pkg.zip"
hashes = ["sha512:deadbeef"]
2 changes: 1 addition & 1 deletion testsuite/tests/index/origin-unknown-kind/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
p = run_alr('show', 'hello_world',
complain_on_error=False, debug=False, quiet=False)
assert_match(
'ERROR: .* unknown origin: .*'
'ERROR: .* unsupported scheme .*'
'\n', p.out)

print('SUCCESS')
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
name = "crate_1234"
version = "0.0.0"
origin = "file://.."
description = "Shiny new project"
maintainers = ["your@email.here"]
maintainers-logins = ["github-username"]
project-files = ["nested/project.gpr"]

[origin]
url = "file:.."

0 comments on commit 3cb3d3f

Please sign in to comment.