Commit b7f15d8c authored by Tobias Hunger's avatar Tobias Hunger

CMake: Do not crash when restarting a filesystem scan

Change-Id: I7a86169f4dd891c91295a7d6daadfd2bac8db751
Reviewed-by: Tim Jenssen's avatarTim Jenssen <tim.jenssen@qt.io>
parent 4b4dc9d0
......@@ -142,11 +142,12 @@ void BuildDirManager::updateReaderData()
void BuildDirManager::parseOnceReaderReady(bool force)
{
m_futureInterface.reset(new QFutureInterface<QList<ProjectExplorer::FileNode *>>());
m_futureWatcher.setFuture(m_futureInterface->future());
auto fi = new QFutureInterface<QList<ProjectExplorer::FileNode *>>();
m_scanFuture = fi->future();
m_futureWatcher.setFuture(m_scanFuture);
Core::ProgressManager::addTask(m_futureInterface->future(), "Scan CMake project tree", "CMake.Scan.Tree");
Utils::runAsync([this]() { BuildDirManager::asyncScanForFiles(*m_futureInterface); });
Core::ProgressManager::addTask(fi->future(), "Scan CMake project tree", "CMake.Scan.Tree");
Utils::runAsync([this, fi]() { BuildDirManager::asyncScanForFiles(fi); });
checkConfiguration();
m_reader->stop();
......@@ -237,9 +238,10 @@ void BuildDirManager::becameDirty()
m_reparseTimer.start(1000);
}
void BuildDirManager::asyncScanForFiles(QFutureInterface<QList<FileNode *> > &fi)
void BuildDirManager::asyncScanForFiles(QFutureInterface<QList<FileNode *>> *fi)
{
fi.reportStarted();
std::unique_ptr<QFutureInterface<QList<FileNode *>>> fip(fi);
fip->reportStarted();
Utils::MimeDatabase mdb;
QList<FileNode *> nodes
......@@ -274,10 +276,10 @@ void BuildDirManager::asyncScanForFiles(QFutureInterface<QList<FileNode *> > &fi
}
return new FileNode(fn, type, false);
},
&fi);
fi.setProgressValue(m_futureInterface->progressMaximum());
fi.reportResult(nodes);
fi.reportFinished();
fip.get());
fip->setProgressValue(fip->progressMaximum());
fip->reportResult(nodes);
fip->reportFinished();
}
void BuildDirManager::forceReparse()
......@@ -298,9 +300,7 @@ void BuildDirManager::resetData()
m_reader->resetData();
m_cmakeCache.clear();
QTC_ASSERT(!m_futureInterface || m_futureInterface->isFinished(), return);
m_futureInterface.reset();
m_futureWatcher.setFuture(QFuture<QList<FileNode *>>());
m_reader.reset();
}
......@@ -327,16 +327,16 @@ bool BuildDirManager::persistCMakeState()
void BuildDirManager::generateProjectTree(CMakeListsNode *root)
{
QTC_ASSERT(m_reader, return);
QTC_ASSERT(m_futureInterface, return);
QTC_ASSERT(m_scanFuture.isFinished(), return);
const Utils::FileName projectFile = m_buildConfiguration->target()->project()->projectFilePath();
QList<FileNode *> tmp = Utils::filtered(m_futureInterface->future().result(),
QList<FileNode *> tmp = Utils::filtered(m_scanFuture.result(),
[projectFile](const FileNode *fn) -> bool {
return !fn->filePath().toString().startsWith(projectFile.toString() + ".user");
});
Utils::sort(tmp, ProjectExplorer::Node::sortByPath);
m_futureInterface.reset(); // Make sure to flush the stale results
m_scanFuture = QFuture<QList<FileNode *>>(); // flush stale results
const QList<FileNode *> allFiles = tmp;
m_reader->generateProjectTree(root, allFiles);
......
......@@ -103,7 +103,7 @@ private:
void becameDirty();
void asyncScanForFiles(QFutureInterface<QList<ProjectExplorer::FileNode*>> &fi);
void asyncScanForFiles(QFutureInterface<QList<ProjectExplorer::FileNode *>> *fi);
CMakeBuildConfiguration *m_buildConfiguration = nullptr;
mutable std::unique_ptr<QTemporaryDir> m_tempDir = nullptr;
......@@ -112,8 +112,8 @@ private:
QTimer m_reparseTimer;
std::unique_ptr<BuildDirReader> m_reader;
std::unique_ptr<QFutureInterface<QList<ProjectExplorer::FileNode*>>> m_futureInterface;
QFutureWatcher<QList<ProjectExplorer::FileNode*>> m_futureWatcher;
QFuture<QList<ProjectExplorer::FileNode*>> m_scanFuture;
};
} // namespace Internal
......
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