mirror of
https://github.com/Kitware/CMake.git
synced 2026-04-28 18:09:42 -05:00
ENH: Improve argument parsing error messages
Previously error messages produced by parsing of command argument
variable references, such as bad $KEY{VAR} syntax or a bad escape
sequence, did not provide good context information. Errors parsing
arguments inside macro invocations gave no context at all. Furthermore,
some errors such as a missing close curly "${VAR" would be reported but
build files would still be generated.
These changes teach CMake to report errors with good context information
for all command argument parsing problems. Policy CMP0010 is introduced
so that existing projects that built despite such errors will continue
to work.
This commit is contained in:
@@ -87,8 +87,10 @@ char* cmCommandArgumentParserHelper::ExpandSpecialVariable(const char* key,
|
||||
}
|
||||
return this->EmptyVariable;
|
||||
}
|
||||
cmSystemTools::Error("Key ", key,
|
||||
" is not used yet. For now only $ENV{..} is allowed");
|
||||
cmOStringStream e;
|
||||
e << "Syntax $" << key << "{} is not supported. "
|
||||
<< "Only ${} and ENV{} are allowed.";
|
||||
this->SetError(e.str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -216,10 +218,11 @@ bool cmCommandArgumentParserHelper::HandleEscapeSymbol
|
||||
this->AllocateParserType(pt, "\0", 1);
|
||||
break;
|
||||
default:
|
||||
char buffer[2];
|
||||
buffer[0] = symbol;
|
||||
buffer[1] = 0;
|
||||
cmSystemTools::Error("Invalid escape sequence \\", buffer);
|
||||
{
|
||||
cmOStringStream e;
|
||||
e << "Invalid escape sequence \\" << symbol;
|
||||
this->SetError(e.str());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -300,7 +303,7 @@ void cmCommandArgumentParserHelper::Error(const char* str)
|
||||
unsigned long pos = static_cast<unsigned long>(this->InputBufferPos);
|
||||
cmOStringStream ostr;
|
||||
ostr << str << " (" << pos << ")";
|
||||
this->ErrorString = ostr.str();
|
||||
this->SetError(ostr.str());
|
||||
}
|
||||
|
||||
void cmCommandArgumentParserHelper::SetMakefile(const cmMakefile* mf)
|
||||
@@ -318,3 +321,11 @@ void cmCommandArgumentParserHelper::SetResult(const char* value)
|
||||
this->Result = value;
|
||||
}
|
||||
|
||||
void cmCommandArgumentParserHelper::SetError(std::string const& msg)
|
||||
{
|
||||
// Keep only the first error.
|
||||
if(this->ErrorString.empty())
|
||||
{
|
||||
this->ErrorString = msg;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user