Commit a5e96dbd authored by Marco Bubke's avatar Marco Bubke Committed by Tim Jenssen

Clang: Work around missing file

We now generate an empty fake file.

Change-Id: I92fef2b24dce788c1d1b675b034d4b31346b80d9
Reviewed-by: Tim Jenssen's avatarTim Jenssen <tim.jenssen@qt.io>
parent d74afaa0
......@@ -56,6 +56,8 @@ public:
auto &preprocessor = compilerInstance.getPreprocessor();
auto &headerSearch = preprocessor.getHeaderSearchInfo();
preprocessor.SetSuppressIncludeNotFoundError(true);
auto macroPreprocessorCallbacks = new CollectIncludesPreprocessorCallbacks(headerSearch,
m_includeIds,
m_filePathCache,
......
......@@ -35,6 +35,10 @@
#include <utils/smallstringvector.h>
#include <QFile>
#include <QDir>
#include <QTemporaryDir>
#include <algorithm>
namespace ClangBackEnd {
......@@ -64,7 +68,7 @@ public:
llvm::StringRef /*relativePath*/,
const clang::Module * /*imported*/) override
{
if (file) {
if (!m_skipInclude && file) {
auto fileUID = file->getUID();
if (isNotInExcludedIncludeUID(fileUID)) {
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
......@@ -131,6 +174,7 @@ private:
StringCache<Utils::PathString> &m_filePathCache;
const std::vector<uint> &m_excludedIncludeUID;
std::vector<uint> &m_alreadyIncludedFileUIDs;
bool m_skipInclude = false;
};
} // namespace ClangBackEnd
#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")));
}
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()
{
collector.addFile(TESTDATA_DIR, "includecollector_main.cpp", "", {"cc", "includecollector_main.cpp"});
......
......@@ -39,8 +39,11 @@
int main(int argc, char *argv[])
{
Utils::TemporaryDirectory::setMasterTemporaryDirectory(QDir::tempPath()
+"/QtCreator-UnitTests-XXXXXX");
const QString temporayDirectoryPath = QDir::tempPath() +"/QtCreator-UnitTests-XXXXXX";
Utils::TemporaryDirectory::setMasterTemporaryDirectory(temporayDirectoryPath);
qputenv("TMPDIR", Utils::TemporaryDirectory::masterDirectoryPath().toUtf8());
qputenv("TEMP", Utils::TemporaryDirectory::masterDirectoryPath().toUtf8());
Sqlite::registerTypes();
QCoreApplication application(argc, argv);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment