diff options
author | Zack Galbreath <zack.galbreath@kitware.com> | 2022-09-23 14:07:18 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2022-09-26 13:40:58 (GMT) |
commit | 65260d6c1e09fbe2dd15e1b01a04c729c9d5bd6f (patch) | |
tree | b55a5a35d2e4caef83e85ca1d98f52d289d4a514 | |
parent | e7fd69fa3660be2283ce53b2a9d050f6ba59efde (diff) | |
download | CMake-65260d6c1e09fbe2dd15e1b01a04c729c9d5bd6f.zip CMake-65260d6c1e09fbe2dd15e1b01a04c729c9d5bd6f.tar.gz CMake-65260d6c1e09fbe2dd15e1b01a04c729c9d5bd6f.tar.bz2 |
ctest: only report make-level errors when no others are found
In commit ab9ad2a6a0 (ctest: report make-level errors to CDash when
using launchers, 2020-09-24, v3.19.0-rc1~84^2~1) we taught CTest to
capture and report errors from the build command when using launchers.
This had the unintended side effect of reporting a separate build error containing
the full build output when the build command returns non-zero. To fix this problem,
we now only report build command errors from CTest launchers when no other
more specific build errors are found.
Fixes: #23991
7 files changed, 68 insertions, 11 deletions
diff --git a/Source/CTest/cmCTestBuildHandler.cxx b/Source/CTest/cmCTestBuildHandler.cxx index 2aba79d..66c30c0 100644 --- a/Source/CTest/cmCTestBuildHandler.cxx +++ b/Source/CTest/cmCTestBuildHandler.cxx @@ -893,16 +893,31 @@ int cmCTestBuildHandler::RunMakeCommand(const std::string& command, // If there was an error running command, report that on the // dashboard. if (this->UseCTestLaunch) { - cmCTestLaunchReporter reporter; - reporter.RealArgs = args; - reporter.ComputeFileNames(); - reporter.ExitCode = *retVal; - reporter.Process = cp; - // Use temporary BuildLog file to populate this error for CDash. - ofs.flush(); - reporter.LogOut = this->LogFileNames["Build"]; - reporter.LogOut += ".tmp"; - reporter.WriteXML(); + // For launchers, do not record this top-level error if other + // more granular build errors have already been captured. + bool launcherXMLFound = false; + cmsys::Directory launchDir; + launchDir.Load(this->CTestLaunchDir); + unsigned long n = launchDir.GetNumberOfFiles(); + for (unsigned long i = 0; i < n; ++i) { + const char* fname = launchDir.GetFile(i); + if (cmHasLiteralSuffix(fname, ".xml")) { + launcherXMLFound = true; + break; + } + } + if (!launcherXMLFound) { + cmCTestLaunchReporter reporter; + reporter.RealArgs = args; + reporter.ComputeFileNames(); + reporter.ExitCode = *retVal; + reporter.Process = cp; + // Use temporary BuildLog file to populate this error for CDash. + ofs.flush(); + reporter.LogOut = this->LogFileNames["Build"]; + reporter.LogOut += ".tmp"; + reporter.WriteXML(); + } } else { cmCTestBuildErrorWarning errorwarning; errorwarning.LineNumber = 0; diff --git a/Tests/RunCMake/ctest_build/CMakeLists.txt.in b/Tests/RunCMake/ctest_build/CMakeLists.txt.in index 133ae36..4a067fa 100644 --- a/Tests/RunCMake/ctest_build/CMakeLists.txt.in +++ b/Tests/RunCMake/ctest_build/CMakeLists.txt.in @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.1) @CASE_CMAKELISTS_PREFIX_CODE@ -project(CTestBuild@CASE_NAME@ NONE) +project(CTestBuild@CASE_NAME@ @LANG@) include(CTest) add_test(NAME RunCMakeVersion COMMAND "${CMAKE_COMMAND}" --version) @CASE_CMAKELISTS_SUFFIX_CODE@ diff --git a/Tests/RunCMake/ctest_build/NinjaLauncherSingleBuildFailure-check.cmake b/Tests/RunCMake/ctest_build/NinjaLauncherSingleBuildFailure-check.cmake new file mode 100644 index 0000000..7089d70 --- /dev/null +++ b/Tests/RunCMake/ctest_build/NinjaLauncherSingleBuildFailure-check.cmake @@ -0,0 +1,23 @@ +file(GLOB build_xml_file "${RunCMake_TEST_BINARY_DIR}/Testing/*/Build.xml") +if(build_xml_file) + file(READ "${build_xml_file}" build_xml LIMIT 8192) + string(FIND "${build_xml}" [[This should not be compiled]] expected_failure_pos) + if(expected_failure_pos EQUAL "-1") + string(REPLACE "\n" "\n " build_xml " ${build_xml}") + set(RunCMake_TEST_FAILED + "Build.xml does not have expected error message:\n${build_xml}" + ) + else() + string(SUBSTRING "${build_xml}" "${expected_failure_pos}" -1 remaining_xml) + string(FIND "${remaining_xml}" [[<Failure type="Error">]] unexpected_failure_pos) + if(NOT unexpected_failure_pos EQUAL "-1") + string(SUBSTRING "${remaining_xml}" "${unexpected_failure_pos}" -1 error_msg_xml) + string(REPLACE "\n" "\n " error_msg_xml " ${error_msg_xml}") + set(RunCMake_TEST_FAILED + "Build.xml contains unexpected extra <Failure> elements:\n${error_msg_xml}" + ) + endif() + endif() +else() + set(RunCMake_TEST_FAILED "Build.xml not found") +endif() diff --git a/Tests/RunCMake/ctest_build/NinjaLauncherSingleBuildFailure-result.txt b/Tests/RunCMake/ctest_build/NinjaLauncherSingleBuildFailure-result.txt new file mode 100644 index 0000000..b57e2de --- /dev/null +++ b/Tests/RunCMake/ctest_build/NinjaLauncherSingleBuildFailure-result.txt @@ -0,0 +1 @@ +(-1|255) diff --git a/Tests/RunCMake/ctest_build/NinjaLauncherSingleBuildFailure-stderr.txt b/Tests/RunCMake/ctest_build/NinjaLauncherSingleBuildFailure-stderr.txt new file mode 100644 index 0000000..bbe9410 --- /dev/null +++ b/Tests/RunCMake/ctest_build/NinjaLauncherSingleBuildFailure-stderr.txt @@ -0,0 +1 @@ +^Error\(s\) when building project diff --git a/Tests/RunCMake/ctest_build/RunCMakeTest.cmake b/Tests/RunCMake/ctest_build/RunCMakeTest.cmake index e94a55d..6f1b4b6 100644 --- a/Tests/RunCMake/ctest_build/RunCMakeTest.cmake +++ b/Tests/RunCMake/ctest_build/RunCMakeTest.cmake @@ -1,5 +1,6 @@ include(RunCTest) +set(LANG NONE) set(CASE_CTEST_BUILD_ARGS "") set(RunCMake_USE_LAUNCHERS TRUE) set(RunCMake_USE_CUSTOM_BUILD_COMMAND FALSE) @@ -70,3 +71,18 @@ set(RunCMake_USE_LAUNCHERS FALSE) set(RunCMake_BUILD_COMMAND "${COLOR_WARNING}") run_ctest(IgnoreColor) unset(RunCMake_BUILD_COMMAND) + +set(RunCMake_USE_CUSTOM_BUILD_COMMAND FALSE) +if(RunCMake_GENERATOR MATCHES "Ninja") + function(run_NinjaLauncherSingleBuildFailure) + set(LANG C) + set(RunCMake_USE_LAUNCHERS TRUE) + set(RunCMake_TEST_SOURCE_DIR "${RunCMake_BINARY_DIR}/NinjaLauncherSingleBuildFailure") + configure_file("${RunCMake_SOURCE_DIR}/error.c" "${RunCMake_TEST_SOURCE_DIR}/error.c" COPYONLY) + set(CASE_CMAKELISTS_SUFFIX_CODE [=[ + add_executable(error error.c) + ]=]) + run_ctest(NinjaLauncherSingleBuildFailure) + endfunction() + run_NinjaLauncherSingleBuildFailure() +endif() diff --git a/Tests/RunCMake/ctest_build/error.c b/Tests/RunCMake/ctest_build/error.c new file mode 100644 index 0000000..f10e687 --- /dev/null +++ b/Tests/RunCMake/ctest_build/error.c @@ -0,0 +1 @@ +#error "This should not be compiled" |