forked from qt-creator/qt-creator
Clang: Work around missing file
We now generate an empty fake file. Change-Id: I92fef2b24dce788c1d1b675b034d4b31346b80d9 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -56,6 +56,8 @@ public:
|
|||||||
auto &preprocessor = compilerInstance.getPreprocessor();
|
auto &preprocessor = compilerInstance.getPreprocessor();
|
||||||
auto &headerSearch = preprocessor.getHeaderSearchInfo();
|
auto &headerSearch = preprocessor.getHeaderSearchInfo();
|
||||||
|
|
||||||
|
preprocessor.SetSuppressIncludeNotFoundError(true);
|
||||||
|
|
||||||
auto macroPreprocessorCallbacks = new CollectIncludesPreprocessorCallbacks(headerSearch,
|
auto macroPreprocessorCallbacks = new CollectIncludesPreprocessorCallbacks(headerSearch,
|
||||||
m_includeIds,
|
m_includeIds,
|
||||||
m_filePathCache,
|
m_filePathCache,
|
||||||
|
|||||||
@@ -35,6 +35,10 @@
|
|||||||
|
|
||||||
#include <utils/smallstringvector.h>
|
#include <utils/smallstringvector.h>
|
||||||
|
|
||||||
|
#include <QFile>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QTemporaryDir>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
namespace ClangBackEnd {
|
namespace ClangBackEnd {
|
||||||
@@ -64,7 +68,7 @@ public:
|
|||||||
llvm::StringRef /*relativePath*/,
|
llvm::StringRef /*relativePath*/,
|
||||||
const clang::Module * /*imported*/) override
|
const clang::Module * /*imported*/) override
|
||||||
{
|
{
|
||||||
if (file) {
|
if (!m_skipInclude && file) {
|
||||||
auto fileUID = file->getUID();
|
auto fileUID = file->getUID();
|
||||||
if (isNotInExcludedIncludeUID(fileUID)) {
|
if (isNotInExcludedIncludeUID(fileUID)) {
|
||||||
flagIncludeAlreadyRead(file);
|
flagIncludeAlreadyRead(file);
|
||||||
@@ -80,6 +84,45 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_skipInclude = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FileNotFound(clang::StringRef fileNameRef, clang::SmallVectorImpl<char> &recoveryPath) override
|
||||||
|
{
|
||||||
|
QTemporaryDir temporaryDirectory;
|
||||||
|
temporaryDirectory.setAutoRemove(false);
|
||||||
|
const QByteArray temporaryDirUtf8 = temporaryDirectory.path().toUtf8();
|
||||||
|
|
||||||
|
const QString fileName = QString::fromUtf8(fileNameRef.data(), int(fileNameRef.size()));
|
||||||
|
QString filePath = temporaryDirectory.path() + '/' + fileName;
|
||||||
|
|
||||||
|
ensureDirectory(temporaryDirectory.path(), fileName);
|
||||||
|
createFakeFile(filePath);
|
||||||
|
|
||||||
|
recoveryPath.append(temporaryDirUtf8.cbegin(), temporaryDirUtf8.cend());
|
||||||
|
|
||||||
|
m_skipInclude = true;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ensureDirectory(const QString &directory, const QString &fileName)
|
||||||
|
{
|
||||||
|
QStringList directoryEntries = fileName.split('/');
|
||||||
|
directoryEntries.pop_back();
|
||||||
|
|
||||||
|
if (!directoryEntries.isEmpty())
|
||||||
|
QDir(directory).mkpath(directoryEntries.join('/'));
|
||||||
|
}
|
||||||
|
|
||||||
|
void createFakeFile(const QString &filePath)
|
||||||
|
{
|
||||||
|
QFile fakeFile;
|
||||||
|
fakeFile.setFileName(filePath);
|
||||||
|
|
||||||
|
fakeFile.open(QIODevice::ReadWrite);
|
||||||
|
fakeFile.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isNotInExcludedIncludeUID(uint uid) const
|
bool isNotInExcludedIncludeUID(uint uid) const
|
||||||
@@ -131,6 +174,7 @@ private:
|
|||||||
StringCache<Utils::PathString> &m_filePathCache;
|
StringCache<Utils::PathString> &m_filePathCache;
|
||||||
const std::vector<uint> &m_excludedIncludeUID;
|
const std::vector<uint> &m_excludedIncludeUID;
|
||||||
std::vector<uint> &m_alreadyIncludedFileUIDs;
|
std::vector<uint> &m_alreadyIncludedFileUIDs;
|
||||||
|
bool m_skipInclude = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ClangBackEnd
|
} // namespace ClangBackEnd
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
#include "missing_file.moc"
|
||||||
|
#include "foo/missing_file.moc"
|
||||||
|
#include <missing_file2.moc>
|
||||||
|
#include <foo2/missing_file2.moc>
|
||||||
|
|
||||||
|
#include "includecollector_external1.h"
|
||||||
@@ -109,6 +109,16 @@ TEST_F(IncludeCollector, LocalPath)
|
|||||||
id(TESTDATA_DIR "/includecollector_external3.h")));
|
id(TESTDATA_DIR "/includecollector_external3.h")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(IncludeCollector, IgnoreMissingFile)
|
||||||
|
{
|
||||||
|
emptyCollector.addFile(TESTDATA_DIR, "includecollector_missingfile.cpp", "", {"cc", "includecollector_missingfile.cpp"});
|
||||||
|
|
||||||
|
emptyCollector.collectIncludes();
|
||||||
|
|
||||||
|
ASSERT_THAT(emptyCollector.takeIncludeIds(),
|
||||||
|
UnorderedElementsAre(id(TESTDATA_DIR "/includecollector_external1.h")));
|
||||||
|
}
|
||||||
|
|
||||||
void IncludeCollector::SetUp()
|
void IncludeCollector::SetUp()
|
||||||
{
|
{
|
||||||
collector.addFile(TESTDATA_DIR, "includecollector_main.cpp", "", {"cc", "includecollector_main.cpp"});
|
collector.addFile(TESTDATA_DIR, "includecollector_main.cpp", "", {"cc", "includecollector_main.cpp"});
|
||||||
|
|||||||
@@ -39,8 +39,11 @@
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
Utils::TemporaryDirectory::setMasterTemporaryDirectory(QDir::tempPath()
|
const QString temporayDirectoryPath = QDir::tempPath() +"/QtCreator-UnitTests-XXXXXX";
|
||||||
+"/QtCreator-UnitTests-XXXXXX");
|
Utils::TemporaryDirectory::setMasterTemporaryDirectory(temporayDirectoryPath);
|
||||||
|
qputenv("TMPDIR", Utils::TemporaryDirectory::masterDirectoryPath().toUtf8());
|
||||||
|
qputenv("TEMP", Utils::TemporaryDirectory::masterDirectoryPath().toUtf8());
|
||||||
|
|
||||||
Sqlite::registerTypes();
|
Sqlite::registerTypes();
|
||||||
|
|
||||||
QCoreApplication application(argc, argv);
|
QCoreApplication application(argc, argv);
|
||||||
|
|||||||
Reference in New Issue
Block a user