From 136bc40c3ddda90a558b9eb4195f59db1c725250 Mon Sep 17 00:00:00 2001 From: Alejandro R Mosteo Date: Mon, 11 May 2020 19:37:20 +0200 Subject: [PATCH] Rely on lockfile for `alr setenv` (#394) * Use lockfile for `alr setenv` * Add a test for setenv with external dependencies --- src/alr/alr-build_env.adb | 9 +----- src/alr/alr-commands-setenv.adb | 11 +------ .../setenv => setenv/basic}/test.py | 6 ++-- .../setenv => setenv/basic}/test.yaml | 0 testsuite/tests/setenv/with-external/test.py | 29 +++++++++++++++++++ .../tests/setenv/with-external/test.yaml | 3 ++ 6 files changed, 38 insertions(+), 20 deletions(-) rename testsuite/tests/{workflows/setenv => setenv/basic}/test.py (82%) rename testsuite/tests/{workflows/setenv => setenv/basic}/test.yaml (100%) create mode 100644 testsuite/tests/setenv/with-external/test.py create mode 100644 testsuite/tests/setenv/with-external/test.yaml diff --git a/src/alr/alr-build_env.adb b/src/alr/alr-build_env.adb index ee3c667d..fc9cda0f 100644 --- a/src/alr/alr-build_env.adb +++ b/src/alr/alr-build_env.adb @@ -10,7 +10,6 @@ with Alire.Solutions; with Alire.Solver; with Alire.Utils; -with Alr.Commands; with Alr.OS_Lib; with Alr.Platform; with Alr.Paths; @@ -94,13 +93,7 @@ package body Alr.Build_Env is procedure Gen_Env (Root : Alire.Roots.Root; Action : not null Env_Var_Action_Callback) is - Needed : constant Query.Solution := - Query.Resolve - (Root.Release.Dependencies.Evaluate (Platform.Properties), - Platform.Properties, - Options => (Age => Commands.Query_Policy, - Detecting => <>, - Hinting => <>)); + Needed : constant Query.Solution := Root.Solution; Existing_Project_Path : GNAT.OS_Lib.String_Access; diff --git a/src/alr/alr-commands-setenv.adb b/src/alr/alr-commands-setenv.adb index 87dcbbbf..c3fb0cfa 100644 --- a/src/alr/alr-commands-setenv.adb +++ b/src/alr/alr-commands-setenv.adb @@ -14,16 +14,7 @@ package body Alr.Commands.Setenv is Requires_Valid_Session; - -- Temporarily raise the log level to avoid spurious status output that - -- would prevent directly sourcing the output. TODO: remove this once - -- the lockfile is used, that will make this unnecessary. - declare - Old_Level : constant Simple_Logging.Levels := Alire.Log_Level; - begin - Alire.Log_Level := Simple_Logging.Always; - Alr.Build_Env.Print (Alr.Root.Current); - Alire.Log_Level := Old_Level; - end; + Alr.Build_Env.Print (Alr.Root.Current); end Execute; ------------- diff --git a/testsuite/tests/workflows/setenv/test.py b/testsuite/tests/setenv/basic/test.py similarity index 82% rename from testsuite/tests/workflows/setenv/test.py rename to testsuite/tests/setenv/basic/test.py index 4c2f2afb..b296dc74 100644 --- a/testsuite/tests/workflows/setenv/test.py +++ b/testsuite/tests/setenv/basic/test.py @@ -1,5 +1,5 @@ """ -Test a basic get-build-run workflow. +Test the environment set for a basic crate """ from glob import glob @@ -16,7 +16,9 @@ import platform run_alr('get', 'hello') os.chdir(glob('hello*')[0]) -p = run_alr('setenv') +# Run it not quietly to ensure that at normal level +# the output is not broken by some log message +p = run_alr('setenv', quiet=False) assert_eq(0, p.status) if platform.system() == 'Windows': diff --git a/testsuite/tests/workflows/setenv/test.yaml b/testsuite/tests/setenv/basic/test.yaml similarity index 100% rename from testsuite/tests/workflows/setenv/test.yaml rename to testsuite/tests/setenv/basic/test.yaml diff --git a/testsuite/tests/setenv/with-external/test.py b/testsuite/tests/setenv/with-external/test.py new file mode 100644 index 00000000..c8d75f5d --- /dev/null +++ b/testsuite/tests/setenv/with-external/test.py @@ -0,0 +1,29 @@ +""" +Test the output when a external crate is in the dependencies +""" + +from glob import glob +import os + +from drivers.alr import run_alr +from drivers.asserts import assert_eq, assert_match + +import re +import platform + + +# Retrieve a crate with a external dependency +run_alr('get', 'libhello=0.9-test_unav_native') +os.chdir('libhello_0.9.0_filesystem') + +# Run it not quietly to ensure that at normal level +# the output is not broken by some log message +p = run_alr('setenv', quiet=False) +assert_eq(0, p.status) + +# Check the setenv output +assert_match('export GPR_PROJECT_PATH=""\n' + 'export ALIRE="True"\n', + p.out) + +print('SUCCESS') diff --git a/testsuite/tests/setenv/with-external/test.yaml b/testsuite/tests/setenv/with-external/test.yaml new file mode 100644 index 00000000..bdadcb7a --- /dev/null +++ b/testsuite/tests/setenv/with-external/test.yaml @@ -0,0 +1,3 @@ +driver: python-script +indexes: + native_index: {} -- 2.39.5