summaryrefslogtreecommitdiffstats
path: root/Source/cmIfCommand.cxx
diff options
context:
space:
mode:
authorBraulio Valdivielso Martinez <bvaldivielso@bloomberg.net>2022-03-25 15:17:05 (GMT)
committerBraulio Valdivielso Martinez <bvaldivielso@bloomberg.net>2022-03-25 16:24:38 (GMT)
commitfd46db174533ee20917ae1b328c43b1e70f07c43 (patch)
tree5cbe3de6941a7f54e6bed7d5213e01d6d8151bca /Source/cmIfCommand.cxx
parent89f2d779f245f2fe4c9921931699e3996af066a0 (diff)
downloadCMake-fd46db174533ee20917ae1b328c43b1e70f07c43.zip
CMake-fd46db174533ee20917ae1b328c43b1e70f07c43.tar.gz
CMake-fd46db174533ee20917ae1b328c43b1e70f07c43.tar.bz2
Trace: process else and elseif commands correctly
There have been two bugs reported about the `else` and `elseif` commands in the context of the tracing functionality and the json-v1 format (#23191 #22315). In essence, the reported traces referred to the layer of the stacktrace immediately on top of the expected ones. This MR fixes both issues. My solution adds a new parameter to the `PrintCommandTrace` function, `commandMissingFromStack`, that callers can specify if the command they want to report a trace for is not a regular part of the stack maintained in `cmMakefile`. This is only the case for `else` and `elseif`. The other bug is fixed by having the caller pass a `cmListFileBacktrace`, which helps in getting the right lines, file names... for the reported command. Fixes: #23191 #22315
Diffstat (limited to 'Source/cmIfCommand.cxx')
-rw-r--r--Source/cmIfCommand.cxx12
1 files changed, 7 insertions, 5 deletions
diff --git a/Source/cmIfCommand.cxx b/Source/cmIfCommand.cxx
index 55f6453..9cd1943 100644
--- a/Source/cmIfCommand.cxx
+++ b/Source/cmIfCommand.cxx
@@ -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;