mirror of
https://github.com/Kitware/CMake.git
synced 2026-03-13 21:09:59 -05:00
Merge topic 'fix-23191'
fd46db1745 Trace: process else and elseif commands correctly
Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Acked-by: Kyle Edwards <kyle.edwards@kitware.com>
Merge-request: !7118
This commit is contained in:
@@ -73,11 +73,11 @@ bool cmIfFunctionBlocker::Replay(std::vector<cmListFileFunction> functions,
|
||||
}
|
||||
// watch for our state change
|
||||
if (scopeDepth == 0 && func.LowerCaseName() == "else") {
|
||||
cmListFileBacktrace elseBT = mf.GetBacktrace().Push(
|
||||
cmListFileContext{ func.OriginalName(),
|
||||
this->GetStartingContext().FilePath, func.Line() });
|
||||
|
||||
if (this->ElseSeen) {
|
||||
cmListFileBacktrace elseBT = mf.GetBacktrace().Push(cmListFileContext{
|
||||
func.OriginalName(), this->GetStartingContext().FilePath,
|
||||
func.Line() });
|
||||
mf.GetCMakeInstance()->IssueMessage(
|
||||
MessageType::FATAL_ERROR,
|
||||
"A duplicate ELSE command was found inside an IF block.", elseBT);
|
||||
@@ -92,7 +92,8 @@ bool cmIfFunctionBlocker::Replay(std::vector<cmListFileFunction> functions,
|
||||
// if trace is enabled, print a (trivially) evaluated "else"
|
||||
// statement
|
||||
if (!this->IsBlocking && mf.GetCMakeInstance()->GetTrace()) {
|
||||
mf.PrintCommandTrace(func);
|
||||
mf.PrintCommandTrace(func, elseBT,
|
||||
cmMakefile::CommandMissingFromStack::Yes);
|
||||
}
|
||||
} else if (scopeDepth == 0 && func.LowerCaseName() == "elseif") {
|
||||
cmListFileBacktrace elseifBT = mf.GetBacktrace().Push(
|
||||
@@ -111,7 +112,8 @@ bool cmIfFunctionBlocker::Replay(std::vector<cmListFileFunction> functions,
|
||||
} else {
|
||||
// if trace is enabled, print the evaluated "elseif" statement
|
||||
if (mf.GetCMakeInstance()->GetTrace()) {
|
||||
mf.PrintCommandTrace(func);
|
||||
mf.PrintCommandTrace(func, elseifBT,
|
||||
cmMakefile::CommandMissingFromStack::Yes);
|
||||
}
|
||||
|
||||
std::string errorString;
|
||||
|
||||
@@ -241,14 +241,14 @@ cmListFileBacktrace cmMakefile::GetBacktrace() const
|
||||
return this->Backtrace;
|
||||
}
|
||||
|
||||
void cmMakefile::PrintCommandTrace(
|
||||
cmListFileFunction const& lff,
|
||||
cm::optional<std::string> const& deferId) const
|
||||
void cmMakefile::PrintCommandTrace(cmListFileFunction const& lff,
|
||||
cmListFileBacktrace const& bt,
|
||||
CommandMissingFromStack missing) const
|
||||
{
|
||||
// Check if current file in the list of requested to trace...
|
||||
std::vector<std::string> const& trace_only_this_files =
|
||||
this->GetCMakeInstance()->GetTraceSources();
|
||||
std::string const& full_path = this->GetBacktrace().Top().FilePath;
|
||||
std::string const& full_path = bt.Top().FilePath;
|
||||
std::string const& only_filename = cmSystemTools::GetFilenameName(full_path);
|
||||
bool trace = trace_only_this_files.empty();
|
||||
if (!trace) {
|
||||
@@ -282,6 +282,7 @@ void cmMakefile::PrintCommandTrace(
|
||||
args.push_back(arg.Value);
|
||||
}
|
||||
}
|
||||
cm::optional<std::string> const& deferId = bt.Top().DeferId;
|
||||
|
||||
switch (this->GetCMakeInstance()->GetTraceFormat()) {
|
||||
case cmake::TraceFormat::TRACE_JSON_V1: {
|
||||
@@ -303,9 +304,9 @@ void cmMakefile::PrintCommandTrace(
|
||||
val["args"].append(arg);
|
||||
}
|
||||
val["time"] = cmSystemTools::GetTime();
|
||||
val["frame"] =
|
||||
val["frame"] = (missing == CommandMissingFromStack::Yes ? 1 : 0) +
|
||||
static_cast<Json::Value::UInt64>(this->ExecutionStatusStack.size());
|
||||
val["global_frame"] =
|
||||
val["global_frame"] = (missing == CommandMissingFromStack::Yes ? 1 : 0) +
|
||||
static_cast<Json::Value::UInt64>(this->RecursionDepth);
|
||||
msg << Json::writeString(builder, val);
|
||||
#endif
|
||||
@@ -427,7 +428,7 @@ bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff,
|
||||
if (!cmSystemTools::GetFatalErrorOccured()) {
|
||||
// if trace is enabled, print out invoke information
|
||||
if (this->GetCMakeInstance()->GetTrace()) {
|
||||
this->PrintCommandTrace(lff, this->Backtrace.Top().DeferId);
|
||||
this->PrintCommandTrace(lff, this->Backtrace);
|
||||
}
|
||||
// Try invoking the command.
|
||||
bool invokeSucceeded = command(lff.Arguments(), status);
|
||||
|
||||
@@ -674,11 +674,18 @@ public:
|
||||
bool copyonly, bool atOnly, bool escapeQuotes,
|
||||
mode_t permissions = 0, cmNewLineStyle = cmNewLineStyle());
|
||||
|
||||
enum class CommandMissingFromStack
|
||||
{
|
||||
No,
|
||||
Yes,
|
||||
};
|
||||
|
||||
/**
|
||||
* Print a command's invocation
|
||||
*/
|
||||
void PrintCommandTrace(cmListFileFunction const& lff,
|
||||
cm::optional<std::string> const& deferId = {}) const;
|
||||
void PrintCommandTrace(
|
||||
cmListFileFunction const& lff, cmListFileBacktrace const& bt,
|
||||
CommandMissingFromStack missing = CommandMissingFromStack::No) const;
|
||||
|
||||
/**
|
||||
* Set a callback that is invoked whenever ExecuteCommand is called.
|
||||
|
||||
@@ -56,6 +56,11 @@ required_traces = [
|
||||
'cmd': 'message',
|
||||
'frame': 3,
|
||||
'global_frame': 6 if expand else 5
|
||||
},
|
||||
{
|
||||
'cmd': 'else',
|
||||
'global_frame': 4 if expand else 3,
|
||||
'line': 3
|
||||
}
|
||||
]
|
||||
|
||||
@@ -98,4 +103,7 @@ with open(trace_file, 'r') as fp:
|
||||
if subset == j:
|
||||
required_traces.remove(j)
|
||||
|
||||
assert not required_traces
|
||||
assert not required_traces, (
|
||||
"The following traces were expected to be part of the "
|
||||
"output but weren't", required_traces
|
||||
)
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
function(function_that_uses_else)
|
||||
if(FALSE)
|
||||
else()
|
||||
endif()
|
||||
endfunction()
|
||||
function(f)
|
||||
message(STATUS "nested global_frame")
|
||||
endfunction()
|
||||
|
||||
@@ -8,3 +8,4 @@ set(FOO 42)
|
||||
set(BAR " space in string!")
|
||||
message(STATUS fff ${ASDF} " ${FOO} ${BAR}" " SPACES !!! ")
|
||||
add_subdirectory(trace-json-v1-nested)
|
||||
function_that_uses_else()
|
||||
|
||||
Reference in New Issue
Block a user