instrumentation: Make hooks compatible with presets
This commit is contained in:
parent
1fb8f4cad7
commit
a2232db802
@ -2638,32 +2638,23 @@ int cmCTest::Run(std::vector<std::string> const& args)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::function<int()> doTest = [this, &cmakeAndTest, &runScripts,
|
// now what should cmake do? if --build-and-test was specified then
|
||||||
&processSteps]() -> int {
|
// we run the build and test handler and return
|
||||||
// now what should cmake do? if --build-and-test was specified then
|
if (cmakeAndTest) {
|
||||||
// we run the build and test handler and return
|
return this->RunCMakeAndTest();
|
||||||
if (cmakeAndTest) {
|
}
|
||||||
return this->RunCMakeAndTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
// -S, -SP, and/or -SP was specified
|
// -S, -SP, and/or -SP was specified
|
||||||
if (!runScripts.empty()) {
|
if (!runScripts.empty()) {
|
||||||
return this->RunScripts(runScripts);
|
return this->RunScripts(runScripts);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -D, -T, and/or -M was specified
|
// -D, -T, and/or -M was specified
|
||||||
if (processSteps) {
|
if (processSteps) {
|
||||||
return this->ProcessSteps();
|
return this->ProcessSteps();
|
||||||
}
|
}
|
||||||
|
|
||||||
return this->ExecuteTests();
|
return this->ExecuteTests(args);
|
||||||
};
|
|
||||||
cmInstrumentation instrumentation(
|
|
||||||
cmSystemTools::GetCurrentWorkingDirectory());
|
|
||||||
int ret = instrumentation.InstrumentCommand("ctest", args,
|
|
||||||
[doTest]() { return doTest(); });
|
|
||||||
instrumentation.CollectTimingData(cmInstrumentationQuery::Hook::PostTest);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int cmCTest::RunScripts(
|
int cmCTest::RunScripts(
|
||||||
@ -2687,7 +2678,7 @@ int cmCTest::RunScripts(
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int cmCTest::ExecuteTests()
|
int cmCTest::ExecuteTests(std::vector<std::string> const& args)
|
||||||
{
|
{
|
||||||
this->Impl->ExtraVerbose = this->Impl->Verbose;
|
this->Impl->ExtraVerbose = this->Impl->Verbose;
|
||||||
this->Impl->Verbose = true;
|
this->Impl->Verbose = true;
|
||||||
@ -2732,7 +2723,14 @@ int cmCTest::ExecuteTests()
|
|||||||
}
|
}
|
||||||
|
|
||||||
handler.SetVerbose(this->Impl->Verbose);
|
handler.SetVerbose(this->Impl->Verbose);
|
||||||
if (handler.ProcessHandler() < 0) {
|
|
||||||
|
cmInstrumentation instrumentation(this->GetBinaryDir());
|
||||||
|
std::function<int()> 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");
|
cmCTestLog(this, ERROR_MESSAGE, "Errors while running CTest\n");
|
||||||
if (!this->Impl->OutputTestOutputOnTestFailure) {
|
if (!this->Impl->OutputTestOutputOnTestFailure) {
|
||||||
std::string const lastTestLog =
|
std::string const lastTestLog =
|
||||||
|
@ -480,7 +480,7 @@ private:
|
|||||||
|
|
||||||
int RunCMakeAndTest();
|
int RunCMakeAndTest();
|
||||||
int RunScripts(std::vector<std::pair<std::string, bool>> const& scripts);
|
int RunScripts(std::vector<std::pair<std::string, bool>> const& scripts);
|
||||||
int ExecuteTests();
|
int ExecuteTests(std::vector<std::string> const& args);
|
||||||
|
|
||||||
struct Private;
|
struct Private;
|
||||||
std::unique_ptr<Private> Impl;
|
std::unique_ptr<Private> Impl;
|
||||||
|
@ -3720,7 +3720,8 @@ std::vector<std::string> cmake::GetDebugConfigs()
|
|||||||
int cmake::Build(int jobs, std::string dir, std::vector<std::string> targets,
|
int cmake::Build(int jobs, std::string dir, std::vector<std::string> targets,
|
||||||
std::string config, std::vector<std::string> nativeOptions,
|
std::string config, std::vector<std::string> nativeOptions,
|
||||||
cmBuildOptions& buildOptions, bool verbose,
|
cmBuildOptions& buildOptions, bool verbose,
|
||||||
std::string const& presetName, bool listPresets)
|
std::string const& presetName, bool listPresets,
|
||||||
|
std::vector<std::string> const& args)
|
||||||
{
|
{
|
||||||
this->SetHomeDirectory("");
|
this->SetHomeDirectory("");
|
||||||
this->SetHomeOutputDirectory("");
|
this->SetHomeOutputDirectory("");
|
||||||
@ -3958,16 +3959,39 @@ int cmake::Build(int jobs, std::string dir, std::vector<std::string> targets,
|
|||||||
return 1;
|
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);
|
this->GlobalGenerator->PrintBuildCommandAdvice(std::cerr, jobs);
|
||||||
std::stringstream ostr;
|
std::stringstream ostr;
|
||||||
// `cmGlobalGenerator::Build` logs metadata about what directory and commands
|
// `cmGlobalGenerator::Build` logs metadata about what directory and commands
|
||||||
// are being executed to the `output` parameter. If CMake is verbose, print
|
// are being executed to the `output` parameter. If CMake is verbose, print
|
||||||
// this out.
|
// this out.
|
||||||
std::ostream& verbose_ostr = verbose ? std::cout : ostr;
|
std::ostream& verbose_ostr = verbose ? std::cout : ostr;
|
||||||
int buildresult = this->GlobalGenerator->Build(
|
std::function<int()> doBuild = [this, jobs, dir, projName, targets,
|
||||||
jobs, "", dir, projName, targets, verbose_ostr, "", config, buildOptions,
|
&verbose_ostr, config, buildOptions, verbose,
|
||||||
verbose, cmDuration::zero(), cmSystemTools::OUTPUT_PASSTHROUGH,
|
nativeOptions]() {
|
||||||
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;
|
return buildresult;
|
||||||
}
|
}
|
||||||
|
@ -640,7 +640,8 @@ public:
|
|||||||
int Build(int jobs, std::string dir, std::vector<std::string> targets,
|
int Build(int jobs, std::string dir, std::vector<std::string> targets,
|
||||||
std::string config, std::vector<std::string> nativeOptions,
|
std::string config, std::vector<std::string> nativeOptions,
|
||||||
cmBuildOptions& buildOptions, bool verbose,
|
cmBuildOptions& buildOptions, bool verbose,
|
||||||
std::string const& presetName, bool listPresets);
|
std::string const& presetName, bool listPresets,
|
||||||
|
std::vector<std::string> const& args);
|
||||||
|
|
||||||
//! run the --open option
|
//! run the --open option
|
||||||
bool Open(std::string const& dir, bool dryRun);
|
bool Open(std::string const& dir, bool dryRun);
|
||||||
|
@ -705,27 +705,12 @@ int do_build(int ac, char const* const* av)
|
|||||||
cmakemainProgressCallback(msg, prog, &cm);
|
cmakemainProgressCallback(msg, prog, &cm);
|
||||||
});
|
});
|
||||||
|
|
||||||
cmInstrumentation instrumentation(dir);
|
|
||||||
if (!instrumentation.errorMsg.empty()) {
|
|
||||||
cmSystemTools::Error(instrumentation.errorMsg);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
cmBuildOptions buildOptions(cleanFirst, false, resolveMode);
|
cmBuildOptions buildOptions(cleanFirst, false, resolveMode);
|
||||||
std::function<int()> 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<std::string> cmd;
|
std::vector<std::string> cmd;
|
||||||
cm::append(cmd, av, av + ac);
|
cm::append(cmd, av, av + ac);
|
||||||
int ret = instrumentation.InstrumentCommand("cmakeBuild", cmd, doBuild);
|
return cm.Build(jobs, dir, std::move(targets), std::move(config),
|
||||||
instrumentation.CollectTimingData(
|
std::move(nativeOptions), buildOptions, verbose, presetName,
|
||||||
cmInstrumentationQuery::Hook::PostCMakeBuild);
|
listPresets, cmd);
|
||||||
return ret;
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,6 +107,15 @@ foreach(snippet IN LISTS snippets)
|
|||||||
snippet_error(${snippet} "Unexpected config: ${config}")
|
snippet_error(${snippet} "Unexpected config: ${config}")
|
||||||
endif()
|
endif()
|
||||||
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()
|
endforeach()
|
||||||
|
|
||||||
# Verify that listed snippets match expected roles
|
# Verify that listed snippets match expected roles
|
||||||
|
Loading…
Reference in New Issue
Block a user