summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/cmCMakePresetErrors.h3
-rw-r--r--Source/cmCMakePresetsGraph.h13
-rw-r--r--Source/cmCMakePresetsGraphReadJSON.cxx10
-rw-r--r--Source/cmCMakePresetsGraphReadJSONConfigurePresets.cxx68
-rw-r--r--Source/cmMakefile.cxx8
-rw-r--r--Source/cmStateTypes.h11
-rw-r--r--Source/cmake.cxx104
-rw-r--r--Source/cmake.h10
8 files changed, 181 insertions, 46 deletions
diff --git a/Source/cmCMakePresetErrors.h b/Source/cmCMakePresetErrors.h
index c669cb1..0db391e 100644
--- a/Source/cmCMakePresetErrors.h
+++ b/Source/cmCMakePresetErrors.h
@@ -176,6 +176,9 @@ const auto CTEST_JUNIT_UNSUPPORTED = [](cmJSONState* state) -> void {
state->AddError(
"File version must be 6 or higher for CTest JUnit output support");
};
+const auto TRACE_UNSUPPORTED = [](cmJSONState* state) -> void {
+ state->AddError("File version must be 7 or higher for trace preset support");
+};
const auto UNRECOGNIZED_CMAKE_VERSION = [](const std::string& version,
int current, int required) {
return [version, current, required](const Json::Value* value,
diff --git a/Source/cmCMakePresetsGraph.h b/Source/cmCMakePresetsGraph.h
index 9d7e5fa..7844624 100644
--- a/Source/cmCMakePresetsGraph.h
+++ b/Source/cmCMakePresetsGraph.h
@@ -15,6 +15,7 @@
#include <cm/optional>
#include "cmJSONState.h"
+#include "cmStateTypes.h"
#include "CTest/cmCTestTypes.h"
@@ -32,6 +33,13 @@ public:
External,
};
+ enum class TraceEnableMode
+ {
+ Disable,
+ Default,
+ Expand,
+ };
+
class CacheVariable
{
public:
@@ -129,6 +137,11 @@ public:
cm::optional<bool> DebugTryCompile;
cm::optional<bool> DebugFind;
+ cm::optional<TraceEnableMode> TraceMode;
+ cm::optional<cmTraceEnums::TraceOutputFormat> TraceFormat;
+ std::vector<std::string> TraceSource;
+ std::string TraceRedirect;
+
bool VisitPresetInherit(const Preset& parent) override;
bool VisitPresetBeforeInherit() override;
bool VisitPresetAfterInherit(int version, cmJSONState* state) override;
diff --git a/Source/cmCMakePresetsGraphReadJSON.cxx b/Source/cmCMakePresetsGraphReadJSON.cxx
index 93c5f7d..bc829f3 100644
--- a/Source/cmCMakePresetsGraphReadJSON.cxx
+++ b/Source/cmCMakePresetsGraphReadJSON.cxx
@@ -35,7 +35,7 @@ using ArchToolsetStrategy = cmCMakePresetsGraph::ArchToolsetStrategy;
using JSONHelperBuilder = cmJSONHelperBuilder;
constexpr int MIN_VERSION = 1;
-constexpr int MAX_VERSION = 6;
+constexpr int MAX_VERSION = 7;
struct CMakeVersion
{
@@ -557,6 +557,14 @@ bool cmCMakePresetsGraph::ReadJSONFile(const std::string& filename,
return false;
}
+ // Support for trace presets added in version 7.
+ if (v < 7 &&
+ (preset.TraceMode.has_value() || preset.TraceFormat.has_value() ||
+ !preset.TraceRedirect.empty() || !preset.TraceSource.empty())) {
+ cmCMakePresetErrors::TRACE_UNSUPPORTED(&this->parseState);
+ return false;
+ }
+
this->ConfigurePresetOrder.push_back(preset.Name);
}
diff --git a/Source/cmCMakePresetsGraphReadJSONConfigurePresets.cxx b/Source/cmCMakePresetsGraphReadJSONConfigurePresets.cxx
index a1774be..66ec6a4 100644
--- a/Source/cmCMakePresetsGraphReadJSONConfigurePresets.cxx
+++ b/Source/cmCMakePresetsGraphReadJSONConfigurePresets.cxx
@@ -17,12 +17,15 @@
#include "cmCMakePresetsGraphInternal.h"
#include "cmJSONHelpers.h"
#include "cmJSONState.h"
+#include "cmStateTypes.h"
namespace {
using CacheVariable = cmCMakePresetsGraph::CacheVariable;
using ConfigurePreset = cmCMakePresetsGraph::ConfigurePreset;
using ArchToolsetStrategy = cmCMakePresetsGraph::ArchToolsetStrategy;
using JSONHelperBuilder = cmJSONHelperBuilder;
+using TraceEnableMode = cmCMakePresetsGraph::TraceEnableMode;
+using TraceOutputFormat = cmTraceEnums::TraceOutputFormat;
bool ArchToolsetStrategyHelper(cm::optional<ArchToolsetStrategy>& out,
const Json::Value* value, cmJSONState* state)
@@ -91,6 +94,58 @@ auto const ArchitectureHelper = ArchToolsetHelper(
auto const ToolsetHelper = ArchToolsetHelper(
&ConfigurePreset::Toolset, &ConfigurePreset::ToolsetStrategy);
+bool TraceEnableModeHelper(cm::optional<TraceEnableMode>& out,
+ const Json::Value* value, cmJSONState* state)
+{
+ if (!value) {
+ out = cm::nullopt;
+ return true;
+ }
+
+ if (!value->isString()) {
+ cmCMakePresetErrors::INVALID_PRESET(value, state);
+ return false;
+ }
+
+ if (value->asString() == "on") {
+ out = TraceEnableMode::Default;
+ } else if (value->asString() == "off") {
+ out = TraceEnableMode::Disable;
+ } else if (value->asString() == "expand") {
+ out = TraceEnableMode::Expand;
+ } else {
+ cmCMakePresetErrors::INVALID_PRESET(value, state);
+ return false;
+ }
+
+ return true;
+}
+
+bool TraceOutputFormatHelper(cm::optional<TraceOutputFormat>& out,
+ const Json::Value* value, cmJSONState* state)
+{
+ if (!value) {
+ out = cm::nullopt;
+ return true;
+ }
+
+ if (!value->isString()) {
+ cmCMakePresetErrors::INVALID_PRESET(value, state);
+ return false;
+ }
+
+ if (value->asString() == "human") {
+ out = TraceOutputFormat::Human;
+ } else if (value->asString() == "json-v1") {
+ out = TraceOutputFormat::JSONv1;
+ } else {
+ cmCMakePresetErrors::INVALID_PRESET(value, state);
+ return false;
+ }
+
+ return true;
+}
+
auto const VariableStringHelper = JSONHelperBuilder::String();
bool VariableValueHelper(std::string& out, const Json::Value* value,
@@ -180,6 +235,18 @@ auto const PresetDebugHelper =
.Bind("find"_s, &ConfigurePreset::DebugFind,
cmCMakePresetsGraphInternal::PresetOptionalBoolHelper, false);
+auto const PresetTraceHelper =
+ JSONHelperBuilder::Object<ConfigurePreset>(
+ cmCMakePresetErrors::INVALID_PRESET_OBJECT, false)
+ .Bind("mode"_s, &ConfigurePreset::TraceMode, TraceEnableModeHelper, false)
+ .Bind("format"_s, &ConfigurePreset::TraceFormat, TraceOutputFormatHelper,
+ false)
+ .Bind("source"_s, &ConfigurePreset::TraceSource,
+ cmCMakePresetsGraphInternal::PresetVectorOneOrMoreStringHelper,
+ false)
+ .Bind("redirect"_s, &ConfigurePreset::TraceRedirect,
+ cmCMakePresetsGraphInternal::PresetStringHelper, false);
+
auto const ConfigurePresetHelper =
JSONHelperBuilder::Object<ConfigurePreset>(
cmCMakePresetErrors::INVALID_PRESET_OBJECT, false)
@@ -217,6 +284,7 @@ auto const ConfigurePresetHelper =
.Bind("warnings"_s, PresetWarningsHelper, false)
.Bind("errors"_s, PresetErrorsHelper, false)
.Bind("debug"_s, PresetDebugHelper, false)
+ .Bind("trace"_s, PresetTraceHelper, false)
.Bind("condition"_s, &ConfigurePreset::ConditionEvaluator,
cmCMakePresetsGraphInternal::PresetConditionHelper, false);
}
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index fc82c14..3a69b2e 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -340,7 +340,7 @@ void cmMakefile::PrintCommandTrace(cmListFileFunction const& lff,
cm::optional<std::string> const& deferId = bt.Top().DeferId;
switch (this->GetCMakeInstance()->GetTraceFormat()) {
- case cmake::TraceFormat::TRACE_JSON_V1: {
+ case cmake::TraceFormat::JSONv1: {
#ifndef CMAKE_BOOTSTRAP
Json::Value val;
Json::StreamWriterBuilder builder;
@@ -367,7 +367,7 @@ void cmMakefile::PrintCommandTrace(cmListFileFunction const& lff,
#endif
break;
}
- case cmake::TraceFormat::TRACE_HUMAN:
+ case cmake::TraceFormat::Human:
msg << full_path << "(" << lff.Line() << "):";
if (deferId) {
msg << "DEFERRED:" << *deferId << ":";
@@ -379,8 +379,8 @@ void cmMakefile::PrintCommandTrace(cmListFileFunction const& lff,
}
msg << ")";
break;
- case cmake::TraceFormat::TRACE_UNDEFINED:
- msg << "INTERNAL ERROR: Trace format is TRACE_UNDEFINED";
+ case cmake::TraceFormat::Undefined:
+ msg << "INTERNAL ERROR: Trace format is Undefined";
break;
}
diff --git a/Source/cmStateTypes.h b/Source/cmStateTypes.h
index 010d7e3..24b809b 100644
--- a/Source/cmStateTypes.h
+++ b/Source/cmStateTypes.h
@@ -60,3 +60,14 @@ enum ArtifactType
ImportLibraryArtifact
};
}
+
+namespace cmTraceEnums {
+
+/** \brief Define supported trace formats **/
+enum class TraceOutputFormat
+{
+ Undefined,
+ Human,
+ JSONv1
+};
+};
diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index f943415..8dee5cc 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -1143,49 +1143,64 @@ void cmake::SetArgs(const std::vector<std::string>& args)
std::cout << ".\n";
return true;
} },
- CommandArgument{ "--trace-expand", CommandArgument::Values::Zero,
+ CommandArgument{ "--trace", CommandArgument::Values::Zero,
[](std::string const&, cmake* state) -> bool {
- std::cout << "Running with expanded trace output on.\n";
+ std::cout << "Put cmake in trace mode.\n";
state->SetTrace(true);
- state->SetTraceExpand(true);
+ state->SetTraceExpand(false);
return true;
} },
- CommandArgument{ "--trace-format", CommandArgument::Values::One,
- [](std::string const& value, cmake* state) -> bool {
+ CommandArgument{ "--trace-expand", CommandArgument::Values::Zero,
+ [](std::string const&, cmake* state) -> bool {
+ std::cout << "Put cmake in trace mode, but with "
+ "variables expanded.\n";
state->SetTrace(true);
- const auto traceFormat = StringToTraceFormat(value);
- if (traceFormat == TraceFormat::TRACE_UNDEFINED) {
- cmSystemTools::Error(
- "Invalid format specified for --trace-format. "
- "Valid formats are human, json-v1.");
- return false;
- }
- state->SetTraceFormat(traceFormat);
+ state->SetTraceExpand(true);
return true;
} },
- CommandArgument{ "--trace-source", CommandArgument::Values::One,
- [](std::string const& value, cmake* state) -> bool {
- std::string file(value);
- cmSystemTools::ConvertToUnixSlashes(file);
- state->AddTraceSource(file);
+ CommandArgument{
+ "--trace-format", "Invalid format specified for --trace-format",
+ CommandArgument::Values::One,
+ [](std::string const& value, cmake* state) -> bool {
+ std::cout << "Put cmake in trace mode and sets the "
+ "trace output format.\n";
+ state->SetTrace(true);
+ const auto traceFormat = StringToTraceFormat(value);
+ if (traceFormat == TraceFormat::Undefined) {
+ cmSystemTools::Error("Invalid format specified for --trace-format. "
+ "Valid formats are human, json-v1.");
+ return false;
+ }
+ state->SetTraceFormat(traceFormat);
+ return true;
+ } },
+ CommandArgument{ "--trace-source", "No file specified for --trace-source",
+ CommandArgument::Values::OneOrMore,
+ [](std::string const& values, cmake* state) -> bool {
+ std::cout << "Put cmake in trace mode, but output only "
+ "lines of a specified file. Multiple "
+ "options are allowed.\n";
+ for (auto file :
+ cmSystemTools::SplitString(values, ';')) {
+ cmSystemTools::ConvertToUnixSlashes(file);
+ state->AddTraceSource(file);
+ }
state->SetTrace(true);
return true;
} },
- CommandArgument{ "--trace-redirect", CommandArgument::Values::One,
+ CommandArgument{ "--trace-redirect",
+ "No file specified for --trace-redirect",
+ CommandArgument::Values::One,
[](std::string const& value, cmake* state) -> bool {
+ std::cout
+ << "Put cmake in trace mode and redirect trace "
+ "output to a file instead of stderr.\n";
std::string file(value);
cmSystemTools::ConvertToUnixSlashes(file);
state->SetTraceFile(file);
state->SetTrace(true);
return true;
} },
- CommandArgument{ "--trace", CommandArgument::Values::Zero,
- [](std::string const&, cmake* state) -> bool {
- std::cout << "Running with trace output on.\n";
- state->SetTrace(true);
- state->SetTraceExpand(false);
- return true;
- } },
CommandArgument{ "--warn-uninitialized", CommandArgument::Values::Zero,
[](std::string const&, cmake* state) -> bool {
std::cout << "Warn about uninitialized values.\n";
@@ -1530,6 +1545,29 @@ void cmake::SetArgs(const std::vector<std::string>& args)
if (expandedPreset->DebugFind == true) {
this->SetDebugFindOutput(true);
}
+ if (expandedPreset->TraceMode &&
+ expandedPreset->TraceMode !=
+ cmCMakePresetsGraph::TraceEnableMode::Disable) {
+ this->SetTrace(true);
+ if (expandedPreset->TraceMode ==
+ cmCMakePresetsGraph::TraceEnableMode::Expand) {
+ this->SetTraceExpand(true);
+ }
+ }
+ if (expandedPreset->TraceFormat) {
+ this->SetTrace(true);
+ this->SetTraceFormat(*expandedPreset->TraceFormat);
+ }
+ if (!expandedPreset->TraceSource.empty()) {
+ this->SetTrace(true);
+ for (std::string const& filePaths : expandedPreset->TraceSource) {
+ this->AddTraceSource(filePaths);
+ }
+ }
+ if (!expandedPreset->TraceRedirect.empty()) {
+ this->SetTrace(true);
+ this->SetTraceFile(expandedPreset->TraceRedirect);
+ }
}
#endif
}
@@ -1586,8 +1624,8 @@ cmake::TraceFormat cmake::StringToTraceFormat(const std::string& traceStr)
{
using TracePair = std::pair<std::string, TraceFormat>;
static const std::vector<TracePair> levels = {
- { "human", TraceFormat::TRACE_HUMAN },
- { "json-v1", TraceFormat::TRACE_JSON_V1 },
+ { "human", TraceFormat::Human },
+ { "json-v1", TraceFormat::JSONv1 },
};
const auto traceStrLowCase = cmSystemTools::LowerCase(traceStr);
@@ -1596,7 +1634,7 @@ cmake::TraceFormat cmake::StringToTraceFormat(const std::string& traceStr)
[&traceStrLowCase](const TracePair& p) {
return p.first == traceStrLowCase;
});
- return (it != levels.cend()) ? it->second : TraceFormat::TRACE_UNDEFINED;
+ return (it != levels.cend()) ? it->second : TraceFormat::Undefined;
}
void cmake::SetTraceFile(const std::string& file)
@@ -1622,7 +1660,7 @@ void cmake::PrintTraceFormatVersion()
std::string msg;
switch (this->GetTraceFormat()) {
- case TraceFormat::TRACE_JSON_V1: {
+ case TraceFormat::JSONv1: {
#ifndef CMAKE_BOOTSTRAP
Json::Value val;
Json::Value version;
@@ -1635,11 +1673,11 @@ void cmake::PrintTraceFormatVersion()
#endif
break;
}
- case TraceFormat::TRACE_HUMAN:
+ case TraceFormat::Human:
msg = "";
break;
- case TraceFormat::TRACE_UNDEFINED:
- msg = "INTERNAL ERROR: Trace format is TRACE_UNDEFINED";
+ case TraceFormat::Undefined:
+ msg = "INTERNAL ERROR: Trace format is Undefined";
break;
}
diff --git a/Source/cmake.h b/Source/cmake.h
index d1f388a..0f8f642 100644
--- a/Source/cmake.h
+++ b/Source/cmake.h
@@ -118,13 +118,7 @@ public:
FIND_PACKAGE_MODE
};
- /** \brief Define supported trace formats **/
- enum TraceFormat
- {
- TRACE_UNDEFINED,
- TRACE_HUMAN,
- TRACE_JSON_V1,
- };
+ using TraceFormat = cmTraceEnums::TraceOutputFormat;
struct GeneratorInfo
{
@@ -719,7 +713,7 @@ private:
bool DebugFindOutput = false;
bool Trace = false;
bool TraceExpand = false;
- TraceFormat TraceFormatVar = TRACE_HUMAN;
+ TraceFormat TraceFormatVar = TraceFormat::Human;
cmGeneratedFileStream TraceFile;
cmake* TraceRedirect = nullptr;
#ifndef CMAKE_BOOTSTRAP