From 1b1df86ce824125da651d2e40ebe301576c4c96f Mon Sep 17 00:00:00 2001 From: "Alejandro R. Mosteo" Date: Fri, 27 Sep 2024 18:05:03 +0200 Subject: [PATCH 1/2] Set up environment during build preparations --- src/alire/alire-roots.adb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/alire/alire-roots.adb b/src/alire/alire-roots.adb index fae9448b8..aa19a5cff 100644 --- a/src/alire/alire-roots.adb +++ b/src/alire/alire-roots.adb @@ -101,6 +101,10 @@ package body Alire.Roots is -- 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. + + -- Set the environment to be used during build + + This.Export_Build_Environment; end Build_Prepare; ----------- @@ -279,8 +283,6 @@ package body Alire.Roots is return True; end if; - This.Export_Build_Environment; - This.Traverse (Build_Single_Release'Access); return True; From c48e3e070b49387826006ebb31e713407496ac6e Mon Sep 17 00:00:00 2001 From: "Alejandro R. Mosteo" Date: Fri, 27 Sep 2024 18:37:11 +0200 Subject: [PATCH 2/2] Test --- testsuite/tests/action/environment/test.py | 51 ++++++++++++++++++++ testsuite/tests/action/environment/test.yaml | 4 ++ 2 files changed, 55 insertions(+) create mode 100644 testsuite/tests/action/environment/test.py create mode 100644 testsuite/tests/action/environment/test.yaml diff --git a/testsuite/tests/action/environment/test.py b/testsuite/tests/action/environment/test.py new file mode 100644 index 000000000..3e2842035 --- /dev/null +++ b/testsuite/tests/action/environment/test.py @@ -0,0 +1,51 @@ +""" +Verify the proper environment is set up for the action. We create an executable +within a crate that will be run during pre-build. For it to be found, the +proper path must be set in the crate environment. This should work for a +regular build (as it did before) and for a manually triggered action (the bug +being fixed). +""" + +import os +from shutil import which +from drivers.alr import run_alr, init_local_crate, add_action, alr_manifest +from drivers.asserts import assert_eq +from drivers.helpers import content_of, on_windows + +tool_name = "myalrtestingtool" + +# Tool crate to be used during build +init_local_crate(tool_name, enter=False) + +# Ensure the tool is not found in path by pure chance! +assert not which(tool_name) + +# Build the tool +run_alr("-C", tool_name, "build") + +# Create the new crate that uses this tool during pre-build step +init_local_crate() + +# Edit its manifest to require it during pre-build +add_action("pre-build", [tool_name + (".exe" if on_windows() else "")]) + +# Build should fail because the tool is not found in the path +run_alr("build", complain_on_error=False) + +# Likewise, stand-alone running of the action should fail +run_alr("action", "pre-build", complain_on_error=False) + +# Add the tool location to the crate environment +with open(alr_manifest(), "at") as f: + f.write(f""" +[environment] +PATH.prepend = "../{tool_name}/bin" +""") + +# assert_eq(content_of(alr_manifest()), "XXX") + +# Now both build and action should succeed +run_alr("build") +run_alr("action", "pre-build") + +print("SUCCESS") diff --git a/testsuite/tests/action/environment/test.yaml b/testsuite/tests/action/environment/test.yaml new file mode 100644 index 000000000..702010525 --- /dev/null +++ b/testsuite/tests/action/environment/test.yaml @@ -0,0 +1,4 @@ +driver: python-script +build_mode: both +indexes: + compiler_only_index: {}