Clang: Fix system pre include search path

We now get the resource path from creator. The -fPIC case is working now
too.

Change-Id: Id191e89e6d46706748d50440038a06a349972cc9
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
Marco Bubke
2019-04-24 14:07:39 +02:00
parent 1975641a3d
commit 2d520140d0
42 changed files with 398 additions and 234 deletions

View File

@@ -0,0 +1,2 @@
#include_next <QtCore/qconfig.h>
#undef QT_REDUCE_RELOCATIONS

View File

@@ -0,0 +1 @@
../qglobal.h

View File

@@ -22,7 +22,8 @@ DATA_DIRS = \
qml-type-descriptions \
modeleditor \
glsl \
cplusplus
cplusplus \
indexer_preincludes
macx: DATA_DIRS += scripts
for(data_dir, DATA_DIRS) {

View File

@@ -217,6 +217,7 @@ HEADERS += \
$$PWD/projectpartcontainer.h \
$$PWD/sourceentry.h \
$$PWD/modifiedtimecheckerinterface.h \
$$PWD/environment.h \
$$PWD/modifiedtimechecker.h
contains(QT_CONFIG, reduce_exports):CONFIG += hide_symbols

View File

@@ -49,7 +49,8 @@ public:
InputFileType sourceType = InputFileType::Header,
FilePathView sourcePath = {},
FilePathView outputPath = {},
FilePathView includePchPath = {})
FilePathView includePchPath = {},
NativeFilePathView preIncludeSearchPath = {})
{
commandLine.reserve(1024);
@@ -61,7 +62,7 @@ public:
addLanguageVersion(projectInfo);
addNoStdIncAndNoStdLibInc(projectInfo.language);
addCompilerMacros(projectInfo.compilerMacros);
addPreIncludeSearchPath();
addPreIncludeSearchPath(preIncludeSearchPath);
addProjectIncludeSearchPaths(
sortedIncludeSearchPaths(projectInfo.projectIncludeSearchPaths));
addSystemAndBuiltInIncludeSearchPaths(
@@ -220,18 +221,12 @@ public:
commandLine.emplace_back(Utils::SmallString{"-D", macro.key, "=", macro.value});
}
QString resourcePath() const
void addPreIncludeSearchPath(NativeFilePathView preIncludeSearchPath)
{
return QDir::cleanPath(QCoreApplication::applicationDirPath() + '/' + RELATIVE_DATA_PATH
+ "/indexing_preincludes");
}
void addPreIncludeSearchPath()
{
static NativeFilePath preIncludeSearchPath{FilePath{resourcePath()}};
commandLine.emplace_back("-I");
commandLine.emplace_back(preIncludeSearchPath);
if (!preIncludeSearchPath.empty()) {
commandLine.emplace_back("-isystem");
commandLine.emplace_back(preIncludeSearchPath);
}
}
IncludeSearchPaths sortedIncludeSearchPaths(const IncludeSearchPaths &unsortedPaths)

View File

@@ -25,7 +25,7 @@
#pragma once
#include <QString>
#include <nativefilepath.h>
namespace ClangBackEnd {
@@ -36,8 +36,9 @@ public:
Environment(const Environment &) = delete;
Environment &operator=(const Environment &) = delete;
virtual QString pchBuildDirectory() const = 0;
virtual Utils::PathString pchBuildDirectory() const = 0;
virtual uint hardwareConcurrency() const = 0;
virtual NativeFilePathView preIncludeSearchPath() const = 0;
protected:
~Environment() = default;

View File

@@ -56,7 +56,8 @@ ClangPchManager::PchManagerConnectionClient::PchManagerConnectionClient(
pchsDirectory.cd("pchs");
m_processCreator.setArguments({connectionName(),
Core::ICore::cacheResourcePath() + "/symbol-experimental-v1.db",
pchsDirectory.absolutePath()});
pchsDirectory.absolutePath(),
Core::ICore::resourcePath()});
stdErrPrefixer().setPrefix("PchManagerConnectionClient.stderr: ");
stdOutPrefixer().setPrefix("PchManagerConnectionClient.stdout: ");

View File

@@ -153,7 +153,6 @@ QStringList ProjectUpdater::toolChainArguments(CppTools::ProjectPart *projectPar
CompilerOptionsBuilder builder(*projectPart, CppTools::UseSystemHeader::Yes);
builder.addWordWidth();
builder.addPicIfCompilerFlagsContainsIt();
// builder.addTargetTriple(); TODO resarch why target triples are different
builder.addExtraCodeModelFlags();
builder.undefineClangVersionMacrosForMsvc();

View File

@@ -48,8 +48,9 @@ RefactoringConnectionClient::RefactoringConnectionClient(RefactoringClientInterf
, m_serverProxy(client)
{
m_processCreator.setTemporaryDirectoryPattern("clangrefactoringbackend-XXXXXX");
m_processCreator.setArguments(
{connectionName(), Core::ICore::cacheResourcePath() + "/symbol-experimental-v1.db"});
m_processCreator.setArguments({connectionName(),
Core::ICore::cacheResourcePath() + "/symbol-experimental-v1.db",
Core::ICore::resourcePath()});
stdErrPrefixer().setPrefix("RefactoringConnectionClient.stderr: ");
stdOutPrefixer().setPrefix("RefactoringConnectionClient.stdout: ");

View File

@@ -95,23 +95,22 @@ public:
class ApplicationEnvironment final : public ClangBackEnd::Environment
{
public:
ApplicationEnvironment(const QString &pchsPath)
: m_pchBuildDirectoryPath(pchsPath)
ApplicationEnvironment(const QString &pchsPath, const QString &preIncludeSearchPath)
: m_pchBuildDirectoryPath(pchsPath.toStdString())
, m_preIncludeSearchPath(ClangBackEnd::FilePath{preIncludeSearchPath})
{
}
QString pchBuildDirectory() const override
Utils::PathString pchBuildDirectory() const override { return m_pchBuildDirectoryPath; }
uint hardwareConcurrency() const override { return std::thread::hardware_concurrency(); }
ClangBackEnd::NativeFilePathView preIncludeSearchPath() const override
{
return m_pchBuildDirectoryPath;
}
uint hardwareConcurrency() const override
{
return std::thread::hardware_concurrency();
return m_preIncludeSearchPath;
}
private:
QString m_pchBuildDirectoryPath;
Utils::PathString m_pchBuildDirectoryPath;
ClangBackEnd::NativeFilePath m_preIncludeSearchPath;
};
QStringList processArguments(QCoreApplication &application)
@@ -123,6 +122,7 @@ QStringList processArguments(QCoreApplication &application)
parser.addPositionalArgument(QStringLiteral("connection"), QStringLiteral("Connection"));
parser.addPositionalArgument(QStringLiteral("databasepath"), QStringLiteral("Database path"));
parser.addPositionalArgument(QStringLiteral("pchspath"), QStringLiteral("PCHs path"));
parser.addPositionalArgument(QStringLiteral("resourcepath"), QStringLiteral("Resource path"));
parser.process(application);
@@ -172,9 +172,9 @@ struct Data // because we have a cycle dependency
{
using TaskScheduler = ClangBackEnd::TaskScheduler<PchCreatorManager, ClangBackEnd::PchTaskQueue::Task>;
Data(const QString &databasePath, const QString &pchsPath)
Data(const QString &databasePath, const QString &pchsPath, const QString &preIncludeSearchPath)
: database{Utils::PathString{databasePath}, 100000ms}
, environment{pchsPath}
, environment{pchsPath, preIncludeSearchPath}
{}
Sqlite::Database database;
ClangBackEnd::RefactoringDatabaseInitializer<Sqlite::Database> databaseInitializer{database};
@@ -205,7 +205,8 @@ struct Data // because we have a cycle dependency
projectTaskScheduler,
pchCreationProgressCounter,
preCompiledHeaderStorage,
database};
database,
environment};
ClangBackEnd::PchTasksMerger pchTaskMerger{pchTaskQueue};
ClangBackEnd::BuildDependenciesStorage<> buildDependencyStorage{database};
ClangBackEnd::BuildDependencyCollector buildDependencyCollector{filePathCache,
@@ -266,8 +267,9 @@ int main(int argc, char *argv[])
const QString connectionName = arguments[0];
const QString databasePath = arguments[1];
const QString pchsPath = arguments[2];
const QString preIncludeSearchPath = arguments[3] + "/indexer_preincludes";
Data data{databasePath, pchsPath};
Data data{databasePath, pchsPath, preIncludeSearchPath};
data.includeWatcher.setNotifier(&data.clangPchManagerServer);

View File

@@ -33,7 +33,7 @@
#include <utils/smallstring.h>
#include <algorithm>
#include <iostream>
namespace ClangBackEnd {
namespace {
@@ -68,18 +68,26 @@ FilePaths generatedFilePaths(const V2::FileContainers &containers) {
BuildDependency BuildDependencyCollector::create(const ProjectPartContainer &projectPart)
{
CommandLineBuilder<ProjectPartContainer, Utils::SmallStringVector>
builder{projectPart, projectPart.toolChainArguments, InputFileType::Source};
if (projectPart.sourcePathIds.size()) {
CommandLineBuilder<ProjectPartContainer, Utils::SmallStringVector> builder{
projectPart,
projectPart.toolChainArguments,
InputFileType::Source,
{},
{},
{},
m_environment.preIncludeSearchPath()};
addFiles(projectPart.sourcePathIds, std::move(builder.commandLine));
addFiles(projectPart.sourcePathIds, std::move(builder.commandLine));
setExcludedFilePaths(m_filePathCache.filePaths(projectPart.headerPathIds +
projectPart.sourcePathIds) +
generatedFilePaths(m_generatedFiles.fileContainers()));
setExcludedFilePaths(
m_filePathCache.filePaths(projectPart.headerPathIds + projectPart.sourcePathIds)
+ generatedFilePaths(m_generatedFiles.fileContainers()));
addUnsavedFiles(m_generatedFiles.fileContainers());
addUnsavedFiles(m_generatedFiles.fileContainers());
collect();
collect();
}
auto buildDependency = std::move(m_buildDependency);
@@ -147,7 +155,7 @@ void BuildDependencyCollector::setExcludedFilePaths(ClangBackEnd::FilePaths &&ex
void BuildDependencyCollector::addFiles(const FilePathIds &filePathIds,
Utils::SmallStringVector &&arguments)
{
m_clangTool.addFile(FilePath{m_environment.pchBuildDirectory().toStdString(), "dummy.cpp"},
m_clangTool.addFile(FilePath{m_environment.pchBuildDirectory(), "dummy.cpp"},
generateFakeFileContent(filePathIds),
std::move(arguments));
m_buildDependency.sourceFiles.insert(m_buildDependency.sourceFiles.end(),

View File

@@ -12,7 +12,6 @@ HEADERS += \
$$PWD/pchmanagerserver.h \
$$PWD/clangpchmanagerbackend_global.h \
$$PWD/pchnotcreatederror.h \
$$PWD/environment.h \
$$PWD/pchcreatorinterface.h \
$$PWD/projectpartsmanager.h \
$$PWD/projectpartsmanagerinterface.h \

View File

@@ -104,7 +104,8 @@ Utils::SmallStringVector PchCreator::generateClangCompilerArguments(const PchTas
InputFileType::Header,
{},
pchOutputPath,
pchTask.systemPchPath};
pchTask.systemPchPath,
pchTask.preIncludeSearchPath};
return builder.commandLine;
}
@@ -117,7 +118,7 @@ void PchCreator::generatePch(PchTask &&pchTask)
auto content = generatePchIncludeFileContent(pchTask.includes);
auto pchOutputPath = generatePchFilePath();
FilePath headerFilePath{m_environment.pchBuildDirectory().toStdString(), "dummy.h"};
FilePath headerFilePath{m_environment.pchBuildDirectory(), "dummy.h"};
Utils::SmallStringVector commandLine = generateClangCompilerArguments(pchTask, pchOutputPath);
m_clangTool.addFile(std::move(headerFilePath), content.clone(), std::move(commandLine));

View File

@@ -94,8 +94,8 @@ public:
&& first.systemIncludeSearchPaths == second.systemIncludeSearchPaths
&& first.projectIncludeSearchPaths == second.projectIncludeSearchPaths
&& first.toolChainArguments == second.toolChainArguments
&& first.language == second.language
&& first.languageVersion == second.languageVersion
&& first.preIncludeSearchPath == second.preIncludeSearchPath
&& first.language == second.language && first.languageVersion == second.languageVersion
&& first.languageExtension == second.languageExtension;
}
@@ -110,6 +110,7 @@ public:
IncludeSearchPaths systemIncludeSearchPaths;
IncludeSearchPaths projectIncludeSearchPaths;
Utils::SmallStringVector toolChainArguments;
NativeFilePathView preIncludeSearchPath;
Utils::Language language = Utils::Language::Cxx;
Utils::LanguageVersion languageVersion = Utils::LanguageVersion::CXX98;
Utils::LanguageExtension languageExtension = Utils::LanguageExtension::None;

View File

@@ -25,6 +25,7 @@
#include "pchtaskqueue.h"
#include <environment.h>
#include <pchcreatorinterface.h>
#include <precompiledheaderstorageinterface.h>
#include <progresscounter.h>
@@ -147,6 +148,7 @@ std::vector<PchTaskQueue::Task> PchTaskQueue::createProjectTasks(PchTasks &&pchT
if (pchTask.includes.size()) {
pchTask.systemPchPath = m_precompiledHeaderStorage.fetchSystemPrecompiledHeaderPath(
projectPartId);
pchTask.preIncludeSearchPath = m_environment.preIncludeSearchPath();
pchCreator.generatePch(std::move(pchTask));
const auto &projectPartPch = pchCreator.projectPartPch();
if (projectPartPch.pchPath.empty()) {
@@ -178,6 +180,7 @@ std::vector<PchTaskQueue::Task> PchTaskQueue::createSystemTasks(PchTasks &&pchTa
return [pchTask = std::move(pchTask), this](PchCreatorInterface &pchCreator) mutable {
const auto projectPartIds = pchTask.projectPartIds;
if (pchTask.includes.size()) {
pchTask.preIncludeSearchPath = m_environment.preIncludeSearchPath();
pchCreator.generatePch(std::move(pchTask));
const auto &projectPartPch = pchCreator.projectPartPch();
if (projectPartPch.pchPath.empty()) {

View File

@@ -36,6 +36,7 @@ namespace ClangBackEnd {
class PchCreatorInterface;
class PrecompiledHeaderStorageInterface;
class ProgressCounter;
class Environment;
class PchTaskQueue final : public PchTaskQueueInterface
{
@@ -46,12 +47,14 @@ public:
TaskSchedulerInterface<Task> &projectPchTaskScheduler,
ProgressCounter &progressCounter,
PrecompiledHeaderStorageInterface &precompiledHeaderStorage,
Sqlite::TransactionInterface &transactionsInterface)
Sqlite::TransactionInterface &transactionsInterface,
const Environment &environment)
: m_systemPchTaskScheduler(systemPchTaskScheduler)
, m_projectPchTaskScheduler(projectPchTaskScheduler)
, m_precompiledHeaderStorage(precompiledHeaderStorage)
, m_transactionsInterface(transactionsInterface)
, m_progressCounter(progressCounter)
, m_environment(environment)
{}
void addSystemPchTasks(PchTasks &&pchTasks) override;
@@ -80,6 +83,7 @@ private:
PrecompiledHeaderStorageInterface &m_precompiledHeaderStorage;
Sqlite::TransactionInterface &m_transactionsInterface;
ProgressCounter &m_progressCounter;
const Environment &m_environment;
};
} // namespace ClangBackEnd

View File

@@ -30,11 +30,12 @@
#include <QDir>
#include <connectionserver.h>
#include <environment.h>
#include <executeinloop.h>
#include <filepathcaching.h>
#include <generatedfiles.h>
#include <refactoringserver.h>
#include <refactoringclientproxy.h>
#include <refactoringserver.h>
#include <symbolindexing.h>
#include <sqliteexception.h>
@@ -59,6 +60,8 @@ QStringList processArguments(QCoreApplication &application)
parser.addHelpOption();
parser.addVersionOption();
parser.addPositionalArgument(QStringLiteral("connection"), QStringLiteral("Connection"));
parser.addPositionalArgument(QStringLiteral("databasepath"), QStringLiteral("Database path"));
parser.addPositionalArgument(QStringLiteral("resourcepath"), QStringLiteral("Resource path"));
parser.process(application);
@@ -85,12 +88,32 @@ public:
}
};
struct Data // because we have a cycle dependency
class ApplicationEnvironment final : public ClangBackEnd::Environment
{
Data(const QString &databasePath)
: database{Utils::PathString{databasePath}, 100000ms}
public:
ApplicationEnvironment(const QString &preIncludeSearchPath)
: m_preIncludeSearchPath(ClangBackEnd::FilePath{preIncludeSearchPath})
{}
Utils::PathString pchBuildDirectory() const override { return {}; }
uint hardwareConcurrency() const override { return std::thread::hardware_concurrency(); }
ClangBackEnd::NativeFilePathView preIncludeSearchPath() const override
{
return m_preIncludeSearchPath;
}
private:
ClangBackEnd::NativeFilePath m_preIncludeSearchPath;
};
struct Data // because we have a cycle dependency
{
Data(const QString &databasePath, const QString &preIncludeSearchPath)
: environment{preIncludeSearchPath}
, database{Utils::PathString{databasePath}, 100000ms}
{}
ApplicationEnvironment environment;
Sqlite::Database database;
RefactoringDatabaseInitializer<Sqlite::Database> databaseInitializer{database};
FilePathCaching filePathCache{database};
@@ -103,7 +126,8 @@ struct Data // because we have a cycle dependency
executeInLoop([&] {
clangCodeModelServer.setProgress(progress, total);
});
}};
},
environment};
};
#ifdef Q_OS_WIN
@@ -131,8 +155,9 @@ int main(int argc, char *argv[])
const QStringList arguments = processArguments(application);
const QString connectionName = arguments[0];
const QString databasePath = arguments[1];
const QString preIncludeSearchPath = arguments[2] + "/indexer_preincludes";
Data data{databasePath};
Data data{databasePath, preIncludeSearchPath};
ConnectionServer<RefactoringServer, RefactoringClientProxy> connectionServer;
connectionServer.setServer(&data.clangCodeModelServer);

View File

@@ -29,6 +29,7 @@
#include "symbolindexertaskqueue.h"
#include <commandlinebuilder.h>
#include <environment.h>
#include <chrono>
#include <iostream>
@@ -67,7 +68,8 @@ SymbolIndexer::SymbolIndexer(SymbolIndexerTaskQueueInterface &symbolIndexerTaskQ
FileStatusCache &fileStatusCache,
Sqlite::TransactionInterface &transactionInterface,
ProjectPartsStorageInterface &projectPartsStorage,
ModifiedTimeCheckerInterface<SourceTimeStamps> &modifiedTimeChecker)
ModifiedTimeCheckerInterface<SourceTimeStamps> &modifiedTimeChecker,
const Environment &environment)
: m_symbolIndexerTaskQueue(symbolIndexerTaskQueue)
, m_symbolStorage(symbolStorage)
, m_buildDependencyStorage(buildDependenciesStorage)
@@ -78,6 +80,7 @@ SymbolIndexer::SymbolIndexer(SymbolIndexerTaskQueueInterface &symbolIndexerTaskQ
, m_transactionInterface(transactionInterface)
, m_projectPartsStorage(projectPartsStorage)
, m_modifiedTimeChecker(modifiedTimeChecker)
, m_environment(environment)
{
pathWatcher.setNotifier(this);
}
@@ -99,8 +102,10 @@ void SymbolIndexer::updateProjectPart(ProjectPartContainer &&projectPart)
sourcePathId);
if (!m_modifiedTimeChecker.isUpToDate(dependentTimeStamps)) {
auto indexing = [projectPart = std::move(projectPart), sourcePathId, this](
SymbolsCollectorInterface &symbolsCollector) {
auto indexing = [projectPart = std::move(projectPart),
sourcePathId,
preIncludeSearchPath = m_environment.preIncludeSearchPath(),
this](SymbolsCollectorInterface &symbolsCollector) {
auto collect = [&](const FilePath &pchPath) {
using Builder = CommandLineBuilder<ProjectPartContainer, Utils::SmallStringVector>;
Builder commandLineBuilder{projectPart,
@@ -108,7 +113,8 @@ void SymbolIndexer::updateProjectPart(ProjectPartContainer &&projectPart)
InputFileType::Source,
{},
{},
pchPath};
pchPath,
preIncludeSearchPath};
symbolsCollector.setFile(sourcePathId, commandLineBuilder.commandLine);
return symbolsCollector.collectSymbols();
@@ -174,13 +180,21 @@ void SymbolIndexer::updateChangedPath(FilePathId filePathId,
SourceTimeStamps dependentTimeStamps = m_symbolStorage.fetchIncludedIndexingTimeStamps(filePathId);
auto indexing = [optionalArtefact = std::move(optionalArtefact), filePathId, this](
SymbolsCollectorInterface &symbolsCollector) {
auto indexing = [optionalArtefact = std::move(optionalArtefact),
filePathId,
preIncludeSearchPath = m_environment.preIncludeSearchPath(),
this](SymbolsCollectorInterface &symbolsCollector) {
auto collect = [&](const FilePath &pchPath) {
const ProjectPartArtefact &artefact = *optionalArtefact;
using Builder = CommandLineBuilder<ProjectPartArtefact, Utils::SmallStringVector>;
Builder builder{artefact, artefact.toolChainArguments, InputFileType::Source, {}, {}, pchPath};
Builder builder{artefact,
artefact.toolChainArguments,
InputFileType::Source,
{},
{},
pchPath,
preIncludeSearchPath};
symbolsCollector.setFile(filePathId, builder.commandLine);

View File

@@ -40,6 +40,7 @@
namespace ClangBackEnd {
class SymbolsCollectorInterface;
class Environment;
class SymbolIndexer final : public ClangPathWatcherNotifier
{
@@ -53,7 +54,8 @@ public:
FileStatusCache &fileStatusCache,
Sqlite::TransactionInterface &transactionInterface,
ProjectPartsStorageInterface &projectPartsStorage,
ModifiedTimeCheckerInterface<SourceTimeStamps> &modifiedTimeChecker);
ModifiedTimeCheckerInterface<SourceTimeStamps> &modifiedTimeChecker,
const Environment &environment);
void updateProjectParts(ProjectPartContainers &&projectParts);
void updateProjectPart(ProjectPartContainer &&projectPart);
@@ -84,6 +86,7 @@ private:
Sqlite::TransactionInterface &m_transactionInterface;
ProjectPartsStorageInterface &m_projectPartsStorage;
ModifiedTimeCheckerInterface<SourceTimeStamps> &m_modifiedTimeChecker;
const Environment &m_environment;
};
} // namespace ClangBackEnd

View File

@@ -85,7 +85,8 @@ public:
SymbolIndexing(Sqlite::Database &database,
FilePathCachingInterface &filePathCache,
const GeneratedFiles &generatedFiles,
ProgressCounter::SetProgressCallback &&setProgressCallback)
ProgressCounter::SetProgressCallback &&setProgressCallback,
const Environment &environment)
: m_filePathCache(filePathCache)
, m_buildDependencyStorage(database)
, m_precompiledHeaderStorage(database)
@@ -93,6 +94,17 @@ public:
, m_symbolStorage(database)
, m_collectorManger(generatedFiles, database)
, m_progressCounter(std::move(setProgressCallback))
, m_indexer(m_indexerQueue,
m_symbolStorage,
m_buildDependencyStorage,
m_precompiledHeaderStorage,
m_sourceWatcher,
m_filePathCache,
m_fileStatusCache,
m_symbolStorage.database,
m_projectPartsStorage,
m_modifiedTimeChecker,
environment)
, m_indexerScheduler(m_collectorManger,
m_indexerQueue,
m_progressCounter,
@@ -139,16 +151,7 @@ private:
}};
ModifiedTimeChecker<ClangBackEnd::SourceTimeStamps> m_modifiedTimeChecker{getModifiedTime,
m_filePathCache};
SymbolIndexer m_indexer{m_indexerQueue,
m_symbolStorage,
m_buildDependencyStorage,
m_precompiledHeaderStorage,
m_sourceWatcher,
m_filePathCache,
m_fileStatusCache,
m_symbolStorage.database,
m_projectPartsStorage,
m_modifiedTimeChecker};
SymbolIndexer m_indexer;
SymbolIndexerTaskQueue m_indexerQueue{m_indexerScheduler, m_progressCounter};
SymbolIndexerTaskScheduler m_indexerScheduler;
};

View File

@@ -12,5 +12,10 @@ inline static QString cacheResourcePath()
return QDir::tempPath();
}
inline static QString resourcePath()
{
return QDir::tempPath();
}
} // namespace ICore
} // namespace Core

View File

@@ -737,10 +737,16 @@ TEST_F(BuildDependencyCollector, Create)
1,
{},
{},
{{TESTDATA_DIR "/builddependencycollector/system", 1, IncludeSearchPathType::System}},
{{TESTDATA_DIR "/builddependencycollector/system",
1,
ClangBackEnd::IncludeSearchPathType::System}},
{
{TESTDATA_DIR "/builddependencycollector/project", 1, IncludeSearchPathType::User},
{TESTDATA_DIR "/builddependencycollector/external", 2, IncludeSearchPathType::User},
{TESTDATA_DIR "/builddependencycollector/project",
1,
ClangBackEnd::IncludeSearchPathType::User},
{TESTDATA_DIR "/builddependencycollector/external",
2,
ClangBackEnd::IncludeSearchPathType::User},
},
{
id(TESTDATA_DIR "/builddependencycollector/project/header1.h"),
@@ -771,6 +777,7 @@ TEST_F(BuildDependencyCollector, Create)
"/builddependencycollector/external/indirect_external2.h"),
fileStatus(TESTDATA_DIR "/builddependencycollector/external/external2.h"),
fileStatus(TESTDATA_DIR "/builddependencycollector/system/system1.h"),
fileStatus(TESTDATA_DIR "/preincludes/system1.h"),
fileStatus(TESTDATA_DIR "/builddependencycollector/system/indirect_system.h"),
fileStatus(TESTDATA_DIR
"/builddependencycollector/system/indirect_system2.h"),
@@ -804,7 +811,7 @@ TEST_F(BuildDependencyCollector, Create)
HasSource(id(TESTDATA_DIR "/builddependencycollector/external/external2.h"),
SourceType::TopProjectInclude),
HasSource(id(TESTDATA_DIR "/builddependencycollector/system/system1.h"),
SourceType::TopSystemInclude),
SourceType::SystemInclude),
HasSource(id(TESTDATA_DIR "/builddependencycollector/system/indirect_system.h"),
SourceType::SystemInclude),
HasSource(id(TESTDATA_DIR
@@ -813,7 +820,8 @@ TEST_F(BuildDependencyCollector, Create)
HasSource(id(TESTDATA_DIR "/builddependencycollector/project/macros.h"),
SourceType::UserInclude),
HasSource(id(TESTDATA_DIR "/builddependencycollector/project/generated_file.h"),
SourceType::UserInclude))),
SourceType::UserInclude),
HasSource(id(TESTDATA_DIR "/preincludes/system1.h"), SourceType::TopSystemInclude))),
Field(&BuildDependency::usedMacros,
UnorderedElementsAre(
UsedMacro{"IFDEF", id(TESTDATA_DIR "/builddependencycollector/project/macros.h")},
@@ -830,6 +838,7 @@ TEST_F(BuildDependencyCollector, Create)
id(TESTDATA_DIR "/builddependencycollector/external/indirect_external2.h"),
id(TESTDATA_DIR "/builddependencycollector/external/external2.h"),
id(TESTDATA_DIR "/builddependencycollector/system/system1.h"),
id(TESTDATA_DIR "/preincludes/system1.h"),
id(TESTDATA_DIR "/builddependencycollector/system/indirect_system.h"),
id(TESTDATA_DIR "/builddependencycollector/system/indirect_system2.h"),
id(TESTDATA_DIR "/builddependencycollector/project/missingfile.h"),
@@ -854,6 +863,8 @@ TEST_F(BuildDependencyCollector, Create)
id(TESTDATA_DIR
"/builddependencycollector/external/external2.h")),
SourceDependency(id(TESTDATA_DIR "/builddependencycollector/project/main4.cpp"),
id(TESTDATA_DIR "/preincludes/system1.h")),
SourceDependency(id(TESTDATA_DIR "/preincludes/system1.h"),
id(TESTDATA_DIR "/builddependencycollector/system/system1.h")),
SourceDependency(id(TESTDATA_DIR "/builddependencycollector/project/main4.cpp"),
id(TESTDATA_DIR "/builddependencycollector/project/macros.h")),
@@ -888,10 +899,42 @@ TEST_F(BuildDependencyCollector, Clear)
1,
{},
{},
{{TESTDATA_DIR "/builddependencycollector/system", 1, IncludeSearchPathType::System}},
{{TESTDATA_DIR "/builddependencycollector/system",
1,
ClangBackEnd::IncludeSearchPathType::System}},
{
{TESTDATA_DIR "/builddependencycollector/project", 1, IncludeSearchPathType::User},
{TESTDATA_DIR "/builddependencycollector/external", 2, IncludeSearchPathType::User},
{TESTDATA_DIR "/builddependencycollector/project",
1,
ClangBackEnd::IncludeSearchPathType::User},
{TESTDATA_DIR "/builddependencycollector/external",
2,
ClangBackEnd::IncludeSearchPathType::User},
},
{
id(TESTDATA_DIR "/builddependencycollector/project/header1.h"),
id(TESTDATA_DIR "/builddependencycollector/project/header2.h"),
id(TESTDATA_DIR "/builddependencycollector/project/missingfile.h"),
id(TESTDATA_DIR "/builddependencycollector/project/macros.h"),
},
{id(TESTDATA_DIR "/builddependencycollector/project/main4.cpp")},
Utils::Language::Cxx,
Utils::LanguageVersion::CXX11,
Utils::LanguageExtension::None};
collector.create(projectPart);
ClangBackEnd::ProjectPartContainer emptyProjectPart{
1,
{},
{},
{{TESTDATA_DIR "/builddependencycollector/system",
1,
ClangBackEnd::IncludeSearchPathType::System}},
{
{TESTDATA_DIR "/builddependencycollector/project",
1,
ClangBackEnd::IncludeSearchPathType::User},
{TESTDATA_DIR "/builddependencycollector/external",
2,
ClangBackEnd::IncludeSearchPathType::User},
},
{
id(TESTDATA_DIR "/builddependencycollector/project/header1.h"),
@@ -903,10 +946,46 @@ TEST_F(BuildDependencyCollector, Clear)
Utils::Language::Cxx,
Utils::LanguageVersion::CXX11,
Utils::LanguageExtension::None};
collector.create(projectPart);
auto buildDependency = collector.create(projectPart);
auto buildDependency = collector.create(emptyProjectPart);
ASSERT_THAT(buildDependency.sources, IsEmpty());
}
TEST_F(BuildDependencyCollector, PreIncludes)
{
using ClangBackEnd::IncludeSearchPathType;
ClangBackEnd::BuildDependencyCollector collector{filePathCache, generatedFiles, environment};
ClangBackEnd::ProjectPartContainer projectPart{
1,
{},
{},
{{TESTDATA_DIR "/builddependencycollector/system",
1,
ClangBackEnd::IncludeSearchPathType::System}},
{
{TESTDATA_DIR "/builddependencycollector/project",
1,
ClangBackEnd::IncludeSearchPathType::User},
{TESTDATA_DIR "/builddependencycollector/external",
2,
ClangBackEnd::IncludeSearchPathType::User},
},
{
id(TESTDATA_DIR "/builddependencycollector/project/header1.h"),
id(TESTDATA_DIR "/builddependencycollector/project/header2.h"),
id(TESTDATA_DIR "/builddependencycollector/project/missingfile.h"),
id(TESTDATA_DIR "/builddependencycollector/project/macros.h"),
},
{id(TESTDATA_DIR "/builddependencycollector/project/main4.cpp")},
Utils::Language::Cxx,
Utils::LanguageVersion::CXX11,
Utils::LanguageExtension::None};
auto buildDependency = collector.create(projectPart);
ASSERT_THAT(buildDependency.sources,
Contains(HasSource(id(TESTDATA_DIR "/preincludes/system1.h"),
SourceType::TopSystemInclude)));
}
} // namespace

View File

@@ -24,7 +24,7 @@
****************************************************************************/
#include "googletest.h"
#include "testenvironment.h"
#include "unittest-utility-functions.h"
#include <clangsupport_global.h>
#include <clangfollowsymboljob.h>
@@ -113,7 +113,7 @@ public:
ClangBackEnd::UnsavedFiles unsavedFiles;
ClangBackEnd::Documents documents{unsavedFiles};
Utf8StringVector compilationArguments{
TestEnvironment::addPlatformArguments({Utf8StringLiteral("-std=c++14")})};
UnitTest::addPlatformArguments({Utf8StringLiteral("-std=c++14")})};
Document document = {sourceFilePath, compilationArguments, {}, documents};
Document headerDocument = {headerFilePath, compilationArguments, {}, documents};
QVector<Utf8String> deps{sourceFilePath, cursorPath};

View File

@@ -24,7 +24,7 @@
****************************************************************************/
#include "googletest.h"
#include "testenvironment.h"
#include "unittest-utility-functions.h"
#include <clangsupport_global.h>
#include <clangreferencescollector.h>
@@ -59,7 +59,7 @@ struct Data {
ClangBackEnd::UnsavedFiles unsavedFiles;
ClangBackEnd::Documents documents{unsavedFiles};
Document document{Utf8StringLiteral(TESTDATA_DIR"/references.cpp"),
TestEnvironment::addPlatformArguments({Utf8StringLiteral("-std=c++14")}),
UnitTest::addPlatformArguments({Utf8StringLiteral("-std=c++14")}),
{},
documents};
};

View File

@@ -24,7 +24,7 @@
****************************************************************************/
#include "googletest.h"
#include "testenvironment.h"
#include "unittest-utility-functions.h"
#include <clangcodecompleteresults.h>
#include <clangdocument.h>
@@ -148,7 +148,7 @@ protected:
protected:
ClangBackEnd::UnsavedFiles unsavedFiles;
ClangBackEnd::Documents documents{unsavedFiles};
Utf8StringVector compilationArguments{TestEnvironment::addPlatformArguments()};
Utf8StringVector compilationArguments{UnitTest::addPlatformArguments()};
Document functionDocument{Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_function.cpp"), compilationArguments, {}, documents};
Document functionOverloadDocument{Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_functionoverload.cpp"), compilationArguments, {}, documents};
Document variableDocument{Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_variable.cpp"), compilationArguments, {}, documents};

View File

@@ -36,6 +36,7 @@ namespace {
template<typename ProjectInfo>
using Builder = ClangBackEnd::CommandLineBuilder<ProjectInfo>;
using ClangBackEnd::FilePath;
using ClangBackEnd::IncludeSearchPathType;
using ClangBackEnd::InputFileType;
@@ -136,8 +137,6 @@ TYPED_TEST(CommandLineBuilder, CHeader)
"c-header",
"-std=c11",
"-nostdinc",
"-I",
toNativePath(resourcePath()),
toNativePath("/source/file.c")));
}
@@ -156,8 +155,6 @@ TYPED_TEST(CommandLineBuilder, CSource)
"c",
"-std=c11",
"-nostdinc",
"-I",
toNativePath(resourcePath()),
toNativePath("/source/file.c")));
}
@@ -177,8 +174,6 @@ TYPED_TEST(CommandLineBuilder, ObjectiveCHeader)
"objective-c-header",
"-std=c11",
"-nostdinc",
"-I",
toNativePath(resourcePath()),
toNativePath("/source/file.c")));
}
@@ -198,8 +193,6 @@ TYPED_TEST(CommandLineBuilder, ObjectiveCSource)
"objective-c",
"-std=c11",
"-nostdinc",
"-I",
toNativePath(resourcePath()),
toNativePath("/source/file.c")));
}
@@ -219,8 +212,6 @@ TYPED_TEST(CommandLineBuilder, CppHeader)
"-std=c++98",
"-nostdinc",
"-nostdinc++",
"-I",
toNativePath(resourcePath()),
toNativePath("/source/file.cpp")));
}
@@ -240,8 +231,6 @@ TYPED_TEST(CommandLineBuilder, CppSource)
"-std=c++98",
"-nostdinc",
"-nostdinc++",
"-I",
toNativePath(resourcePath()),
toNativePath("/source/file.cpp")));
}
@@ -262,8 +251,6 @@ TYPED_TEST(CommandLineBuilder, ObjectiveCppHeader)
"-std=c++98",
"-nostdinc",
"-nostdinc++",
"-I",
toNativePath(resourcePath()),
toNativePath("/source/file.cpp")));
}
@@ -284,8 +271,6 @@ TYPED_TEST(CommandLineBuilder, ObjectiveCppSource)
"-std=c++98",
"-nostdinc",
"-nostdinc++",
"-I",
toNativePath(resourcePath()),
toNativePath("/source/file.cpp")));
}
@@ -509,7 +494,13 @@ TYPED_TEST(CommandLineBuilder, IncludesOrder)
{"/system/foo", 3, IncludeSearchPathType::Framework},
{"/builtin/bar", 2, IncludeSearchPathType::BuiltIn},
{"/builtin/foo", 1, IncludeSearchPathType::BuiltIn}};
Builder<TypeParam> builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.cpp"};
Builder<TypeParam> builder{this->emptyProjectInfo,
{},
InputFileType::Header,
"/source/file.cpp",
{},
{},
ClangBackEnd::NativeFilePath{FilePath{"/resource/path"}}};
ASSERT_THAT(builder.commandLine,
ElementsAre("clang++",
@@ -520,8 +511,8 @@ TYPED_TEST(CommandLineBuilder, IncludesOrder)
"-std=c++11",
"-nostdinc",
"-nostdinc++",
"-I",
toNativePath(resourcePath()),
"-isystem",
toNativePath("/resource/path"),
"-I",
toNativePath("/include/foo"),
"-I",
@@ -549,9 +540,7 @@ TYPED_TEST(CommandLineBuilder, EmptySourceFile)
"c++-header",
"-std=c++98",
"-nostdinc",
"-nostdinc++",
"-I",
toNativePath(resourcePath())));
"-nostdinc++"));
}
TYPED_TEST(CommandLineBuilder, SourceFile)
@@ -567,8 +556,6 @@ TYPED_TEST(CommandLineBuilder, SourceFile)
"-std=c++98",
"-nostdinc",
"-nostdinc++",
"-I",
toNativePath(resourcePath()),
toNativePath("/source/file.cpp")));
}
@@ -586,8 +573,6 @@ TYPED_TEST(CommandLineBuilder, EmptyOutputFile)
"-std=c++98",
"-nostdinc",
"-nostdinc++",
"-I",
toNativePath(resourcePath()),
toNativePath("/source/file.cpp")));
}
@@ -608,13 +593,24 @@ TYPED_TEST(CommandLineBuilder, OutputFile)
"-std=c++98",
"-nostdinc",
"-nostdinc++",
"-I",
toNativePath(resourcePath()),
"-o",
toNativePath("/output/file.o"),
toNativePath("/source/file.cpp")));
}
TYPED_TEST(CommandLineBuilder, PreIncludeSearchPath)
{
Builder<TypeParam> builder{this->emptyProjectInfo,
{},
{},
{},
{},
{},
ClangBackEnd::NativeFilePath{FilePath{"/resource/path"}}};
ASSERT_THAT(builder.commandLine, Contains(toNativePath("/resource/path")));
}
TYPED_TEST(CommandLineBuilder, IncludePchPath)
{
Builder<TypeParam> builder{this->emptyProjectInfo,
@@ -633,8 +629,6 @@ TYPED_TEST(CommandLineBuilder, IncludePchPath)
"-std=c++98",
"-nostdinc",
"-nostdinc++",
"-I",
toNativePath(resourcePath()),
"-Xclang",
"-include-pch",
"-Xclang",
@@ -660,9 +654,7 @@ TYPED_TEST(CommandLineBuilder, CompilerMacros)
"-nostdinc",
"-nostdinc++",
"-DER=2",
"-DYI=1",
"-I",
toNativePath(resourcePath())));
"-DYI=1"));
}
} // namespace

View File

@@ -26,7 +26,7 @@
#include "googletest.h"
#include "clangcompareoperators.h"
#include "testenvironment.h"
#include "unittest-utility-functions.h"
#include <clangdocument.h>
#include <clangdocuments.h>
@@ -63,7 +63,7 @@ struct Data {
ClangBackEnd::Documents documents{unsavedFiles};
Utf8String filePath{Utf8StringLiteral(TESTDATA_DIR"/cursor.cpp")};
Document document{filePath,
TestEnvironment::addPlatformArguments({Utf8StringLiteral("-std=c++11")}),
UnitTest::addPlatformArguments({Utf8StringLiteral("-std=c++11")}),
{},
documents};
TranslationUnit translationUnit{filePath,

View File

@@ -0,0 +1 @@
#include_next <system1.h>

View File

@@ -23,10 +23,10 @@
**
****************************************************************************/
#include "googletest.h"
#include "diagnosticcontainer-matcher.h"
#include "googletest.h"
#include "rundocumentparse-utility.h"
#include "testenvironment.h"
#include "unittest-utility-functions.h"
#include <diagnostic.h>
#include <diagnosticcontainer.h>
@@ -87,7 +87,7 @@ protected:
ClangBackEnd::UnsavedFiles unsavedFiles;
ClangBackEnd::Documents documents{unsavedFiles};
Document document{Utf8StringLiteral(TESTDATA_DIR"/diagnostic_diagnostic.cpp"),
TestEnvironment::addPlatformArguments({Utf8StringLiteral("-std=c++11")}),
UnitTest::addPlatformArguments({Utf8StringLiteral("-std=c++11")}),
{},
documents};
UnitTest::RunDocumentParse _1{document};

View File

@@ -23,9 +23,9 @@
**
****************************************************************************/
#include "googletest.h"
#include "diagnosticcontainer-matcher.h"
#include "testenvironment.h"
#include "googletest.h"
#include "unittest-utility-functions.h"
#include <clangsupport_global.h>
#include <clangdocument.h>
@@ -64,7 +64,7 @@ protected:
ClangBackEnd::UnsavedFiles unsavedFiles;
ClangBackEnd::Documents documents{unsavedFiles};
Utf8StringVector compilationArguments{
TestEnvironment::addPlatformArguments({Utf8StringLiteral("-pedantic")})};
UnitTest::addPlatformArguments({Utf8StringLiteral("-pedantic")})};
Document document{Utf8StringLiteral(TESTDATA_DIR "/diagnostic_diagnosticset.cpp"),
compilationArguments,
{},

View File

@@ -24,7 +24,7 @@
****************************************************************************/
#include "googletest.h"
#include "testenvironment.h"
#include "unittest-utility-functions.h"
#include <chunksreportedmonitor.h>
#include <clangdocument.h>
@@ -51,7 +51,7 @@ struct Data {
UnsavedFiles unsavedFiles;
Documents documents{unsavedFiles};
Document document{Utf8StringLiteral(TESTDATA_DIR "/highlightingmarks.cpp"),
TestEnvironment::addPlatformArguments({Utf8StringLiteral("-std=c++14")}),
UnitTest::addPlatformArguments({Utf8StringLiteral("-std=c++14")}),
Utf8StringVector(),
documents};
};

View File

@@ -27,6 +27,7 @@
#include "fakeprocess.h"
#include "filesystem-utilities.h"
#include "testenvironment.h"
#include "mockbuilddependenciesstorage.h"
#include "mockclangpathwatcher.h"
@@ -79,7 +80,11 @@ MATCHER_P2(HasIdAndType,
class PchCreator: public ::testing::Test
{
protected:
PchCreator() { creator.setUnsavedFiles({generatedFile}); }
PchCreator()
{
creator.setUnsavedFiles({generatedFile});
pchTask1.preIncludeSearchPath = testEnvironment.preIncludeSearchPath();
}
ClangBackEnd::FilePathId id(ClangBackEnd::FilePathView path)
{
@@ -121,6 +126,7 @@ protected:
{TESTDATA_DIR "/builddependencycollector/external", 1, IncludeSearchPathType::System}},
{{TESTDATA_DIR "/builddependencycollector/project", 1, IncludeSearchPathType::User}},
};
TestEnvironment testEnvironment;
};
using PchCreatorSlowTest = PchCreator;
using PchCreatorVerySlowTest = PchCreator;
@@ -148,8 +154,8 @@ TEST_F(PchCreator, CreateProjectPartClangCompilerArguments)
"-std=c++98",
"-nostdinc",
"-nostdinc++",
"-I",
toNativePath(resourcePath()),
"-isystem",
toNativePath(TESTDATA_DIR "/preincludes"),
"-I",
toNativePath(TESTDATA_DIR "/builddependencycollector/project"),
"-isystem",
@@ -175,8 +181,8 @@ TEST_F(PchCreator, CreateProjectPartClangCompilerArgumentsWithSystemPch)
"-std=c++98",
"-nostdinc",
"-nostdinc++",
"-I",
toNativePath(resourcePath()),
"-isystem",
toNativePath(TESTDATA_DIR "/preincludes"),
"-I",
toNativePath(TESTDATA_DIR "/builddependencycollector/project"),
"-isystem",

View File

@@ -29,6 +29,7 @@
#include "mockprecompiledheaderstorage.h"
#include "mocksqlitetransactionbackend.h"
#include "mocktaskscheduler.h"
#include "testenvironment.h"
#include <pchtaskqueue.h>
#include <progresscounter.h>
@@ -50,11 +51,13 @@ protected:
MockSqliteTransactionBackend mockSqliteTransactionBackend;
NiceMock<MockFunction<void(int, int)>> mockSetProgressCallback;
ClangBackEnd::ProgressCounter progressCounter{mockSetProgressCallback.AsStdFunction()};
TestEnvironment testEnvironment;
ClangBackEnd::PchTaskQueue queue{mockSytemPchTaskScheduler,
mockProjectPchTaskScheduler,
progressCounter,
mockPrecompiledHeaderStorage,
mockSqliteTransactionBackend};
mockSqliteTransactionBackend,
testEnvironment};
IncludeSearchPaths systemIncludeSearchPaths{
{"/includes", 1, IncludeSearchPathType::BuiltIn},
{"/other/includes", 2, IncludeSearchPathType::System}};
@@ -297,6 +300,7 @@ TEST_F(PchTaskQueue, CreateProjectTaskFromPchTask)
auto tasks = queue.createProjectTasks({projectTask1});
auto projectTask = projectTask1;
projectTask.systemPchPath = "/path/to/pch";
projectTask.preIncludeSearchPath = testEnvironment.preIncludeSearchPath();
EXPECT_CALL(mockPrecompiledHeaderStorage, fetchSystemPrecompiledHeaderPath(Eq(1)))
.WillOnce(Return(ClangBackEnd::FilePath{"/path/to/pch"}));
@@ -316,6 +320,7 @@ TEST_F(PchTaskQueue, DeleteProjectPchEntryInDatabaseIfNoPchIsGenerated)
auto tasks = queue.createProjectTasks({projectTask1});
auto projectTask = projectTask1;
projectTask.systemPchPath = "/path/to/pch";
projectTask.preIncludeSearchPath = testEnvironment.preIncludeSearchPath();
EXPECT_CALL(mockPrecompiledHeaderStorage, fetchSystemPrecompiledHeaderPath(Eq(1)))
.WillOnce(Return(ClangBackEnd::FilePath{"/path/to/pch"}));
@@ -355,8 +360,10 @@ TEST_F(PchTaskQueue, CreateSystemTaskFromPchTask)
MockPchCreator mockPchCreator;
ClangBackEnd::ProjectPartPch projectPartPch{{}, "/path/to/pch", 99};
auto tasks = queue.createSystemTasks({systemTask4});
auto systemTask = systemTask4;
systemTask.preIncludeSearchPath = testEnvironment.preIncludeSearchPath();
EXPECT_CALL(mockPchCreator, generatePch(Eq(systemTask4)));
EXPECT_CALL(mockPchCreator, generatePch(Eq(systemTask)));
EXPECT_CALL(mockPchCreator, projectPartPch()).WillOnce(ReturnRef(projectPartPch));
EXPECT_CALL(mockPrecompiledHeaderStorage,
insertSystemPrecompiledHeaders(UnorderedElementsAre(1, 3), Eq("/path/to/pch"), 99));
@@ -370,8 +377,10 @@ TEST_F(PchTaskQueue, DeleteSystemPchEntryInDatabaseIfNoPchIsGenerated)
MockPchCreator mockPchCreator;
ClangBackEnd::ProjectPartPch projectPartPch{{}, "", 0};
auto tasks = queue.createSystemTasks({systemTask4});
auto systemTask = systemTask4;
systemTask.preIncludeSearchPath = testEnvironment.preIncludeSearchPath();
EXPECT_CALL(mockPchCreator, generatePch(Eq(systemTask4)));
EXPECT_CALL(mockPchCreator, generatePch(Eq(systemTask)));
EXPECT_CALL(mockPchCreator, projectPartPch()).WillOnce(ReturnRef(projectPartPch));
EXPECT_CALL(mockPrecompiledHeaderStorage,
deleteSystemPrecompiledHeaders(UnorderedElementsAre(1, 3)));

View File

@@ -351,7 +351,6 @@ TEST_F(ProjectUpdater, ToolChainArguments)
ASSERT_THAT(arguments,
ElementsAre(QString{"-m32"},
QString{"-fPIC"},
QString{"extraflags"},
QString{"-include"},
QString{"config.h"}));

View File

@@ -24,7 +24,7 @@
****************************************************************************/
#include "googletest.h"
#include "testenvironment.h"
#include "unittest-utility-functions.h"
#include <cursor.h>
#include <clangdocument.h>
@@ -89,7 +89,7 @@ struct Data {
ClangBackEnd::UnsavedFiles unsavedFiles;
ClangBackEnd::Documents documents{unsavedFiles};
Utf8String filePath = Utf8StringLiteral(TESTDATA_DIR"/skippedsourceranges.cpp");
Utf8StringVector compilationArguments{TestEnvironment::addPlatformArguments(
Utf8StringVector compilationArguments{UnitTest::addPlatformArguments(
{Utf8StringLiteral("-std=c++11"), {}, Utf8StringLiteral("-DBLAH")})};
Document document{filePath, compilationArguments, {}, documents};
TranslationUnit translationUnit{filePath,

View File

@@ -25,7 +25,7 @@
#include "googletest.h"
#include "rundocumentparse-utility.h"
#include "testenvironment.h"
#include "unittest-utility-functions.h"
#include <clangtranslationunit.h>
#include <diagnostic.h>
@@ -75,7 +75,7 @@ struct Data {
ClangBackEnd::Documents documents{unsavedFiles};
Utf8String filePath{Utf8StringLiteral(TESTDATA_DIR"/diagnostic_source_range.cpp")};
Document document{filePath,
{TestEnvironment::addPlatformArguments({Utf8StringLiteral("-pedantic")})},
{UnitTest::addPlatformArguments({Utf8StringLiteral("-pedantic")})},
{},
documents};
UnitTest::RunDocumentParse _1{document};

View File

@@ -34,6 +34,7 @@
#include "mocksqlitetransactionbackend.h"
#include "mocksymbolscollector.h"
#include "mocksymbolstorage.h"
#include "testenvironment.h"
#include <filepathcaching.h>
#include <filestatuscache.h>
@@ -254,6 +255,7 @@ protected:
NiceMock<MockFunction<void(int, int)>> mockSetProgressCallback;
ClangBackEnd::ProgressCounter progressCounter{mockSetProgressCallback.AsStdFunction()};
NiceMock<MockSourceTimeStampsModifiedTimeChecker> mockModifiedTimeChecker;
TestEnvironment testEnvironment;
ClangBackEnd::SymbolIndexer indexer{indexerQueue,
mockSymbolStorage,
mockBuildDependenciesStorage,
@@ -263,7 +265,8 @@ protected:
fileStatusCache,
mockSqliteTransactionBackend,
mockProjectPartsStorage,
mockModifiedTimeChecker};
mockModifiedTimeChecker,
testEnvironment};
SymbolIndexerTaskQueue indexerQueue{indexerScheduler, progressCounter};
Scheduler indexerScheduler{collectorManger,
indexerQueue,
@@ -290,8 +293,8 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddFilesInCollector)
"-nostdinc++",
"-DBAR=1",
"-DFOO=1",
"-I",
toNativePath(resourcePath()),
"-isystem",
toNativePath(TESTDATA_DIR "/preincludes"),
"-I",
toNativePath("/project/includes"),
"-I",
@@ -324,8 +327,8 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddFilesWithPrecompiledHeaderInColl
"-nostdinc++",
"-DBAR=1",
"-DFOO=1",
"-I",
toNativePath(resourcePath()),
"-isystem",
toNativePath(TESTDATA_DIR "/preincludes"),
"-I",
toNativePath("/project/includes"),
"-I",
@@ -362,8 +365,8 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddFilesWithoutPrecompiledHeaderInC
"-nostdinc++",
"-DBAR=1",
"-DFOO=1",
"-I",
toNativePath(resourcePath()),
"-isystem",
toNativePath(TESTDATA_DIR "/preincludes"),
"-I",
toNativePath("/project/includes"),
"-I",
@@ -402,7 +405,7 @@ TEST_F(SymbolIndexer, UpdateProjectPartsDoesNotCallAddFilesInCollectorForEmptyEv
TEST_F(SymbolIndexer, UpdateProjectPartsCallscollectSymbolsInCollector)
{
EXPECT_CALL(mockCollector, collectSymbols()).Times(2);;
EXPECT_CALL(mockCollector, collectSymbols()).Times(2);
indexer.updateProjectParts({projectPart1, projectPart2});
}
@@ -453,8 +456,8 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsInOrder)
"-nostdinc++",
"-DBAR=1",
"-DFOO=1",
"-I",
toNativePath(resourcePath()),
"-isystem",
toNativePath(TESTDATA_DIR "/preincludes"),
"-I",
toNativePath("/project/includes"),
"-I",
@@ -492,8 +495,8 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsGetsProjectAndSystemPchPathsAndHasN
"-nostdinc++",
"-DBAR=1",
"-DFOO=1",
"-I",
toNativePath(resourcePath()),
"-isystem",
toNativePath(TESTDATA_DIR "/preincludes"),
"-I",
toNativePath("/project/includes"),
"-I",
@@ -534,8 +537,8 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsGetsProjectAndSystemPchPathsAndHasE
"-nostdinc++",
"-DBAR=1",
"-DFOO=1",
"-I",
toNativePath(resourcePath()),
"-isystem",
toNativePath(TESTDATA_DIR "/preincludes"),
"-I",
toNativePath("/project/includes"),
"-I",
@@ -565,8 +568,8 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsGetsProjectAndSystemPchPathsAndHasE
"-nostdinc++",
"-DBAR=1",
"-DFOO=1",
"-I",
toNativePath(resourcePath()),
"-isystem",
toNativePath(TESTDATA_DIR "/preincludes"),
"-I",
toNativePath("/project/includes"),
"-I",
@@ -608,8 +611,8 @@ TEST_F(SymbolIndexer,
"-nostdinc++",
"-DBAR=1",
"-DFOO=1",
"-I",
toNativePath(resourcePath()),
"-isystem",
toNativePath(TESTDATA_DIR "/preincludes"),
"-I",
toNativePath("/project/includes"),
"-I",
@@ -639,8 +642,8 @@ TEST_F(SymbolIndexer,
"-nostdinc++",
"-DBAR=1",
"-DFOO=1",
"-I",
toNativePath(resourcePath()),
"-isystem",
toNativePath(TESTDATA_DIR "/preincludes"),
"-I",
toNativePath("/project/includes"),
"-I",
@@ -670,8 +673,8 @@ TEST_F(SymbolIndexer,
"-nostdinc++",
"-DBAR=1",
"-DFOO=1",
"-I",
toNativePath(resourcePath()),
"-isystem",
toNativePath(TESTDATA_DIR "/preincludes"),
"-I",
toNativePath("/project/includes"),
"-I",
@@ -707,8 +710,8 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsGetsProjectAndSystemPchPathsAndHasO
"-nostdinc++",
"-DBAR=1",
"-DFOO=1",
"-I",
toNativePath(resourcePath()),
"-isystem",
toNativePath(TESTDATA_DIR "/preincludes"),
"-I",
toNativePath("/project/includes"),
"-I",
@@ -738,8 +741,8 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsGetsProjectAndSystemPchPathsAndHasO
"-nostdinc++",
"-DBAR=1",
"-DFOO=1",
"-I",
toNativePath(resourcePath()),
"-isystem",
toNativePath(TESTDATA_DIR "/preincludes"),
"-I",
toNativePath("/project/includes"),
"-I",
@@ -769,8 +772,8 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsGetsProjectAndSystemPchPathsAndHasO
"-nostdinc++",
"-DBAR=1",
"-DFOO=1",
"-I",
toNativePath(resourcePath()),
"-isystem",
toNativePath(TESTDATA_DIR "/preincludes"),
"-I",
toNativePath("/project/includes"),
"-I",
@@ -806,8 +809,8 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsGetsSystemPchPathsAndHasErrorWithPr
"-nostdinc++",
"-DBAR=1",
"-DFOO=1",
"-I",
toNativePath(resourcePath()),
"-isystem",
toNativePath(TESTDATA_DIR "/preincludes"),
"-I",
toNativePath("/project/includes"),
"-I",
@@ -847,8 +850,8 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsGetsNoPchPathsAndHasErrors)
"-nostdinc++",
"-DBAR=1",
"-DFOO=1",
"-I",
toNativePath(resourcePath()),
"-isystem",
toNativePath(TESTDATA_DIR "/preincludes"),
"-I",
toNativePath("/project/includes"),
"-I",
@@ -931,7 +934,8 @@ TEST_F(SymbolIndexer, CallSetNotifier)
fileStatusCache,
mockSqliteTransactionBackend,
mockProjectPartsStorage,
mockModifiedTimeChecker};
mockModifiedTimeChecker,
testEnvironment};
}
TEST_F(SymbolIndexer, PathChangedCallsFetchProjectPartArtefactInStorage)
@@ -1013,8 +1017,8 @@ TEST_F(SymbolIndexer, UpdateChangedPathCallsInOrder)
"-nostdinc++",
"-DBAR=1",
"-DFOO=1",
"-I",
toNativePath(resourcePath()),
"-isystem",
toNativePath(TESTDATA_DIR "/preincludes"),
"-I",
toNativePath("/project/includes"),
"-I",
@@ -1073,8 +1077,8 @@ TEST_F(SymbolIndexer, PathsChangedCallsGetsProjectAndSystemPchPathsAndHasNoError
"-nostdinc++",
"-DBAR=1",
"-DFOO=1",
"-I",
toNativePath(resourcePath()),
"-isystem",
toNativePath(TESTDATA_DIR "/preincludes"),
"-I",
toNativePath("/project/includes"),
"-I",
@@ -1118,8 +1122,8 @@ TEST_F(SymbolIndexer, PathsChangedCallsGetsProjectAndSystemPchPathsAndHasErrorWi
"-nostdinc++",
"-DBAR=1",
"-DFOO=1",
"-I",
toNativePath(resourcePath()),
"-isystem",
toNativePath(TESTDATA_DIR "/preincludes"),
"-I",
toNativePath("/project/includes"),
"-I",
@@ -1149,8 +1153,8 @@ TEST_F(SymbolIndexer, PathsChangedCallsGetsProjectAndSystemPchPathsAndHasErrorWi
"-nostdinc++",
"-DBAR=1",
"-DFOO=1",
"-I",
toNativePath(resourcePath()),
"-isystem",
toNativePath(TESTDATA_DIR "/preincludes"),
"-I",
toNativePath("/project/includes"),
"-I",
@@ -1194,8 +1198,8 @@ TEST_F(SymbolIndexer, PathsChangedCallsGetsProjectAndSystemPchPathsAndHasErrorWi
"-nostdinc++",
"-DBAR=1",
"-DFOO=1",
"-I",
toNativePath(resourcePath()),
"-isystem",
toNativePath(TESTDATA_DIR "/preincludes"),
"-I",
toNativePath("/project/includes"),
"-I",
@@ -1225,8 +1229,8 @@ TEST_F(SymbolIndexer, PathsChangedCallsGetsProjectAndSystemPchPathsAndHasErrorWi
"-nostdinc++",
"-DBAR=1",
"-DFOO=1",
"-I",
toNativePath(resourcePath()),
"-isystem",
toNativePath(TESTDATA_DIR "/preincludes"),
"-I",
toNativePath("/project/includes"),
"-I",
@@ -1256,8 +1260,8 @@ TEST_F(SymbolIndexer, PathsChangedCallsGetsProjectAndSystemPchPathsAndHasErrorWi
"-nostdinc++",
"-DBAR=1",
"-DFOO=1",
"-I",
toNativePath(resourcePath()),
"-isystem",
toNativePath(TESTDATA_DIR "/preincludes"),
"-I",
toNativePath("/project/includes"),
"-I",
@@ -1296,8 +1300,8 @@ TEST_F(SymbolIndexer, PathsChangedCallsGetsProjectAndSystemPchPathsAndHasOnlyErr
"-nostdinc++",
"-DBAR=1",
"-DFOO=1",
"-I",
toNativePath(resourcePath()),
"-isystem",
toNativePath(TESTDATA_DIR "/preincludes"),
"-I",
toNativePath("/project/includes"),
"-I",
@@ -1327,8 +1331,8 @@ TEST_F(SymbolIndexer, PathsChangedCallsGetsProjectAndSystemPchPathsAndHasOnlyErr
"-nostdinc++",
"-DBAR=1",
"-DFOO=1",
"-I",
toNativePath(resourcePath()),
"-isystem",
toNativePath(TESTDATA_DIR "/preincludes"),
"-I",
toNativePath("/project/includes"),
"-I",
@@ -1358,8 +1362,8 @@ TEST_F(SymbolIndexer, PathsChangedCallsGetsProjectAndSystemPchPathsAndHasOnlyErr
"-nostdinc++",
"-DBAR=1",
"-DFOO=1",
"-I",
toNativePath(resourcePath()),
"-isystem",
toNativePath(TESTDATA_DIR "/preincludes"),
"-I",
toNativePath("/project/includes"),
"-I",
@@ -1398,8 +1402,8 @@ TEST_F(SymbolIndexer, PathsChangedCallsGetsSystemPchPathsAndHasErrorWithProjectP
"-nostdinc++",
"-DBAR=1",
"-DFOO=1",
"-I",
toNativePath(resourcePath()),
"-isystem",
toNativePath(TESTDATA_DIR "/preincludes"),
"-I",
toNativePath("/project/includes"),
"-I",
@@ -1442,8 +1446,8 @@ TEST_F(SymbolIndexer, PathsChangedCallsGetsNoPchPathsAndHasErrors)
"-nostdinc++",
"-DBAR=1",
"-DFOO=1",
"-I",
toNativePath(resourcePath()),
"-isystem",
toNativePath(TESTDATA_DIR "/preincludes"),
"-I",
toNativePath("/project/includes"),
"-I",
@@ -1482,8 +1486,8 @@ TEST_F(SymbolIndexer, UpdateChangedPathIsUsingPrecompiledHeader)
"-nostdinc++",
"-DBAR=1",
"-DFOO=1",
"-I",
toNativePath(resourcePath()),
"-isystem",
toNativePath(TESTDATA_DIR "/preincludes"),
"-I",
toNativePath("/project/includes"),
"-I",
@@ -1521,8 +1525,8 @@ TEST_F(SymbolIndexer, UpdateChangedPathIsNotUsingPrecompiledHeaderIfItNotExists)
"-nostdinc++",
"-DBAR=1",
"-DFOO=1",
"-I",
toNativePath(resourcePath()),
"-isystem",
toNativePath(TESTDATA_DIR "/preincludes"),
"-I",
toNativePath("/project/includes"),
"-I",

View File

@@ -24,6 +24,7 @@
****************************************************************************/
#include "googletest.h"
#include "testenvironment.h"
#include <symbolindexing.h>
#include <symbolquery.h>
@@ -85,7 +86,12 @@ protected:
ClangBackEnd::GeneratedFiles generatedFiles;
NiceMock<MockFunction<void(int, int)>> mockSetProgressCallback;
ClangBackEnd::ProjectPartsStorage<Sqlite::Database> projectPartStorage{database};
ClangBackEnd::SymbolIndexing indexing{database, filePathCache, generatedFiles, mockSetProgressCallback.AsStdFunction()};
TestEnvironment testEnvironment;
ClangBackEnd::SymbolIndexing indexing{database,
filePathCache,
generatedFiles,
mockSetProgressCallback.AsStdFunction(),
testEnvironment};
StatementFactory queryFactory{database};
Query query{queryFactory};
PathString main1Path = TESTDATA_DIR "/symbolindexing_main1.cpp";

View File

@@ -27,36 +27,24 @@
#include <environment.h>
#include <utf8string.h>
#include <utils/hostosinfo.h>
#include <filepath.h>
#include <QTemporaryDir>
#include <QVector>
class TestEnvironment final : public ClangBackEnd::Environment
{
public:
TestEnvironment() {
temporaryDirectory.setAutoRemove(true);
}
QString pchBuildDirectory() const override
{
return temporaryDirectory.path();
}
TestEnvironment() { temporaryDirectory.setAutoRemove(true); }
uint hardwareConcurrency() const
Utils::PathString pchBuildDirectory() const override { return temporaryDirectory.path(); }
uint hardwareConcurrency() const { return 2; }
ClangBackEnd::NativeFilePathView preIncludeSearchPath() const override
{
return 2;
}
static QVector<Utf8String> addPlatformArguments(std::initializer_list<Utf8String> arguments = {})
{
QVector<Utf8String> result{arguments};
if (Utils::HostOsInfo::isWindowsHost())
result.append(Utf8StringLiteral("-fno-delayed-template-parsing"));
return result;
return includeSearchPath;
}
private:
QTemporaryDir temporaryDirectory;
ClangBackEnd::NativeFilePath includeSearchPath{
ClangBackEnd::FilePath{TESTDATA_DIR "/preincludes"}};
};

View File

@@ -25,7 +25,7 @@
#include "googletest.h"
#include "testenvironment.h"
#include "unittest-utility-functions.h"
#include <clangdocument.h>
#include <clangdocuments.h>
@@ -55,7 +55,7 @@ struct Data {
ClangBackEnd::Documents documents{unsavedFiles};
Utf8String filePath{Utf8StringLiteral(TESTDATA_DIR"/token.cpp")};
Utf8StringVector compilationArguments{
TestEnvironment::addPlatformArguments({Utf8StringLiteral("-std=c++11")})};
UnitTest::addPlatformArguments({Utf8StringLiteral("-std=c++11")})};
Document document{filePath, compilationArguments, {}, documents};
TranslationUnit translationUnit{filePath,
filePath,

View File

@@ -24,7 +24,7 @@
****************************************************************************/
#include "googletest.h"
#include "testenvironment.h"
#include "unittest-utility-functions.h"
#include <clangdocument.h>
#include <clangdocuments.h>
@@ -128,7 +128,7 @@ struct Data {
ClangBackEnd::Documents documents{unsavedFiles};
Utf8String filePath{Utf8StringLiteral(TESTDATA_DIR"/highlightingmarks.cpp")};
Document document{filePath,
TestEnvironment::addPlatformArguments(
UnitTest::addPlatformArguments(
{Utf8StringLiteral("-std=c++14"),
Utf8StringLiteral("-I" TESTDATA_DIR)}),
{},

View File

@@ -25,10 +25,12 @@
#pragma once
#include <utils/hostosinfo.h>
#include <utils/smallstring.h>
#include <utils/temporarydirectory.h>
#include <utf8stringvector.h>
inline
bool operator==(const QString &first, const char *second)
{
@@ -42,4 +44,12 @@ Utils::PathString temporaryDirPath()
{
return Utils::PathString::fromQString(Utils::TemporaryDirectory::masterDirectoryPath());
}
inline QVector<Utf8String> addPlatformArguments(std::initializer_list<Utf8String> arguments = {})
{
QVector<Utf8String> result{arguments};
if (Utils::HostOsInfo::isWindowsHost())
result.append(Utf8StringLiteral("-fno-delayed-template-parsing"));
return result;
}
} // namespace UnitTest