From 2753a7c9696f49ea6568244526b4b0065f4b797e Mon Sep 17 00:00:00 2001 From: Alejandro R Mosteo Date: Wed, 27 Sep 2023 16:46:09 +0200 Subject: [PATCH] Comprehensive shared builds tests and related tweaks (#1459) * Added `shared-build` driver * Added `build_mode` key to the Python driver * Fix config generation in `alr update` in shared mode * Remove need for compiler in absence of dependencies * Fixed monorepo tests and base dir * Delay config generation in sandboxed mode too * Include explicit switches in build hash inputs This is necessary because for shared builds we're never regenerating the configuration, so changes in switches went undetected * Require complete config for sandboxed build * Self-review * Update new tests --- src/alire/alire-builds-hashes.adb | 34 ++++- src/alire/alire-builds.adb | 26 +++- src/alire/alire-builds.ads | 7 +- src/alire/alire-crate_configuration.adb | 22 ++++ src/alire/alire-crate_configuration.ads | 8 ++ .../alire-properties-actions-executor.adb | 3 +- src/alire/alire-roots.adb | 93 +++++++------ src/alire/alire-roots.ads | 14 ++ src/alr/alr-commands-action.adb | 4 + testsuite/README.md | 7 + testsuite/drivers/builds.py | 18 +++ testsuite/drivers/driver/python_script.py | 122 ++++++++++++++++-- .../gnat_external/gnat_external-external.toml | 12 ++ .../he/hello/hello-1.0.0.toml | 16 +++ .../he/hello/hello-1.0.1.toml | 29 +++++ .../basic_no_compiler_index/index.toml | 1 + .../li/libhello/libhello-1.0.0.toml | 23 ++++ .../ma/make/make-external.toml | 8 ++ .../gnat_external/gnat_external-external.toml | 12 ++ .../fixtures/compiler_only_index/index.toml | 1 + .../gnat_external/gnat_external-external.toml | 12 ++ testsuite/run.py | 10 +- testsuite/skels/global-index/test.yaml | 4 +- testsuite/skels/local-index/test.yaml | 4 + testsuite/skels/no-index/test.yaml | 6 + testsuite/tests/action/trigger/test.yaml | 1 + testsuite/tests/alias/basic/test.yaml | 1 + .../tests/build/hashes/compiler-input/test.py | 3 - .../build/hashes/compiler-input/test.yaml | 1 + .../build/hashes/compiler-missing/test.py | 10 +- .../build/hashes/compiler-missing/test.yaml | 4 +- .../tests/build/hashes/config-types/test.py | 3 +- .../tests/build/hashes/config-types/test.yaml | 1 + .../tests/build/hashes/hashing-inputs/test.py | 17 ++- .../build/hashes/hashing-inputs/test.yaml | 1 + .../build/hashes/incomplete-config/test.py | 9 +- .../build/hashes/incomplete-config/test.yaml | 1 + .../build_profile/alr_build_switches/test.py | 10 +- .../alr_build_switches/test.yaml | 2 + .../build_profile/custom_profiles/test.yaml | 2 + .../build_profile/custom_switches/test.yaml | 2 + .../tests/build_profile/default/test.yaml | 2 + .../build_profile/get-build-profile/test.yaml | 1 + .../tests/build_profile/recursive/test.py | 3 + .../tests/build_profile/recursive/test.yaml | 2 + .../config/missing-config-default/test.py | 17 +-- .../config/missing-config-default/test.yaml | 1 + testsuite/tests/config/shared-deps/test.py | 3 - testsuite/tests/config/shared-deps/test.yaml | 1 + testsuite/tests/crate_config/basic/test.yaml | 1 + .../tests/crate_config/gen_control/test.yaml | 1 + .../tests/crate_config/value_conflict/test.py | 2 +- .../dockerized/misc/default-cache/test.py | 5 +- testsuite/tests/exec/basic/test.py | 13 +- testsuite/tests/exec/with_project/test.yaml | 1 + .../get/external-tool-dependency/test.py | 36 +++--- testsuite/tests/get/git-local/test.py | 6 - testsuite/tests/get/unpack-in-place/test.py | 6 - testsuite/tests/index/bad-config-vars/test.py | 8 +- .../tests/install/dynamic-linking/test.yaml | 2 + .../install/executable-dependency/test.yaml | 2 + .../tests/install/static-linking/test.yaml | 2 + testsuite/tests/misc/git-ungit/test.py | 11 +- testsuite/tests/misc/sync-manual-edit/test.py | 6 +- .../tests/misc/sync-manual-edit/test.yaml | 1 + .../tests/misc/sync-missing-deps/test.py | 3 +- .../tests/misc/sync-missing-deps/test.yaml | 1 + testsuite/tests/monorepo/basic/test.py | 14 +- testsuite/tests/monorepo/basic/test.yaml | 1 + .../tests/monorepo/doubly-nested/test.py | 11 +- .../tests/monorepo/doubly-nested/test.yaml | 1 + testsuite/tests/monorepo/multi-commit/test.py | 35 +++-- .../tests/monorepo/multi-commit/test.yaml | 1 + testsuite/tests/pin/downgrade/test.py | 17 ++- testsuite/tests/pin/downgrade/test.yaml | 1 + testsuite/tests/pin/equivalent/test.py | 2 +- testsuite/tests/pin/equivalent/test.yaml | 1 + testsuite/tests/pin/from-subdir/test.yaml | 2 + testsuite/tests/pin/post-update/test.yaml | 1 + testsuite/tests/pin/remote/test.yaml | 1 + testsuite/tests/pin/to-parent/test.yaml | 2 + testsuite/tests/printenv/basic/test.py | 17 ++- .../tests/printenv/env-during-fetch/test.py | 24 +++- .../tests/printenv/env-during-fetch/test.yaml | 1 + .../tests/printenv/linked-paths/test.yaml | 1 + .../tests/publish/check-properties/test.yaml | 1 + testsuite/tests/publish/pin-removal/test.yaml | 1 + .../publish/remote-origin-nonstd/test.py | 3 + testsuite/tests/publish/remote-origin/test.py | 3 + .../tests/solver/compiler-installed/test.py | 3 +- testsuite/tests/update/selective/test.yaml | 1 + .../with/auto-gpr-with/gpr_in_subdir/test.py | 5 + .../auto-gpr-with/gpr_in_subdir/test.yaml | 2 + testsuite/tests/with/changes-info/test.yaml | 4 +- testsuite/tests/with/equivalent/test.yaml | 1 + .../workflows/actions-as-dependency/test.py | 64 ++++----- .../workflows/actions-as-dependency/test.yaml | 2 + .../tests/workflows/actions-as-root/test.yaml | 1 + .../workflows/get-build-run-clean/test.yaml | 1 + 99 files changed, 711 insertions(+), 215 deletions(-) create mode 100644 testsuite/fixtures/basic_index/gn/gnat_external/gnat_external-external.toml create mode 100644 testsuite/fixtures/basic_no_compiler_index/he/hello/hello-1.0.0.toml create mode 100644 testsuite/fixtures/basic_no_compiler_index/he/hello/hello-1.0.1.toml create mode 100644 testsuite/fixtures/basic_no_compiler_index/index.toml create mode 100644 testsuite/fixtures/basic_no_compiler_index/li/libhello/libhello-1.0.0.toml create mode 100644 testsuite/fixtures/basic_no_compiler_index/ma/make/make-external.toml create mode 100644 testsuite/fixtures/compiler_only_index/gn/gnat_external/gnat_external-external.toml create mode 100644 testsuite/fixtures/compiler_only_index/index.toml create mode 100644 testsuite/fixtures/solver_index/gn/gnat_external/gnat_external-external.toml diff --git a/src/alire/alire-builds-hashes.adb b/src/alire/alire-builds-hashes.adb index 16692c29f..012f0f588 100644 --- a/src/alire/alire-builds-hashes.adb +++ b/src/alire/alire-builds-hashes.adb @@ -104,6 +104,27 @@ package body Alire.Builds.Hashes is Root.Configuration.Build_Profile (Rel.Name)'Image); end Add_Profile; + ------------------ + -- Add_Switches -- + ------------------ + + procedure Add_Switches is + -- List the exact switches used for compilation due to Alire, as + -- any changes in those will require regen of configuration files. + -- We add a single entry, alphabetically sorted. + Switches : AAA.Strings.Set; + Config : Crate_Configuration.Global_Config := + Root.Configuration.all; + begin + for Switch of Config.Build_Switches (Root, Rel.Name) + loop + Switches.Include (Switch); + end loop; + Add ("switches", + Rel.Name.As_String, + Switches.To_Vector.Flatten (",")); + end Add_Switches; + ------------------- -- Add_Externals -- ------------------- @@ -214,6 +235,7 @@ package body Alire.Builds.Hashes is -- Add individual contributors to the hash input Add_Profile; -- Build profile + Add_Switches; -- Exact list of build switches Add_Configuration; -- Crate configuration variables -- These are only relevant for shared dependencies, as they don't @@ -222,7 +244,17 @@ package body Alire.Builds.Hashes is if not Builds.Sandboxed_Dependencies then Add_Externals; -- GPR externals Add_Environment; -- Environment variables - Add_Compiler; -- Compiler version + + -- In the root crate we can skip compiler detection, as it has no + -- bearing on the hash or config regeneration. This allows most + -- operations in a crate without dependencies to succeed even in + -- absence of a configured compiler. Note that for linked crates, + -- even if they don't have a proper build dir, the hash is + -- important for dependents. + if not Root.Is_Root_Release (Rel.Name) then + Add_Compiler; -- Compiler version + end if; + Add_Dependencies; -- Hash of dependencies end if; diff --git a/src/alire/alire-builds.adb b/src/alire/alire-builds.adb index 73ddf0f4d..f632b95f1 100644 --- a/src/alire/alire-builds.adb +++ b/src/alire/alire-builds.adb @@ -30,7 +30,11 @@ package body Alire.Builds is is Src : constant Absolute_Path := Paths.Vault.Path / Release.Deployment_Folder; - Dst : constant Absolute_Path := Builds.Path (Root, Release); + Dst : constant Absolute_Path := Builds.Path (Root, + Release, + Subdir => False); + -- In case of monorepo, the first time the repo is deployed, it will be + -- synced in its entirety. Synced : Flags.Flag := Flags.Complete_Copy (Dst); begin Was_There := False; @@ -87,11 +91,21 @@ package body Alire.Builds is ---------- function Path (Root : in out Roots.Root; - Release : Releases.Release) + Release : Releases.Release; + Subdir : Boolean) return Absolute_Path - is (Builds.Path - / (Release.Deployment_Folder - & "_" - & Root.Build_Hash (Release.Name))); + is + Base : constant Absolute_Path := + Builds.Path + / (Release.Deployment_Folder + & "_" + & Root.Build_Hash (Release.Name)); + begin + if Subdir and then Release.Origin.Is_Monorepo then + return Base / Release.Origin.Subdir; + else + return Base; + end if; + end Path; end Alire.Builds; diff --git a/src/alire/alire-builds.ads b/src/alire/alire-builds.ads index 0735f6167..c84316812 100644 --- a/src/alire/alire-builds.ads +++ b/src/alire/alire-builds.ads @@ -39,8 +39,11 @@ package Alire.Builds is -- Location of shared builds function Path (Root : in out Roots.Root; - Release : Releases.Release) + Release : Releases.Release; + Subdir : Boolean) return Absolute_Path; - -- Computes the complete path in which the release is going to be built + -- Computes the complete path in which the release is going to be built. + -- If Subdir and Release is in monorepo, include the extra path inside the + -- monorepo. Has no effect for ordinary releases. end Alire.Builds; diff --git a/src/alire/alire-crate_configuration.adb b/src/alire/alire-crate_configuration.adb index ebcf24bf5..e96776531 100644 --- a/src/alire/alire-crate_configuration.adb +++ b/src/alire/alire-crate_configuration.adb @@ -40,6 +40,11 @@ package body Alire.Crate_Configuration is subtype Crate_Name_Set is Containers.Crate_Name_Sets.Set; + procedure Make_Switches_Map (This : in out Global_Config; + Root : in out Alire.Roots.Root; + Rel_Vect : Crate_Name_Set); + -- Prepare the list of switches that apply to a release + -- The Host info types below could be Enums instead of Strings. This would -- have the advantage of providing users the entire list of potential -- values. However, using enums in Ada would have a very high risk of @@ -89,6 +94,23 @@ package body Alire.Crate_Configuration is return Utils.Switches.Profile_Kind is (This.Profile_Map (Crate)); + -------------------- + -- Build_Switches -- + -------------------- + + function Build_Switches (This : in out Global_Config; + Root : in out Roots.Root; + Crate : Crate_Name) + return Utils.Switches.Switch_List + is + begin + -- Ensure they're up to date + Make_Switches_Map (This, Root, + Containers.Crate_Name_Sets.To_Set (Crate)); + + return This.Switches_Map (Crate); + end Build_Switches; + ----------------------- -- Build_Profile_Key -- ----------------------- diff --git a/src/alire/alire-crate_configuration.ads b/src/alire/alire-crate_configuration.ads index 2bc654614..e05b48e8e 100644 --- a/src/alire/alire-crate_configuration.ads +++ b/src/alire/alire-crate_configuration.ads @@ -46,6 +46,14 @@ package Alire.Crate_Configuration is return Utils.Switches.Profile_Kind with Pre => This.Is_Valid; + function Build_Switches (This : in out Global_Config; + Root : in out Roots.Root; + Crate : Crate_Name) + return Utils.Switches.Switch_List + with Pre => This.Is_Valid; + -- The exact switches that apply to a crate (the ones that will be written + -- to their config .gpr files) + function Is_Default_Profile (This : Global_Config; Crate : Crate_Name) return Boolean; diff --git a/src/alire/alire-properties-actions-executor.adb b/src/alire/alire-properties-actions-executor.adb index e6b56035b..6fc40d9e8 100644 --- a/src/alire/alire-properties-actions-executor.adb +++ b/src/alire/alire-properties-actions-executor.adb @@ -143,7 +143,8 @@ package body Alire.Properties.Actions.Executor is end if; for Act of Release.On_Platform_Actions (Env, Now) loop - Trace.Detail ("Running action: " & Act.Image); + Trace.Detail ("Running action: " & Act.Image + & " (cwd:" & Directories.Current & ")"); Execute_Run (This => Runners.Run (Act), Capture => Capture, Err_To_Out => Err_To_Out, diff --git a/src/alire/alire-roots.adb b/src/alire/alire-roots.adb index 2184c42da..c7a9b2d7d 100644 --- a/src/alire/alire-roots.adb +++ b/src/alire/alire-roots.adb @@ -33,6 +33,41 @@ package body Alire.Roots is use type UString; + ------------------- + -- Build_Prepare -- + ------------------- + + procedure Build_Prepare (This : in out Root; + Saved_Profiles : Boolean; + Force_Regen : Boolean) is + begin + -- Check whether we should override configuration with the last one used + -- and stored on disk. Since the first time the one from disk will be be + -- empty, we may still have to generate files in the next step. + + if Saved_Profiles then + This.Set_Build_Profiles (Crate_Configuration.Last_Build_Profiles); + end if; + + This.Load_Configuration; + This.Configuration.Ensure_Complete; + -- For proceeding to build, the configuration must be complete + + -- Ensure sources are up to date + + if not Builds.Sandboxed_Dependencies then + This.Sync_Builds; + -- Changes in configuration may require new build dirs. + end if; + + -- Ensure configurations are in place and up-to-date + + This.Generate_Configuration (Full => Force or else Force_Regen); + -- Will regenerate on demand only those changed. For shared + -- dependencies, will also generate any missing configs not generated + -- during sync, such as for linked releases and the root release. + end Build_Prepare; + ----------- -- Build -- ----------- @@ -182,31 +217,8 @@ package body Alire.Roots is begin - -- Check whether we should override configuration with the last one used - -- and stored on disk. Since the first time the one from disk will be be - -- empty, we may still have to generate files in the next step. - - if Saved_Profiles then - This.Set_Build_Profiles (Crate_Configuration.Last_Build_Profiles); - end if; - - This.Load_Configuration; - This.Configuration.Ensure_Complete; - -- For proceeding to build, the configuration must be complete - - -- Ensure sources are up to date - - if not Builds.Sandboxed_Dependencies then - This.Sync_Builds; - -- Changes in configuration may require new build dirs. - end if; - - -- Ensure configurations are in place and up-to-date - - This.Generate_Configuration (Full => Force); - -- Will regenerate on demand only those changed. For shared - -- dependencies, will also generate any missing configs not generated - -- during sync, such as for linked releases and the root release. + This.Build_Prepare (Saved_Profiles => Saved_Profiles, + Force_Regen => False); This.Export_Build_Environment; @@ -766,11 +778,10 @@ package body Alire.Roots is This.Solution.Print_Hints (This.Environment); - -- Update/Create configuration files - - if Builds.Sandboxed_Dependencies then - This.Generate_Configuration (Full => Force); - end if; + -- For sandboxed deps we could already generate config files, but for + -- shared builds we cannot yet until we are sure the configuration is + -- complete. To have the same behavior in both cases, we also delay + -- configuration generation to build time for sandboxed dependencies. -- Check that the solution does not contain suspicious dependencies, -- taking advantage that this procedure is called whenever a change @@ -1431,7 +1442,7 @@ package body Alire.Roots is return This.Release_Parent (Rel, For_Deploy) / Rel.Base_Folder; when For_Build => - return Builds.Path (This, Rel); + return Builds.Path (This, Rel, Subdir => True); end case; end if; end; @@ -1591,6 +1602,15 @@ package body Alire.Roots is return Boolean is (Dep.Has_Release and then Dep.Crate = This.Release.Reference.Name); + --------------------- + -- Is_Root_Release -- + --------------------- + + function Is_Root_Release (This : in out Root; + Name : Crate_Name) + return Boolean + is (This.Release.Reference.Name = Name); + ------------------------ -- Sync_From_Manifest -- ------------------------ @@ -1716,6 +1736,12 @@ package body Alire.Roots is begin This.Traverse (Removing_Post_Fetch_Flag'Access); end; + + -- Regenerate config files to avoid the unintuitive behavior that after + -- an update they may still not exist (or use old switches). + + This.Build_Prepare (Saved_Profiles => False, + Force_Regen => True); end Update; -------------------- @@ -1845,11 +1871,6 @@ package body Alire.Roots is This.Set (Solution => Needed); This.Deploy_Dependencies; - -- Update/Create configuration files - if Builds.Sandboxed_Dependencies then - This.Generate_Configuration (Full => True); - end if; - Trace.Detail ("Update completed"); end; end Update_Dependencies; diff --git a/src/alire/alire-roots.ads b/src/alire/alire-roots.ads index c55a5985e..57b3bc01c 100644 --- a/src/alire/alire-roots.ads +++ b/src/alire/alire-roots.ads @@ -179,6 +179,11 @@ package Alire.Roots is return Boolean; -- Say if a state during Traverse is the Root release itself + function Is_Root_Release (This : in out Root; + Name : Crate_Name) + return Boolean; + -- Say if the root release matches the given name + procedure Sync_From_Manifest (This : in out Root; Silent : Boolean; Interact : Boolean; @@ -278,6 +283,15 @@ package Alire.Roots is return String; -- Returns the build hash of a crate if the solution; computes on demand. + procedure Build_Prepare (This : in out Root; + Saved_Profiles : Boolean; + Force_Regen : Boolean); + -- Perform all preparations but the building step itself. This will require + -- complete configuration, and will leave all files on disk as if an actual + -- build were attempted. May optionally use saved profiles from the command + -- line (instead of manifests) and force full regeneration (for example, + -- during `alr update`) + function Config_Outdated (This : in out Root; Name : Crate_Name) return Boolean; diff --git a/src/alr/alr-commands-action.adb b/src/alr/alr-commands-action.adb index 7755d920c..fb62cef0b 100644 --- a/src/alr/alr-commands-action.adb +++ b/src/alr/alr-commands-action.adb @@ -160,6 +160,10 @@ package body Alr.Commands.Action is Reportaise_Wrong_Arguments ("Invalid action: " & Arg); end if; + -- Ensure that all directories are ready + Cmd.Root.Build_Prepare (Saved_Profiles => False, + Force_Regen => False); + Cmd.Root.Traverse (Doing => Run_One'Access); if not Some_Output then Put_Line ("No actions to run."); diff --git a/testsuite/README.md b/testsuite/README.md index 14c014001..5a212dbe0 100644 --- a/testsuite/README.md +++ b/testsuite/README.md @@ -34,3 +34,10 @@ $ pip install e3-testsuite # made it available with your PATH): $ ./run.py ``` + +# Creating tests +All tests are based on running a Python script. There are three test drivers: + +- `python-script`: run in host in both sandboxed and shared build mode. + - The build mode can be narrowed down with the `build_mode` attribute. +- `docker-wrapper`: run in a pristine docker Ubuntu image in shared build mode. diff --git a/testsuite/drivers/builds.py b/testsuite/drivers/builds.py index d8479df71..9de84a282 100644 --- a/testsuite/drivers/builds.py +++ b/testsuite/drivers/builds.py @@ -16,6 +16,17 @@ def enable_shared() -> None: run_alr("config", "--global", "--set", "dependencies.shared", "true") +def are_shared() -> bool: + """ + Return True if shared builds are enabled + """ + try: + return run_alr("config", "--global", "--get", + "dependencies.shared").out.strip().lower() == "true" + except: + return False + + def clear_builds_dir() -> None: """ Clear the shared build directory @@ -56,6 +67,13 @@ def path() -> str: return alr_builds_dir() +def vault_path() -> str: + """ + Return the path to the read-only release vault. + """ + return os.path.join(path(), "..", "releases") + + def sync() -> None: """ Sync the shared build directory diff --git a/testsuite/drivers/driver/python_script.py b/testsuite/drivers/driver/python_script.py index 29fc90e57..4e86be460 100644 --- a/testsuite/drivers/driver/python_script.py +++ b/testsuite/drivers/driver/python_script.py @@ -1,7 +1,9 @@ +import copy import os +import shutil import sys -from drivers.alr import prepare_env, prepare_indexes +from drivers.alr import prepare_env, prepare_indexes, run_alr from e3.testsuite.driver.classic import (ClassicTestDriver, TestAbortWithFailure, TestSkip) @@ -14,7 +16,8 @@ class PythonScriptDriver(ClassicTestDriver): This test driver runs a Python script. For a testcase to succeeds, the script expects it to exit with status code 0, its standard error stream to be empty and its standard output stream to end with a line that contains - "SUCCESS". Anything else results in the test failing. + "SUCCESS". If a test must be skipped, it should print "SKIP: ". + Anything else results in the test failing. """ # This is a workaround for Windows, where attempting to use rlimit by e3-core @@ -23,10 +26,11 @@ class PythonScriptDriver(ClassicTestDriver): def default_process_timeout(self): return None - def run(self): + def prepare(self) -> dict: + # prepare a private environment for Python scripts to run "alr". + env = dict(os.environ) - # prepare a private environment for Python scripts to run "alr". config_dir = os.path.join(self.test_env['working_dir'], 'alr-config') prepare_env(config_dir, env) @@ -45,13 +49,19 @@ def run(self): path_for_drivers, os.path.pathsep, python_path ) if python_path else path_for_drivers + return env + + + def run_script(self, env): # Run the Python script with the current interpreter. check_call aborts # the test if the interpreter exits with non-zero status code. - p = self.shell([sys.executable, 'test.py'], - env=env, - cwd=self.test_env['working_dir']) + return self.shell([sys.executable, 'test.py'], + env=env, + cwd=self.test_env['working_dir']) + - # Check that the last line in stdout is "SUCCESS" or "SKIP" + def check_result(self, p): + # Check that the test output is proper (no missing status) out_lines = p.out.splitlines() if out_lines and out_lines[-1] == 'SUCCESS': pass @@ -60,3 +70,99 @@ def run(self): else: self.result.log += 'missing SUCCESS output line' raise TestAbortWithFailure('missing SUCCESS output line') + + + def save_working_dir(self): + # Save the working directory state for later restoration. + + base = self.test_env['working_dir'] + orig_name = ".orig" + orig = os.path.join(base, orig_name) + + # Save the original files under ".orig" folder + os.mkdir(orig) + for f in os.listdir(base): + if f == orig_name: + continue + path = os.path.join(base, f) + if os.path.isfile(path): + shutil.copy(path, orig) + else: + shutil.copytree(path, os.path.join(orig, f)) + + + def restore_working_dir(self): + # Restore the working directory to its initial state, by deleting + # everything and copying originals back from .orig dir + + def make_writable(path): + # Make everything inside a directory writable recursively + for root, dirs, files in os.walk(path): + for d in dirs: + os.chmod(os.path.join(root, d), 0o777) + for f in files: + os.chmod(os.path.join(root, f), 0o666) + + base = self.test_env['working_dir'] + orig_name = ".orig" + + # Delete anything not called ".orig" + for f in os.listdir(base): + if f != orig_name: + path = os.path.join(base, f) + if os.path.isfile(path): + os.remove(path) + else: + # Git marks some files read-only, so make them writable + make_writable(path) + shutil.rmtree(path) + + # Restore the original files + orig = os.path.join(base, orig_name) + for f in os.listdir(orig): + path = os.path.join(orig, f) + if os.path.isfile(path): + shutil.copy(path, base) + else: + shutil.copytree(path, os.path.join(base, f)) + + + def run(self): + # Run the test itself. Depending on the build mode, it may be run + # twice. + DEFAULT_MODE = "both" + + pristine_env = self.prepare() + + # Obtain the build mode for the test + mode = self.test_env.get('build_mode', + self.test_env.get('build-mode', + DEFAULT_MODE)) + # One of 'shared', 'sandboxed', or 'both' + + # If mode is "both", track original files for later + if mode == "both": + self.save_working_dir() + + # First run with shared builds disabled + + if mode in ["sandboxed", "both"]: + self.result.log.log += "Build mode: SANDBOXED\n" + p = self.run_script(copy.deepcopy(pristine_env)) + self.check_result(p) + + # Second run with shared builds enabled + + # Start by cleaning up anything the 1st run may have left behind + if mode == "both": + self.restore_working_dir() + + if mode in ["shared", "both"]: + self.result.log.log += "Build mode: SHARED\n" + # Activate shared builds. Using "-c" is needed as the environment + # still isn't activated at the driver script level. + run_alr("-c", pristine_env["ALR_CONFIG"], + "config", "--global", "--set", + "dependencies.shared", "true") + p = self.run_script(copy.deepcopy(pristine_env)) + self.check_result(p) diff --git a/testsuite/fixtures/basic_index/gn/gnat_external/gnat_external-external.toml b/testsuite/fixtures/basic_index/gn/gnat_external/gnat_external-external.toml new file mode 100644 index 000000000..f1171a6ba --- /dev/null +++ b/testsuite/fixtures/basic_index/gn/gnat_external/gnat_external-external.toml @@ -0,0 +1,12 @@ +description = "GNAT is a compiler for the Ada programming language" +name = "gnat_external" + +maintainers = ["alejandro@mosteo.com"] +maintainers-logins = ["mosteo"] + +[[external]] +kind = "version-output" +# We look for make instead that should be always installed. +version-command = ["make", "--version"] +version-regexp = ".*Make ([\\d\\.]+).*" +provides = "gnat" diff --git a/testsuite/fixtures/basic_no_compiler_index/he/hello/hello-1.0.0.toml b/testsuite/fixtures/basic_no_compiler_index/he/hello/hello-1.0.0.toml new file mode 100644 index 000000000..bf47cfcae --- /dev/null +++ b/testsuite/fixtures/basic_no_compiler_index/he/hello/hello-1.0.0.toml @@ -0,0 +1,16 @@ +description = "\"Hello, world!\" demonstration project" +long-description = "This is an example of long description in a multi-line string.\n\nMarkdown formating `can` be used to have \"nice\" display on the website.\n" +name = "hello" +version = "1.0.0" +website = "example.com" +authors = ["Bob", "Alice"] +licenses = "GPL-3.0-only OR MIT" +maintainers = ["alejandro@mosteo.com", "bob@example.com"] +maintainers-logins = ["mylogin"] +tags = ["tag1", "other-tag"] + +[[depends-on]] +libhello = "^1.0" + +[origin] +url = "file:../../../crates/hello_1.0.0" diff --git a/testsuite/fixtures/basic_no_compiler_index/he/hello/hello-1.0.1.toml b/testsuite/fixtures/basic_no_compiler_index/he/hello/hello-1.0.1.toml new file mode 100644 index 000000000..e67e218c6 --- /dev/null +++ b/testsuite/fixtures/basic_no_compiler_index/he/hello/hello-1.0.1.toml @@ -0,0 +1,29 @@ +description = "\"Hello, world!\" demonstration project" +long-description = "This is an example of long description in a multi-line string.\n\nMarkdown formating `can` be used to have \"nice\" display on the website.\n" +name = "hello" +version = "1.0.1" +website = "example.com" +authors = ["Bob", "Alice"] +licenses = "GPL-3.0-only OR MIT" +maintainers = ["alejandro@mosteo.com", "bob@example.com"] +maintainers-logins = ["mylogin"] +tags = ["tag1", "other-tag"] + +[[depends-on]] +libhello = "^1.0" + +[configuration.variables] +Var1={type="Boolean"} +Var2={type="String", default="str"} +Var3={type="Enum", values=["A", "B"], default="A"} +Var4={type="Integer", default=0} +Var5={type="Integer", first=-1, last=1, default=0} +Var7={type="Real", default=0.0} +Var6={type="Real", first=-1.0, last=1.0, default=0.0} + +[configuration.values] +hello.Var1=true # So far it is possible for a crate to set its own var +libhello.Var1=false + +[origin] +url = "file:../../../crates/hello_1.0.1" diff --git a/testsuite/fixtures/basic_no_compiler_index/index.toml b/testsuite/fixtures/basic_no_compiler_index/index.toml new file mode 100644 index 000000000..bad265e4f --- /dev/null +++ b/testsuite/fixtures/basic_no_compiler_index/index.toml @@ -0,0 +1 @@ +version = "1.1" diff --git a/testsuite/fixtures/basic_no_compiler_index/li/libhello/libhello-1.0.0.toml b/testsuite/fixtures/basic_no_compiler_index/li/libhello/libhello-1.0.0.toml new file mode 100644 index 000000000..c46f09fab --- /dev/null +++ b/testsuite/fixtures/basic_no_compiler_index/li/libhello/libhello-1.0.0.toml @@ -0,0 +1,23 @@ +description = "\"Hello, world!\" demonstration project support library" +name = "libhello" +version = "1.0.0" +maintainers = ["alejandro@mosteo.com"] +maintainers-logins = ["mylogin"] +tags = ["libhello-tag1"] + +[configuration.variables] +Var1={type="Boolean", default=true} + +[gpr-externals] +TEST_GPR_EXTERNAL = ["gpr_ext_A", "gpr_ext_B", "gpr_ext_C"] +TEST_FREEFORM_UNSET = "" # to test build hashing with an unset var + +[gpr-set-externals] +TEST_GPR_EXTERNAL = "gpr_ext_B" +TEST_UNDECLARED = "used_by_another_crate" + +[environment] +TEST_ENV.set = "myenv" + +[origin] +url = "file:../../../crates/libhello_1.0.0" diff --git a/testsuite/fixtures/basic_no_compiler_index/ma/make/make-external.toml b/testsuite/fixtures/basic_no_compiler_index/ma/make/make-external.toml new file mode 100644 index 000000000..eaf4b23eb --- /dev/null +++ b/testsuite/fixtures/basic_no_compiler_index/ma/make/make-external.toml @@ -0,0 +1,8 @@ +description = "Utility for directing compilation" +name = "make" +maintainers = ["alejandro@mosteo.com"] +maintainers-logins = ["mylogin"] + +[[external]] +kind = "system" +origin = [] # Empty on purpose to ensure unavailable in tests diff --git a/testsuite/fixtures/compiler_only_index/gn/gnat_external/gnat_external-external.toml b/testsuite/fixtures/compiler_only_index/gn/gnat_external/gnat_external-external.toml new file mode 100644 index 000000000..f1171a6ba --- /dev/null +++ b/testsuite/fixtures/compiler_only_index/gn/gnat_external/gnat_external-external.toml @@ -0,0 +1,12 @@ +description = "GNAT is a compiler for the Ada programming language" +name = "gnat_external" + +maintainers = ["alejandro@mosteo.com"] +maintainers-logins = ["mosteo"] + +[[external]] +kind = "version-output" +# We look for make instead that should be always installed. +version-command = ["make", "--version"] +version-regexp = ".*Make ([\\d\\.]+).*" +provides = "gnat" diff --git a/testsuite/fixtures/compiler_only_index/index.toml b/testsuite/fixtures/compiler_only_index/index.toml new file mode 100644 index 000000000..bad265e4f --- /dev/null +++ b/testsuite/fixtures/compiler_only_index/index.toml @@ -0,0 +1 @@ +version = "1.1" diff --git a/testsuite/fixtures/solver_index/gn/gnat_external/gnat_external-external.toml b/testsuite/fixtures/solver_index/gn/gnat_external/gnat_external-external.toml new file mode 100644 index 000000000..f1171a6ba --- /dev/null +++ b/testsuite/fixtures/solver_index/gn/gnat_external/gnat_external-external.toml @@ -0,0 +1,12 @@ +description = "GNAT is a compiler for the Ada programming language" +name = "gnat_external" + +maintainers = ["alejandro@mosteo.com"] +maintainers-logins = ["mosteo"] + +[[external]] +kind = "version-output" +# We look for make instead that should be always installed. +version-command = ["make", "--version"] +version-regexp = ".*Make ([\\d\\.]+).*" +provides = "gnat" diff --git a/testsuite/run.py b/testsuite/run.py index 43843648e..8254dbbad 100755 --- a/testsuite/run.py +++ b/testsuite/run.py @@ -9,17 +9,15 @@ from __future__ import absolute_import, print_function -from argparse import ArgumentTypeError -import sys import os.path +import sys +from argparse import ArgumentTypeError import e3.testsuite import e3.testsuite.driver -from e3.testsuite.result import TestStatus - -from drivers.helpers import on_windows -from drivers.driver.python_script import PythonScriptDriver from drivers.driver.docker_wrapper import DockerWrapperDriver +from drivers.driver.python_script import PythonScriptDriver +from drivers.helpers import on_windows class Testsuite(e3.testsuite.Testsuite): diff --git a/testsuite/skels/global-index/test.yaml b/testsuite/skels/global-index/test.yaml index 872fc1274..1a71b1b05 100644 --- a/testsuite/skels/global-index/test.yaml +++ b/testsuite/skels/global-index/test.yaml @@ -1,3 +1,5 @@ driver: python-script +build_mode: both # one of shared, sandboxed, both (default) indexes: - basic_index: {} + basic_index: + in_fixtures: true diff --git a/testsuite/skels/local-index/test.yaml b/testsuite/skels/local-index/test.yaml index 0a859639c..a0ce9ba5e 100644 --- a/testsuite/skels/local-index/test.yaml +++ b/testsuite/skels/local-index/test.yaml @@ -1,4 +1,8 @@ driver: python-script +build_mode: both # one of shared, sandboxed, both (default) indexes: my_index: in_fixtures: false +# Note that shared builds require a detected compiler to be able to compute +# build hashes, which is needed for many subcommands: build, get, printenv, +# update... See compiler_only_index for an example of mock compiler detector. diff --git a/testsuite/skels/no-index/test.yaml b/testsuite/skels/no-index/test.yaml index 32c747b3f..45e528c23 100644 --- a/testsuite/skels/no-index/test.yaml +++ b/testsuite/skels/no-index/test.yaml @@ -1 +1,7 @@ driver: python-script +build_mode: both # one of shared, sandboxed, both (default) +indexes: + compiler_only_index: {} + # Note that shared builds require a detected compiler to be able to compute + # build hashes, which is needed for many subcommands: build, get, printenv, + # update... \ No newline at end of file diff --git a/testsuite/tests/action/trigger/test.yaml b/testsuite/tests/action/trigger/test.yaml index 0a859639c..d6aa8a36d 100644 --- a/testsuite/tests/action/trigger/test.yaml +++ b/testsuite/tests/action/trigger/test.yaml @@ -2,3 +2,4 @@ driver: python-script indexes: my_index: in_fixtures: false + compiler_only_index: {} diff --git a/testsuite/tests/alias/basic/test.yaml b/testsuite/tests/alias/basic/test.yaml index 872fc1274..e2c5af220 100644 --- a/testsuite/tests/alias/basic/test.yaml +++ b/testsuite/tests/alias/basic/test.yaml @@ -1,3 +1,4 @@ driver: python-script indexes: basic_index: {} + compiler_only_index: {} diff --git a/testsuite/tests/build/hashes/compiler-input/test.py b/testsuite/tests/build/hashes/compiler-input/test.py index 377bd9ae9..14a7f4c9a 100644 --- a/testsuite/tests/build/hashes/compiler-input/test.py +++ b/testsuite/tests/build/hashes/compiler-input/test.py @@ -23,9 +23,6 @@ def check_hash(signature: str) -> None: # Disable compiler selection, so the external is used run_alr("toolchain", "--disable-assistant") -# Enable shared dependencies -run_alr("config", "--set", "--global", "dependencies.shared", "true") - # Init a crate without explicit compiler dependency init_local_crate("xxx") alr_with("crate_real") # A regular crate in the index diff --git a/testsuite/tests/build/hashes/compiler-input/test.yaml b/testsuite/tests/build/hashes/compiler-input/test.yaml index 8185c03b5..80973aefa 100644 --- a/testsuite/tests/build/hashes/compiler-input/test.yaml +++ b/testsuite/tests/build/hashes/compiler-input/test.yaml @@ -1,4 +1,5 @@ driver: python-script +build_mode: shared indexes: toolchain_index: in_fixtures: true diff --git a/testsuite/tests/build/hashes/compiler-missing/test.py b/testsuite/tests/build/hashes/compiler-missing/test.py index 55e943291..13b372fe1 100644 --- a/testsuite/tests/build/hashes/compiler-missing/test.py +++ b/testsuite/tests/build/hashes/compiler-missing/test.py @@ -9,14 +9,18 @@ # The index in this test has no compilers configured; hence we cannot locate # even the default external compiler. -run_alr("config", "--set", "--global", "dependencies.shared", "true") - # Init a crate without explicit compiler dependency # This does not fail because hashes are not computed until build time init_local_crate("xxx") + +# A standalone crate can be built because the compiler isn't used for the root +# crate hash inputs +run_alr("build") + +# Adding a dependency works because this doen't yet trigger an update/build run_alr("with", "libhello") -# The build fails because we cannot compute the build hash without a compiler +# The build fails because we cannot compute the dependency hash without a compiler p = run_alr("build", complain_on_error=False) assert_match(".*Unable to determine compiler version", p.out) diff --git a/testsuite/tests/build/hashes/compiler-missing/test.yaml b/testsuite/tests/build/hashes/compiler-missing/test.yaml index 8929d590a..42e4f842f 100644 --- a/testsuite/tests/build/hashes/compiler-missing/test.yaml +++ b/testsuite/tests/build/hashes/compiler-missing/test.yaml @@ -1,4 +1,4 @@ driver: python-script +build_mode: shared indexes: - basic_index: - in_fixtures: true + basic_no_compiler_index: {} diff --git a/testsuite/tests/build/hashes/config-types/test.py b/testsuite/tests/build/hashes/config-types/test.py index 2df2bb4ff..45a044dae 100644 --- a/testsuite/tests/build/hashes/config-types/test.py +++ b/testsuite/tests/build/hashes/config-types/test.py @@ -7,8 +7,6 @@ from drivers.asserts import assert_eq from drivers import builds -run_alr("config", "--set", "--global", "dependencies.shared", "true") - init_local_crate() alr_with("hello=1.0.1") builds.sync() @@ -27,6 +25,7 @@ 'external:HELLO_LIBRARY_TYPE=default\n' 'external:LIBRARY_TYPE=default\n' 'profile:hello=RELEASE\n' + 'switches:hello=-O3,-fdata-sections,-ffunction-sections,-gnatW8,-gnatn\n' f'version:gnat_external={external_compiler_version()}\n', hash_input("hello")) diff --git a/testsuite/tests/build/hashes/config-types/test.yaml b/testsuite/tests/build/hashes/config-types/test.yaml index 8e25447d9..90efa1f5a 100644 --- a/testsuite/tests/build/hashes/config-types/test.yaml +++ b/testsuite/tests/build/hashes/config-types/test.yaml @@ -1,3 +1,4 @@ driver: python-script +build_mode: shared indexes: build_hash_index: {} diff --git a/testsuite/tests/build/hashes/hashing-inputs/test.py b/testsuite/tests/build/hashes/hashing-inputs/test.py index d56eb55fc..22006a6d7 100644 --- a/testsuite/tests/build/hashes/hashing-inputs/test.py +++ b/testsuite/tests/build/hashes/hashing-inputs/test.py @@ -11,7 +11,6 @@ from drivers import builds from drivers.helpers import content_of -run_alr("config", "--set", "--global", "dependencies.shared", "true") init_local_crate() alr_with("hello") @@ -45,6 +44,11 @@ 'external:TEST_GPR_EXTERNAL=gpr_ext_B\n' # declared set GPR external 'external:TEST_UNDECLARED=used_by_another_crate\n' # modified GPR external 'profile:libhello=VALIDATION\n' # build profile + 'switches:libhello=-O3,-fdata-sections,-ffunction-sections,-g,-gnatVa,' + '-gnatW8,-gnata,-gnatn,-gnato,-gnatw.X,-gnatwa,-gnatwe,-gnaty-d,-gnaty3,' + '-gnatyA,-gnatyB,-gnatyI,-gnatyO,-gnatyS,-gnatya,-gnatyb,-gnatyc,-gnatye,' + '-gnatyf,-gnatyh,-gnatyi,-gnatyk,-gnatyl,-gnatym,-gnatyn,-gnatyp,-gnatyr,' + '-gnatyt,-gnatyu,-gnatyx\n' f'version:gnat_external={external_compiler_version()}\n', # compiler version hash_input("libhello")) @@ -63,6 +67,11 @@ 'external:HELLO_LIBRARY_TYPE=default\n' 'external:LIBRARY_TYPE=default\n' 'profile:hello=VALIDATION\n' + 'switches:hello=-O3,-fdata-sections,-ffunction-sections,-g,-gnatVa,' + '-gnatW8,-gnata,-gnatn,-gnato,-gnatw.X,-gnatwa,-gnatwe,-gnaty-d,-gnaty3,' + '-gnatyA,-gnatyB,-gnatyI,-gnatyO,-gnatyS,-gnatya,-gnatyb,-gnatyc,-gnatye,' + '-gnatyf,-gnatyh,-gnatyi,-gnatyk,-gnatyl,-gnatym,-gnatyn,-gnatyp,-gnatyr,' + '-gnatyt,-gnatyu,-gnatyx\n' f'version:gnat_external={external_compiler_version()}\n', hash_input("hello")) @@ -74,7 +83,11 @@ 'external:LIBRARY_TYPE=default\n' 'external:XXX_LIBRARY_TYPE=default\n' 'profile:xxx=VALIDATION\n' - f'version:gnat_external={external_compiler_version()}\n', + 'switches:xxx=-O3,-fdata-sections,-ffunction-sections,-g,-gnatVa,' + '-gnatW8,-gnata,-gnatn,-gnato,-gnatw.X,-gnatwa,-gnatwe,-gnaty-d,-gnaty3,' + '-gnatyA,-gnatyB,-gnatyI,-gnatyO,-gnatyS,-gnatya,-gnatyb,-gnatyc,-gnatye,' + '-gnatyf,-gnatyh,-gnatyi,-gnatyk,-gnatyl,-gnatym,-gnatyn,-gnatyp,-gnatyr,' + '-gnatyt,-gnatyu,-gnatyx\n', content_of(os.path.join("alire", "build_hash_inputs")) ) diff --git a/testsuite/tests/build/hashes/hashing-inputs/test.yaml b/testsuite/tests/build/hashes/hashing-inputs/test.yaml index 8e25447d9..90efa1f5a 100644 --- a/testsuite/tests/build/hashes/hashing-inputs/test.yaml +++ b/testsuite/tests/build/hashes/hashing-inputs/test.yaml @@ -1,3 +1,4 @@ driver: python-script +build_mode: shared indexes: build_hash_index: {} diff --git a/testsuite/tests/build/hashes/incomplete-config/test.py b/testsuite/tests/build/hashes/incomplete-config/test.py index c649ea5a9..430de6684 100644 --- a/testsuite/tests/build/hashes/incomplete-config/test.py +++ b/testsuite/tests/build/hashes/incomplete-config/test.py @@ -3,13 +3,8 @@ built/hashed """ -import shutil -from drivers.alr import alr_with, external_compiler_version, init_local_crate, run_alr -from drivers.builds import find_hash, hash_input -from drivers.asserts import assert_eq, assert_match -from drivers import builds - -run_alr("config", "--set", "--global", "dependencies.shared", "true") +from drivers.alr import alr_with, init_local_crate, run_alr +from drivers.builds import hash_input init_local_crate() alr_with("libhello=0.9") diff --git a/testsuite/tests/build/hashes/incomplete-config/test.yaml b/testsuite/tests/build/hashes/incomplete-config/test.yaml index 8e25447d9..90efa1f5a 100644 --- a/testsuite/tests/build/hashes/incomplete-config/test.yaml +++ b/testsuite/tests/build/hashes/incomplete-config/test.yaml @@ -1,3 +1,4 @@ driver: python-script +build_mode: shared indexes: build_hash_index: {} diff --git a/testsuite/tests/build_profile/alr_build_switches/test.py b/testsuite/tests/build_profile/alr_build_switches/test.py index b97b559c6..8b6ec7a29 100644 --- a/testsuite/tests/build_profile/alr_build_switches/test.py +++ b/testsuite/tests/build_profile/alr_build_switches/test.py @@ -71,13 +71,13 @@ def check_config_not_changed(): check_config_changed() check_config(bin_config, 'release') -# Alr with will re-generate the crate config and default to DEVELOPMENT +# Alr with does not touch config, that happens at build time alr_with('lib_1', path='../lib_1') -check_config_changed() -check_config(bin_config, 'development') +check_config_not_changed() -# Build with default profile, the config should not change +# Build with default profile, the config should change and revert to development run_alr('build') -check_config_not_changed() +check_config_changed() +check_config(bin_config, 'development') print('SUCCESS') diff --git a/testsuite/tests/build_profile/alr_build_switches/test.yaml b/testsuite/tests/build_profile/alr_build_switches/test.yaml index 32c747b3f..fa855459b 100644 --- a/testsuite/tests/build_profile/alr_build_switches/test.yaml +++ b/testsuite/tests/build_profile/alr_build_switches/test.yaml @@ -1 +1,3 @@ driver: python-script +indexes: + compiler_only_index: {} diff --git a/testsuite/tests/build_profile/custom_profiles/test.yaml b/testsuite/tests/build_profile/custom_profiles/test.yaml index 32c747b3f..fa855459b 100644 --- a/testsuite/tests/build_profile/custom_profiles/test.yaml +++ b/testsuite/tests/build_profile/custom_profiles/test.yaml @@ -1 +1,3 @@ driver: python-script +indexes: + compiler_only_index: {} diff --git a/testsuite/tests/build_profile/custom_switches/test.yaml b/testsuite/tests/build_profile/custom_switches/test.yaml index 32c747b3f..fa855459b 100644 --- a/testsuite/tests/build_profile/custom_switches/test.yaml +++ b/testsuite/tests/build_profile/custom_switches/test.yaml @@ -1 +1,3 @@ driver: python-script +indexes: + compiler_only_index: {} diff --git a/testsuite/tests/build_profile/default/test.yaml b/testsuite/tests/build_profile/default/test.yaml index 32c747b3f..fa855459b 100644 --- a/testsuite/tests/build_profile/default/test.yaml +++ b/testsuite/tests/build_profile/default/test.yaml @@ -1 +1,3 @@ driver: python-script +indexes: + compiler_only_index: {} diff --git a/testsuite/tests/build_profile/get-build-profile/test.yaml b/testsuite/tests/build_profile/get-build-profile/test.yaml index 872fc1274..a1bd56a2e 100644 --- a/testsuite/tests/build_profile/get-build-profile/test.yaml +++ b/testsuite/tests/build_profile/get-build-profile/test.yaml @@ -1,3 +1,4 @@ driver: python-script indexes: basic_index: {} + compiler_only_index: {} \ No newline at end of file diff --git a/testsuite/tests/build_profile/recursive/test.py b/testsuite/tests/build_profile/recursive/test.py index f0c314d53..3f6448850 100644 --- a/testsuite/tests/build_profile/recursive/test.py +++ b/testsuite/tests/build_profile/recursive/test.py @@ -2,11 +2,14 @@ Check build --profiles switch """ +from drivers import builds from drivers.alr import run_alr, init_local_crate, alr_pin, alr_manifest from drivers.helpers import lines_of, content_of import os +from drivers.asserts import assert_contents, assert_match + def check_profile(profile: str, file: str): line = f' Build_Profile : Build_Profile_Kind := "{profile}";\n' diff --git a/testsuite/tests/build_profile/recursive/test.yaml b/testsuite/tests/build_profile/recursive/test.yaml index 32c747b3f..7654732d6 100644 --- a/testsuite/tests/build_profile/recursive/test.yaml +++ b/testsuite/tests/build_profile/recursive/test.yaml @@ -1 +1,3 @@ driver: python-script +indexes: + compiler_only_index: {} \ No newline at end of file diff --git a/testsuite/tests/config/missing-config-default/test.py b/testsuite/tests/config/missing-config-default/test.py index b334cd5d8..554bcf8a3 100644 --- a/testsuite/tests/config/missing-config-default/test.py +++ b/testsuite/tests/config/missing-config-default/test.py @@ -30,9 +30,12 @@ assert_match('.*Configuration variables without a default remain unset\n', p.out) -# Get without build must succeed with the missing values as warnings +# Get without build succeeds as no config is needed yet p = run_alr("get", "hello=1.0.0", quiet=False) +# Building must fail and complaint about missing variables +os.chdir(glob("hello_1.0.0_*")[0]) +p = run_alr("build", complain_on_error=False, quiet=False) assert_match('.*Configuration variable \'hello.var1\' not set and has no default value.\n' '.*Configuration variable \'hello.var2\' not set and has no default value.\n' '.*Configuration variable \'hello.var3\' not set and has no default value.\n' @@ -43,17 +46,7 @@ '.*Configuration variable \'libhello.var3\' not set and has no default value.\n' '.*Configuration variable \'libhello.var4\' not set and has no default value.\n' '.*Configuration variable \'libhello.var5\' not set and has no default value.\n' - '.*Skipping generation of incomplete configuration files for crate hello\n' - '.*Skipping generation of incomplete configuration files for crate libhello\n' - '\n' - 'hello=1.0.0 successfully retrieved.', - p.out) - -# Attempting to build now should fail -os.chdir(glob("hello_1.0.0_*")[0]) -p = run_alr("build", complain_on_error=False) -assert p.status != 0, "Build should have failed" -assert_match('.*Configuration variables without a default remain unset\n', + '.*Configuration variables without a default remain unset\n', p.out) # Verify that providing the values in the manifest allows the build to work diff --git a/testsuite/tests/config/missing-config-default/test.yaml b/testsuite/tests/config/missing-config-default/test.yaml index 0a859639c..d6aa8a36d 100644 --- a/testsuite/tests/config/missing-config-default/test.yaml +++ b/testsuite/tests/config/missing-config-default/test.yaml @@ -2,3 +2,4 @@ driver: python-script indexes: my_index: in_fixtures: false + compiler_only_index: {} diff --git a/testsuite/tests/config/shared-deps/test.py b/testsuite/tests/config/shared-deps/test.py index ed458638e..84291e547 100644 --- a/testsuite/tests/config/shared-deps/test.py +++ b/testsuite/tests/config/shared-deps/test.py @@ -19,9 +19,6 @@ def check_in(file : str, expected : str) -> bool: vault_dir = alr_vault_dir() build_dir = alr_builds_dir() -# Enable shared builds -run_alr("config", "--global", "--set", "dependencies.shared", "true") - # Create a crate with a dependency init_local_crate() alr_with("hello") diff --git a/testsuite/tests/config/shared-deps/test.yaml b/testsuite/tests/config/shared-deps/test.yaml index 8e25447d9..90efa1f5a 100644 --- a/testsuite/tests/config/shared-deps/test.yaml +++ b/testsuite/tests/config/shared-deps/test.yaml @@ -1,3 +1,4 @@ driver: python-script +build_mode: shared indexes: build_hash_index: {} diff --git a/testsuite/tests/crate_config/basic/test.yaml b/testsuite/tests/crate_config/basic/test.yaml index 0a859639c..d6aa8a36d 100644 --- a/testsuite/tests/crate_config/basic/test.yaml +++ b/testsuite/tests/crate_config/basic/test.yaml @@ -2,3 +2,4 @@ driver: python-script indexes: my_index: in_fixtures: false + compiler_only_index: {} diff --git a/testsuite/tests/crate_config/gen_control/test.yaml b/testsuite/tests/crate_config/gen_control/test.yaml index 0a859639c..d6aa8a36d 100644 --- a/testsuite/tests/crate_config/gen_control/test.yaml +++ b/testsuite/tests/crate_config/gen_control/test.yaml @@ -2,3 +2,4 @@ driver: python-script indexes: my_index: in_fixtures: false + compiler_only_index: {} diff --git a/testsuite/tests/crate_config/value_conflict/test.py b/testsuite/tests/crate_config/value_conflict/test.py index 69ad4cc11..b54bcadff 100644 --- a/testsuite/tests/crate_config/value_conflict/test.py +++ b/testsuite/tests/crate_config/value_conflict/test.py @@ -9,7 +9,7 @@ import os import platform -p = run_alr('get', 'hello_world', complain_on_error=False) +p = run_alr('get', '--build', 'hello_world', complain_on_error=False) assert p.status != 0, "alr should have errored" print(p.out) diff --git a/testsuite/tests/dockerized/misc/default-cache/test.py b/testsuite/tests/dockerized/misc/default-cache/test.py index b97356f0d..f8afc0222 100644 --- a/testsuite/tests/dockerized/misc/default-cache/test.py +++ b/testsuite/tests/dockerized/misc/default-cache/test.py @@ -5,6 +5,7 @@ import os +from drivers import builds from drivers.alr import alr_with, init_local_crate, run_alr from drivers.helpers import contents @@ -26,7 +27,7 @@ # First, prevent an attempt at downloading a real compiler run_alr("toolchain", "--disable-assistant") -run_alr("config", "--global", "--set", "dependencies.shared", "true") +builds.enable_shared() # Enabled here as we are using the Docker driver alr_with("crate_real") # This release will go in the cache # Read-only vault @@ -43,7 +44,7 @@ # We hardcode this hash so we detect unwilling changes to our hashing scheme. # Every time this hash changes we must know the reason (changes in the hashing # procedures) -hash = "cc2adb8312e543d98d36736d6220023a47a4508f547109334ee36916280e73ac" +hash = "0774083df8ff003084c32cabdec6090a58b41c6be317cec0475df5eacbca0d23" assert \ os.path.isdir(f"{base}/builds/crate_real_1.0.0_filesystem_{hash}"), \ f"Shared build not found at the expected location: f{contents(base)}" diff --git a/testsuite/tests/exec/basic/test.py b/testsuite/tests/exec/basic/test.py index 0e5e1db73..a0eca167f 100644 --- a/testsuite/tests/exec/basic/test.py +++ b/testsuite/tests/exec/basic/test.py @@ -27,9 +27,16 @@ ' alire context:" ${GPR_PROJECT_PATH}', quiet=False) # -q will hide the output of the exec command -assert_match('.* GPR_PROJECT_PATH from alire context.*' - 'hello_[0-9\.]*_filesystem.*' - 'libhello_[0-9\.]*_filesystem.*', +# These may appear in both orders depending on the cache location +try: + assert_match('.* GPR_PROJECT_PATH from alire context.*' + 'hello_[0-9\.]*_filesystem.*' + 'libhello_[0-9\.]*_filesystem.*', + p.out, flags=re.S) +except: + assert_match('.* GPR_PROJECT_PATH from alire context.*' + 'libhello_[0-9\.]*_filesystem.*' + 'hello_[0-9\.]*_filesystem.*', p.out, flags=re.S) print('SUCCESS') diff --git a/testsuite/tests/exec/with_project/test.yaml b/testsuite/tests/exec/with_project/test.yaml index 872fc1274..e2c5af220 100644 --- a/testsuite/tests/exec/with_project/test.yaml +++ b/testsuite/tests/exec/with_project/test.yaml @@ -1,3 +1,4 @@ driver: python-script indexes: basic_index: {} + compiler_only_index: {} diff --git a/testsuite/tests/get/external-tool-dependency/test.py b/testsuite/tests/get/external-tool-dependency/test.py index 8ac1efb32..6509127bf 100644 --- a/testsuite/tests/get/external-tool-dependency/test.py +++ b/testsuite/tests/get/external-tool-dependency/test.py @@ -4,6 +4,7 @@ import re +from drivers import builds from drivers.alr import run_alr from drivers.asserts import assert_eq from drivers.helpers import compare, contents @@ -16,7 +17,7 @@ dir_content = contents('main_1.0.0_filesystem/') -# The directrory for the external dependencies 'make' contains a version number +# The directory for the external dependencies 'make' contains a version number # that can be different depending on the platform or version of the # distribution. We search through the content to find that directory and use it # in the expected output. @@ -25,28 +26,33 @@ if re.match('^.*/alire/cache/dependencies/make_.*_external$', elt): make_dep_dir = elt -# Check folder contents -compare(dir_content, - ['main_1.0.0_filesystem/alire', - 'main_1.0.0_filesystem/alire.toml', - 'main_1.0.0_filesystem/alire/alire.lock', - 'main_1.0.0_filesystem/alire/build_hash_inputs', - 'main_1.0.0_filesystem/alire/cache', +# These only appear if dependencies are sandboxed +extra = ['main_1.0.0_filesystem/alire/cache', 'main_1.0.0_filesystem/alire/cache/dependencies', make_dep_dir, make_dep_dir + "/alire", make_dep_dir + "/alire/flags", - make_dep_dir + "/alire/flags/complete_copy", - 'main_1.0.0_filesystem/alire/config.toml', - 'main_1.0.0_filesystem/alire/flags', + make_dep_dir + "/alire/flags/complete_copy"] + +# Check folder contents +compare(dir_content, + ['main_1.0.0_filesystem/alire', + 'main_1.0.0_filesystem/alire.toml', + 'main_1.0.0_filesystem/alire/alire.lock'] + + (extra if not builds.are_shared() else []) + + ['main_1.0.0_filesystem/alire/flags', 'main_1.0.0_filesystem/alire/flags/complete_copy', - 'main_1.0.0_filesystem/config', - 'main_1.0.0_filesystem/config/main_config.ads', - 'main_1.0.0_filesystem/config/main_config.gpr', - 'main_1.0.0_filesystem/config/main_config.h', 'main_1.0.0_filesystem/noop.gpr', 'main_1.0.0_filesystem/src', 'main_1.0.0_filesystem/src/noop.adb' ]) +if builds.are_shared(): + # External tools that have no sources don't have a shared build dir: + try: + assert builds.find_dir("make") # This should raise + raise Exception("Should not have found make build dir") + except: + pass + print('SUCCESS') diff --git a/testsuite/tests/get/git-local/test.py b/testsuite/tests/get/git-local/test.py index d4a441ab3..86fb1ab6a 100644 --- a/testsuite/tests/get/git-local/test.py +++ b/testsuite/tests/get/git-local/test.py @@ -16,8 +16,6 @@ 'libfoo_1.0.0_9ddda32b/alire', 'libfoo_1.0.0_9ddda32b/alire.toml', 'libfoo_1.0.0_9ddda32b/alire/alire.lock', - 'libfoo_1.0.0_9ddda32b/alire/build_hash_inputs', - 'libfoo_1.0.0_9ddda32b/alire/config.toml', 'libfoo_1.0.0_9ddda32b/alire/flags', 'libfoo_1.0.0_9ddda32b/alire/flags/complete_copy', 'libfoo_1.0.0_9ddda32b/b', @@ -27,10 +25,6 @@ 'libfoo_1.0.0_9ddda32b/b/y/q', 'libfoo_1.0.0_9ddda32b/b/z', 'libfoo_1.0.0_9ddda32b/c', - 'libfoo_1.0.0_9ddda32b/config', - 'libfoo_1.0.0_9ddda32b/config/libfoo_config.ads', - 'libfoo_1.0.0_9ddda32b/config/libfoo_config.gpr', - 'libfoo_1.0.0_9ddda32b/config/libfoo_config.h' ]) # Check as dependency diff --git a/testsuite/tests/get/unpack-in-place/test.py b/testsuite/tests/get/unpack-in-place/test.py index 18d72a6a3..afe1909bf 100644 --- a/testsuite/tests/get/unpack-in-place/test.py +++ b/testsuite/tests/get/unpack-in-place/test.py @@ -12,14 +12,8 @@ ['libhello_1.0.0_filesystem/alire', 'libhello_1.0.0_filesystem/alire.toml', 'libhello_1.0.0_filesystem/alire/alire.lock', - 'libhello_1.0.0_filesystem/alire/build_hash_inputs', - 'libhello_1.0.0_filesystem/alire/config.toml', 'libhello_1.0.0_filesystem/alire/flags', 'libhello_1.0.0_filesystem/alire/flags/complete_copy', - 'libhello_1.0.0_filesystem/config', - 'libhello_1.0.0_filesystem/config/libhello_config.ads', - 'libhello_1.0.0_filesystem/config/libhello_config.gpr', - 'libhello_1.0.0_filesystem/config/libhello_config.h', 'libhello_1.0.0_filesystem/libhello.gpr', 'libhello_1.0.0_filesystem/src', 'libhello_1.0.0_filesystem/src/libhello.adb', diff --git a/testsuite/tests/index/bad-config-vars/test.py b/testsuite/tests/index/bad-config-vars/test.py index 47bba445b..6ffa78423 100644 --- a/testsuite/tests/index/bad-config-vars/test.py +++ b/testsuite/tests/index/bad-config-vars/test.py @@ -42,9 +42,11 @@ def check_ok(var_def): p = run_alr('show', 'hello_world', complain_on_error=True, debug=False, quiet=True) - -os.remove(os.path.join("my_index", "index", "he", "hello_world", - ".gitignore")) +try: + os.remove(os.path.join("my_index", "index", "he", "hello_world", + ".gitignore")) +except: + pass # Will have been removed by 1st test run check_error('var1=["plop"]', 'variable definition must be a table') check_error('var1={}', "configuration.variables.var1:") diff --git a/testsuite/tests/install/dynamic-linking/test.yaml b/testsuite/tests/install/dynamic-linking/test.yaml index 32c747b3f..fa855459b 100644 --- a/testsuite/tests/install/dynamic-linking/test.yaml +++ b/testsuite/tests/install/dynamic-linking/test.yaml @@ -1 +1,3 @@ driver: python-script +indexes: + compiler_only_index: {} diff --git a/testsuite/tests/install/executable-dependency/test.yaml b/testsuite/tests/install/executable-dependency/test.yaml index 32c747b3f..fa855459b 100644 --- a/testsuite/tests/install/executable-dependency/test.yaml +++ b/testsuite/tests/install/executable-dependency/test.yaml @@ -1 +1,3 @@ driver: python-script +indexes: + compiler_only_index: {} diff --git a/testsuite/tests/install/static-linking/test.yaml b/testsuite/tests/install/static-linking/test.yaml index 32c747b3f..fa855459b 100644 --- a/testsuite/tests/install/static-linking/test.yaml +++ b/testsuite/tests/install/static-linking/test.yaml @@ -1 +1,3 @@ driver: python-script +indexes: + compiler_only_index: {} diff --git a/testsuite/tests/misc/git-ungit/test.py b/testsuite/tests/misc/git-ungit/test.py index 88ddb010d..4054d27cd 100644 --- a/testsuite/tests/misc/git-ungit/test.py +++ b/testsuite/tests/misc/git-ungit/test.py @@ -5,6 +5,7 @@ import os import shutil +from drivers import builds from drivers.alr import alr_with, crate_dirname, init_local_crate, run_alr from drivers.asserts import assert_file_exists @@ -26,9 +27,13 @@ init_local_crate() alr_with("libfoo") - assert_file_exists(os.path.join("alire", "cache", "dependencies", - foo_dir, ".git"), - wanted=wanted) + if builds.are_shared(): + assert_file_exists(os.path.join(builds.vault_path(), foo_dir, ".git"), + wanted=False) + else: + assert_file_exists(os.path.join("alire", "cache", "dependencies", + foo_dir, ".git"), + wanted=wanted) if not wanted: # Enable for next round diff --git a/testsuite/tests/misc/sync-manual-edit/test.py b/testsuite/tests/misc/sync-manual-edit/test.py index fe355f208..85179752b 100644 --- a/testsuite/tests/misc/sync-manual-edit/test.py +++ b/testsuite/tests/misc/sync-manual-edit/test.py @@ -5,6 +5,7 @@ import os.path +from drivers import builds from drivers.alr import run_alr, alr_touch_manifest from shutil import rmtree # from drivers.asserts import assert_eq, assert_match @@ -31,7 +32,10 @@ run_alr(cmd) # Check dependency folder is at the expected location: - assert os.path.isdir(target), "Directory missing at expected location" + if builds.are_shared(): + assert builds.find_dir("libhello") + else: + assert os.path.isdir(target), "Directory missing at expected location" # Go back up and clean up for next command os.chdir("..") diff --git a/testsuite/tests/misc/sync-manual-edit/test.yaml b/testsuite/tests/misc/sync-manual-edit/test.yaml index 872fc1274..e2c5af220 100644 --- a/testsuite/tests/misc/sync-manual-edit/test.yaml +++ b/testsuite/tests/misc/sync-manual-edit/test.yaml @@ -1,3 +1,4 @@ driver: python-script indexes: basic_index: {} + compiler_only_index: {} diff --git a/testsuite/tests/misc/sync-missing-deps/test.py b/testsuite/tests/misc/sync-missing-deps/test.py index ba91edda1..1ce92b910 100644 --- a/testsuite/tests/misc/sync-missing-deps/test.py +++ b/testsuite/tests/misc/sync-missing-deps/test.py @@ -7,6 +7,7 @@ from drivers.alr import run_alr from drivers.builds import find_hash +from drivers import builds # Create a new project and set up dependencies run_alr('init', '--bin', 'xxx') @@ -24,7 +25,7 @@ for round in range(2): if round == 2: # Prepare same test for shared dependencies - run_alr("config", "--set", "--global", "dependencies.shared", "true") + builds.enable_shared() run_alr("update") target = f"builds.path()/hello_1.0.1_filesystem_{find_hash('hello')}" diff --git a/testsuite/tests/misc/sync-missing-deps/test.yaml b/testsuite/tests/misc/sync-missing-deps/test.yaml index 872fc1274..5ccb3287e 100644 --- a/testsuite/tests/misc/sync-missing-deps/test.yaml +++ b/testsuite/tests/misc/sync-missing-deps/test.yaml @@ -1,3 +1,4 @@ driver: python-script +build_mode: sandboxed indexes: basic_index: {} diff --git a/testsuite/tests/monorepo/basic/test.py b/testsuite/tests/monorepo/basic/test.py index 16d4bf8a0..4d5137170 100644 --- a/testsuite/tests/monorepo/basic/test.py +++ b/testsuite/tests/monorepo/basic/test.py @@ -4,8 +4,8 @@ """ import os -import shutil +from drivers import builds from drivers.alr import run_alr, init_local_crate, alr_with, alr_publish from drivers.helpers import init_git_repo, on_windows # from drivers.asserts import assert_eq, assert_match @@ -49,16 +49,18 @@ init_local_crate("top") alr_with("mycrate") run_alr("build") +base = (builds.find_dir("monoproject") if builds.are_shared() + else os.path.join("alire", "cache", "dependencies", f"monoproject_{commit[:8]}")) assert os.path.isfile(os.path.join( - "alire", "cache", "dependencies", - f"monoproject_{commit[:8]}", "mycrate", "bin", + base, "mycrate", "bin", f"mycrate{'.exe' if on_windows() else ''}")), \ "Expected binary does not exist" # Also that the info file is there -assert os.path.isfile(os.path.join( - "alire", "cache", "dependencies", - f"mycrate_0.1.0_in_monoproject_{commit[:8]}")), \ +deps_dir = (builds.vault_path() if builds.are_shared() + else os.path.dirname(base)) +infofile = f"mycrate_0.1.0_in_monoproject_{commit[:8]}" +assert os.path.isfile(os.path.join(deps_dir, infofile)), \ "Expected info file does not exist" print('SUCCESS') diff --git a/testsuite/tests/monorepo/basic/test.yaml b/testsuite/tests/monorepo/basic/test.yaml index 0a859639c..d6aa8a36d 100644 --- a/testsuite/tests/monorepo/basic/test.yaml +++ b/testsuite/tests/monorepo/basic/test.yaml @@ -2,3 +2,4 @@ driver: python-script indexes: my_index: in_fixtures: false + compiler_only_index: {} diff --git a/testsuite/tests/monorepo/doubly-nested/test.py b/testsuite/tests/monorepo/doubly-nested/test.py index 0c51634c9..6995e796a 100644 --- a/testsuite/tests/monorepo/doubly-nested/test.py +++ b/testsuite/tests/monorepo/doubly-nested/test.py @@ -3,8 +3,8 @@ """ import os -import shutil +from drivers import builds from drivers.alr import run_alr, init_local_crate, alr_with, alr_publish from drivers.helpers import init_git_repo from subprocess import run @@ -46,9 +46,12 @@ init_local_crate("top") alr_with("mychild") run_alr("build") -assert os.path.isdir(os.path.join("alire", "cache", "dependencies", - f"monoproject_{commit[:8]}", - "myparent", "mychild")), \ +if builds.are_shared(): + path = builds.find_dir("monoproject") +else: + path = os.path.join("alire", "cache", "dependencies", + f"monoproject_{commit[:8]}") +assert os.path.isdir(os.path.join(path, "myparent", "mychild")), \ "Expected directory does not exist" # Verify that "with"ing the parent does not result in a new checkout diff --git a/testsuite/tests/monorepo/doubly-nested/test.yaml b/testsuite/tests/monorepo/doubly-nested/test.yaml index 0a859639c..d6aa8a36d 100644 --- a/testsuite/tests/monorepo/doubly-nested/test.yaml +++ b/testsuite/tests/monorepo/doubly-nested/test.yaml @@ -2,3 +2,4 @@ driver: python-script indexes: my_index: in_fixtures: false + compiler_only_index: {} diff --git a/testsuite/tests/monorepo/multi-commit/test.py b/testsuite/tests/monorepo/multi-commit/test.py index 41a54621e..344948c85 100644 --- a/testsuite/tests/monorepo/multi-commit/test.py +++ b/testsuite/tests/monorepo/multi-commit/test.py @@ -5,13 +5,12 @@ """ import os -import shutil - -from drivers.alr import run_alr, init_local_crate, alr_with, alr_publish -from drivers.helpers import init_git_repo, on_windows, commit_all -# from drivers.asserts import assert_eq, assert_match from subprocess import run +from drivers import builds +from drivers.alr import alr_publish, alr_with, init_local_crate, run_alr +from drivers.helpers import commit_all, init_git_repo, on_windows + # We create a repository with two nested crates that will act as the upstream # remote repository: start_dir = os.getcwd() @@ -50,24 +49,36 @@ alr_with("crate2") run_alr("build") + +def release_base(commit: str) -> str: + if builds.are_shared(): + return builds.find_dir(f"monoproject_{commit[:8]}") + else: + return os.path.join("alire", "cache", "dependencies", + f"monoproject_{commit[:8]}") + + assert os.path.isfile(os.path.join( - "alire", "cache", "dependencies", - f"monoproject_{commit1[:8]}", "crate1", "bin", + release_base(commit1), "crate1", "bin", f"crate1{'.exe' if on_windows() else ''}")), \ "Expected binary does not exist" assert os.path.isfile(os.path.join( - "alire", "cache", "dependencies", - f"monoproject_{commit2[:8]}", "crate2", "bin", + release_base(commit2), "crate2", "bin", f"crate2{'.exe' if on_windows() else ''}")), \ "Expected binary does not exist" # Also that the info files are there +if builds.are_shared(): + deps_dir = builds.vault_path() +else: + deps_dir = os.path.join("alire", "cache", "dependencies") + assert os.path.isfile(os.path.join( - "alire", "cache", "dependencies", + deps_dir, f"crate1_0.1.0_in_monoproject_{commit1[:8]}")), \ - "Expected info file does not exist" + f"Expected info file does not exist" assert os.path.isfile(os.path.join( - "alire", "cache", "dependencies", + deps_dir, f"crate2_0.1.0_in_monoproject_{commit2[:8]}")), \ "Expected info file does not exist" diff --git a/testsuite/tests/monorepo/multi-commit/test.yaml b/testsuite/tests/monorepo/multi-commit/test.yaml index 0a859639c..d6aa8a36d 100644 --- a/testsuite/tests/monorepo/multi-commit/test.yaml +++ b/testsuite/tests/monorepo/multi-commit/test.yaml @@ -2,3 +2,4 @@ driver: python-script indexes: my_index: in_fixtures: false + compiler_only_index: {} diff --git a/testsuite/tests/pin/downgrade/test.py b/testsuite/tests/pin/downgrade/test.py index 736779c78..5255dbee3 100644 --- a/testsuite/tests/pin/downgrade/test.py +++ b/testsuite/tests/pin/downgrade/test.py @@ -3,14 +3,13 @@ """ import os +import re -from drivers.alr import run_alr, alr_pin, alr_lockfile -from drivers.asserts import assert_eq, assert_match +from drivers import builds +from drivers.alr import alr_lockfile, alr_pin, run_alr +from drivers.asserts import assert_match from drivers.helpers import check_line_in -import os -import re - # Verify that proper version of libchild is in the printed and disk solution def check_child(version, output, pinned): @@ -26,8 +25,12 @@ def check_child(version, output, pinned): check_line_in(alr_lockfile(), f'version = "{version}"') # Verify dependency folders - assert os.path.exists('alire/cache/dependencies/libchild_' + version + - '_filesystem') + if builds.are_shared(): + run_alr('update') # force hash computation + assert builds.find_dir('libchild_' + version + '_filesystem') + else: + assert os.path.exists('alire/cache/dependencies/libchild_' + version + + '_filesystem') # Create a new "xxx" program project diff --git a/testsuite/tests/pin/downgrade/test.yaml b/testsuite/tests/pin/downgrade/test.yaml index 0a859639c..d6aa8a36d 100644 --- a/testsuite/tests/pin/downgrade/test.yaml +++ b/testsuite/tests/pin/downgrade/test.yaml @@ -2,3 +2,4 @@ driver: python-script indexes: my_index: in_fixtures: false + compiler_only_index: {} diff --git a/testsuite/tests/pin/equivalent/test.py b/testsuite/tests/pin/equivalent/test.py index b6695240d..0c74e2cf3 100644 --- a/testsuite/tests/pin/equivalent/test.py +++ b/testsuite/tests/pin/equivalent/test.py @@ -3,7 +3,7 @@ """ from drivers.alr import run_alr, alr_pin, init_local_crate -from drivers.asserts import assert_eq, assert_match +from drivers.asserts import assert_eq from drivers.helpers import init_git_repo, git_branch import os diff --git a/testsuite/tests/pin/equivalent/test.yaml b/testsuite/tests/pin/equivalent/test.yaml index 872fc1274..e2c5af220 100644 --- a/testsuite/tests/pin/equivalent/test.yaml +++ b/testsuite/tests/pin/equivalent/test.yaml @@ -1,3 +1,4 @@ driver: python-script indexes: basic_index: {} + compiler_only_index: {} diff --git a/testsuite/tests/pin/from-subdir/test.yaml b/testsuite/tests/pin/from-subdir/test.yaml index 32c747b3f..fa855459b 100644 --- a/testsuite/tests/pin/from-subdir/test.yaml +++ b/testsuite/tests/pin/from-subdir/test.yaml @@ -1 +1,3 @@ driver: python-script +indexes: + compiler_only_index: {} diff --git a/testsuite/tests/pin/post-update/test.yaml b/testsuite/tests/pin/post-update/test.yaml index 0a859639c..d6aa8a36d 100644 --- a/testsuite/tests/pin/post-update/test.yaml +++ b/testsuite/tests/pin/post-update/test.yaml @@ -2,3 +2,4 @@ driver: python-script indexes: my_index: in_fixtures: false + compiler_only_index: {} diff --git a/testsuite/tests/pin/remote/test.yaml b/testsuite/tests/pin/remote/test.yaml index 872fc1274..e2c5af220 100644 --- a/testsuite/tests/pin/remote/test.yaml +++ b/testsuite/tests/pin/remote/test.yaml @@ -1,3 +1,4 @@ driver: python-script indexes: basic_index: {} + compiler_only_index: {} diff --git a/testsuite/tests/pin/to-parent/test.yaml b/testsuite/tests/pin/to-parent/test.yaml index 32c747b3f..fa855459b 100644 --- a/testsuite/tests/pin/to-parent/test.yaml +++ b/testsuite/tests/pin/to-parent/test.yaml @@ -1 +1,3 @@ driver: python-script +indexes: + compiler_only_index: {} diff --git a/testsuite/tests/printenv/basic/test.py b/testsuite/tests/printenv/basic/test.py index 2f4d711a7..10f91e8b8 100644 --- a/testsuite/tests/printenv/basic/test.py +++ b/testsuite/tests/printenv/basic/test.py @@ -5,6 +5,7 @@ from glob import glob import os +from drivers import builds from drivers.alr import run_alr from drivers.asserts import assert_eq, assert_match @@ -27,10 +28,22 @@ def make_path(list): else: return "/".join(list) +# Force dependency syncing for the shared case +run_alr("update") + expected_hello_path = make_path(['.*', 'hello_1.0.1_filesystem']) -expected_libhello_path = make_path(['.*', 'alire', 'cache', 'dependencies', 'libhello_1\.0\.0_filesystem']) +expected_libhello_path = \ +make_path(['.*', os.path.basename(builds.find_dir('libhello'))]) \ +if builds.are_shared() else \ +make_path(['.*', 'alire', 'cache', 'dependencies', 'libhello_1\.0\.0_filesystem']) -expected_gpr_path = os.pathsep.join([expected_hello_path, expected_libhello_path]) +# Depending on the dependency location, both orders may occur +expected_gpr_path = \ + "(" \ + f"{os.pathsep.join([expected_hello_path, expected_libhello_path])}" \ + "|" \ + f"{os.pathsep.join([expected_libhello_path, expected_hello_path])}" \ + ")" assert_match('export ALIRE="True"\n' '.*' diff --git a/testsuite/tests/printenv/env-during-fetch/test.py b/testsuite/tests/printenv/env-during-fetch/test.py index 2ccf9daa0..5c57bfe0d 100644 --- a/testsuite/tests/printenv/env-during-fetch/test.py +++ b/testsuite/tests/printenv/env-during-fetch/test.py @@ -2,17 +2,22 @@ Check that an env var is defined during dependency retrieval (get and with) """ -from glob import glob import os import re +from glob import glob +from drivers import builds from drivers.alr import run_alr from drivers.asserts import assert_match -def verify_output(text): - assert_match('.*CHECKENV_TEST_VAR exists\n.*', - text, flags=re.S) +def verify_output(text, exists: bool): + if exists: + assert_match('.*CHECKENV_TEST_VAR exists\n.*', + text, flags=re.S) + else: + assert "CHECKENV_TEST_VAR exists" not in text, \ + "Unexpected output: " + text # The "checkenv" crate defines CHECKENV_TEST_VAR. Also, its executable prints # "CHECKENV_TEST_VAR exists" or "CHECKENV_TEST_VAR does NOT exist" when run. @@ -24,14 +29,21 @@ def verify_output(text): # Build the crate to trigger the post-fetch action os.chdir(glob("checkparent*")[0]) p = run_alr("build", complain_on_error=False) -verify_output(p.out) +verify_output(p.out, exists=True) # Create a crate from scratch and add the same dependency to perform the check # during retrieval by `with` + run_alr("init", "--bin", "xxx") os.chdir("xxx") run_alr("with", "checkenv") p = run_alr("build") -verify_output(p.out) +# For shared builds, the crate has been already fetched as a dependency of +# checkparent, so it should not emit anything. For sandboxed builds, it should +# emit as expected. +if builds.are_shared(): + verify_output(p.out, exists=False) +else: + verify_output(p.out, exists=True) print('SUCCESS') diff --git a/testsuite/tests/printenv/env-during-fetch/test.yaml b/testsuite/tests/printenv/env-during-fetch/test.yaml index 0a859639c..d6aa8a36d 100644 --- a/testsuite/tests/printenv/env-during-fetch/test.yaml +++ b/testsuite/tests/printenv/env-during-fetch/test.yaml @@ -2,3 +2,4 @@ driver: python-script indexes: my_index: in_fixtures: false + compiler_only_index: {} diff --git a/testsuite/tests/printenv/linked-paths/test.yaml b/testsuite/tests/printenv/linked-paths/test.yaml index 0a859639c..d6aa8a36d 100644 --- a/testsuite/tests/printenv/linked-paths/test.yaml +++ b/testsuite/tests/printenv/linked-paths/test.yaml @@ -2,3 +2,4 @@ driver: python-script indexes: my_index: in_fixtures: false + compiler_only_index: {} diff --git a/testsuite/tests/publish/check-properties/test.yaml b/testsuite/tests/publish/check-properties/test.yaml index 8929d590a..0415476b1 100644 --- a/testsuite/tests/publish/check-properties/test.yaml +++ b/testsuite/tests/publish/check-properties/test.yaml @@ -1,4 +1,5 @@ driver: python-script +build_mode: sandboxed indexes: basic_index: in_fixtures: true diff --git a/testsuite/tests/publish/pin-removal/test.yaml b/testsuite/tests/publish/pin-removal/test.yaml index 0a859639c..d6aa8a36d 100644 --- a/testsuite/tests/publish/pin-removal/test.yaml +++ b/testsuite/tests/publish/pin-removal/test.yaml @@ -2,3 +2,4 @@ driver: python-script indexes: my_index: in_fixtures: false + compiler_only_index: {} diff --git a/testsuite/tests/publish/remote-origin-nonstd/test.py b/testsuite/tests/publish/remote-origin-nonstd/test.py index f891f7e88..2651efc2d 100644 --- a/testsuite/tests/publish/remote-origin-nonstd/test.py +++ b/testsuite/tests/publish/remote-origin-nonstd/test.py @@ -59,4 +59,7 @@ def verify_manifest(): p = run_alr("search", "--crates") assert "xxx" in p.out, "Crate not found in index contents" +# Remove the index for the next test +run_alr("index", "--del", "my_index") + print('SUCCESS') diff --git a/testsuite/tests/publish/remote-origin/test.py b/testsuite/tests/publish/remote-origin/test.py index 0e87ece07..f35c29510 100644 --- a/testsuite/tests/publish/remote-origin/test.py +++ b/testsuite/tests/publish/remote-origin/test.py @@ -56,4 +56,7 @@ def verify_manifest(): p = run_alr("search", "--crates") assert "xxx" in p.out, "Crate not found in index contents" +# Remove the index for the next test +run_alr("index", "--del", "my_index") + print('SUCCESS') diff --git a/testsuite/tests/solver/compiler-installed/test.py b/testsuite/tests/solver/compiler-installed/test.py index 2b2e95373..e5c16fcab 100644 --- a/testsuite/tests/solver/compiler-installed/test.py +++ b/testsuite/tests/solver/compiler-installed/test.py @@ -3,11 +3,10 @@ locally available one is used). """ -import subprocess import re from drivers.alr import run_alr, init_local_crate, alr_with -from drivers.asserts import assert_eq, assert_match, match_solution +from drivers.asserts import assert_match, match_solution # With no compiler selected, the external compiler in the environment should be # the only one available. We will verify this and capture its version (which is diff --git a/testsuite/tests/update/selective/test.yaml b/testsuite/tests/update/selective/test.yaml index 0a859639c..d6aa8a36d 100644 --- a/testsuite/tests/update/selective/test.yaml +++ b/testsuite/tests/update/selective/test.yaml @@ -2,3 +2,4 @@ driver: python-script indexes: my_index: in_fixtures: false + compiler_only_index: {} diff --git a/testsuite/tests/with/auto-gpr-with/gpr_in_subdir/test.py b/testsuite/tests/with/auto-gpr-with/gpr_in_subdir/test.py index 33a88b19b..bb2ea243e 100644 --- a/testsuite/tests/with/auto-gpr-with/gpr_in_subdir/test.py +++ b/testsuite/tests/with/auto-gpr-with/gpr_in_subdir/test.py @@ -20,6 +20,11 @@ run_alr('with', 'libhello') run_alr('with', 'gpr_in_subdir') +# In shared mode, a "with" won't generate config files yet (which is desirable +# in case the withed crate has configuration variables without defaults). So we +# need to trigger the generation of the config files. +run_alr("update") + check_line_in('config/myhello_config.gpr', 'with "libhello.gpr";') # When the crate declares a project file: `dir1/dir2/dir3/prj.gpr`, the with diff --git a/testsuite/tests/with/auto-gpr-with/gpr_in_subdir/test.yaml b/testsuite/tests/with/auto-gpr-with/gpr_in_subdir/test.yaml index 496a1d1a7..ea8ef3a20 100644 --- a/testsuite/tests/with/auto-gpr-with/gpr_in_subdir/test.yaml +++ b/testsuite/tests/with/auto-gpr-with/gpr_in_subdir/test.yaml @@ -5,3 +5,5 @@ indexes: my_index: in_fixtures: false copy_crates_src: true + compiler_only_index: + in_fixtures: true diff --git a/testsuite/tests/with/changes-info/test.yaml b/testsuite/tests/with/changes-info/test.yaml index e0a82ba80..028a69369 100644 --- a/testsuite/tests/with/changes-info/test.yaml +++ b/testsuite/tests/with/changes-info/test.yaml @@ -1,4 +1,4 @@ driver: python-script indexes: - solver_index: - in_fixtures: true + solver_index: {} + compiler_only_index: {} \ No newline at end of file diff --git a/testsuite/tests/with/equivalent/test.yaml b/testsuite/tests/with/equivalent/test.yaml index 872fc1274..e2c5af220 100644 --- a/testsuite/tests/with/equivalent/test.yaml +++ b/testsuite/tests/with/equivalent/test.yaml @@ -1,3 +1,4 @@ driver: python-script indexes: basic_index: {} + compiler_only_index: {} diff --git a/testsuite/tests/workflows/actions-as-dependency/test.py b/testsuite/tests/workflows/actions-as-dependency/test.py index 8f56f5b20..69d1166f2 100644 --- a/testsuite/tests/workflows/actions-as-dependency/test.py +++ b/testsuite/tests/workflows/actions-as-dependency/test.py @@ -2,33 +2,34 @@ Test pre-build/post-build/post-fetch executions in a crate that is a dependency """ -from drivers.alr import run_alr, init_local_crate, add_action, alr_with -from drivers.asserts import assert_match -from drivers.helpers import compare, contents, on_windows +import os from glob import glob from pathlib import Path from shutil import rmtree -import os +from drivers import builds +from drivers.alr import alr_with, init_local_crate, run_alr +from drivers.asserts import assert_match +from drivers.helpers import contents, neutral_path -def check_expected(expected): - if not (expected in contents('.')): +def check_expected(expected, path): + if not (expected in contents(path)): assert False, "%s expected in %s\n Got: %s" % \ - (expected, '.', str(contents('.'))) + (expected, path, str(contents(path))) -def check_not_expected(expected): - if expected in contents('.'): +def check_not_expected(expected, path): + if expected in contents(path): assert False, "%s is unexpected in %s\n Got: %s" % \ - (expected, '.', str(contents('.'))) + (expected, path, str(contents(path))) -def check(file, to_be_or_not_to_be): +def check(file, to_be_or_not_to_be, path): if to_be_or_not_to_be: - check_expected(file) + check_expected(file, path) else: - check_not_expected(file) + check_not_expected(file, path) def do_checks(path_to_dependency): @@ -37,9 +38,9 @@ def do_checks(path_to_dependency): flag_post_build = path_to_dependency + "/test_post_build" # Immediately after adding the dependency, this is the situation: - check(flag_post_fetch, False) - check(flag_pre_build, False) - check(flag_post_build, False) + check(flag_post_fetch, False, path_to_dependency) + check(flag_pre_build, False, path_to_dependency) + check(flag_post_build, False, path_to_dependency) # Build with error, so only pre-build runs but not post-build Path(f"{path_to_dependency}/src/empty.adb").touch() @@ -49,17 +50,17 @@ def do_checks(path_to_dependency): # Post build shouldn't be here because of build failure; post-fetch should # however now exist because a build has been attempted and post-fetch # succeeded (even if the build failed at a later stage) - check(flag_post_fetch, True) - check(flag_pre_build, True) - check(flag_post_build, False) + check(flag_post_fetch, True, path_to_dependency) + check(flag_pre_build, True, path_to_dependency) + check(flag_post_build, False, path_to_dependency) # Remove post-fetch to check it doesn't come back unexpectedly os.remove(flag_post_fetch) # Post build shouldn't be here because of build failure - check(flag_post_fetch, False) - check(flag_pre_build, True) - check(flag_post_build, False) + check(flag_post_fetch, False, path_to_dependency) + check(flag_pre_build, True, path_to_dependency) + check(flag_post_build, False, path_to_dependency) os.remove(flag_pre_build) os.remove(f"{path_to_dependency}/src/empty.adb") @@ -68,23 +69,22 @@ def do_checks(path_to_dependency): run_alr('build') # pre/post-build expected for successful build - check(flag_post_fetch, False) - check(flag_pre_build, True) - check(flag_post_build, True) + check(flag_post_fetch, False, path_to_dependency) + check(flag_pre_build, True, path_to_dependency) + check(flag_post_build, True, path_to_dependency) return - # updating dependencies causes the post-fetch action to run: - run_alr('update') - check(flag_post_fetch, True) - check(flag_pre_build, True) - check(flag_post_build, True) - # Initialize a crate and add as dependency the crate that contains the triggers init_local_crate("root", binary=False) # Lib so all contents are compiled alr_with("hello_world") +run_alr("update") # Test all triggers -do_checks(glob("./alire/cache/dependencies/hello*")[0].replace('\\', '/')) +if builds.are_shared(): + base = neutral_path(builds.find_dir("hello_world")) +else: + base = neutral_path(glob("./alire/cache/dependencies/hello*")[0]) +do_checks(base) # Repeat tests, for a crate that has been added as a linked dependency os.chdir("..") diff --git a/testsuite/tests/workflows/actions-as-dependency/test.yaml b/testsuite/tests/workflows/actions-as-dependency/test.yaml index 0a859639c..b3537ee9a 100644 --- a/testsuite/tests/workflows/actions-as-dependency/test.yaml +++ b/testsuite/tests/workflows/actions-as-dependency/test.yaml @@ -1,4 +1,6 @@ driver: python-script +build_mode: shared indexes: my_index: in_fixtures: false + compiler_only_index: {} diff --git a/testsuite/tests/workflows/actions-as-root/test.yaml b/testsuite/tests/workflows/actions-as-root/test.yaml index 0a859639c..d6aa8a36d 100644 --- a/testsuite/tests/workflows/actions-as-root/test.yaml +++ b/testsuite/tests/workflows/actions-as-root/test.yaml @@ -2,3 +2,4 @@ driver: python-script indexes: my_index: in_fixtures: false + compiler_only_index: {} diff --git a/testsuite/tests/workflows/get-build-run-clean/test.yaml b/testsuite/tests/workflows/get-build-run-clean/test.yaml index 872fc1274..e2c5af220 100644 --- a/testsuite/tests/workflows/get-build-run-clean/test.yaml +++ b/testsuite/tests/workflows/get-build-run-clean/test.yaml @@ -1,3 +1,4 @@ driver: python-script indexes: basic_index: {} + compiler_only_index: {}