Parser: Issue messages through cmake, not cmSystemTools

Make these messages uniform with regard to other messages issued by
cmake.
This commit is contained in:
Stephen Kelly 2016-01-28 22:10:23 +01:00 committed by Brad King
parent db7de303c2
commit 33bb9cfa36
20 changed files with 115 additions and 149 deletions

View File

@ -24,6 +24,7 @@ struct cmListFileParser
cmListFileParser(cmListFile* lf, cmMakefile* mf, const char* filename); cmListFileParser(cmListFile* lf, cmMakefile* mf, const char* filename);
~cmListFileParser(); ~cmListFileParser();
void IssueFileOpenError(std::string const& text) const; void IssueFileOpenError(std::string const& text) const;
void IssueError(std::string const& text) const;
bool ParseFile(); bool ParseFile();
bool ParseFunction(const char* name, long line); bool ParseFunction(const char* name, long line);
bool AddArgument(cmListFileLexer_Token* token, bool AddArgument(cmListFileLexer_Token* token,
@ -62,6 +63,18 @@ void cmListFileParser::IssueFileOpenError(const std::string& text) const
this->Makefile->IssueMessage(cmake::FATAL_ERROR, text); this->Makefile->IssueMessage(cmake::FATAL_ERROR, text);
} }
void cmListFileParser::IssueError(const std::string& text) const
{
cmListFileContext lfc;
lfc.FilePath = this->FileName;
lfc.Line = cmListFileLexer_GetCurrentLine(this->Lexer);
cmListFileBacktrace lfbt = this->Backtrace;
lfbt = lfbt.Push(lfc);
this->Makefile->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, text,
lfbt);
cmSystemTools::SetFatalErrorOccured();
}
bool cmListFileParser::ParseFile() bool cmListFileParser::ParseFile()
{ {
// Open the file. // Open the file.
@ -98,22 +111,18 @@ bool cmListFileParser::ParseFile()
} }
} else { } else {
std::ostringstream error; std::ostringstream error;
error << "Error in cmake code at\n" error << "Parse error. Expected a newline, got "
<< this->FileName << ":" << token->line << ":\n"
<< "Parse error. Expected a newline, got "
<< cmListFileLexer_GetTypeAsString(this->Lexer, token->type) << cmListFileLexer_GetTypeAsString(this->Lexer, token->type)
<< " with text \"" << token->text << "\"."; << " with text \"" << token->text << "\".";
cmSystemTools::Error(error.str().c_str()); this->IssueError(error.str());
return false; return false;
} }
} else { } else {
std::ostringstream error; std::ostringstream error;
error << "Error in cmake code at\n" error << "Parse error. Expected a command name, got "
<< this->FileName << ":" << token->line << ":\n"
<< "Parse error. Expected a command name, got "
<< cmListFileLexer_GetTypeAsString(this->Lexer, token->type) << cmListFileLexer_GetTypeAsString(this->Lexer, token->type)
<< " with text \"" << token->text << "\"."; << " with text \"" << token->text << "\".";
cmSystemTools::Error(error.str().c_str()); this->IssueError(error.str());
return false; return false;
} }
} }
@ -156,18 +165,15 @@ bool cmListFileParser::ParseFunction(const char* name, long line)
<< cmListFileLexer_GetCurrentLine(this->Lexer) << ":\n" << cmListFileLexer_GetCurrentLine(this->Lexer) << ":\n"
<< "Parse error. Function missing opening \"(\"."; << "Parse error. Function missing opening \"(\".";
/* clang-format on */ /* clang-format on */
cmSystemTools::Error(error.str().c_str()); this->IssueError(error.str());
return false; return false;
} }
if (token->type != cmListFileLexer_Token_ParenLeft) { if (token->type != cmListFileLexer_Token_ParenLeft) {
std::ostringstream error; std::ostringstream error;
error << "Error in cmake code at\n" error << "Parse error. Expected \"(\", got "
<< this->FileName << ":"
<< cmListFileLexer_GetCurrentLine(this->Lexer) << ":\n"
<< "Parse error. Expected \"(\", got "
<< cmListFileLexer_GetTypeAsString(this->Lexer, token->type) << cmListFileLexer_GetTypeAsString(this->Lexer, token->type)
<< " with text \"" << token->text << "\"."; << " with text \"" << token->text << "\".";
cmSystemTools::Error(error.str().c_str()); this->IssueError(error.str());
return false; return false;
} }
@ -219,25 +225,25 @@ bool cmListFileParser::ParseFunction(const char* name, long line)
} else { } else {
// Error. // Error.
std::ostringstream error; std::ostringstream error;
error << "Error in cmake code at\n" error << "Parse error. Function missing ending \")\". "
<< this->FileName << ":"
<< cmListFileLexer_GetCurrentLine(this->Lexer) << ":\n"
<< "Parse error. Function missing ending \")\". "
<< "Instead found " << "Instead found "
<< cmListFileLexer_GetTypeAsString(this->Lexer, token->type) << cmListFileLexer_GetTypeAsString(this->Lexer, token->type)
<< " with text \"" << token->text << "\"."; << " with text \"" << token->text << "\".";
cmSystemTools::Error(error.str().c_str()); this->IssueError(error.str());
return false; return false;
} }
} }
std::ostringstream error; std::ostringstream error;
error << "Error in cmake code at\n" cmListFileContext lfc;
<< this->FileName << ":" << lastLine << ":\n" lfc.FilePath = this->FileName;
<< "Parse error. Function missing ending \")\". " lfc.Line = lastLine;
cmListFileBacktrace lfbt = this->Backtrace;
lfbt = lfbt.Push(lfc);
error << "Parse error. Function missing ending \")\". "
<< "End of file reached."; << "End of file reached.";
cmSystemTools::Error(error.str().c_str()); this->Makefile->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR,
error.str(), lfbt);
return false; return false;
} }
@ -252,17 +258,21 @@ bool cmListFileParser::AddArgument(cmListFileLexer_Token* token,
bool isError = (this->Separation == SeparationError || bool isError = (this->Separation == SeparationError ||
delim == cmListFileArgument::Bracket); delim == cmListFileArgument::Bracket);
std::ostringstream m; std::ostringstream m;
/* clang-format off */ cmListFileContext lfc;
m << "Syntax " << (isError? "Error":"Warning") << " in cmake code at\n" lfc.FilePath = this->FileName;
<< " " << this->FileName << ":" << token->line << ":" lfc.Line = token->line;
<< token->column << "\n" cmListFileBacktrace lfbt = this->Backtrace;
lfbt = lfbt.Push(lfc);
m << "Syntax " << (isError ? "Error" : "Warning") << " in cmake code at "
<< "column " << token->column << "\n"
<< "Argument not separated from preceding token by whitespace."; << "Argument not separated from preceding token by whitespace.";
/* clang-format on */ /* clang-format on */
if (isError) { if (isError) {
this->Makefile->IssueMessage(cmake::FATAL_ERROR, m.str()); this->Makefile->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, m.str(), lfbt);
return false; return false;
} }
this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, m.str()); this->Makefile->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING, m.str(), lfbt);
return true; return true;
} }

View File

@ -1,7 +1,4 @@
CMake Error: Error in cmake code at CMake Error at BracketComment4.cmake:3:
.*/Tests/RunCMake/Syntax/BracketComment4.cmake:3: Parse error. Expected a newline, got identifier with text "message".
Parse error. Expected a newline, got identifier with text "message". Call Stack \(most recent call first\):
CMake Error at CMakeLists.txt:3 \(include\): CMakeLists.txt:3 \(include\)
include could not find load file:
BracketComment4.cmake

View File

@ -1,7 +1,5 @@
CMake Error in BracketNoSpace0.cmake: CMake Error at BracketNoSpace0.cmake:1:
Syntax Error in cmake code at Syntax Error in cmake code at column 27
.*/Tests/RunCMake/Syntax/BracketNoSpace0.cmake:1:27
Argument not separated from preceding token by whitespace. Argument not separated from preceding token by whitespace.
Call Stack \(most recent call first\): Call Stack \(most recent call first\):

View File

@ -1,7 +1,5 @@
CMake Error in BracketNoSpace1.cmake: CMake Error at BracketNoSpace1.cmake:1:
Syntax Error in cmake code at Syntax Error in cmake code at column 24
.*/Tests/RunCMake/Syntax/BracketNoSpace1.cmake:1:24
Argument not separated from preceding token by whitespace. Argument not separated from preceding token by whitespace.
Call Stack \(most recent call first\): Call Stack \(most recent call first\):

View File

@ -1,7 +1,5 @@
CMake Error in BracketNoSpace2.cmake: CMake Error at BracketNoSpace2.cmake:1:
Syntax Error in cmake code at Syntax Error in cmake code at column 44
.*/Tests/RunCMake/Syntax/BracketNoSpace2.cmake:1:44
Argument not separated from preceding token by whitespace. Argument not separated from preceding token by whitespace.
Call Stack \(most recent call first\): Call Stack \(most recent call first\):

View File

@ -1,7 +1,5 @@
CMake Error in BracketNoSpace3.cmake: CMake Error at BracketNoSpace3.cmake:1:
Syntax Error in cmake code at Syntax Error in cmake code at column 45
.*/Tests/RunCMake/Syntax/BracketNoSpace3.cmake:1:45
Argument not separated from preceding token by whitespace. Argument not separated from preceding token by whitespace.
Call Stack \(most recent call first\): Call Stack \(most recent call first\):

View File

@ -1,7 +1,5 @@
CMake Error in BracketNoSpace4.cmake: CMake Error at BracketNoSpace4.cmake:1:
Syntax Error in cmake code at Syntax Error in cmake code at column 44
.*/Tests/RunCMake/Syntax/BracketNoSpace4.cmake:1:44
Argument not separated from preceding token by whitespace. Argument not separated from preceding token by whitespace.
Call Stack \(most recent call first\): Call Stack \(most recent call first\):

View File

@ -1,7 +1,5 @@
CMake Error in BracketNoSpace5.cmake: CMake Error at BracketNoSpace5.cmake:1:
Syntax Error in cmake code at Syntax Error in cmake code at column 45
.*/Tests/RunCMake/Syntax/BracketNoSpace5.cmake:1:45
Argument not separated from preceding token by whitespace. Argument not separated from preceding token by whitespace.
Call Stack \(most recent call first\): Call Stack \(most recent call first\):

View File

@ -1,8 +1,6 @@
CMake Error: Error in cmake code at CMake Error at CommandError0.cmake:2:
.*/Tests/RunCMake/Syntax/CommandError0.cmake:2: Parse error. Expected "\(", got newline with text "
Parse error. Expected "\(", got newline with text "
".
CMake Error at CMakeLists.txt:3 \(include\):
include could not find load file:
CommandError0.cmake ".
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)

View File

@ -1,7 +1,4 @@
CMake Error: Error in cmake code at CMake Error at CommandError1.cmake:1:
.*/Tests/RunCMake/Syntax/CommandError1.cmake:1: Parse error. Expected a newline, got identifier with text "message".
Parse error. Expected a newline, got identifier with text "message". Call Stack \(most recent call first\):
CMake Error at CMakeLists.txt:3 \(include\): CMakeLists.txt:3 \(include\)
include could not find load file:
CommandError1.cmake

View File

@ -1,7 +1,5 @@
CMake Error: Error in cmake code at CMake Error at CommandError2.cmake:1:
.*/Tests/RunCMake/Syntax/CommandError2.cmake:1: Parse error. Expected a command name, got bracket argument with text
Parse error. Expected a command name, got bracket argument with text "oops-not-a-comment". "oops-not-a-comment".
CMake Error at CMakeLists.txt:3 \(include\): Call Stack \(most recent call first\):
include could not find load file: CMakeLists.txt:3 \(include\)
CommandError2.cmake

View File

@ -1,7 +1,5 @@
CMake Warning \(dev\) in ParenInENV.cmake: CMake Warning \(dev\) at ParenInENV.cmake:2:
Syntax Warning in cmake code at Syntax Warning in cmake code at column 21
.*/Tests/RunCMake/Syntax/ParenInENV.cmake:2:21
Argument not separated from preceding token by whitespace. Argument not separated from preceding token by whitespace.
Call Stack \(most recent call first\): Call Stack \(most recent call first\):
@ -11,7 +9,7 @@ This warning is for project developers. Use -Wno-dev to suppress it.
CMake Error at ParenInENV.cmake:2 \(message\): CMake Error at ParenInENV.cmake:2 \(message\):
Syntax error in cmake code at Syntax error in cmake code at
.*/Tests/RunCMake/Syntax/ParenInENV.cmake:2 .*Tests/RunCMake/Syntax/ParenInENV.cmake:2
when parsing string when parsing string

View File

@ -1,27 +1,21 @@
CMake Warning \(dev\) in ParenNoSpace1.cmake: CMake Warning \(dev\) at ParenNoSpace1.cmake:1:
Syntax Warning in cmake code at Syntax Warning in cmake code at column 26
.*/Tests/RunCMake/Syntax/ParenNoSpace1.cmake:1:26
Argument not separated from preceding token by whitespace. Argument not separated from preceding token by whitespace.
Call Stack \(most recent call first\): Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\) CMakeLists.txt:3 \(include\)
This warning is for project developers. Use -Wno-dev to suppress it. This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning \(dev\) in ParenNoSpace1.cmake: CMake Warning \(dev\) at ParenNoSpace1.cmake:2:
Syntax Warning in cmake code at Syntax Warning in cmake code at column 26
.*/Tests/RunCMake/Syntax/ParenNoSpace1.cmake:2:26
Argument not separated from preceding token by whitespace. Argument not separated from preceding token by whitespace.
Call Stack \(most recent call first\): Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\) CMakeLists.txt:3 \(include\)
This warning is for project developers. Use -Wno-dev to suppress it. This warning is for project developers. Use -Wno-dev to suppress it.
CMake Error in ParenNoSpace1.cmake: CMake Error at ParenNoSpace1.cmake:3:
Syntax Error in cmake code at Syntax Error in cmake code at column 29
.*/Tests/RunCMake/Syntax/ParenNoSpace1.cmake:3:29
Argument not separated from preceding token by whitespace. Argument not separated from preceding token by whitespace.
Call Stack \(most recent call first\): Call Stack \(most recent call first\):

View File

@ -1,17 +1,13 @@
CMake Warning \(dev\) in StringNoSpace.cmake: CMake Warning \(dev\) at StringNoSpace.cmake:2:
Syntax Warning in cmake code at Syntax Warning in cmake code at column 28
.*/Tests/RunCMake/Syntax/StringNoSpace.cmake:2:28
Argument not separated from preceding token by whitespace. Argument not separated from preceding token by whitespace.
Call Stack \(most recent call first\): Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\) CMakeLists.txt:3 \(include\)
This warning is for project developers. Use -Wno-dev to suppress it. This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning \(dev\) in StringNoSpace.cmake: CMake Warning \(dev\) at StringNoSpace.cmake:2:
Syntax Warning in cmake code at Syntax Warning in cmake code at column 31
.*/Tests/RunCMake/Syntax/StringNoSpace.cmake:2:31
Argument not separated from preceding token by whitespace. Argument not separated from preceding token by whitespace.
Call Stack \(most recent call first\): Call Stack \(most recent call first\):

View File

@ -1,8 +1,7 @@
CMake Error: Error in cmake code at CMake Error at UnterminatedBracket0.cmake:2:
.*/Syntax/UnterminatedBracket0.cmake:2: Parse error. Function missing ending "\)". Instead found unterminated
Parse error. Function missing ending "\)". Instead found unterminated bracket with text "\) bracket with text "\)
".
CMake Error at CMakeLists.txt:3 \(include\):
include could not find load file:
UnterminatedBracket0.cmake$ ".
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)

View File

@ -1,8 +1,7 @@
CMake Error: Error in cmake code at CMake Error at UnterminatedBracket1.cmake:2:
.*/Syntax/UnterminatedBracket1.cmake:2: Parse error. Function missing ending "\)". Instead found unterminated
Parse error. Function missing ending "\)". Instead found unterminated bracket with text "\]\]\) bracket with text "]]\)
".
CMake Error at CMakeLists.txt:3 \(include\):
include could not find load file:
UnterminatedBracket1.cmake$ ".
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)

View File

@ -1,8 +1,7 @@
CMake Error: Error in cmake code at CMake Error at UnterminatedBracketComment.cmake:3:
.*/Syntax/UnterminatedBracketComment.cmake:1: Parse error. Expected a command name, got unterminated bracket with text
Parse error. Expected a command name, got unterminated bracket with text "#\]\] "#]]
".
CMake Error at CMakeLists.txt:3 \(include\):
include could not find load file:
UnterminatedBracketComment.cmake ".
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)

View File

@ -1,7 +1,4 @@
CMake Error: Error in cmake code at CMake Error at UnterminatedCall1.cmake:2:
.*/Syntax/UnterminatedCall1.cmake:2: Parse error. Function missing ending "\)". End of file reached.
Parse error. Function missing ending "\)". End of file reached. Call Stack \(most recent call first\):
CMake Error at CMakeLists.txt:3 \(include\): CMakeLists.txt:3 \(include\)
include could not find load file:
UnterminatedCall1.cmake

View File

@ -1,7 +1,4 @@
CMake Error: Error in cmake code at CMake Error at UnterminatedCall2.cmake:4:
.*/Syntax/UnterminatedCall2.cmake:4: Parse error. Function missing ending "\)". End of file reached.
Parse error. Function missing ending "\)". End of file reached. Call Stack \(most recent call first\):
CMake Error at CMakeLists.txt:3 \(include\): CMakeLists.txt:3 \(include\)
include could not find load file:
UnterminatedCall2.cmake

View File

@ -1,8 +1,7 @@
CMake Error: Error in cmake code at CMake Error at UnterminatedString.cmake:2:
.*/Syntax/UnterminatedString.cmake:2: Parse error. Function missing ending "\)". Instead found unterminated
Parse error. Function missing ending "\)". Instead found unterminated string with text "\) string with text "\)
".
CMake Error at CMakeLists.txt:3 \(include\):
include could not find load file:
UnterminatedString.cmake$ ".
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)