message: Add CONFIGURE_LOG mode to record a message in the configure log

Provide a replacement for `file(APPEND .../CMake{Output,Error}.log)`
that records messages in the configure log.

Issue: #23200
This commit is contained in:
Brad King
2023-01-16 14:32:36 -05:00
parent 645671d36f
commit a78cba5197
13 changed files with 164 additions and 1 deletions
+1
View File
@@ -52,6 +52,7 @@ Json::Value ConfigureLog::DumpEventKindNames()
// major version of the configureLog object kind is needed.
Json::Value eventKindNames = Json::arrayValue;
if (this->Version == 1) {
eventKindNames.append("message-v1"); // WriteMessageEvent
eventKindNames.append("try_compile-v1"); // WriteTryCompileEvent
eventKindNames.append("try_run-v1"); // WriteTryRunEvent
}
+28
View File
@@ -8,6 +8,7 @@
#include <cm/string_view>
#include <cmext/string_view>
#include "cmConfigureLog.h"
#include "cmExecutionStatus.h"
#include "cmMakefile.h"
#include "cmMessageType.h"
@@ -64,6 +65,25 @@ void ReportCheckResult(cm::string_view what, std::string result,
}
}
namespace {
#ifndef CMAKE_BOOTSTRAP
void WriteMessageEvent(cmConfigureLog& log, cmMakefile const& mf,
std::string const& message)
{
// Keep in sync with cmFileAPIConfigureLog's DumpEventKindNames.
static const std::vector<unsigned long> LogVersionsWithMessageV1{ 1 };
if (log.IsAnyLogVersionEnabled(LogVersionsWithMessageV1)) {
log.BeginEvent("message-v1");
log.WriteBacktrace(mf);
log.WriteChecks(mf);
log.WriteLiteralTextBlock("message"_s, message);
log.EndEvent();
}
}
#endif
}
} // anonymous namespace
// cmLibraryCommand
@@ -121,6 +141,14 @@ bool cmMessageCommand(std::vector<std::string> const& args,
level = Message::LogLevel::LOG_STATUS;
checkingType = CheckingType::CHECK_FAIL;
++i;
} else if (*i == "CONFIGURE_LOG") {
#ifndef CMAKE_BOOTSTRAP
if (cmConfigureLog* log = mf.GetCMakeInstance()->GetConfigureLog()) {
++i;
WriteMessageEvent(*log, mf, cmJoin(cmMakeRange(i, args.cend()), ""_s));
}
#endif
return true;
} else if (*i == "STATUS") {
level = Message::LogLevel::LOG_STATUS;
++i;