Răsfoiți Sursa

ConfigureLog: De-duplicate event backtrace and check key generation

All event kinds have these fields, so centralize their implementation.
Brad King 2 ani în urmă
părinte
comite
0a48d8fe5c

+ 3 - 1
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()

+ 4 - 4
Source/cmConfigureLog.h

@@ -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);

+ 1 - 3
Source/cmMessageCommand.cxx

@@ -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();
   }

+ 1 - 3
Source/cmTryCompileCommand.cxx

@@ -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();
   }

+ 1 - 3
Source/cmTryRunCommand.cxx

@@ -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);