From a328f1fdc24fd1d02b2d79dc2dd56334a99ab1fc Mon Sep 17 00:00:00 2001 From: Alejandro R Mosteo Date: Fri, 5 Jun 2020 19:07:18 +0200 Subject: [PATCH] Exit code fix for `get --build` with build failure (#428) We were not erroring if the build failed, which is counterintuitive. We now require successful retrieval and build to exit with code 0. A test to verify this situation has been added. --- src/alr/alr-commands-get.adb | 9 +++++++- .../get/build/my_index/crates/bad/bad.gpr | 22 +++++++++++++++++++ .../get/build/my_index/crates/bad/src/bad.adb | 4 ++++ .../get/build/my_index/crates/good/good.gpr | 22 +++++++++++++++++++ .../build/my_index/crates/good/src/good.adb | 4 ++++ .../get/build/my_index/index/ba/bad.toml | 8 +++++++ .../get/build/my_index/index/go/good.toml | 8 +++++++ .../tests/get/build/my_index/index/index.toml | 1 + testsuite/tests/get/build/test.py | 16 ++++++++++++++ testsuite/tests/get/build/test.yaml | 4 ++++ 10 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 testsuite/tests/get/build/my_index/crates/bad/bad.gpr create mode 100644 testsuite/tests/get/build/my_index/crates/bad/src/bad.adb create mode 100644 testsuite/tests/get/build/my_index/crates/good/good.gpr create mode 100644 testsuite/tests/get/build/my_index/crates/good/src/good.adb create mode 100644 testsuite/tests/get/build/my_index/index/ba/bad.toml create mode 100644 testsuite/tests/get/build/my_index/index/go/good.toml create mode 100644 testsuite/tests/get/build/my_index/index/index.toml create mode 100644 testsuite/tests/get/build/test.py create mode 100644 testsuite/tests/get/build/test.yaml diff --git a/src/alr/alr-commands-get.adb b/src/alr/alr-commands-get.adb index f362c282..2750be7a 100644 --- a/src/alr/alr-commands-get.adb +++ b/src/alr/alr-commands-get.adb @@ -43,7 +43,7 @@ package body Alr.Commands.Get is Diff : Alire.Solutions.Diffs.Diff; -- Used to present dependencies to the user - Build_OK : Boolean; + Build_OK : Boolean := False; begin declare Result : Alire.Outcome; @@ -139,6 +139,8 @@ package body Alr.Commands.Get is if Cmd.Build then Build_OK := Commands.Build.Execute; + else + Build_OK := True; end if; end; @@ -162,6 +164,11 @@ package body Alr.Commands.Get is else Trace.Info ("There are no dependencies."); end if; + + if not Build_OK then + raise Command_Failed with "Build ended with errors"; + -- This is not displayed at default level, but ensures exit code /= 0 + end if; end Retrieve; ------------- diff --git a/testsuite/tests/get/build/my_index/crates/bad/bad.gpr b/testsuite/tests/get/build/my_index/crates/bad/bad.gpr new file mode 100644 index 00000000..16df1f34 --- /dev/null +++ b/testsuite/tests/get/build/my_index/crates/bad/bad.gpr @@ -0,0 +1,22 @@ +project Bad is + + for Source_Dirs use ("src"); + for Object_Dir use "obj"; + for Exec_Dir use "bin"; + for Main use ("bad.adb"); + + package Builder is + for Switches ("ada") use ("-j0", "-g"); + end Builder; + + package Compiler is + for Switches ("ada") use + ("-gnatVa", "-gnatwa", "-g", "-O2", + "-gnata", "-gnato", "-fstack-check"); + end Compiler; + + package Binder is + for Switches ("ada") use ("-Es"); + end Binder; + +end Bad; diff --git a/testsuite/tests/get/build/my_index/crates/bad/src/bad.adb b/testsuite/tests/get/build/my_index/crates/bad/src/bad.adb new file mode 100644 index 00000000..8a3f0970 --- /dev/null +++ b/testsuite/tests/get/build/my_index/crates/bad/src/bad.adb @@ -0,0 +1,4 @@ +procedure Bad is +begin + Won't build +end Bad; diff --git a/testsuite/tests/get/build/my_index/crates/good/good.gpr b/testsuite/tests/get/build/my_index/crates/good/good.gpr new file mode 100644 index 00000000..4ce9fea6 --- /dev/null +++ b/testsuite/tests/get/build/my_index/crates/good/good.gpr @@ -0,0 +1,22 @@ +project Good is + + for Source_Dirs use ("src"); + for Object_Dir use "obj"; + for Exec_Dir use "bin"; + for Main use ("good.adb"); + + package Builder is + for Switches ("ada") use ("-j0", "-g"); + end Builder; + + package Compiler is + for Switches ("ada") use + ("-gnatVa", "-gnatwa", "-g", "-O2", + "-gnata", "-gnato", "-fstack-check"); + end Compiler; + + package Binder is + for Switches ("ada") use ("-Es"); + end Binder; + +end Good; diff --git a/testsuite/tests/get/build/my_index/crates/good/src/good.adb b/testsuite/tests/get/build/my_index/crates/good/src/good.adb new file mode 100644 index 00000000..d3524974 --- /dev/null +++ b/testsuite/tests/get/build/my_index/crates/good/src/good.adb @@ -0,0 +1,4 @@ +procedure Good is +begin + null; +end Good; diff --git a/testsuite/tests/get/build/my_index/index/ba/bad.toml b/testsuite/tests/get/build/my_index/index/ba/bad.toml new file mode 100644 index 00000000..0ca283d3 --- /dev/null +++ b/testsuite/tests/get/build/my_index/index/ba/bad.toml @@ -0,0 +1,8 @@ +[general] +description = "Bad crate" +maintainers = ["jane@doe.com"] +maintainers-logins = ["mylogin"] +licenses = [] + +['1.0'] +origin = "file://./../../crates/bad" diff --git a/testsuite/tests/get/build/my_index/index/go/good.toml b/testsuite/tests/get/build/my_index/index/go/good.toml new file mode 100644 index 00000000..b7e9a455 --- /dev/null +++ b/testsuite/tests/get/build/my_index/index/go/good.toml @@ -0,0 +1,8 @@ +[general] +description = "Good crate" +maintainers = ["john@doe.com"] +maintainers-logins = ["mylogin"] +licenses = [] + +['1.0'] +origin = "file://./../../crates/good" diff --git a/testsuite/tests/get/build/my_index/index/index.toml b/testsuite/tests/get/build/my_index/index/index.toml new file mode 100644 index 00000000..7c969026 --- /dev/null +++ b/testsuite/tests/get/build/my_index/index/index.toml @@ -0,0 +1 @@ +version = "0.2" diff --git a/testsuite/tests/get/build/test.py b/testsuite/tests/get/build/test.py new file mode 100644 index 00000000..3a9a4719 --- /dev/null +++ b/testsuite/tests/get/build/test.py @@ -0,0 +1,16 @@ +""" +Check the `alr get --build` combo for crates that [don't] build +""" + +from drivers.alr import run_alr + +# Should succeed +p = run_alr('get', '--build', 'good') + +# Should err out +p = run_alr('get', '--build', 'bad', + complain_on_error=False) +assert p.status == 1, "Expected command to exit with code 1" + + +print('SUCCESS') diff --git a/testsuite/tests/get/build/test.yaml b/testsuite/tests/get/build/test.yaml new file mode 100644 index 00000000..0a859639 --- /dev/null +++ b/testsuite/tests/get/build/test.yaml @@ -0,0 +1,4 @@ +driver: python-script +indexes: + my_index: + in_fixtures: false -- 2.39.5