diff options
author | Daniel Mensinger <daniel@mensinger-ka.de> | 2019-11-30 11:48:26 (GMT) |
---|---|---|
committer | Daniel Mensinger <daniel@mensinger-ka.de> | 2019-12-23 13:05:36 (GMT) |
commit | 482497e0debc3de9f125c8c849a40872971a4a7e (patch) | |
tree | 2ae4aefba1e626668e411c53399cc241662e18d7 /Source/cmMakefile.cxx | |
parent | 10fea25139cc302ef0f0a41aa68b44cda72a4fd2 (diff) | |
download | CMake-482497e0debc3de9f125c8c849a40872971a4a7e.zip CMake-482497e0debc3de9f125c8c849a40872971a4a7e.tar.gz CMake-482497e0debc3de9f125c8c849a40872971a4a7e.tar.bz2 |
trace: Add JSON output format
Add a new `--trace-format=` flag, to enable the new JSON trace
output format. This new format is easier to parse by machines
than the existing format. This new format also removes the
ambiguity of the whitespace in the "old" format (e.g. is that
whitespace part of a file path, or does it seperate arguments)
Diffstat (limited to 'Source/cmMakefile.cxx')
-rw-r--r-- | Source/cmMakefile.cxx | 47 |
1 files changed, 40 insertions, 7 deletions
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 75f00fc..eff7ddc 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -7,6 +7,7 @@ #include <algorithm> #include <cassert> #include <cctype> +#include <cstdint> #include <cstdio> #include <cstdlib> #include <cstring> @@ -20,6 +21,8 @@ #include "cmsys/FStream.hxx" #include "cmsys/RegularExpression.hxx" +#include "cm_jsoncpp_value.h" +#include "cm_jsoncpp_writer.h" #include "cm_sys_stat.h" #include "cmAlgorithms.h" @@ -315,21 +318,51 @@ void cmMakefile::PrintCommandTrace(const cmListFileFunction& lff) const } std::ostringstream msg; - msg << full_path << "(" << lff.Line << "): "; - msg << lff.Name.Original << "("; - bool expand = this->GetCMakeInstance()->GetTraceExpand(); + std::vector<std::string> args; std::string temp; + bool expand = this->GetCMakeInstance()->GetTraceExpand(); + + args.reserve(lff.Arguments.size()); for (cmListFileArgument const& arg : lff.Arguments) { if (expand) { temp = arg.Value; this->ExpandVariablesInString(temp); - msg << temp; + args.push_back(temp); } else { - msg << arg.Value; + args.push_back(arg.Value); + } + } + + switch (this->GetCMakeInstance()->GetTraceFormat()) { + case cmake::TraceFormat::TRACE_JSON_V1: { +#ifndef CMAKE_BOOTSTRAP + Json::Value val; + Json::StreamWriterBuilder builder; + builder["indentation"] = ""; + val["file"] = full_path; + val["line"] = static_cast<std::int64_t>(lff.Line); + val["cmd"] = lff.Name.Original; + val["args"] = Json::Value(Json::arrayValue); + for (std::string const& arg : args) { + val["args"].append(arg); + } + msg << Json::writeString(builder, val); +#endif + break; } - msg << " "; + case cmake::TraceFormat::TRACE_HUMAN: + msg << full_path << "(" << lff.Line << "): "; + msg << lff.Name.Original << "("; + + for (std::string const& arg : args) { + msg << arg << " "; + } + msg << ")"; + break; + case cmake::TraceFormat::TRACE_UNDEFINED: + msg << "INTERNAL ERROR: Trace format is TRACE_UNDEFINED"; + break; } - msg << ")"; auto& f = this->GetCMakeInstance()->GetTraceFile(); if (f) { |