From 0a48d8fe5ccf8a44bcada7b528f4cf4dd591b18e Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 30 Jan 2023 10:37:33 -0500 Subject: ConfigureLog: De-duplicate event backtrace and check key generation All event kinds have these fields, so centralize their implementation. --- Source/cmConfigureLog.cxx | 4 +++- Source/cmConfigureLog.h | 8 ++++---- Source/cmMessageCommand.cxx | 4 +--- Source/cmTryCompileCommand.cxx | 4 +--- Source/cmTryRunCommand.cxx | 4 +--- 5 files changed, 10 insertions(+), 14 deletions(-) diff --git a/Source/cmConfigureLog.cxx b/Source/cmConfigureLog.cxx index 1b00b4f..1cf785a 100644 --- a/Source/cmConfigureLog.cxx +++ b/Source/cmConfigureLog.cxx @@ -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() diff --git a/Source/cmConfigureLog.h b/Source/cmConfigureLog.h index d672445..eb25702 100644 --- a/Source/cmConfigureLog.h +++ b/Source/cmConfigureLog.h @@ -28,12 +28,9 @@ public: list is enabled. */ bool IsAnyLogVersionEnabled(std::vector 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 Encoder; + void WriteBacktrace(cmMakefile const& mf); + void WriteChecks(cmMakefile const& mf); + cmsys::ofstream& BeginLine(); void EndLine(); void WriteEscape(unsigned char c); diff --git a/Source/cmMessageCommand.cxx b/Source/cmMessageCommand.cxx index 205f01f..52373f3 100644 --- a/Source/cmMessageCommand.cxx +++ b/Source/cmMessageCommand.cxx @@ -74,9 +74,7 @@ void WriteMessageEvent(cmConfigureLog& log, cmMakefile const& mf, static const std::vector 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(); } diff --git a/Source/cmTryCompileCommand.cxx b/Source/cmTryCompileCommand.cxx index 789ffe9..d2cc75b 100644 --- a/Source/cmTryCompileCommand.cxx +++ b/Source/cmTryCompileCommand.cxx @@ -25,9 +25,7 @@ void WriteTryCompileEvent(cmConfigureLog& log, cmMakefile const& mf, static const std::vector 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(); } diff --git a/Source/cmTryRunCommand.cxx b/Source/cmTryRunCommand.cxx index 21bd95a..b648d9b 100644 --- a/Source/cmTryRunCommand.cxx +++ b/Source/cmTryRunCommand.cxx @@ -44,9 +44,7 @@ void WriteTryRunEvent(cmConfigureLog& log, cmMakefile const& mf, static const std::vector 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); -- cgit v0.12