diff options
author | Brad King <brad.king@kitware.com> | 2019-08-20 13:18:41 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2019-08-20 13:20:49 (GMT) |
commit | a0c8405d681d504f5d96489c2b5d44f10a29c6ed (patch) | |
tree | 260f79572b035b6791aa3d2480e729d6fffc0da9 /Source | |
parent | b80417f0fd1491d1c0f5d57019b47d4c13729545 (diff) | |
parent | 3c94069660112f841df3bae66891e05bfc7bad00 (diff) | |
download | CMake-a0c8405d681d504f5d96489c2b5d44f10a29c6ed.zip CMake-a0c8405d681d504f5d96489c2b5d44f10a29c6ed.tar.gz CMake-a0c8405d681d504f5d96489c2b5d44f10a29c6ed.tar.bz2 |
Merge topic 'trace-redirect'
3c94069660 Add --trace-redirect parameter to redirect trace output to a file
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !3645
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmMakefile.cxx | 9 | ||||
-rw-r--r-- | Source/cmake.cxx | 20 | ||||
-rw-r--r-- | Source/cmake.h | 5 | ||||
-rw-r--r-- | Source/cmakemain.cxx | 2 |
4 files changed, 35 insertions, 1 deletions
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 992fc1b..3c1bc38 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -23,6 +23,7 @@ #include "cmExpandedCommandArgument.h" // IWYU pragma: keep #include "cmFileLockPool.h" #include "cmFunctionBlocker.h" +#include "cmGeneratedFileStream.h" #include "cmGeneratorExpression.h" #include "cmGeneratorExpressionEvaluationFile.h" #include "cmGlobalGenerator.h" @@ -321,7 +322,13 @@ void cmMakefile::PrintCommandTrace(const cmListFileFunction& lff) const msg << " "; } msg << ")"; - cmSystemTools::Message(msg.str()); + + auto& f = this->GetCMakeInstance()->GetTraceFile(); + if (f) { + f << msg.str() << '\n'; + } else { + cmSystemTools::Message(msg.str()); + } } // Helper class to make sure the call stack is valid. diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 1625931..4ed17a3 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -140,6 +140,7 @@ cmake::cmake(Role role, cmState::Mode mode) , State(cm::make_unique<cmState>()) , Messenger(cm::make_unique<cmMessenger>()) { + this->TraceFile.close(); this->State->SetMode(mode); this->CurrentSnapshot = this->State->CreateBaseSnapshot(); @@ -740,6 +741,11 @@ void cmake::SetArgs(const std::vector<std::string>& args) cmSystemTools::ConvertToUnixSlashes(file); this->AddTraceSource(file); this->SetTrace(true); + } else if (arg.find("--trace-redirect=", 0) == 0) { + std::string file = arg.substr(strlen("--trace-redirect=")); + cmSystemTools::ConvertToUnixSlashes(file); + this->SetTraceFile(file); + this->SetTrace(true); } else if (arg.find("--trace", 0) == 0) { std::cout << "Running with trace output on.\n"; this->SetTrace(true); @@ -870,6 +876,20 @@ cmake::LogLevel cmake::StringToLogLevel(const std::string& levelStr) return (it != levels.cend()) ? it->second : LogLevel::LOG_UNDEFINED; } +void cmake::SetTraceFile(const std::string& file) +{ + this->TraceFile.close(); + this->TraceFile.open(file.c_str()); + if (!this->TraceFile) { + std::stringstream ss; + ss << "Error opening trace file " << file << ": " + << cmSystemTools::GetLastSystemError(); + cmSystemTools::Error(ss.str()); + return; + } + std::cout << "Trace will be written to " << file << "\n"; +} + void cmake::SetDirectoriesFromFile(const std::string& arg) { // Check if the argument refers to a CMakeCache.txt or diff --git a/Source/cmake.h b/Source/cmake.h index 4c73519..081e120 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -13,6 +13,7 @@ #include <unordered_set> #include <vector> +#include "cmGeneratedFileStream.h" #include "cmInstalledFile.h" #include "cmListFileCache.h" #include "cmMessageType.h" @@ -401,6 +402,9 @@ public: { return this->TraceOnlyThisSources; } + cmGeneratedFileStream& GetTraceFile() { return this->TraceFile; } + void SetTraceFile(std::string const& file); + bool GetWarnUninitialized() { return this->WarnUninitialized; } void SetWarnUninitialized(bool b) { this->WarnUninitialized = b; } bool GetWarnUnused() { return this->WarnUnused; } @@ -547,6 +551,7 @@ private: bool DebugOutput = false; bool Trace = false; bool TraceExpand = false; + cmGeneratedFileStream TraceFile; bool WarnUninitialized = false; bool WarnUnused = false; bool WarnUnusedCli = true; diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx index 74c0d0f..a210959 100644 --- a/Source/cmakemain.cxx +++ b/Source/cmakemain.cxx @@ -80,6 +80,8 @@ const char* cmDocumentationOptions[][2] = { { "--trace-expand", "Put cmake in trace mode with variable expansion." }, { "--trace-source=<file>", "Trace only this CMake file/module. Multiple options allowed." }, + { "--trace-redirect=<file>", + "Redirect trace output to a file instead of stderr." }, { "--warn-uninitialized", "Warn about uninitialized values." }, { "--warn-unused-vars", "Warn about unused variables." }, { "--no-warn-unused-cli", "Don't warn about command line options." }, |