From 31745e195dbf0219c10fe176a01f862e111820d2 Mon Sep 17 00:00:00 2001 From: Alejandro R Mosteo Date: Wed, 14 Sep 2022 10:15:26 +0200 Subject: [PATCH] Use release build when `alr get --build`ing. (#1169) This will also make `alr test` to use release builds, which is what we want as submitted crates are tested in release mode. Co-authored-by: GHA --- src/alr/alr-commands-get.adb | 14 +++++++++----- testsuite/drivers/asserts.py | 16 +++++++++++++++- .../build_profile/get-build-profile/test.py | 13 +++++++++++++ .../build_profile/get-build-profile/test.yaml | 3 +++ 4 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 testsuite/tests/build_profile/get-build-profile/test.py create mode 100644 testsuite/tests/build_profile/get-build-profile/test.yaml diff --git a/src/alr/alr-commands-get.adb b/src/alr/alr-commands-get.adb index 972d6248..9ea04159 100644 --- a/src/alr/alr-commands-get.adb +++ b/src/alr/alr-commands-get.adb @@ -10,11 +10,10 @@ with Alire.Platforms.Current; with Alire.Root; with Alire.Solutions.Diffs; with Alire.Solver; +with Alire.Utils.Switches; with CLIC.User_Input; -with Alr.Commands.Build; - with Semantic_Versioning.Extended; package body Alr.Commands.Get is @@ -181,12 +180,17 @@ package body Alr.Commands.Get is Build_OK := True; else + -- Build in release mode for a `get --build` + Cmd.Root.Set_Build_Profile + (Crate => Cmd.Root.Name, + Profile => Alire.Utils.Switches.Release); -- The complete build environment has been set up already by -- Deploy_Dependencies, so we must not do it again. - Build_OK := Commands.Build.Execute (Cmd, - AAA.Strings.Empty_Vector, - Export_Build_Env => False); + Build_OK := Cmd.Root.Build + (Cmd_Args => AAA.Strings.Empty_Vector, + Saved_Profiles => False, + Export_Build_Env => False); end if; else Build_OK := True; diff --git a/testsuite/drivers/asserts.py b/testsuite/drivers/asserts.py index e8ac37e1..c866b874 100644 --- a/testsuite/drivers/asserts.py +++ b/testsuite/drivers/asserts.py @@ -3,11 +3,13 @@ This module provides several helpers to perform user-friendly assertions in testcases based on Python scripts. """ +import difflib +import os import re import difflib from drivers.alr import run_alr -from drivers.helpers import contents +from drivers.helpers import contents, lines_of def indent(text, prefix=' '): """ @@ -59,6 +61,18 @@ def assert_match(expected_re, actual, label=None, flags=re.S): assert False, '\n'.join(text) +def assert_profile(profile: str, crate: str, root: str = "."): + """ + Verify that a crate was built with a certain profile + root: path to where the crate root is + """ + line = f' Build_Profile : Build_Profile_Kind := "{profile}";\n' + file = os.path.join(root, "config", f"{crate}_config.gpr") + assert line in lines_of(file), \ + f"Unexpected contents: missing line '{line}' in {file}:\n" + \ + f"{content_of(file)}" + + def match_solution(regex, escape=False, whole=False): "Check whether a regex matches the current solution" p = run_alr("with", "--solve") diff --git a/testsuite/tests/build_profile/get-build-profile/test.py b/testsuite/tests/build_profile/get-build-profile/test.py new file mode 100644 index 00000000..9136e805 --- /dev/null +++ b/testsuite/tests/build_profile/get-build-profile/test.py @@ -0,0 +1,13 @@ +""" +Check that a crate built with `get --build` is built in release mode +""" + +from drivers.alr import run_alr +from drivers.asserts import assert_profile +from glob import glob + +run_alr("get", "--build", "hello=1.0") + +assert_profile("release", "hello", glob("hello_1.0.0_*")[0]) + +print('SUCCESS') diff --git a/testsuite/tests/build_profile/get-build-profile/test.yaml b/testsuite/tests/build_profile/get-build-profile/test.yaml new file mode 100644 index 00000000..872fc127 --- /dev/null +++ b/testsuite/tests/build_profile/get-build-profile/test.yaml @@ -0,0 +1,3 @@ +driver: python-script +indexes: + basic_index: {} -- 2.39.5