diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index 8927faeb62..0b4aef8f13 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -2638,32 +2638,23 @@ int cmCTest::Run(std::vector const& args) } #endif - std::function doTest = [this, &cmakeAndTest, &runScripts, - &processSteps]() -> int { - // now what should cmake do? if --build-and-test was specified then - // we run the build and test handler and return - if (cmakeAndTest) { - return this->RunCMakeAndTest(); - } + // now what should cmake do? if --build-and-test was specified then + // we run the build and test handler and return + if (cmakeAndTest) { + return this->RunCMakeAndTest(); + } - // -S, -SP, and/or -SP was specified - if (!runScripts.empty()) { - return this->RunScripts(runScripts); - } + // -S, -SP, and/or -SP was specified + if (!runScripts.empty()) { + return this->RunScripts(runScripts); + } - // -D, -T, and/or -M was specified - if (processSteps) { - return this->ProcessSteps(); - } + // -D, -T, and/or -M was specified + if (processSteps) { + return this->ProcessSteps(); + } - return this->ExecuteTests(); - }; - cmInstrumentation instrumentation( - cmSystemTools::GetCurrentWorkingDirectory()); - int ret = instrumentation.InstrumentCommand("ctest", args, - [doTest]() { return doTest(); }); - instrumentation.CollectTimingData(cmInstrumentationQuery::Hook::PostTest); - return ret; + return this->ExecuteTests(args); } int cmCTest::RunScripts( @@ -2687,7 +2678,7 @@ int cmCTest::RunScripts( return res; } -int cmCTest::ExecuteTests() +int cmCTest::ExecuteTests(std::vector const& args) { this->Impl->ExtraVerbose = this->Impl->Verbose; this->Impl->Verbose = true; @@ -2732,7 +2723,14 @@ int cmCTest::ExecuteTests() } handler.SetVerbose(this->Impl->Verbose); - if (handler.ProcessHandler() < 0) { + + cmInstrumentation instrumentation(this->GetBinaryDir()); + std::function processHandler = [&handler]() { + return handler.ProcessHandler(); + }; + int ret = instrumentation.InstrumentCommand("ctest", args, processHandler); + instrumentation.CollectTimingData(cmInstrumentationQuery::Hook::PostTest); + if (ret < 0) { cmCTestLog(this, ERROR_MESSAGE, "Errors while running CTest\n"); if (!this->Impl->OutputTestOutputOnTestFailure) { std::string const lastTestLog = diff --git a/Source/cmCTest.h b/Source/cmCTest.h index bcc4087940..fd6d8b1c71 100644 --- a/Source/cmCTest.h +++ b/Source/cmCTest.h @@ -480,7 +480,7 @@ private: int RunCMakeAndTest(); int RunScripts(std::vector> const& scripts); - int ExecuteTests(); + int ExecuteTests(std::vector const& args); struct Private; std::unique_ptr Impl; diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 25a3357343..d525a5a4e9 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -3720,7 +3720,8 @@ std::vector cmake::GetDebugConfigs() int cmake::Build(int jobs, std::string dir, std::vector targets, std::string config, std::vector nativeOptions, cmBuildOptions& buildOptions, bool verbose, - std::string const& presetName, bool listPresets) + std::string const& presetName, bool listPresets, + std::vector const& args) { this->SetHomeDirectory(""); this->SetHomeOutputDirectory(""); @@ -3958,16 +3959,39 @@ int cmake::Build(int jobs, std::string dir, std::vector targets, return 1; } +#if !defined(CMAKE_BOOTSTRAP) + cmInstrumentation instrumentation(dir); + if (!instrumentation.errorMsg.empty()) { + cmSystemTools::Error(instrumentation.errorMsg); + return 1; + } + instrumentation.CollectTimingData( + cmInstrumentationQuery::Hook::PreCMakeBuild); +#endif + this->GlobalGenerator->PrintBuildCommandAdvice(std::cerr, jobs); std::stringstream ostr; // `cmGlobalGenerator::Build` logs metadata about what directory and commands // are being executed to the `output` parameter. If CMake is verbose, print // this out. std::ostream& verbose_ostr = verbose ? std::cout : ostr; - int buildresult = this->GlobalGenerator->Build( - jobs, "", dir, projName, targets, verbose_ostr, "", config, buildOptions, - verbose, cmDuration::zero(), cmSystemTools::OUTPUT_PASSTHROUGH, - nativeOptions); + std::function doBuild = [this, jobs, dir, projName, targets, + &verbose_ostr, config, buildOptions, verbose, + nativeOptions]() { + return this->GlobalGenerator->Build( + jobs, "", dir, projName, targets, verbose_ostr, "", config, buildOptions, + verbose, cmDuration::zero(), cmSystemTools::OUTPUT_PASSTHROUGH, + nativeOptions); + }; + +#if !defined(CMAKE_BOOTSTRAP) + int buildresult = + instrumentation.InstrumentCommand("cmakeBuild", args, doBuild); + instrumentation.CollectTimingData( + cmInstrumentationQuery::Hook::PostCMakeBuild); +#else + int buildresult = doBuild(); +#endif return buildresult; } diff --git a/Source/cmake.h b/Source/cmake.h index 49231f4491..829bb7c471 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -640,7 +640,8 @@ public: int Build(int jobs, std::string dir, std::vector targets, std::string config, std::vector nativeOptions, cmBuildOptions& buildOptions, bool verbose, - std::string const& presetName, bool listPresets); + std::string const& presetName, bool listPresets, + std::vector const& args); //! run the --open option bool Open(std::string const& dir, bool dryRun); diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx index 80a0ce8ab9..cc55343fc5 100644 --- a/Source/cmakemain.cxx +++ b/Source/cmakemain.cxx @@ -705,27 +705,12 @@ int do_build(int ac, char const* const* av) cmakemainProgressCallback(msg, prog, &cm); }); - cmInstrumentation instrumentation(dir); - if (!instrumentation.errorMsg.empty()) { - cmSystemTools::Error(instrumentation.errorMsg); - return 1; - } cmBuildOptions buildOptions(cleanFirst, false, resolveMode); - std::function doBuild = [&cm, &jobs, &dir, &targets, &config, - &nativeOptions, &buildOptions, &verbose, - &presetName, &listPresets]() { - return cm.Build(jobs, dir, std::move(targets), std::move(config), - std::move(nativeOptions), buildOptions, verbose, - presetName, listPresets); - }; - instrumentation.CollectTimingData( - cmInstrumentationQuery::Hook::PreCMakeBuild); std::vector cmd; cm::append(cmd, av, av + ac); - int ret = instrumentation.InstrumentCommand("cmakeBuild", cmd, doBuild); - instrumentation.CollectTimingData( - cmInstrumentationQuery::Hook::PostCMakeBuild); - return ret; + return cm.Build(jobs, dir, std::move(targets), std::move(config), + std::move(nativeOptions), buildOptions, verbose, presetName, + listPresets, cmd); #endif } diff --git a/Tests/RunCMake/Instrumentation/check-data-dir.cmake b/Tests/RunCMake/Instrumentation/check-data-dir.cmake index f2e8235b18..a20d2cdfa4 100644 --- a/Tests/RunCMake/Instrumentation/check-data-dir.cmake +++ b/Tests/RunCMake/Instrumentation/check-data-dir.cmake @@ -107,6 +107,15 @@ foreach(snippet IN LISTS snippets) snippet_error(${snippet} "Unexpected config: ${config}") endif() endif() + + # Verify command args were passed + if (filename MATCHES "^cmakeBuild|^ctest") + string(JSON command GET "${contents}" command) + if (NOT command MATCHES "-.* Debug") + snippet_error(${snippet} "Command value missing passed arguments") + endif() + endif() + endforeach() # Verify that listed snippets match expected roles