Better fix for #1371.
Now handles also system includes. And have couple of tests.
This commit is contained in:
parent
9d29ee6edd
commit
618076a65f
|
@ -1322,6 +1322,9 @@ Preprocessor::HeaderTypes Preprocessor::getHeaderFileName(std::string &str)
|
||||||
result.append(1, str[i]);
|
result.append(1, str[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Linux can't open include paths with \ separator, so fix them
|
||||||
|
std::replace(result.begin(), result.end(), '\\', '/');
|
||||||
|
|
||||||
str = result;
|
str = result;
|
||||||
if (c == '"')
|
if (c == '"')
|
||||||
return UserHeader;
|
return UserHeader;
|
||||||
|
@ -1397,11 +1400,7 @@ void Preprocessor::handleIncludes(std::string &code, const std::string &filePath
|
||||||
if (headerType == UserHeader && !fileOpened)
|
if (headerType == UserHeader && !fileOpened)
|
||||||
{
|
{
|
||||||
filename = paths.back() + filename;
|
filename = paths.back() + filename;
|
||||||
|
fin.open(filename.c_str());
|
||||||
// Linux can't open include paths with \ separator, so fix them
|
|
||||||
std::string fixedname(filename);
|
|
||||||
std::replace(fixedname.begin(), fixedname.end(), '\\', '/');
|
|
||||||
fin.open(fixedname.c_str());
|
|
||||||
if (fin.is_open())
|
if (fin.is_open())
|
||||||
{
|
{
|
||||||
fileOpened = true;
|
fileOpened = true;
|
||||||
|
|
|
@ -2030,6 +2030,18 @@ private:
|
||||||
ASSERT_EQUALS(OurPreprocessor::SystemHeader, OurPreprocessor::getHeaderFileName(src));
|
ASSERT_EQUALS(OurPreprocessor::SystemHeader, OurPreprocessor::getHeaderFileName(src));
|
||||||
ASSERT_EQUALS("c.h", src);
|
ASSERT_EQUALS("c.h", src);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
std::string src = "#include \"d/d.h\"";
|
||||||
|
ASSERT_EQUALS(OurPreprocessor::UserHeader, OurPreprocessor::getHeaderFileName(src));
|
||||||
|
ASSERT_EQUALS("d/d.h", src);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
std::string src = "#include \"e\\e.h\"";
|
||||||
|
ASSERT_EQUALS(OurPreprocessor::UserHeader, OurPreprocessor::getHeaderFileName(src));
|
||||||
|
ASSERT_EQUALS("e/e.h", src);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ifdef_ifdefined()
|
void ifdef_ifdefined()
|
||||||
|
|
Loading…
Reference in New Issue