From cb5f136c6636677bb496869b2c0d87d209bc2655 Mon Sep 17 00:00:00 2001 From: Nikita Nemkin Date: Tue, 4 Feb 2025 14:43:06 +0500 Subject: [PATCH] ctest: Prevent infinite loop in ctest_run_script(NEW_PROCESS) ctest passes an internal -SR argument to inform a subprocess which script to run. Because all arguments are propagated to the subprocess, nested subprocess receives multiple -SR arguments and re-runs the parent script in addition to its own, leading to a loop. Ignore redundant -SR arguments on input and also filter out parent's -SR argument when constructing a child process. Fixes: #8837 --- Source/CTest/cmCTestScriptHandler.cxx | 7 ++++++- Source/cmCTest.cxx | 9 ++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Source/CTest/cmCTestScriptHandler.cxx b/Source/CTest/cmCTestScriptHandler.cxx index 85ea2152d9..cde5a041a2 100644 --- a/Source/CTest/cmCTestScriptHandler.cxx +++ b/Source/CTest/cmCTestScriptHandler.cxx @@ -97,7 +97,12 @@ int cmCTestScriptHandler::ExecuteScript(std::string const& total_script_arg) this->CTest->GetInitialCommandLineArguments(); //*** need to make sure this does not have the current script *** for (size_t i = 1; i < initArgs.size(); ++i) { - argv.push_back(initArgs[i]); + // in a nested subprocess, skip the parent's `-SR ` arguments. + if (initArgs[i] == "-SR") { + i++; // + } else { + argv.push_back(initArgs[i]); + } } // Now create process object diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index 603b1f4b5e..c23adb8ad7 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -1975,9 +1975,12 @@ int cmCTest::Run(std::vector const& args) }; auto const dashSR = [&runScripts, &SRArgumentSpecified](std::string const& script) -> bool { - SRArgumentSpecified = true; - runScripts.emplace_back(cmSystemTools::ToNormalizedPathOnDisk(script), - true); + // -SR should be processed only once + if (!SRArgumentSpecified) { + SRArgumentSpecified = true; + runScripts.emplace_back(cmSystemTools::ToNormalizedPathOnDisk(script), + true); + } return true; }; auto const dash_S =