ConfigureLog: De-duplicate event backtrace and check key generation

All event kinds have these fields, so centralize their implementation.
This commit is contained in:
Brad King
2023-01-30 10:37:33 -05:00
parent e86bebfd14
commit 0a48d8fe5c
5 changed files with 10 additions and 14 deletions

View File

@@ -136,7 +136,7 @@ void cmConfigureLog::EndObject()
--this->Indent;
}
void cmConfigureLog::BeginEvent(std::string const& kind)
void cmConfigureLog::BeginEvent(std::string const& kind, cmMakefile const& mf)
{
this->EnsureInit();
@@ -146,6 +146,8 @@ void cmConfigureLog::BeginEvent(std::string const& kind)
++this->Indent;
this->WriteValue("kind"_s, kind);
this->WriteBacktrace(mf);
this->WriteChecks(mf);
}
void cmConfigureLog::EndEvent()

View File

@@ -28,12 +28,9 @@ public:
list is enabled. */
bool IsAnyLogVersionEnabled(std::vector<unsigned long> const& v) const;
void WriteBacktrace(cmMakefile const& mf);
void WriteChecks(cmMakefile const& mf);
void EnsureInit();
void BeginEvent(std::string const& kind);
void BeginEvent(std::string const& kind, cmMakefile const& mf);
void EndEvent();
void BeginObject(cm::string_view key);
@@ -63,6 +60,9 @@ private:
std::unique_ptr<Json::StreamWriter> Encoder;
void WriteBacktrace(cmMakefile const& mf);
void WriteChecks(cmMakefile const& mf);
cmsys::ofstream& BeginLine();
void EndLine();
void WriteEscape(unsigned char c);

View File

@@ -74,9 +74,7 @@ void WriteMessageEvent(cmConfigureLog& log, cmMakefile const& mf,
static const std::vector<unsigned long> LogVersionsWithMessageV1{ 1 };
if (log.IsAnyLogVersionEnabled(LogVersionsWithMessageV1)) {
log.BeginEvent("message-v1");
log.WriteBacktrace(mf);
log.WriteChecks(mf);
log.BeginEvent("message-v1", mf);
log.WriteLiteralTextBlock("message"_s, message);
log.EndEvent();
}

View File

@@ -25,9 +25,7 @@ void WriteTryCompileEvent(cmConfigureLog& log, cmMakefile const& mf,
static const std::vector<unsigned long> LogVersionsWithTryCompileV1{ 1 };
if (log.IsAnyLogVersionEnabled(LogVersionsWithTryCompileV1)) {
log.BeginEvent("try_compile-v1");
log.WriteBacktrace(mf);
log.WriteChecks(mf);
log.BeginEvent("try_compile-v1", mf);
cmCoreTryCompile::WriteTryCompileEventFields(log, compileResult);
log.EndEvent();
}

View File

@@ -44,9 +44,7 @@ void WriteTryRunEvent(cmConfigureLog& log, cmMakefile const& mf,
static const std::vector<unsigned long> LogVersionsWithTryRunV1{ 1 };
if (log.IsAnyLogVersionEnabled(LogVersionsWithTryRunV1)) {
log.BeginEvent("try_run-v1");
log.WriteBacktrace(mf);
log.WriteChecks(mf);
log.BeginEvent("try_run-v1", mf);
cmCoreTryCompile::WriteTryCompileEventFields(log, compileResult);
log.BeginObject("runResult"_s);