From 87c860ebadabb669a570119186aabbd99cad1e5e Mon Sep 17 00:00:00 2001 From: lumberyard-employee-dm Date: Thu, 11 Jun 2020 17:51:19 +0100 Subject: cmake --build: Fix exit code when building multiple targets Updated the cmGlobalGenerator::Build method to check the return `retVal` parameter supplied to the `cmSystemTools::RunSingleCommand` to validate that each invocation of the build command returned an exit code of zero. Fixes: #20790 --- Source/cmGlobalGenerator.cxx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 4dc4092..1ed5e8b 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -1988,8 +1988,9 @@ int cmGlobalGenerator::Build( std::string makeCommandStr; output += "\nRun Build Command(s):"; - for (auto command = makeCommand.begin(); command != makeCommand.end(); - ++command) { + retVal = 0; + for (auto command = makeCommand.begin(); + command != makeCommand.end() && retVal == 0; ++command) { makeCommandStr = command->Printable(); if (command != makeCommand.end()) { makeCommandStr += " && "; -- cgit v0.12 From b9dd072e05cf73969eb6e3306c82c3eaa94cfb9b Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 12 Jun 2020 11:32:29 -0400 Subject: Tests: Add case for cmake --build with a failing target --- .../CommandLine/BuildDir--build-multiple-targets-fail-result.txt | 1 + .../CommandLine/BuildDir--build-multiple-targets-fail-stderr.txt | 1 + Tests/RunCMake/CommandLine/BuildDir/CMakeLists.txt | 1 + Tests/RunCMake/CommandLine/RunCMakeTest.cmake | 2 ++ 4 files changed, 5 insertions(+) create mode 100644 Tests/RunCMake/CommandLine/BuildDir--build-multiple-targets-fail-result.txt create mode 100644 Tests/RunCMake/CommandLine/BuildDir--build-multiple-targets-fail-stderr.txt diff --git a/Tests/RunCMake/CommandLine/BuildDir--build-multiple-targets-fail-result.txt b/Tests/RunCMake/CommandLine/BuildDir--build-multiple-targets-fail-result.txt new file mode 100644 index 0000000..d197c91 --- /dev/null +++ b/Tests/RunCMake/CommandLine/BuildDir--build-multiple-targets-fail-result.txt @@ -0,0 +1 @@ +[^0] diff --git a/Tests/RunCMake/CommandLine/BuildDir--build-multiple-targets-fail-stderr.txt b/Tests/RunCMake/CommandLine/BuildDir--build-multiple-targets-fail-stderr.txt new file mode 100644 index 0000000..8d98f9d --- /dev/null +++ b/Tests/RunCMake/CommandLine/BuildDir--build-multiple-targets-fail-stderr.txt @@ -0,0 +1 @@ +.* diff --git a/Tests/RunCMake/CommandLine/BuildDir/CMakeLists.txt b/Tests/RunCMake/CommandLine/BuildDir/CMakeLists.txt index d2a2831..cf2c087 100644 --- a/Tests/RunCMake/CommandLine/BuildDir/CMakeLists.txt +++ b/Tests/RunCMake/CommandLine/BuildDir/CMakeLists.txt @@ -5,3 +5,4 @@ add_custom_command( add_custom_target(CustomTarget ALL DEPENDS output.txt) add_custom_target(CustomTarget2 ALL DEPENDS output.txt) add_custom_target(CustomTarget3 ALL DEPENDS output.txt) +add_custom_target(CustomTargetFail COMMAND DoesNotExist) diff --git a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake index 973391d..16fdeef 100644 --- a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake +++ b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake @@ -134,6 +134,8 @@ function(run_BuildDir) ${CMAKE_COMMAND} --build BuildDir-build --target CustomTarget) run_cmake_command(BuildDir--build-multiple-targets ${CMAKE_COMMAND} -E chdir .. ${CMAKE_COMMAND} --build BuildDir-build -t CustomTarget2 --target CustomTarget3) + run_cmake_command(BuildDir--build-multiple-targets-fail ${CMAKE_COMMAND} -E chdir .. + ${CMAKE_COMMAND} --build BuildDir-build -t CustomTargetFail --target CustomTarget3) run_cmake_command(BuildDir--build-multiple-targets-jobs ${CMAKE_COMMAND} -E chdir .. ${CMAKE_COMMAND} --build BuildDir-build --target CustomTarget CustomTarget2 -j2 --target CustomTarget3) run_cmake_command(BuildDir--build-multiple-targets-with-clean-first ${CMAKE_COMMAND} -E chdir .. -- cgit v0.12