From 2f53db74d1762fd0888936767357086e0008a679 Mon Sep 17 00:00:00 2001 From: Alejandro R Mosteo Date: Mon, 26 Feb 2024 20:38:08 +0100 Subject: [PATCH] Interpret `environment` entries as path parts (#1483) * Intepret environment values as paths This is the likely intended behavior. Down the road we can have a way to have literal values in these strings. * Fixes for Windows brokenness --- doc/catalog-format-spec.md | 7 +++ src/alire/alire-environment-formatting.adb | 21 ++++++- src/alire/alire-os_lib-subprocess.adb | 2 - src/alire/alire-os_lib.ads | 58 +++++++++++++++++++ src/alire/alire-properties-environment.adb | 24 +++++++- src/alire/alire-properties-environment.ads | 2 +- src/alire/alire-publish.adb | 21 +++---- src/alire/alire-toml_adapters.adb | 24 ++++++-- src/alire/alire-toml_adapters.ads | 12 +++- src/alire/alire-utils-tools.adb | 16 +++++ src/alire/alire-utils-tools.ads | 4 ++ src/alire/alire-vfs.adb | 15 ----- src/alire/alire-vfs.ads | 18 +++--- src/alire/alire.ads | 5 +- testsuite/drivers/asserts.py | 2 +- .../gn/gnat_native/gnat_native-8888.0.0.toml | 3 +- .../gn/gnat_native/gnat_native-8888.0.0.toml | 3 +- .../my_index/crates/crate/.emptydir | 0 .../my_index/index/cr/crate/crate-1.0.0.toml | 14 +++++ .../env-bad-path/my_index/index/index.toml | 1 + testsuite/tests/index/env-bad-path/test.py | 13 +++++ testsuite/tests/index/env-bad-path/test.yaml | 5 ++ .../env-path/my_index/crates/crate/.emptydir | 0 .../my_index/index/cr/crate/crate-1.0.0.toml | 12 ++++ .../index/env-path/my_index/index/index.toml | 1 + testsuite/tests/index/env-path/test.py | 31 ++++++++++ testsuite/tests/index/env-path/test.yaml | 5 ++ .../tests/monorepo/subdir-in-tar/test.py | 2 +- .../publish/tarball-plaindir-nonstd/test.py | 6 +- .../tests/publish/tarball-plaindir/test.py | 4 +- 30 files changed, 272 insertions(+), 59 deletions(-) create mode 100644 testsuite/tests/index/env-bad-path/my_index/crates/crate/.emptydir create mode 100644 testsuite/tests/index/env-bad-path/my_index/index/cr/crate/crate-1.0.0.toml create mode 100644 testsuite/tests/index/env-bad-path/my_index/index/index.toml create mode 100644 testsuite/tests/index/env-bad-path/test.py create mode 100644 testsuite/tests/index/env-bad-path/test.yaml create mode 100644 testsuite/tests/index/env-path/my_index/crates/crate/.emptydir create mode 100644 testsuite/tests/index/env-path/my_index/index/cr/crate/crate-1.0.0.toml create mode 100644 testsuite/tests/index/env-path/my_index/index/index.toml create mode 100644 testsuite/tests/index/env-path/test.py create mode 100644 testsuite/tests/index/env-path/test.yaml diff --git a/doc/catalog-format-spec.md b/doc/catalog-format-spec.md index 2307460d6..6e80666f5 100644 --- a/doc/catalog-format-spec.md +++ b/doc/catalog-format-spec.md @@ -316,6 +316,10 @@ static, i.e. they cannot depend on the context. PATH.append = "${DISTRIB_ROOT}/usr/bin" ``` + Path fragments in this table must use portable format, that is, '/' for path + separation. Alire will take care of using the native separator when setting + these variables. + Predefined variables are provided by Alire and will be replaced in the value: @@ -325,6 +329,9 @@ static, i.e. they cannot depend on the context. be the `msys2` installation directory (e.g. `C:\Users\user_name\.cache\alire\msys2`). + The escaping `"\$"` can be used to prevent the expansion of a + dollar-bracketed expression. + Environment entries can use dynamic expressions: ```toml diff --git a/src/alire/alire-environment-formatting.adb b/src/alire/alire-environment-formatting.adb index e11852cd7..4f8029f7a 100644 --- a/src/alire/alire-environment-formatting.adb +++ b/src/alire/alire-environment-formatting.adb @@ -1,5 +1,6 @@ with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; +with Alire.OS_Lib; with Alire.Platforms.Current; package body Alire.Environment.Formatting is @@ -81,6 +82,23 @@ package body Alire.Environment.Formatting is end if; end Replace; + --------------- + -- To_Native -- + --------------- + -- Replace forward slashes with native slashes on Windows, unless they + -- are an escape sequence. + function To_Native (S : String) return String is + begin + case OS_Lib.Dir_Separator is + when '/' => return S; + when '\' => null; + when others => raise Unimplemented with + "Unknown OS with dir separator: " & OS_Lib.Dir_Separator; + end case; + + return AAA.Strings.Replace (S, "/", "" & OS_Lib.Dir_Separator); + end To_Native; + Result : Unbounded_String := To_Unbounded_String (Value); From : Natural := 1; To : Natural; @@ -107,7 +125,8 @@ package body Alire.Environment.Formatting is From := 1; end loop; - return To_String (Result); + -- For final usage, we use the native separator + return To_Native (+Result); end Format; end Alire.Environment.Formatting; diff --git a/src/alire/alire-os_lib-subprocess.adb b/src/alire/alire-os_lib-subprocess.adb index 29cd39c2c..7ef0dbd8a 100644 --- a/src/alire/alire-os_lib-subprocess.adb +++ b/src/alire/alire-os_lib-subprocess.adb @@ -10,8 +10,6 @@ with GNAT.OS_Lib; package body Alire.OS_Lib.Subprocess is - use AAA.Strings; - function To_Argument_List (Args : AAA.Strings.Vector) return GNAT.OS_Lib.Argument_List_Access; diff --git a/src/alire/alire-os_lib.ads b/src/alire/alire-os_lib.ads index 6d7d0f12f..b2c88852a 100644 --- a/src/alire/alire-os_lib.ads +++ b/src/alire/alire-os_lib.ads @@ -1,3 +1,7 @@ +private with AAA.Strings; + +with GNATCOLL.OS.Constants; + package Alire.OS_Lib with Preelaborate is function "/" (L, R : String) return String; @@ -20,4 +24,58 @@ package Alire.OS_Lib with Preelaborate is -- Return the location of an executable if found on PATH, or "" otherwise. -- On Windows, no need to append ".exe" as it will be found without it. + Forbidden_Dir_Separator : constant Character := + (case GNATCOLL.OS.Constants.Dir_Sep is + when '/' => '\', + when '\' => '/', + when others => + raise Unimplemented + with "Unknown dir separator"); + + -- For things that may contain path fragments but are not proper paths + + Dir_Separator : Character renames GNATCOLL.OS.Constants.Dir_Sep; + + subtype Native_Path_Like is String + with Dynamic_Predicate => + (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 /= '\') + or else raise Ada.Assertions.Assertion_Error + with "Not a portable-path-like: " & 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; + +private + + use AAA.Strings; + use all type GNATCOLL.OS.OS_Type; + + ---------------------- + -- To_Portable_Like -- + ---------------------- + + function To_Portable (Path : Any_Path) + return Portable_Path_Like + is (case GNATCOLL.OS.Constants.OS is + when MacOS | Unix => Path, + when Windows => Replace (Path, "\", "/")); + + -------------------- + -- To_Native_Like -- + -------------------- + + function To_Native (Path : Portable_Path_Like) return Native_Path_Like + is (case GNATCOLL.OS.Constants.OS is + when MacOS | Unix => Path, + when Windows => Replace (String (Path), "/", "\")); + end Alire.OS_Lib; diff --git a/src/alire/alire-properties-environment.adb b/src/alire/alire-properties-environment.adb index 9d89ca1b4..3bd544375 100644 --- a/src/alire/alire-properties-environment.adb +++ b/src/alire/alire-properties-environment.adb @@ -71,6 +71,24 @@ package body Alire.Properties.Environment is use type Conditional.Properties; use TOML; Env : TOML_Value; + + ---------------- + -- Path_Check -- + ---------------- + + procedure Path_Check (Var, S : String) is + begin + -- We expect something resembling a portable path, but we admit "\$" + -- as an escape sequence. + for I in S'Range loop + if S (I) = '\' and then (I = S'Last or else S (I + 1) /= '$') then + Raise_Checked_Error + (Var & ": forbidden '\' character in environment path; " + & "use '/' instead"); + end if; + end loop; + end Path_Check; + begin if From.Unwrap.Kind /= TOML_Table then From.Checked_Error @@ -87,7 +105,7 @@ package body Alire.Properties.Environment is for Name of Env.Keys loop declare Var : Variable; -- The env. var. being parsed - Val : TOML_Value; -- The env. var. value + Val : TOML_Value; -- The env. var. action. value begin Var.Name := Name; @@ -109,8 +127,10 @@ package body Alire.Properties.Environment is Actions_Suggestion (Action_Image)); end; - -- Value (already type checked in previous pop) + -- We consider values as possibly containing paths, so we check + -- that path separators are portable + Path_Check (+Name, Val.As_String); Var.Value := +Val.As_String; -- Pop entry to avoid upper "unexpected key" errors diff --git a/src/alire/alire-properties-environment.ads b/src/alire/alire-properties-environment.ads index f71a00824..de217eb63 100644 --- a/src/alire/alire-properties-environment.ads +++ b/src/alire/alire-properties-environment.ads @@ -41,7 +41,7 @@ private type Variable is new Property with record Action : Actions; Name : UString; - Value : UString; + Value : UString; -- Value with portable path separators end record; end Alire.Properties.Environment; diff --git a/src/alire/alire-publish.adb b/src/alire/alire-publish.adb index 2c4a8485b..7933986d4 100644 --- a/src/alire/alire-publish.adb +++ b/src/alire/alire-publish.adb @@ -25,6 +25,7 @@ with Alire.TOML_Index; with Alire.TOML_Keys; with Alire.TOML_Load; with Alire.User_Pins.Maps; +with Alire.Utils.Tools; with Alire.Utils.TTY; with Alire.Utils.User_Input.Query_Config; with Alire.VCSs.Git; @@ -32,8 +33,6 @@ with Alire.VFS; with CLIC.User_Input; -with GNATCOLL.OS.Constants; - with Semantic_Versioning; with TOML.File_IO; @@ -631,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 -- @@ -669,14 +666,15 @@ 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") -- Exclude top-level alire folder, before applying prefix - -- exclude .git and the like, with workaround for macOS bsd tar - & (if GNATCOLL.OS.Constants.OS in GNATCOLL.OS.MacOS + -- exclude .git and the like, with workaround for bsdtar used by + -- macOS and Windows without MSYS2 + & (if Utils.Tools.Is_BSD_Tar then Empty_Vector & "--exclude=./.git" & "--exclude=./.hg" @@ -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; diff --git a/src/alire/alire-toml_adapters.adb b/src/alire/alire-toml_adapters.adb index 3bf67cc61..75a229436 100644 --- a/src/alire/alire-toml_adapters.adb +++ b/src/alire/alire-toml_adapters.adb @@ -263,8 +263,8 @@ package body Alire.TOML_Adapters is ---------------------- function Pop_Single_Table (Queue : Key_Queue; - Value : out TOML.TOML_Value; - Kind : TOML.Any_Value_Kind) return String + Value : out TOML.TOML_Value) + return String is use TOML; begin @@ -280,14 +280,28 @@ package body Alire.TOML_Adapters is Value := Queue.Value.Get (Queue.Value.Keys (1)); + return Key : constant String := +Queue.Value.Keys (1) do + Queue.Value.Unset (Queue.Value.Keys (1)); + end return; + end Pop_Single_Table; + + ---------------------- + -- Pop_Single_Table -- + ---------------------- + + function Pop_Single_Table (Queue : Key_Queue; + Value : out TOML.TOML_Value; + Kind : TOML.Any_Value_Kind) return String + is + use TOML; + Key : constant String := Queue.Pop_Single_Table (Value); + begin if Value.Kind /= Kind then Queue.Checked_Error ("expected a single entry of type " & Kind'Img & ", but got a " & Value.Kind'Img); end if; - return Key : constant String := +Queue.Value.Keys (1) do - Queue.Value.Unset (Queue.Value.Keys (1)); - end return; + return Key; end Pop_Single_Table; ----------------------- diff --git a/src/alire/alire-toml_adapters.ads b/src/alire/alire-toml_adapters.ads index 3667c46e5..9d950142d 100644 --- a/src/alire/alire-toml_adapters.ads +++ b/src/alire/alire-toml_adapters.ads @@ -98,8 +98,16 @@ package Alire.TOML_Adapters with Preelaborate is -- intended use is to process keys beginning with "case(" in the table. function Pop_Single_Table (Queue : Key_Queue; - Value : out TOML.TOML_Value; - Kind : TOML.Any_Value_Kind) return String; + Value : out TOML.TOML_Value) + return String; + -- For constructions like [parent.child.grandchild], where only one child + -- is allowed. Child is returned as String, and Value is set to granchild. + -- Raises Checked_Error if Queue is not a table, or it doesn't contain + -- exactly one key. + + function Pop_Single_Table (Queue : Key_Queue; + Value : out TOML.TOML_Value; + Kind : TOML.Any_Value_Kind) return String; -- For constructions like [parent.child.grandchild], where we known that -- only one child can exist. Will raise Checked_Error if any of these -- happens: Queue is not a table; Queue doesn't have exactly one key; Value diff --git a/src/alire/alire-utils-tools.adb b/src/alire/alire-utils-tools.adb index ce79cb2f1..e92b8dfe1 100644 --- a/src/alire/alire-utils-tools.adb +++ b/src/alire/alire-utils-tools.adb @@ -1,3 +1,5 @@ +with AAA.Strings; + with Alire.OS_Lib.Subprocess; use Alire.OS_Lib.Subprocess; with Alire.OS_Lib; with Alire.Platforms.Current; @@ -157,4 +159,18 @@ package body Alire.Utils.Tools is Install_From_Distrib (Tool, Fail); end Check_Tool; + ---------------- + -- Is_BSD_Tar -- + ---------------- + + function Is_BSD_Tar return Boolean is + use AAA.Strings; + begin + return Contains + (To_Lower_Case + (Checked_Spawn_And_Capture + ("tar", To_Vector ("--version")).Flatten), + "bsdtar"); + end Is_BSD_Tar; + end Alire.Utils.Tools; diff --git a/src/alire/alire-utils-tools.ads b/src/alire/alire-utils-tools.ads index 09093ae65..6acb95bdd 100644 --- a/src/alire/alire-utils-tools.ads +++ b/src/alire/alire-utils-tools.ads @@ -18,4 +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 + with Pre => Available (Tar); + -- Say if the tar in PATH is the bsdtar variant, which lacks some features + end Alire.Utils.Tools; diff --git a/src/alire/alire-vfs.adb b/src/alire/alire-vfs.adb index 2fb2e3b6c..323c5c13b 100644 --- a/src/alire/alire-vfs.adb +++ b/src/alire/alire-vfs.adb @@ -21,21 +21,6 @@ package body Alire.VFS is end if; end Attempt_Portable; - ----------------- - -- To_Portable -- - ----------------- - - function To_Portable (Path : Relative_Path) return Portable_Path - is - begin - case GNATCOLL.OS.Constants.OS is - when MacOS | Unix => - return Portable_Path (Path); - when Windows => - return Portable_Path (Replace (Path, "\", "/")); - end case; - end To_Portable; - -------------- -- Read_Dir -- -------------- diff --git a/src/alire/alire-vfs.ads b/src/alire/alire-vfs.ads index 743ddd224..022c7f6a0 100644 --- a/src/alire/alire-vfs.ads +++ b/src/alire/alire-vfs.ads @@ -1,8 +1,8 @@ with Ada.Containers.Vectors; with Alire.Directories; +private with Alire.OS_Lib; -private with GNATCOLL.OS.Constants; with GNATCOLL.VFS; with AAA.Strings; use AAA.Strings; @@ -85,8 +85,6 @@ package Alire.VFS is private - use all type GNATCOLL.OS.OS_Type; - ----------------- -- Is_Portable -- ----------------- @@ -96,14 +94,20 @@ private and then not Check_Absolute_Path (Path)); + ----------------- + -- To_Portable -- + ----------------- + + function To_Portable (Path : Relative_Path) return Portable_Path + is (Portable_Path + (OS_Lib.To_Portable + (Path))); + --------------- -- To_Native -- --------------- function To_Native (Path : Portable_Path) return Relative_Path - is (case GNATCOLL.OS.Constants.OS is - when MacOS | Unix => Relative_Path (Path), - when Windows => Relative_Path - (Replace (String (Path), "/", "\"))); + is (Relative_Path (OS_Lib.To_Native (OS_Lib.Portable_Path_Like (Path)))); end Alire.VFS; diff --git a/src/alire/alire.ads b/src/alire/alire.ads index 76b0b5bb2..e2d207f54 100644 --- a/src/alire/alire.ads +++ b/src/alire/alire.ads @@ -1,3 +1,4 @@ +with Ada.Assertions; with Ada.Exceptions; with Ada.Strings.Unbounded; private with Ada.Strings.UTF_Encoding.Wide_Wide_Strings; @@ -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 diff --git a/testsuite/drivers/asserts.py b/testsuite/drivers/asserts.py index 2cc332349..fd96d4cb0 100644 --- a/testsuite/drivers/asserts.py +++ b/testsuite/drivers/asserts.py @@ -141,4 +141,4 @@ def assert_substring(target: str, text: str): Check that a string is contained in another string """ assert target in text, \ - f"Missing expected string '{target}' in text:\n{text}" \ No newline at end of file + f"Missing expected string '{target}' in text:\n{text}" diff --git a/testsuite/fixtures/build_hash_index/gn/gnat_native/gnat_native-8888.0.0.toml b/testsuite/fixtures/build_hash_index/gn/gnat_native/gnat_native-8888.0.0.toml index 242786d5f..d5a8e5c29 100644 --- a/testsuite/fixtures/build_hash_index/gn/gnat_native/gnat_native-8888.0.0.toml +++ b/testsuite/fixtures/build_hash_index/gn/gnat_native/gnat_native-8888.0.0.toml @@ -6,8 +6,7 @@ maintainers-logins = ["mylogin"] provides = ["gnat=8888.0"] # Although the compiler is fake, we use this path in some tests -environment.'case(os)'.'windows'.TEST_PATH.append = '${CRATE_ROOT}\bin' -environment.'case(os)'.'...'.TEST_PATH.append = '${CRATE_ROOT}/bin' +environment.TEST_PATH.append = '${CRATE_ROOT}/bin' # Test dynamic expression, but for all OSes [origin."case(os)"."..."] diff --git a/testsuite/fixtures/toolchain_index/gn/gnat_native/gnat_native-8888.0.0.toml b/testsuite/fixtures/toolchain_index/gn/gnat_native/gnat_native-8888.0.0.toml index 242786d5f..d5a8e5c29 100644 --- a/testsuite/fixtures/toolchain_index/gn/gnat_native/gnat_native-8888.0.0.toml +++ b/testsuite/fixtures/toolchain_index/gn/gnat_native/gnat_native-8888.0.0.toml @@ -6,8 +6,7 @@ maintainers-logins = ["mylogin"] provides = ["gnat=8888.0"] # Although the compiler is fake, we use this path in some tests -environment.'case(os)'.'windows'.TEST_PATH.append = '${CRATE_ROOT}\bin' -environment.'case(os)'.'...'.TEST_PATH.append = '${CRATE_ROOT}/bin' +environment.TEST_PATH.append = '${CRATE_ROOT}/bin' # Test dynamic expression, but for all OSes [origin."case(os)"."..."] diff --git a/testsuite/tests/index/env-bad-path/my_index/crates/crate/.emptydir b/testsuite/tests/index/env-bad-path/my_index/crates/crate/.emptydir new file mode 100644 index 000000000..e69de29bb diff --git a/testsuite/tests/index/env-bad-path/my_index/index/cr/crate/crate-1.0.0.toml b/testsuite/tests/index/env-bad-path/my_index/index/cr/crate/crate-1.0.0.toml new file mode 100644 index 000000000..c61f329aa --- /dev/null +++ b/testsuite/tests/index/env-bad-path/my_index/index/cr/crate/crate-1.0.0.toml @@ -0,0 +1,14 @@ +description = "Sample crate" +name = "crate" +version = "1.0.0" +licenses = [] +maintainers = ["any@bo.dy"] +maintainers-logins = ["someone"] + +[environment] +VAR1.set = "${CRATE_ROOT}/crate_test_bin" # OK +VAR2.set = "\\${CRATE_ROOT}/crate_test_bin" # OK, escape the $ to avoid expansion +VAR3.set = "${CRATE_ROOT}\\bin" # BAD, non-portable path + +[origin] +url = "file:../../../crates/crate" diff --git a/testsuite/tests/index/env-bad-path/my_index/index/index.toml b/testsuite/tests/index/env-bad-path/my_index/index/index.toml new file mode 100644 index 000000000..c2a2c7dbc --- /dev/null +++ b/testsuite/tests/index/env-bad-path/my_index/index/index.toml @@ -0,0 +1 @@ +version = "1.2" diff --git a/testsuite/tests/index/env-bad-path/test.py b/testsuite/tests/index/env-bad-path/test.py new file mode 100644 index 000000000..5cd841267 --- /dev/null +++ b/testsuite/tests/index/env-bad-path/test.py @@ -0,0 +1,13 @@ +""" +Detect a bad path in an environment variable +""" + +from drivers.alr import run_alr +from drivers.asserts import assert_match + +# Attempting to load the crate to show it should fail but only for the VAR3 bad variable + +assert_match(".*VAR3: forbidden", + run_alr("show", "crate", complain_on_error=False).out) + +print('SUCCESS') diff --git a/testsuite/tests/index/env-bad-path/test.yaml b/testsuite/tests/index/env-bad-path/test.yaml new file mode 100644 index 000000000..9f4d48305 --- /dev/null +++ b/testsuite/tests/index/env-bad-path/test.yaml @@ -0,0 +1,5 @@ +driver: python-script +build_mode: both +indexes: + my_index: + in_fixtures: false diff --git a/testsuite/tests/index/env-path/my_index/crates/crate/.emptydir b/testsuite/tests/index/env-path/my_index/crates/crate/.emptydir new file mode 100644 index 000000000..e69de29bb diff --git a/testsuite/tests/index/env-path/my_index/index/cr/crate/crate-1.0.0.toml b/testsuite/tests/index/env-path/my_index/index/cr/crate/crate-1.0.0.toml new file mode 100644 index 000000000..d8d20095e --- /dev/null +++ b/testsuite/tests/index/env-path/my_index/index/cr/crate/crate-1.0.0.toml @@ -0,0 +1,12 @@ +description = "Sample crate" +name = "crate" +version = "1.0.0" +licenses = [] +maintainers = ["any@bo.dy"] +maintainers-logins = ["someone"] + +[environment] +PATH.append = "${CRATE_ROOT}/crate_test_bin" + +[origin] +url = "file:../../../crates/crate" diff --git a/testsuite/tests/index/env-path/my_index/index/index.toml b/testsuite/tests/index/env-path/my_index/index/index.toml new file mode 100644 index 000000000..c2a2c7dbc --- /dev/null +++ b/testsuite/tests/index/env-path/my_index/index/index.toml @@ -0,0 +1 @@ +version = "1.2" diff --git a/testsuite/tests/index/env-path/test.py b/testsuite/tests/index/env-path/test.py new file mode 100644 index 000000000..ee1f246a6 --- /dev/null +++ b/testsuite/tests/index/env-path/test.py @@ -0,0 +1,31 @@ +""" +Paths in environment values should use native path separators in the index, and +be converted to the native separator for usage. +""" + +import os +import re + +from drivers.alr import crate_dirname, run_alr +from drivers.asserts import assert_match +from drivers.helpers import content_of + +# Check that the output of `alr show` shows the proper slashes + +# Show uses the path with portable separators, as the conversion is done just +# for printenv output. +assert_match(f".*/crate_test_bin", + run_alr("show", "crate").out) + +# Similarly, if we retrieve the crate, the output to the manifest must be in +# portable format (always forward slashes). +run_alr("get", "crate") +assert_match(f".*/crate_test_bin", + content_of(f"{crate_dirname('crate')}/alire.toml")) + +# When obtained via printenv, the path must be native +os.chdir(crate_dirname('crate')) +assert_match(".*PATH=[^\n]*" + re.escape(f"{os.sep}crate_test_bin"), + run_alr("printenv").out) + +print('SUCCESS') diff --git a/testsuite/tests/index/env-path/test.yaml b/testsuite/tests/index/env-path/test.yaml new file mode 100644 index 000000000..9f4d48305 --- /dev/null +++ b/testsuite/tests/index/env-path/test.yaml @@ -0,0 +1,5 @@ +driver: python-script +build_mode: both +indexes: + my_index: + in_fixtures: false diff --git a/testsuite/tests/monorepo/subdir-in-tar/test.py b/testsuite/tests/monorepo/subdir-in-tar/test.py index fe5ce4c3b..686a2bba5 100644 --- a/testsuite/tests/monorepo/subdir-in-tar/test.py +++ b/testsuite/tests/monorepo/subdir-in-tar/test.py @@ -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 diff --git a/testsuite/tests/publish/tarball-plaindir-nonstd/test.py b/testsuite/tests/publish/tarball-plaindir-nonstd/test.py index b6730ec51..0b54ebc52 100644 --- a/testsuite/tests/publish/tarball-plaindir-nonstd/test.py +++ b/testsuite/tests/publish/tarball-plaindir-nonstd/test.py @@ -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() diff --git a/testsuite/tests/publish/tarball-plaindir/test.py b/testsuite/tests/publish/tarball-plaindir/test.py index 4716e1028..a3b910d33 100644 --- a/testsuite/tests/publish/tarball-plaindir/test.py +++ b/testsuite/tests/publish/tarball-plaindir/test.py @@ -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(), \