2017-08-02 16:00:55 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2017 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
|
**
|
|
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "symbolindexer.h"
|
|
|
|
|
|
2018-12-17 12:06:57 +01:00
|
|
|
#include "symbolscollectorinterface.h"
|
|
|
|
|
#include "symbolindexertaskqueue.h"
|
|
|
|
|
|
|
|
|
|
#include <commandlinebuilder.h>
|
2019-04-24 14:07:39 +02:00
|
|
|
#include <environment.h>
|
2018-08-28 12:08:37 +02:00
|
|
|
|
2018-09-03 14:38:01 +02:00
|
|
|
#include <chrono>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
2017-08-02 16:00:55 +02:00
|
|
|
namespace ClangBackEnd {
|
|
|
|
|
|
2018-09-03 14:38:01 +02:00
|
|
|
using namespace std::chrono;
|
|
|
|
|
|
|
|
|
|
class Timer
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Timer(Utils::SmallStringView name)
|
|
|
|
|
: name(name)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
void commit()
|
|
|
|
|
{
|
|
|
|
|
auto end = steady_clock::now();
|
|
|
|
|
auto time_difference = duration_cast<milliseconds>(end - begin);
|
|
|
|
|
begin = end;
|
|
|
|
|
std::cerr << name << " " << timePoint++ << ": " << time_difference.count() << "\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Utils::SmallString name;
|
|
|
|
|
time_point<steady_clock> begin{steady_clock::now()};
|
|
|
|
|
int timePoint = 1;
|
|
|
|
|
};
|
|
|
|
|
|
2018-08-28 12:08:37 +02:00
|
|
|
SymbolIndexer::SymbolIndexer(SymbolIndexerTaskQueueInterface &symbolIndexerTaskQueue,
|
2017-10-26 13:23:27 +02:00
|
|
|
SymbolStorageInterface &symbolStorage,
|
2019-02-22 16:44:40 +01:00
|
|
|
BuildDependenciesStorageInterface &buildDependenciesStorage,
|
|
|
|
|
PrecompiledHeaderStorageInterface &precompiledHeaderStorage,
|
2018-01-22 14:21:01 +01:00
|
|
|
ClangPathWatcherInterface &pathWatcher,
|
|
|
|
|
FilePathCachingInterface &filePathCache,
|
2018-02-08 17:49:02 +01:00
|
|
|
FileStatusCache &fileStatusCache,
|
2019-03-13 15:09:30 +01:00
|
|
|
Sqlite::TransactionInterface &transactionInterface,
|
2019-03-21 17:55:24 +01:00
|
|
|
ProjectPartsStorageInterface &projectPartsStorage,
|
2019-04-24 14:07:39 +02:00
|
|
|
ModifiedTimeCheckerInterface<SourceTimeStamps> &modifiedTimeChecker,
|
|
|
|
|
const Environment &environment)
|
2019-02-22 16:44:40 +01:00
|
|
|
: m_symbolIndexerTaskQueue(symbolIndexerTaskQueue)
|
|
|
|
|
, m_symbolStorage(symbolStorage)
|
|
|
|
|
, m_buildDependencyStorage(buildDependenciesStorage)
|
|
|
|
|
, m_precompiledHeaderStorage(precompiledHeaderStorage)
|
|
|
|
|
, m_pathWatcher(pathWatcher)
|
|
|
|
|
, m_filePathCache(filePathCache)
|
|
|
|
|
, m_fileStatusCache(fileStatusCache)
|
|
|
|
|
, m_transactionInterface(transactionInterface)
|
2019-03-13 15:09:30 +01:00
|
|
|
, m_projectPartsStorage(projectPartsStorage)
|
2019-03-21 17:55:24 +01:00
|
|
|
, m_modifiedTimeChecker(modifiedTimeChecker)
|
2019-04-24 14:07:39 +02:00
|
|
|
, m_environment(environment)
|
2017-08-02 16:00:55 +02:00
|
|
|
{
|
2017-12-27 13:20:24 +01:00
|
|
|
pathWatcher.setNotifier(this);
|
2017-08-02 16:00:55 +02:00
|
|
|
}
|
|
|
|
|
|
2018-12-17 12:06:57 +01:00
|
|
|
void SymbolIndexer::updateProjectParts(ProjectPartContainers &&projectParts)
|
2018-01-22 14:21:01 +01:00
|
|
|
{
|
2018-12-17 12:06:57 +01:00
|
|
|
for (ProjectPartContainer &projectPart : projectParts)
|
2018-09-03 14:38:01 +02:00
|
|
|
updateProjectPart(std::move(projectPart));
|
2018-01-22 14:21:01 +01:00
|
|
|
}
|
|
|
|
|
|
2018-12-17 12:06:57 +01:00
|
|
|
void SymbolIndexer::updateProjectPart(ProjectPartContainer &&projectPart)
|
2017-08-02 16:00:55 +02:00
|
|
|
{
|
2019-03-13 15:09:30 +01:00
|
|
|
ProjectPartId projectPartId = projectPart.projectPartId;
|
2018-08-28 12:08:37 +02:00
|
|
|
|
|
|
|
|
std::vector<SymbolIndexerTask> symbolIndexerTask;
|
|
|
|
|
symbolIndexerTask.reserve(projectPart.sourcePathIds.size());
|
|
|
|
|
for (FilePathId sourcePathId : projectPart.sourcePathIds) {
|
2019-03-21 17:55:24 +01:00
|
|
|
SourceTimeStamps dependentTimeStamps = m_symbolStorage.fetchIncludedIndexingTimeStamps(
|
|
|
|
|
sourcePathId);
|
|
|
|
|
|
|
|
|
|
if (!m_modifiedTimeChecker.isUpToDate(dependentTimeStamps)) {
|
2019-04-25 17:58:15 +02:00
|
|
|
auto indexing = [projectPart,
|
2019-04-24 14:07:39 +02:00
|
|
|
sourcePathId,
|
|
|
|
|
preIncludeSearchPath = m_environment.preIncludeSearchPath(),
|
|
|
|
|
this](SymbolsCollectorInterface &symbolsCollector) {
|
2019-04-10 19:24:36 +02:00
|
|
|
auto collect = [&](const FilePath &pchPath) {
|
|
|
|
|
using Builder = CommandLineBuilder<ProjectPartContainer, Utils::SmallStringVector>;
|
|
|
|
|
Builder commandLineBuilder{projectPart,
|
|
|
|
|
projectPart.toolChainArguments,
|
|
|
|
|
InputFileType::Source,
|
|
|
|
|
{},
|
|
|
|
|
{},
|
2019-04-24 14:07:39 +02:00
|
|
|
pchPath,
|
|
|
|
|
preIncludeSearchPath};
|
2019-04-10 19:24:36 +02:00
|
|
|
symbolsCollector.setFile(sourcePathId, commandLineBuilder.commandLine);
|
|
|
|
|
|
|
|
|
|
return symbolsCollector.collectSymbols();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
auto store = [&] {
|
2019-03-21 17:55:24 +01:00
|
|
|
Sqlite::ImmediateTransaction transaction{m_transactionInterface};
|
|
|
|
|
m_symbolStorage.insertOrUpdateIndexingTimeStamps(symbolsCollector.fileStatuses());
|
|
|
|
|
m_symbolStorage.addSymbolsAndSourceLocations(symbolsCollector.symbols(),
|
|
|
|
|
symbolsCollector.sourceLocations());
|
|
|
|
|
transaction.commit();
|
2019-04-10 19:24:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const PchPaths pchPaths = m_precompiledHeaderStorage.fetchPrecompiledHeaders(
|
|
|
|
|
projectPart.projectPartId);
|
|
|
|
|
|
|
|
|
|
if (pchPaths.projectPchPath.size() && collect(pchPaths.projectPchPath)) {
|
|
|
|
|
store();
|
|
|
|
|
} else if (pchPaths.systemPchPath.size() && collect(pchPaths.systemPchPath)) {
|
|
|
|
|
store();
|
|
|
|
|
} else if (collect({})) {
|
|
|
|
|
store();
|
2019-03-21 17:55:24 +01:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
symbolIndexerTask.emplace_back(sourcePathId, projectPartId, std::move(indexing));
|
|
|
|
|
}
|
2018-02-07 16:18:16 +01:00
|
|
|
}
|
2018-08-28 12:08:37 +02:00
|
|
|
|
|
|
|
|
m_symbolIndexerTaskQueue.addOrUpdateTasks(std::move(symbolIndexerTask));
|
2018-09-11 17:02:45 +02:00
|
|
|
m_symbolIndexerTaskQueue.processEntries();
|
2017-08-02 16:00:55 +02:00
|
|
|
}
|
|
|
|
|
|
2019-03-13 15:09:30 +01:00
|
|
|
void SymbolIndexer::pathsWithIdsChanged(const ProjectPartIds &) {}
|
2017-12-27 13:20:24 +01:00
|
|
|
|
|
|
|
|
void SymbolIndexer::pathsChanged(const FilePathIds &filePathIds)
|
|
|
|
|
{
|
2019-03-21 17:55:24 +01:00
|
|
|
FilePathIds dependentSourcePathIds = m_symbolStorage.fetchDependentSourceIds(filePathIds);
|
|
|
|
|
|
2018-08-28 12:08:37 +02:00
|
|
|
std::vector<SymbolIndexerTask> symbolIndexerTask;
|
2019-03-21 17:55:24 +01:00
|
|
|
symbolIndexerTask.reserve(dependentSourcePathIds.size());
|
2018-08-28 12:08:37 +02:00
|
|
|
|
2019-03-21 17:55:24 +01:00
|
|
|
for (FilePathId dependentSourcePathId : dependentSourcePathIds)
|
|
|
|
|
updateChangedPath(dependentSourcePathId, symbolIndexerTask);
|
2018-08-28 12:08:37 +02:00
|
|
|
|
|
|
|
|
m_symbolIndexerTaskQueue.addOrUpdateTasks(std::move(symbolIndexerTask));
|
2018-09-11 17:02:45 +02:00
|
|
|
m_symbolIndexerTaskQueue.processEntries();
|
2018-02-06 11:16:29 +01:00
|
|
|
}
|
|
|
|
|
|
2018-08-28 12:08:37 +02:00
|
|
|
void SymbolIndexer::updateChangedPath(FilePathId filePathId,
|
|
|
|
|
std::vector<SymbolIndexerTask> &symbolIndexerTask)
|
2018-02-06 11:16:29 +01:00
|
|
|
{
|
2018-02-08 17:49:02 +01:00
|
|
|
m_fileStatusCache.update(filePathId);
|
2018-02-06 11:16:29 +01:00
|
|
|
|
2018-08-28 12:08:37 +02:00
|
|
|
Sqlite::DeferredTransaction transaction{m_transactionInterface};
|
2019-03-13 15:09:30 +01:00
|
|
|
const Utils::optional<ProjectPartArtefact>
|
|
|
|
|
optionalArtefact = m_projectPartsStorage.fetchProjectPartArtefact(filePathId);
|
2018-09-04 14:24:42 +02:00
|
|
|
if (!optionalArtefact)
|
|
|
|
|
return;
|
2019-04-10 18:21:22 +02:00
|
|
|
transaction.commit();
|
2018-09-04 14:24:42 +02:00
|
|
|
|
2019-04-10 18:43:03 +02:00
|
|
|
ProjectPartId projectPartId = optionalArtefact->projectPartId;
|
|
|
|
|
|
2019-03-21 17:55:24 +01:00
|
|
|
SourceTimeStamps dependentTimeStamps = m_symbolStorage.fetchIncludedIndexingTimeStamps(filePathId);
|
|
|
|
|
|
2019-04-24 14:07:39 +02:00
|
|
|
auto indexing = [optionalArtefact = std::move(optionalArtefact),
|
|
|
|
|
filePathId,
|
|
|
|
|
preIncludeSearchPath = m_environment.preIncludeSearchPath(),
|
|
|
|
|
this](SymbolsCollectorInterface &symbolsCollector) {
|
2019-04-10 19:24:36 +02:00
|
|
|
auto collect = [&](const FilePath &pchPath) {
|
|
|
|
|
const ProjectPartArtefact &artefact = *optionalArtefact;
|
2018-02-06 11:16:29 +01:00
|
|
|
|
2019-04-10 19:24:36 +02:00
|
|
|
using Builder = CommandLineBuilder<ProjectPartArtefact, Utils::SmallStringVector>;
|
2019-04-24 14:07:39 +02:00
|
|
|
Builder builder{artefact,
|
|
|
|
|
artefact.toolChainArguments,
|
|
|
|
|
InputFileType::Source,
|
|
|
|
|
{},
|
|
|
|
|
{},
|
|
|
|
|
pchPath,
|
|
|
|
|
preIncludeSearchPath};
|
2018-08-28 12:08:37 +02:00
|
|
|
|
2019-04-10 19:24:36 +02:00
|
|
|
symbolsCollector.setFile(filePathId, builder.commandLine);
|
2018-02-06 11:16:29 +01:00
|
|
|
|
2019-04-10 19:24:36 +02:00
|
|
|
return symbolsCollector.collectSymbols();
|
|
|
|
|
};
|
2018-02-06 11:16:29 +01:00
|
|
|
|
2019-04-10 19:24:36 +02:00
|
|
|
auto store = [&] {
|
2019-02-07 12:20:51 +01:00
|
|
|
Sqlite::ImmediateTransaction transaction{m_transactionInterface};
|
2019-03-21 17:55:24 +01:00
|
|
|
m_symbolStorage.insertOrUpdateIndexingTimeStamps(symbolsCollector.fileStatuses());
|
2019-02-07 12:20:51 +01:00
|
|
|
m_symbolStorage.addSymbolsAndSourceLocations(symbolsCollector.symbols(),
|
|
|
|
|
symbolsCollector.sourceLocations());
|
|
|
|
|
transaction.commit();
|
2019-04-10 19:24:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const PchPaths pchPaths = m_precompiledHeaderStorage.fetchPrecompiledHeaders(
|
|
|
|
|
optionalArtefact->projectPartId);
|
|
|
|
|
|
|
|
|
|
if (pchPaths.projectPchPath.size() && collect(pchPaths.projectPchPath)) {
|
|
|
|
|
store();
|
|
|
|
|
} else if (pchPaths.systemPchPath.size() && collect(pchPaths.systemPchPath)) {
|
|
|
|
|
store();
|
|
|
|
|
} else if (collect({})) {
|
|
|
|
|
store();
|
2019-02-07 12:20:51 +01:00
|
|
|
}
|
2019-01-23 14:10:58 +01:00
|
|
|
};
|
|
|
|
|
|
2019-04-10 18:43:03 +02:00
|
|
|
symbolIndexerTask.emplace_back(filePathId, projectPartId, std::move(indexing));
|
2017-12-27 13:20:24 +01:00
|
|
|
}
|
|
|
|
|
|
2018-02-20 12:43:05 +01:00
|
|
|
bool SymbolIndexer::compilerMacrosOrIncludeSearchPathsAreDifferent(
|
2018-12-17 12:06:57 +01:00
|
|
|
const ProjectPartContainer &projectPart,
|
2018-02-20 12:43:05 +01:00
|
|
|
const Utils::optional<ProjectPartArtefact> &optionalArtefact) const
|
2018-02-07 16:18:16 +01:00
|
|
|
{
|
2018-02-08 12:48:46 +01:00
|
|
|
if (optionalArtefact) {
|
|
|
|
|
const ProjectPartArtefact &artefact = optionalArtefact.value();
|
2018-04-04 18:25:23 +02:00
|
|
|
return projectPart.compilerMacros != artefact.compilerMacros
|
2018-12-17 12:06:57 +01:00
|
|
|
|| projectPart.systemIncludeSearchPaths != artefact.systemIncludeSearchPaths
|
|
|
|
|
|| projectPart.projectIncludeSearchPaths != artefact.projectIncludeSearchPaths;
|
2018-02-08 12:48:46 +01:00
|
|
|
}
|
2018-02-07 16:18:16 +01:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-17 12:06:57 +01:00
|
|
|
FilePathIds SymbolIndexer::filterChangedFiles(const ProjectPartContainer &projectPart) const
|
2018-02-08 17:49:02 +01:00
|
|
|
{
|
|
|
|
|
FilePathIds ids;
|
2018-04-04 18:25:23 +02:00
|
|
|
ids.reserve(projectPart.sourcePathIds.size());
|
2018-02-08 17:49:02 +01:00
|
|
|
|
2018-04-04 18:25:23 +02:00
|
|
|
for (const FilePathId &sourceId : projectPart.sourcePathIds) {
|
2018-12-17 12:06:57 +01:00
|
|
|
long long oldLastModified = m_buildDependencyStorage.fetchLowestLastModifiedTime(sourceId);
|
2018-02-08 17:49:02 +01:00
|
|
|
long long currentLastModified = m_fileStatusCache.lastModifiedTime(sourceId);
|
|
|
|
|
if (oldLastModified < currentLastModified)
|
|
|
|
|
ids.push_back(sourceId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ids;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-17 12:06:57 +01:00
|
|
|
FilePathIds SymbolIndexer::updatableFilePathIds(const ProjectPartContainer &projectPart,
|
2018-02-20 12:43:05 +01:00
|
|
|
const Utils::optional<ProjectPartArtefact> &optionalArtefact) const
|
2018-02-08 17:49:02 +01:00
|
|
|
{
|
2018-02-20 12:43:05 +01:00
|
|
|
if (compilerMacrosOrIncludeSearchPathsAreDifferent(projectPart, optionalArtefact))
|
2018-04-04 18:25:23 +02:00
|
|
|
return projectPart.sourcePathIds;
|
2018-02-08 17:49:02 +01:00
|
|
|
|
|
|
|
|
return filterChangedFiles(projectPart);
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-02 16:00:55 +02:00
|
|
|
} // namespace ClangBackEnd
|