mirror of
https://github.com/Kitware/CMake.git
synced 2026-04-24 07:08:38 -05:00
ConfigureLog: Version individual events instead of the whole log
In order to support multiple log versions without buffering the entire log, move versioning to the level of individual events. Multiple versions of an event may then be logged consecutively. Issue: #23200
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include <sstream>
|
||||
#include <utility>
|
||||
|
||||
#include <cmext/algorithm>
|
||||
#include <cmext/string_view>
|
||||
|
||||
#include <cm3p/json/writer.h>
|
||||
@@ -20,9 +21,17 @@
|
||||
#include "cmSystemTools.h"
|
||||
#include "cmake.h"
|
||||
|
||||
cmConfigureLog::cmConfigureLog(std::string logDir)
|
||||
cmConfigureLog::cmConfigureLog(std::string logDir,
|
||||
std::vector<unsigned long> logVersions)
|
||||
: LogDir(std::move(logDir))
|
||||
, LogVersions(std::move(logVersions))
|
||||
{
|
||||
// Always emit events for the latest log version.
|
||||
static const unsigned long LatestLogVersion = 1;
|
||||
if (!cm::contains(this->LogVersions, LatestLogVersion)) {
|
||||
this->LogVersions.emplace_back(LatestLogVersion);
|
||||
}
|
||||
|
||||
Json::StreamWriterBuilder builder;
|
||||
this->Encoder.reset(builder.newStreamWriter());
|
||||
}
|
||||
@@ -35,6 +44,24 @@ cmConfigureLog::~cmConfigureLog()
|
||||
}
|
||||
}
|
||||
|
||||
bool cmConfigureLog::IsAnyLogVersionEnabled(
|
||||
std::vector<unsigned long> const& v) const
|
||||
{
|
||||
// Both input lists are sorted. Look for a matching element.
|
||||
auto i1 = v.cbegin();
|
||||
auto i2 = this->LogVersions.cbegin();
|
||||
while (i1 != v.cend() && i2 != this->LogVersions.cend()) {
|
||||
if (*i1 < *i2) {
|
||||
++i1;
|
||||
} else if (*i2 < *i1) {
|
||||
++i2;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void cmConfigureLog::WriteBacktrace(cmMakefile const& mf)
|
||||
{
|
||||
std::vector<std::string> backtrace;
|
||||
@@ -64,10 +91,6 @@ void cmConfigureLog::EnsureInit()
|
||||
this->Opened = true;
|
||||
|
||||
this->Stream << "\n---\n";
|
||||
this->BeginObject("version"_s);
|
||||
this->WriteValue("major"_s, 1);
|
||||
this->WriteValue("minor"_s, 0);
|
||||
this->EndObject();
|
||||
this->BeginObject("events"_s);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,9 +19,15 @@ class cmMakefile;
|
||||
class cmConfigureLog
|
||||
{
|
||||
public:
|
||||
cmConfigureLog(std::string logDir);
|
||||
/** Construct with the log directory and a sorted list of enabled log
|
||||
versions. The latest log version will be enabled regardless. */
|
||||
cmConfigureLog(std::string logDir, std::vector<unsigned long> logVersions);
|
||||
~cmConfigureLog();
|
||||
|
||||
/** Return true if at least one of the log versions in the given sorted
|
||||
list is enabled. */
|
||||
bool IsAnyLogVersionEnabled(std::vector<unsigned long> const& v) const;
|
||||
|
||||
void WriteBacktrace(cmMakefile const& mf);
|
||||
|
||||
void EnsureInit();
|
||||
@@ -49,6 +55,7 @@ public:
|
||||
|
||||
private:
|
||||
std::string LogDir;
|
||||
std::vector<unsigned long> LogVersions;
|
||||
cmsys::ofstream Stream;
|
||||
unsigned Indent = 0;
|
||||
bool Opened = false;
|
||||
|
||||
@@ -21,10 +21,14 @@ namespace {
|
||||
void WriteTryCompileEvent(cmConfigureLog& log, cmMakefile const& mf,
|
||||
cmTryCompileResult const& compileResult)
|
||||
{
|
||||
log.BeginEvent("try_compile");
|
||||
log.WriteBacktrace(mf);
|
||||
cmCoreTryCompile::WriteTryCompileEventFields(log, compileResult);
|
||||
log.EndEvent();
|
||||
static const std::vector<unsigned long> LogVersionsWithTryCompileV1{ 1 };
|
||||
|
||||
if (log.IsAnyLogVersionEnabled(LogVersionsWithTryCompileV1)) {
|
||||
log.BeginEvent("try_compile-v1");
|
||||
log.WriteBacktrace(mf);
|
||||
cmCoreTryCompile::WriteTryCompileEventFields(log, compileResult);
|
||||
log.EndEvent();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
+23
-19
@@ -40,28 +40,32 @@ void WriteTryRunEvent(cmConfigureLog& log, cmMakefile const& mf,
|
||||
cmTryCompileResult const& compileResult,
|
||||
cmTryRunResult const& runResult)
|
||||
{
|
||||
log.BeginEvent("try_run");
|
||||
log.WriteBacktrace(mf);
|
||||
cmCoreTryCompile::WriteTryCompileEventFields(log, compileResult);
|
||||
static const std::vector<unsigned long> LogVersionsWithTryRunV1{ 1 };
|
||||
|
||||
log.BeginObject("runResult"_s);
|
||||
log.WriteValue("variable"_s, runResult.Variable);
|
||||
log.WriteValue("cached"_s, runResult.VariableCached);
|
||||
if (runResult.Stdout) {
|
||||
log.WriteLiteralTextBlock("stdout"_s, *runResult.Stdout);
|
||||
}
|
||||
if (runResult.Stderr) {
|
||||
log.WriteLiteralTextBlock("stderr"_s, *runResult.Stderr);
|
||||
}
|
||||
if (runResult.ExitCode) {
|
||||
try {
|
||||
log.WriteValue("exitCode"_s, std::stoi(*runResult.ExitCode));
|
||||
} catch (std::invalid_argument const&) {
|
||||
log.WriteValue("exitCode"_s, *runResult.ExitCode);
|
||||
if (log.IsAnyLogVersionEnabled(LogVersionsWithTryRunV1)) {
|
||||
log.BeginEvent("try_run-v1");
|
||||
log.WriteBacktrace(mf);
|
||||
cmCoreTryCompile::WriteTryCompileEventFields(log, compileResult);
|
||||
|
||||
log.BeginObject("runResult"_s);
|
||||
log.WriteValue("variable"_s, runResult.Variable);
|
||||
log.WriteValue("cached"_s, runResult.VariableCached);
|
||||
if (runResult.Stdout) {
|
||||
log.WriteLiteralTextBlock("stdout"_s, *runResult.Stdout);
|
||||
}
|
||||
if (runResult.Stderr) {
|
||||
log.WriteLiteralTextBlock("stderr"_s, *runResult.Stderr);
|
||||
}
|
||||
if (runResult.ExitCode) {
|
||||
try {
|
||||
log.WriteValue("exitCode"_s, std::stoi(*runResult.ExitCode));
|
||||
} catch (std::invalid_argument const&) {
|
||||
log.WriteValue("exitCode"_s, *runResult.ExitCode);
|
||||
}
|
||||
}
|
||||
log.EndObject();
|
||||
log.EndEvent();
|
||||
}
|
||||
log.EndObject();
|
||||
log.EndEvent();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
+2
-1
@@ -2428,7 +2428,8 @@ int cmake::ActualConfigure()
|
||||
if (!this->GetIsInTryCompile()) {
|
||||
this->TruncateOutputLog("CMakeConfigureLog.yaml");
|
||||
this->ConfigureLog = cm::make_unique<cmConfigureLog>(
|
||||
cmStrCat(this->GetHomeOutputDirectory(), "/CMakeFiles"_s));
|
||||
cmStrCat(this->GetHomeOutputDirectory(), "/CMakeFiles"_s),
|
||||
std::vector<unsigned long>());
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user