Fixed #9260 (--template=gcc does not work correctly with -j)

This commit is contained in:
Daniel Marjamäki 2019-08-18 16:33:32 +02:00
parent e07cb807e1
commit a5ba82c2d3
4 changed files with 39 additions and 38 deletions

View File

@ -559,19 +559,15 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
} catch (const InternalError &e) {
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
ErrorLogger::ErrorMessage::FileLocation loc;
if (e.token) {
loc.line = e.token->linenr();
loc.column = e.token->column();
const std::string fixedpath = Path::toNativeSeparators(mTokenizer.list.file(e.token));
loc.setfile(fixedpath);
ErrorLogger::ErrorMessage::FileLocation loc(e.token, &mTokenizer.list);
locationList.push_back(loc);
} else {
ErrorLogger::ErrorMessage::FileLocation loc2;
loc2.setfile(Path::toNativeSeparators(filename));
ErrorLogger::ErrorMessage::FileLocation loc(mTokenizer.list.getSourceFilePath(), 0, 0);
ErrorLogger::ErrorMessage::FileLocation loc2(filename, 0, 0);
locationList.push_back(loc2);
loc.setfile(mTokenizer.list.getSourceFilePath());
locationList.push_back(loc);
}
locationList.push_back(loc);
ErrorLogger::ErrorMessage errmsg(locationList,
mTokenizer.list.getSourceFilePath(),
Severity::error,

View File

@ -247,7 +247,7 @@ std::string ErrorLogger::ErrorMessage::serialize() const
for (std::list<ErrorLogger::ErrorMessage::FileLocation>::const_iterator loc = callStack.begin(); loc != callStack.end(); ++loc) {
std::ostringstream smallStream;
smallStream << (*loc).line << ':' << (*loc).column << ':' << (*loc).getfile() << '\t' << loc->getinfo();
smallStream << (*loc).line << '\t' << (*loc).column << '\t' << (*loc).getfile(false) << '\t' << loc->getOrigFile(false) << '\t' << loc->getinfo();
oss << smallStream.str().length() << " " << smallStream.str();
}
@ -309,28 +309,29 @@ bool ErrorLogger::ErrorMessage::deserialize(const std::string &data)
temp.append(1, c);
}
const std::string::size_type colonPos1 = temp.find(':');
if (colonPos1 == std::string::npos)
throw InternalError(nullptr, "Internal Error: No colon found in <line:col:filename> pattern");
const std::string::size_type colonPos2 = temp.find(':', colonPos1+1);
if (colonPos2 == std::string::npos)
throw InternalError(nullptr, "Internal Error: second colon not found in <line:col:filename> pattern");
const std::string::size_type tabPos = temp.find('\t');
if (tabPos == std::string::npos)
throw InternalError(nullptr, "Internal Error: No tab found in <filename:line> pattern");
std::vector<std::string> substrings;
for (std::string::size_type pos = 0; pos < temp.size() && substrings.size() < 5; ++pos) {
if (substrings.size() == 4) {
substrings.push_back(temp.substr(pos));
break;
}
const std::string::size_type start = pos;
pos = temp.find("\t", pos);
if (pos == std::string::npos) {
substrings.push_back(temp.substr(start));
break;
}
substrings.push_back(temp.substr(start, pos - start));
}
if (substrings.size() < 4)
throw InternalError(nullptr, "Internal Error: serializing/deserializing of error message failed!");
const std::string tempinfo = temp.substr(tabPos + 1);
temp.erase(tabPos);
const std::string tempfile = temp.substr(colonPos2 + 1);
temp.erase(colonPos2);
const std::string tempcolumn = temp.substr(colonPos1 + 1);
temp.erase(colonPos1);
const std::string templine = temp;
ErrorLogger::ErrorMessage::FileLocation loc;
loc.setfile(tempfile);
loc.setinfo(tempinfo);
loc.column = MathLib::toLongNumber(tempcolumn);
loc.line = MathLib::toLongNumber(templine);
// (*loc).line << '\t' << (*loc).column << '\t' << (*loc).getfile(false) << '\t' << loc->getOrigFile(false) << '\t' << loc->getinfo();
ErrorLogger::ErrorMessage::FileLocation loc(substrings[3], MathLib::toLongNumber(substrings[0]), MathLib::toLongNumber(substrings[1]));
loc.setfile(substrings[2]);
if (substrings.size() == 5)
loc.setinfo(substrings[4]);
callStack.push_back(loc);
@ -441,7 +442,7 @@ void ErrorLogger::ErrorMessage::findAndReplace(std::string &source, const std::s
}
// TODO: read info from some shared resource instead?
static std::string readCode(const std::string &file, unsigned int linenr, unsigned int column, const char endl[])
static std::string readCode(const std::string &file, int linenr, int column, const char endl[])
{
std::ifstream fin(file);
std::string line;

View File

@ -211,6 +211,11 @@ public:
*/
std::string getfile(bool convert = true) const;
/**
* Filename with the whole path (no --rp)
* @param convert If true convert path to native separators.
* @return filename.
*/
std::string getOrigFile(bool convert = true) const;
/**

View File

@ -291,10 +291,8 @@ private:
}
void SerializeFileLocation() const {
ErrorLogger::ErrorMessage::FileLocation loc1;
loc1.setfile(":/,");
loc1.line = 643;
loc1.column = 33;
ErrorLogger::ErrorMessage::FileLocation loc1(":/,;", 654, 33);
loc1.setfile("[]:;,()");
loc1.setinfo("abcd:/,");
std::list<ErrorLogger::ErrorMessage::FileLocation> locs{loc1};
@ -303,8 +301,9 @@ private:
ErrorMessage msg2;
msg2.deserialize(msg.serialize());
ASSERT_EQUALS(":/,", msg2.callStack.front().getfile(false));
ASSERT_EQUALS(643, msg2.callStack.front().line);
ASSERT_EQUALS("[]:;,()", msg2.callStack.front().getfile(false));
ASSERT_EQUALS(":/,;", msg2.callStack.front().getOrigFile(false));
ASSERT_EQUALS(654, msg2.callStack.front().line);
ASSERT_EQUALS(33, msg2.callStack.front().column);
ASSERT_EQUALS("abcd:/,", msg2.callStack.front().getinfo());
}