summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2023-01-17 14:26:40 (GMT)
committerKitware Robot <kwrobot@kitware.com>2023-01-17 14:26:50 (GMT)
commit45f86b9990e3ac7e9ec5909253275dbf2728bccc (patch)
treed6efcff17db9cd192d0b38442a0e7e0f5bb9d358 /Source
parentdd18be5ebf6486486a272f47df3318d1db3a03cc (diff)
parent48292c8624b901a842b6d4f8a88ca00f898e5639 (diff)
downloadCMake-45f86b9990e3ac7e9ec5909253275dbf2728bccc.zip
CMake-45f86b9990e3ac7e9ec5909253275dbf2728bccc.tar.gz
CMake-45f86b9990e3ac7e9ec5909253275dbf2728bccc.tar.bz2
Merge topic 'configure-log'
48292c8624 try_compile: Record stack of in-progess checks in configure log d4bf7d80c6 try_compile: Add a NO_LOG option to skip recording in the configure log 9d9e8450a8 try_compile: Add optional LOG_DESCRIPTION to record in configure log 65ed5c2ca8 try_compile: Report underlying error when COPY_FILE fails 0418efb7ad Tests: Add explicit ConfigureLog case to RunCMake.try_compile 189557bd74 cmake: Make entire in-progress check stack available internally 96ce3581ab Help: Clarify backtrace order in cmake-configure-log(7) Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: buildbot <buildbot@kitware.com> Merge-request: !8072
Diffstat (limited to 'Source')
-rw-r--r--Source/cmConfigureLog.cxx16
-rw-r--r--Source/cmConfigureLog.h1
-rw-r--r--Source/cmCoreTryCompile.cxx44
-rw-r--r--Source/cmCoreTryCompile.h4
-rw-r--r--Source/cmTryCompileCommand.cxx8
-rw-r--r--Source/cmTryRunCommand.cxx3
-rw-r--r--Source/cmake.h13
7 files changed, 68 insertions, 21 deletions
diff --git a/Source/cmConfigureLog.cxx b/Source/cmConfigureLog.cxx
index c2a5b5e..1b00b4f 100644
--- a/Source/cmConfigureLog.cxx
+++ b/Source/cmConfigureLog.cxx
@@ -17,6 +17,7 @@
#include "cmListFileCache.h"
#include "cmMakefile.h"
+#include "cmRange.h"
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
#include "cmake.h"
@@ -78,6 +79,21 @@ void cmConfigureLog::WriteBacktrace(cmMakefile const& mf)
this->WriteValue("backtrace"_s, backtrace);
}
+void cmConfigureLog::WriteChecks(cmMakefile const& mf)
+{
+ if (!mf.GetCMakeInstance()->HasCheckInProgress()) {
+ return;
+ }
+ this->BeginObject("checks"_s);
+ for (auto const& value :
+ cmReverseRange(mf.GetCMakeInstance()->GetCheckInProgressMessages())) {
+ this->BeginLine() << "- ";
+ this->Encoder->write(value, &this->Stream);
+ this->EndLine();
+ }
+ this->EndObject();
+}
+
void cmConfigureLog::EnsureInit()
{
if (this->Opened) {
diff --git a/Source/cmConfigureLog.h b/Source/cmConfigureLog.h
index 9caac66..d672445 100644
--- a/Source/cmConfigureLog.h
+++ b/Source/cmConfigureLog.h
@@ -29,6 +29,7 @@ public:
bool IsAnyLogVersionEnabled(std::vector<unsigned long> const& v) const;
void WriteBacktrace(cmMakefile const& mf);
+ void WriteChecks(cmMakefile const& mf);
void EnsureInit();
diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx
index 2a4ea80..2084b33 100644
--- a/Source/cmCoreTryCompile.cxx
+++ b/Source/cmCoreTryCompile.cxx
@@ -151,7 +151,9 @@ cmArgumentParser<Arguments> makeTryRunParser(
auto const TryCompileBaseArgParser =
cmArgumentParser<Arguments>{}
.Bind(0, &Arguments::CompileResultVariable)
+ .Bind("LOG_DESCRIPTION"_s, &Arguments::LogDescription)
.Bind("NO_CACHE"_s, &Arguments::NoCache)
+ .Bind("NO_LOG"_s, &Arguments::NoLog)
.Bind("CMAKE_FLAGS"_s, &Arguments::CMakeFlags)
.Bind("__CMAKE_INTERNAL"_s, &Arguments::CMakeInternal)
/* keep semicolon on own line */;
@@ -1099,23 +1101,35 @@ cm::optional<cmTryCompileResult> cmCoreTryCompile::TryCompileCode(
if ((res == 0) && arguments.CopyFileTo) {
std::string const& copyFile = *arguments.CopyFileTo;
- if (this->OutputFile.empty() ||
- !cmSystemTools::CopyFileAlways(this->OutputFile, copyFile)) {
- std::ostringstream emsg;
+ cmsys::SystemTools::CopyStatus status =
+ cmSystemTools::CopyFileAlways(this->OutputFile, copyFile);
+ if (!status) {
+ std::string err = status.GetString();
+ switch (status.Path) {
+ case cmsys::SystemTools::CopyStatus::SourcePath:
+ err = cmStrCat(err, " (input)");
+ break;
+ case cmsys::SystemTools::CopyStatus::DestPath:
+ err = cmStrCat(err, " (output)");
+ break;
+ default:
+ break;
+ }
/* clang-format off */
- emsg << "Cannot copy output executable\n"
- << " '" << this->OutputFile << "'\n"
- << "to destination specified by COPY_FILE:\n"
- << " '" << copyFile << "'\n";
+ err = cmStrCat(
+ "Cannot copy output executable\n",
+ " '", this->OutputFile, "'\n",
+ "to destination specified by COPY_FILE:\n",
+ " '", copyFile, "'\n",
+ "because:\n",
+ " ", err, "\n",
+ this->FindErrorMessage);
/* clang-format on */
- if (!this->FindErrorMessage.empty()) {
- emsg << this->FindErrorMessage;
- }
if (!arguments.CopyFileError) {
- this->Makefile->IssueMessage(MessageType::FATAL_ERROR, emsg.str());
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR, err);
return cm::nullopt;
}
- copyFileErrorMessage = emsg.str();
+ copyFileErrorMessage = std::move(err);
}
}
@@ -1126,6 +1140,9 @@ cm::optional<cmTryCompileResult> cmCoreTryCompile::TryCompileCode(
}
cmTryCompileResult result;
+ if (arguments.LogDescription) {
+ result.LogDescription = *arguments.LogDescription;
+ }
result.SourceDirectory = sourceDirectory;
result.BinaryDirectory = this->BinaryDirectory;
result.Variable = *arguments.CompileResultVariable;
@@ -1278,6 +1295,9 @@ void cmCoreTryCompile::WriteTryCompileEventFields(
cmConfigureLog& log, cmTryCompileResult const& compileResult)
{
#ifndef CMAKE_BOOTSTRAP
+ if (compileResult.LogDescription) {
+ log.WriteValue("description"_s, *compileResult.LogDescription);
+ }
log.BeginObject("directories"_s);
log.WriteValue("source"_s, compileResult.SourceDirectory);
log.WriteValue("binary"_s, compileResult.BinaryDirectory);
diff --git a/Source/cmCoreTryCompile.h b/Source/cmCoreTryCompile.h
index 6d29586..1ec4405 100644
--- a/Source/cmCoreTryCompile.h
+++ b/Source/cmCoreTryCompile.h
@@ -21,6 +21,8 @@ class cmRange;
struct cmTryCompileResult
{
+ cm::optional<std::string> LogDescription;
+
std::string SourceDirectory;
std::string BinaryDirectory;
@@ -71,7 +73,9 @@ public:
cm::optional<std::string> OutputVariable;
cm::optional<std::string> CopyFileTo;
cm::optional<std::string> CopyFileError;
+ cm::optional<ArgumentParser::NonEmpty<std::string>> LogDescription;
bool NoCache = false;
+ bool NoLog = false;
// Argument for try_run only.
// Keep in sync with warnings in cmCoreTryCompile::ParseArgs.
diff --git a/Source/cmTryCompileCommand.cxx b/Source/cmTryCompileCommand.cxx
index c70c03e..789ffe9 100644
--- a/Source/cmTryCompileCommand.cxx
+++ b/Source/cmTryCompileCommand.cxx
@@ -27,6 +27,7 @@ void WriteTryCompileEvent(cmConfigureLog& log, cmMakefile const& mf,
if (log.IsAnyLogVersionEnabled(LogVersionsWithTryCompileV1)) {
log.BeginEvent("try_compile-v1");
log.WriteBacktrace(mf);
+ log.WriteChecks(mf);
cmCoreTryCompile::WriteTryCompileEventFields(log, compileResult);
log.EndEvent();
}
@@ -81,14 +82,15 @@ bool cmTryCompileCommand(std::vector<std::string> const& args,
return true;
}
- if (cm::optional<cmTryCompileResult> compileResult =
- tc.TryCompileCode(arguments, targetType)) {
+ cm::optional<cmTryCompileResult> compileResult =
+ tc.TryCompileCode(arguments, targetType);
#ifndef CMAKE_BOOTSTRAP
+ if (compileResult && !arguments.NoLog) {
if (cmConfigureLog* log = mf.GetCMakeInstance()->GetConfigureLog()) {
WriteTryCompileEvent(*log, mf, *compileResult);
}
-#endif
}
+#endif
// if They specified clean then we clean up what we can
if (tc.SrcFileSignature) {
diff --git a/Source/cmTryRunCommand.cxx b/Source/cmTryRunCommand.cxx
index ef59c32..21bd95a 100644
--- a/Source/cmTryRunCommand.cxx
+++ b/Source/cmTryRunCommand.cxx
@@ -46,6 +46,7 @@ void WriteTryRunEvent(cmConfigureLog& log, cmMakefile const& mf,
if (log.IsAnyLogVersionEnabled(LogVersionsWithTryRunV1)) {
log.BeginEvent("try_run-v1");
log.WriteBacktrace(mf);
+ log.WriteChecks(mf);
cmCoreTryCompile::WriteTryCompileEventFields(log, compileResult);
log.BeginObject("runResult"_s);
@@ -246,7 +247,7 @@ bool TryRunCommandImpl::TryRunCode(std::vector<std::string> const& argv)
}
#ifndef CMAKE_BOOTSTRAP
- if (compileResult) {
+ if (compileResult && !arguments.NoLog) {
cmMakefile const& mf = *(this->Makefile);
if (cmConfigureLog* log = mf.GetCMakeInstance()->GetConfigureLog()) {
WriteTryRunEvent(*log, mf, *compileResult, runResult);
diff --git a/Source/cmake.h b/Source/cmake.h
index 10db87d..d1f388a 100644
--- a/Source/cmake.h
+++ b/Source/cmake.h
@@ -9,7 +9,6 @@
#include <map>
#include <memory>
#include <set>
-#include <stack>
#include <string>
#include <unordered_set>
#include <utility>
@@ -472,13 +471,17 @@ public:
}
std::string GetTopCheckInProgressMessage()
{
- auto message = this->CheckInProgressMessages.top();
- this->CheckInProgressMessages.pop();
+ auto message = this->CheckInProgressMessages.back();
+ this->CheckInProgressMessages.pop_back();
return message;
}
void PushCheckInProgressMessage(std::string message)
{
- this->CheckInProgressMessages.emplace(std::move(message));
+ this->CheckInProgressMessages.emplace_back(std::move(message));
+ }
+ std::vector<std::string> const& GetCheckInProgressMessages() const
+ {
+ return this->CheckInProgressMessages;
}
//! Should `message` command display context.
@@ -773,7 +776,7 @@ private:
bool LogLevelWasSetViaCLI = false;
bool LogContext = false;
- std::stack<std::string> CheckInProgressMessages;
+ std::vector<std::string> CheckInProgressMessages;
std::unique_ptr<cmGlobalGenerator> GlobalGenerator;