diff options
author | Brad King <brad.king@kitware.com> | 2023-02-01 16:47:26 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2023-02-01 16:47:46 (GMT) |
commit | 8ec1c9ab6a555ad1045c368872f54c3ff31d3ea6 (patch) | |
tree | 35704c91a461029b32411307789d096df0a52a10 /Source | |
parent | e86bebfd146c07d3a5eb34f9f35e133b6c3b805c (diff) | |
parent | 5252c885693ce35467f6c4c7fdc8deb6406df149 (diff) | |
download | CMake-8ec1c9ab6a555ad1045c368872f54c3ff31d3ea6.zip CMake-8ec1c9ab6a555ad1045c368872f54c3ff31d3ea6.tar.gz CMake-8ec1c9ab6a555ad1045c368872f54c3ff31d3ea6.tar.bz2 |
Merge topic 'configure-log'
5252c88569 try_compile: Record propagated CMake variables in configure log
0a48d8fe5c ConfigureLog: De-duplicate event backtrace and check key generation
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !8140
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmConfigureLog.cxx | 28 | ||||
-rw-r--r-- | Source/cmConfigureLog.h | 11 | ||||
-rw-r--r-- | Source/cmCoreTryCompile.cxx | 21 | ||||
-rw-r--r-- | Source/cmCoreTryCompile.h | 1 | ||||
-rw-r--r-- | Source/cmMessageCommand.cxx | 4 | ||||
-rw-r--r-- | Source/cmTryCompileCommand.cxx | 4 | ||||
-rw-r--r-- | Source/cmTryRunCommand.cxx | 4 |
7 files changed, 59 insertions, 14 deletions
diff --git a/Source/cmConfigureLog.cxx b/Source/cmConfigureLog.cxx index 1b00b4f..a6658e2 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() @@ -191,6 +193,30 @@ void cmConfigureLog::WriteValue(cm::string_view key, this->EndObject(); } +void cmConfigureLog::WriteValue(cm::string_view key, + std::map<std::string, std::string> const& map) +{ + static const std::string rawKeyChars = // + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" // + "abcdefghijklmnopqrstuvwxyz" // + "0123456789" // + "-_" // + ; + this->BeginObject(key); + for (auto const& entry : map) { + if (entry.first.find_first_not_of(rawKeyChars) == std::string::npos) { + this->WriteValue(entry.first, entry.second); + } else { + this->BeginLine(); + this->Encoder->write(entry.first, &this->Stream); + this->Stream << ": "; + this->Encoder->write(entry.second, &this->Stream); + this->EndLine(); + } + } + this->EndObject(); +} + void cmConfigureLog::WriteLiteralTextBlock(cm::string_view key, cm::string_view text) { diff --git a/Source/cmConfigureLog.h b/Source/cmConfigureLog.h index d672445..7edc3ed 100644 --- a/Source/cmConfigureLog.h +++ b/Source/cmConfigureLog.h @@ -2,6 +2,7 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #pragma once +#include <map> #include <memory> #include <string> #include <vector> @@ -28,12 +29,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); @@ -45,6 +43,8 @@ public: void WriteValue(cm::string_view key, int value); void WriteValue(cm::string_view key, std::string const& value); void WriteValue(cm::string_view key, std::vector<std::string> const& list); + void WriteValue(cm::string_view key, + std::map<std::string, std::string> const& map); void WriteTextBlock(cm::string_view key, cm::string_view text); void WriteLiteralTextBlock(cm::string_view key, cm::string_view text); @@ -63,6 +63,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); diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx index 618c794..acf1c20 100644 --- a/Source/cmCoreTryCompile.cxx +++ b/Source/cmCoreTryCompile.cxx @@ -471,6 +471,8 @@ cm::optional<cmTryCompileResult> cmCoreTryCompile::TryCompileCode( return cm::nullopt; } + std::map<std::string, std::string> cmakeVariables; + std::string outFileName = this->BinaryDirectory + "/CMakeLists.txt"; // which signature are we using? If we are using var srcfile bindir if (this->SrcFileSignature) { @@ -592,6 +594,7 @@ cm::optional<cmTryCompileResult> cmCoreTryCompile::TryCompileCode( cmVersion::GetPatchVersion(), cmVersion::GetTweakVersion()); if (def) { fprintf(fout, "set(CMAKE_MODULE_PATH \"%s\")\n", def->c_str()); + cmakeVariables.emplace("CMAKE_MODULE_PATH", *def); } /* Set MSVC runtime library policy to match our selection. */ @@ -653,10 +656,12 @@ cm::optional<cmTryCompileResult> cmCoreTryCompile::TryCompileCode( this->Makefile->GetDefinition(rulesOverrideLang)) { fprintf(fout, "set(%s \"%s\")\n", rulesOverrideLang.c_str(), rulesOverridePath->c_str()); + cmakeVariables.emplace(rulesOverrideLang, *rulesOverridePath); } else if (cmValue rulesOverridePath2 = this->Makefile->GetDefinition(rulesOverrideBase)) { fprintf(fout, "set(%s \"%s\")\n", rulesOverrideBase.c_str(), rulesOverridePath2->c_str()); + cmakeVariables.emplace(rulesOverrideBase, *rulesOverridePath2); } } fprintf(fout, "project(CMAKE_TRY_COMPILE%s)\n", projectLangs.c_str()); @@ -687,6 +692,9 @@ cm::optional<cmTryCompileResult> cmCoreTryCompile::TryCompileCode( "set(CMAKE_%s_FLAGS \"${CMAKE_%s_FLAGS}" " ${COMPILE_DEFINITIONS}\")\n", li.c_str(), li.c_str()); + if (flags) { + cmakeVariables.emplace(langFlags, *flags); + } } switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0066)) { case cmPolicies::WARN: @@ -723,6 +731,9 @@ cm::optional<cmTryCompileResult> cmCoreTryCompile::TryCompileCode( cmValue flagsCfg = this->Makefile->GetDefinition(langFlagsCfg); fprintf(fout, "set(%s %s)\n", langFlagsCfg.c_str(), cmOutputConverter::EscapeForCMake(*flagsCfg).c_str()); + if (flagsCfg) { + cmakeVariables.emplace(langFlagsCfg, *flagsCfg); + } } } break; } @@ -757,6 +768,9 @@ cm::optional<cmTryCompileResult> cmCoreTryCompile::TryCompileCode( this->Makefile->GetDefinition("CMAKE_EXE_LINKER_FLAGS"); fprintf(fout, "set(CMAKE_EXE_LINKER_FLAGS %s)\n", cmOutputConverter::EscapeForCMake(*exeLinkFlags).c_str()); + if (exeLinkFlags) { + cmakeVariables.emplace("CMAKE_EXE_LINKER_FLAGS", *exeLinkFlags); + } } break; } @@ -1044,12 +1058,14 @@ cm::optional<cmTryCompileResult> cmCoreTryCompile::TryCompileCode( vars.erase(kCMAKE_OSX_ARCHITECTURES); std::string flag = "-DCMAKE_OSX_ARCHITECTURES=" + *tcArchs; arguments.CMakeFlags.emplace_back(std::move(flag)); + cmakeVariables.emplace("CMAKE_OSX_ARCHITECTURES", *tcArchs); } for (std::string const& var : vars) { if (cmValue val = this->Makefile->GetDefinition(var)) { std::string flag = "-D" + var + "=" + *val; arguments.CMakeFlags.emplace_back(std::move(flag)); + cmakeVariables.emplace(var, *val); } } } @@ -1060,6 +1076,7 @@ cm::optional<cmTryCompileResult> cmCoreTryCompile::TryCompileCode( if (cmValue val = this->Makefile->GetDefinition(var)) { std::string flag = "-D" + var + "=" + "'" + *val + "'"; arguments.CMakeFlags.emplace_back(std::move(flag)); + cmakeVariables.emplace(var, *val); } } } @@ -1145,6 +1162,7 @@ cm::optional<cmTryCompileResult> cmCoreTryCompile::TryCompileCode( if (arguments.LogDescription) { result.LogDescription = *arguments.LogDescription; } + result.CMakeVariables = std::move(cmakeVariables); result.SourceDirectory = sourceDirectory; result.BinaryDirectory = this->BinaryDirectory; result.Variable = *arguments.CompileResultVariable; @@ -1304,6 +1322,9 @@ void cmCoreTryCompile::WriteTryCompileEventFields( log.WriteValue("source"_s, compileResult.SourceDirectory); log.WriteValue("binary"_s, compileResult.BinaryDirectory); log.EndObject(); + if (!compileResult.CMakeVariables.empty()) { + log.WriteValue("cmakeVariables"_s, compileResult.CMakeVariables); + } log.BeginObject("buildResult"_s); log.WriteValue("variable"_s, compileResult.Variable); log.WriteValue("cached"_s, compileResult.VariableCached); diff --git a/Source/cmCoreTryCompile.h b/Source/cmCoreTryCompile.h index 1ec4405..ba38c19 100644 --- a/Source/cmCoreTryCompile.h +++ b/Source/cmCoreTryCompile.h @@ -22,6 +22,7 @@ class cmRange; struct cmTryCompileResult { cm::optional<std::string> LogDescription; + std::map<std::string, std::string> CMakeVariables; std::string SourceDirectory; std::string BinaryDirectory; 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<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(); } 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<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(); } 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<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); |