diff options
author | Marco Bubke <[email protected]> | 2019-04-24 14:07:39 +0200 |
---|---|---|
committer | Marco Bubke <[email protected]> | 2019-04-29 12:52:05 +0000 |
commit | 2d520140d01a8c6d9ff88c7f7205dfa28cc06d2d (patch) | |
tree | 04113edcfbf43f62552acfe226b5a6bd307f5ded | |
parent | 1975641a3d0ccb3f36452524a57f7d2303b62b25 (diff) |
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 <[email protected]>
42 files changed, 397 insertions, 233 deletions
diff --git a/share/qtcreator/indexer_preincludes/QtCore/qconfig.h b/share/qtcreator/indexer_preincludes/QtCore/qconfig.h new file mode 100644 index 00000000000..9534d0d8bf4 --- /dev/null +++ b/share/qtcreator/indexer_preincludes/QtCore/qconfig.h @@ -0,0 +1,2 @@ +#include_next <QtCore/qconfig.h> +#undef QT_REDUCE_RELOCATIONS diff --git a/share/qtcreator/indexer_preincludes/QtCore/qglobal.h b/share/qtcreator/indexer_preincludes/QtCore/qglobal.h new file mode 120000 index 00000000000..1ff1b445120 --- /dev/null +++ b/share/qtcreator/indexer_preincludes/QtCore/qglobal.h @@ -0,0 +1 @@ +../qglobal.h
\ No newline at end of file diff --git a/share/qtcreator/static.pro b/share/qtcreator/static.pro index cda672829a9..7f39ae2faed 100644 --- a/share/qtcreator/static.pro +++ b/share/qtcreator/static.pro @@ -22,7 +22,8 @@ DATA_DIRS = \ qml-type-descriptions \ modeleditor \ glsl \ - cplusplus + cplusplus \ + indexer_preincludes macx: DATA_DIRS += scripts for(data_dir, DATA_DIRS) { diff --git a/src/libs/clangsupport/clangsupport-lib.pri b/src/libs/clangsupport/clangsupport-lib.pri index 0eaa7b8938d..201c5bf5380 100644 --- a/src/libs/clangsupport/clangsupport-lib.pri +++ b/src/libs/clangsupport/clangsupport-lib.pri @@ -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 diff --git a/src/libs/clangsupport/commandlinebuilder.h b/src/libs/clangsupport/commandlinebuilder.h index db11d773d45..dedcf1c518a 100644 --- a/src/libs/clangsupport/commandlinebuilder.h +++ b/src/libs/clangsupport/commandlinebuilder.h @@ -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) diff --git a/src/tools/clangpchmanagerbackend/source/environment.h b/src/libs/clangsupport/environment.h index 7f575fe169b..ffa4d907cc2 100644 --- a/src/tools/clangpchmanagerbackend/source/environment.h +++ b/src/libs/clangsupport/environment.h @@ -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; diff --git a/src/plugins/clangpchmanager/pchmanagerconnectionclient.cpp b/src/plugins/clangpchmanager/pchmanagerconnectionclient.cpp index a8e7e7a2ef4..536d80bfb3e 100644 --- a/src/plugins/clangpchmanager/pchmanagerconnectionclient.cpp +++ b/src/plugins/clangpchmanager/pchmanagerconnectionclient.cpp @@ -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: "); diff --git a/src/plugins/clangpchmanager/projectupdater.cpp b/src/plugins/clangpchmanager/projectupdater.cpp index f2bd14b383e..df611ef1bc7 100644 --- a/src/plugins/clangpchmanager/projectupdater.cpp +++ b/src/plugins/clangpchmanager/projectupdater.cpp @@ -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(); diff --git a/src/plugins/clangrefactoring/refactoringconnectionclient.cpp b/src/plugins/clangrefactoring/refactoringconnectionclient.cpp index a42ed38a161..e94e8a311ff 100644 --- a/src/plugins/clangrefactoring/refactoringconnectionclient.cpp +++ b/src/plugins/clangrefactoring/refactoringconnectionclient.cpp @@ -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: "); diff --git a/src/tools/clangpchmanagerbackend/clangpchmanagerbackendmain.cpp b/src/tools/clangpchmanagerbackend/clangpchmanagerbackendmain.cpp index f8b71f61b9a..0ce49e829dd 100644 --- a/src/tools/clangpchmanagerbackend/clangpchmanagerbackendmain.cpp +++ b/src/tools/clangpchmanagerbackend/clangpchmanagerbackendmain.cpp @@ -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); diff --git a/src/tools/clangpchmanagerbackend/source/builddependencycollector.cpp b/src/tools/clangpchmanagerbackend/source/builddependencycollector.cpp index 1d08442c517..2bd0b87af0d 100644 --- a/src/tools/clangpchmanagerbackend/source/builddependencycollector.cpp +++ b/src/tools/clangpchmanagerbackend/source/builddependencycollector.cpp @@ -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(), diff --git a/src/tools/clangpchmanagerbackend/source/clangpchmanagerbackend-source.pri b/src/tools/clangpchmanagerbackend/source/clangpchmanagerbackend-source.pri index bbf3bf16f44..6b79e2e71fb 100644 --- a/src/tools/clangpchmanagerbackend/source/clangpchmanagerbackend-source.pri +++ b/src/tools/clangpchmanagerbackend/source/clangpchmanagerbackend-source.pri @@ -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 \ diff --git a/src/tools/clangpchmanagerbackend/source/pchcreator.cpp b/src/tools/clangpchmanagerbackend/source/pchcreator.cpp index 9b8683bcac5..9dd1bf36476 100644 --- a/src/tools/clangpchmanagerbackend/source/pchcreator.cpp +++ b/src/tools/clangpchmanagerbackend/source/pchcreator.cpp @@ -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)); diff --git a/src/tools/clangpchmanagerbackend/source/pchtask.h b/src/tools/clangpchmanagerbackend/source/pchtask.h index 7d8879fcbd4..74b410831e4 100644 --- a/src/tools/clangpchmanagerbackend/source/pchtask.h +++ b/src/tools/clangpchmanagerbackend/source/pchtask.h @@ -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; diff --git a/src/tools/clangpchmanagerbackend/source/pchtaskqueue.cpp b/src/tools/clangpchmanagerbackend/source/pchtaskqueue.cpp index d2507ee8641..1edbe15806b 100644 --- a/src/tools/clangpchmanagerbackend/source/pchtaskqueue.cpp +++ b/src/tools/clangpchmanagerbackend/source/pchtaskqueue.cpp @@ -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()) { diff --git a/src/tools/clangpchmanagerbackend/source/pchtaskqueue.h b/src/tools/clangpchmanagerbackend/source/pchtaskqueue.h index 2d6d76ee587..80d96b8e852 100644 --- a/src/tools/clangpchmanagerbackend/source/pchtaskqueue.h +++ b/src/tools/clangpchmanagerbackend/source/pchtaskqueue.h @@ -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 diff --git a/src/tools/clangrefactoringbackend/clangrefactoringbackendmain.cpp b/src/tools/clangrefactoringbackend/clangrefactoringbackendmain.cpp index 9579f760c9c..aaef21b6085 100644 --- a/src/tools/clangrefactoringbackend/clangrefactoringbackendmain.cpp +++ b/src/tools/clangrefactoringbackend/clangrefactoringbackendmain.cpp @@ -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: } }; +class ApplicationEnvironment final : public ClangBackEnd::Environment +{ +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) - : database{Utils::PathString{databasePath}, 100000ms} + 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); diff --git a/src/tools/clangrefactoringbackend/source/symbolindexer.cpp b/src/tools/clangrefactoringbackend/source/symbolindexer.cpp index 109e6c5e80a..dd1069736ff 100644 --- a/src/tools/clangrefactoringbackend/source/symbolindexer.cpp +++ b/src/tools/clangrefactoringbackend/source/symbolindexer.cpp @@ -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); diff --git a/src/tools/clangrefactoringbackend/source/symbolindexer.h b/src/tools/clangrefactoringbackend/source/symbolindexer.h index d574d0e01d8..64b442bf33d 100644 --- a/src/tools/clangrefactoringbackend/source/symbolindexer.h +++ b/src/tools/clangrefactoringbackend/source/symbolindexer.h @@ -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 diff --git a/src/tools/clangrefactoringbackend/source/symbolindexing.h b/src/tools/clangrefactoringbackend/source/symbolindexing.h index 10df4e397b0..d4e36499b12 100644 --- a/src/tools/clangrefactoringbackend/source/symbolindexing.h +++ b/src/tools/clangrefactoringbackend/source/symbolindexing.h @@ -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; }; diff --git a/tests/unit/mockup/coreplugin/icore.h b/tests/unit/mockup/coreplugin/icore.h index 579fbc3b56f..8cf88f70376 100644 --- a/tests/unit/mockup/coreplugin/icore.h +++ b/tests/unit/mockup/coreplugin/icore.h @@ -12,5 +12,10 @@ inline static QString cacheResourcePath() return QDir::tempPath(); } +inline static QString resourcePath() +{ + return QDir::tempPath(); +} + } // namespace ICore } // namespace Core diff --git a/tests/unit/unittest/builddependencycollector-test.cpp b/tests/unit/unittest/builddependencycollector-test.cpp index 6c2153fe0c4..0d1b9650dce 100644 --- a/tests/unit/unittest/builddependencycollector-test.cpp +++ b/tests/unit/unittest/builddependencycollector-test.cpp @@ -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,16 @@ 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"), @@ -899,14 +916,76 @@ TEST_F(BuildDependencyCollector, Clear) 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"), + id(TESTDATA_DIR "/builddependencycollector/project/header2.h"), + id(TESTDATA_DIR "/builddependencycollector/project/missingfile.h"), + id(TESTDATA_DIR "/builddependencycollector/project/macros.h"), + }, + {}, + Utils::Language::Cxx, + Utils::LanguageVersion::CXX11, + Utils::LanguageExtension::None}; - 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 diff --git a/tests/unit/unittest/clangfollowsymbol-test.cpp b/tests/unit/unittest/clangfollowsymbol-test.cpp index 628aa076186..e836cc83c66 100644 --- a/tests/unit/unittest/clangfollowsymbol-test.cpp +++ b/tests/unit/unittest/clangfollowsymbol-test.cpp @@ -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}; diff --git a/tests/unit/unittest/clangreferencescollector-test.cpp b/tests/unit/unittest/clangreferencescollector-test.cpp index acf7c42ac3d..bb04d8c8d1d 100644 --- a/tests/unit/unittest/clangreferencescollector-test.cpp +++ b/tests/unit/unittest/clangreferencescollector-test.cpp @@ -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}; }; diff --git a/tests/unit/unittest/codecompletionsextractor-test.cpp b/tests/unit/unittest/codecompletionsextractor-test.cpp index ae7559ce788..509dfd49dc4 100644 --- a/tests/unit/unittest/codecompletionsextractor-test.cpp +++ b/tests/unit/unittest/codecompletionsextractor-test.cpp @@ -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}; diff --git a/tests/unit/unittest/commandlinebuilder-test.cpp b/tests/unit/unittest/commandlinebuilder-test.cpp index d16bb008bbe..c5765037dc5 100644 --- a/tests/unit/unittest/commandlinebuilder-test.cpp +++ b/tests/unit/unittest/commandlinebuilder-test.cpp @@ -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 diff --git a/tests/unit/unittest/cursor-test.cpp b/tests/unit/unittest/cursor-test.cpp index e55668d420c..2fa4bff7098 100644 --- a/tests/unit/unittest/cursor-test.cpp +++ b/tests/unit/unittest/cursor-test.cpp @@ -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, diff --git a/tests/unit/unittest/data/preincludes/system1.h b/tests/unit/unittest/data/preincludes/system1.h new file mode 100644 index 00000000000..005a65916e3 --- /dev/null +++ b/tests/unit/unittest/data/preincludes/system1.h @@ -0,0 +1 @@ +#include_next <system1.h> diff --git a/tests/unit/unittest/diagnostic-test.cpp b/tests/unit/unittest/diagnostic-test.cpp index fac44162cd0..3ab382c46b0 100644 --- a/tests/unit/unittest/diagnostic-test.cpp +++ b/tests/unit/unittest/diagnostic-test.cpp @@ -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}; diff --git a/tests/unit/unittest/diagnosticset-test.cpp b/tests/unit/unittest/diagnosticset-test.cpp index f37d00e13fb..b59325e0e71 100644 --- a/tests/unit/unittest/diagnosticset-test.cpp +++ b/tests/unit/unittest/diagnosticset-test.cpp @@ -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, {}, diff --git a/tests/unit/unittest/highlightingresultreporter-test.cpp b/tests/unit/unittest/highlightingresultreporter-test.cpp index dfe8dfbd2e0..dd2001e02ff 100644 --- a/tests/unit/unittest/highlightingresultreporter-test.cpp +++ b/tests/unit/unittest/highlightingresultreporter-test.cpp @@ -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}; }; diff --git a/tests/unit/unittest/pchcreator-test.cpp b/tests/unit/unittest/pchcreator-test.cpp index 9c40b7fea76..19bc087ca6d 100644 --- a/tests/unit/unittest/pchcreator-test.cpp +++ b/tests/unit/unittest/pchcreator-test.cpp @@ -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", diff --git a/tests/unit/unittest/pchtaskqueue-test.cpp b/tests/unit/unittest/pchtaskqueue-test.cpp index 4a8c0862eef..0851224d9d0 100644 --- a/tests/unit/unittest/pchtaskqueue-test.cpp +++ b/tests/unit/unittest/pchtaskqueue-test.cpp @@ -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))); diff --git a/tests/unit/unittest/projectupdater-test.cpp b/tests/unit/unittest/projectupdater-test.cpp index 21ee3f5781e..494eed57139 100644 --- a/tests/unit/unittest/projectupdater-test.cpp +++ b/tests/unit/unittest/projectupdater-test.cpp @@ -351,7 +351,6 @@ TEST_F(ProjectUpdater, ToolChainArguments) ASSERT_THAT(arguments, ElementsAre(QString{"-m32"}, - QString{"-fPIC"}, QString{"extraflags"}, QString{"-include"}, QString{"config.h"})); diff --git a/tests/unit/unittest/skippedsourceranges-test.cpp b/tests/unit/unittest/skippedsourceranges-test.cpp index 083f795ec95..fd95dc47797 100644 --- a/tests/unit/unittest/skippedsourceranges-test.cpp +++ b/tests/unit/unittest/skippedsourceranges-test.cpp @@ -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, diff --git a/tests/unit/unittest/sourcerange-test.cpp b/tests/unit/unittest/sourcerange-test.cpp index c66b9854dbc..1b2b44a8f90 100644 --- a/tests/unit/unittest/sourcerange-test.cpp +++ b/tests/unit/unittest/sourcerange-test.cpp @@ -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}; diff --git a/tests/unit/unittest/symbolindexer-test.cpp b/tests/unit/unittest/symbolindexer-test.cpp index c1373e03c45..35943235325 100644 --- a/tests/unit/unittest/symbolindexer-test.cpp +++ b/tests/unit/unittest/symbolindexer-test.cpp @@ -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", diff --git a/tests/unit/unittest/symbolindexing-test.cpp b/tests/unit/unittest/symbolindexing-test.cpp index 6e094951f34..67411efd370 100644 --- a/tests/unit/unittest/symbolindexing-test.cpp +++ b/tests/unit/unittest/symbolindexing-test.cpp @@ -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"; diff --git a/tests/unit/unittest/testenvironment.h b/tests/unit/unittest/testenvironment.h index a9529c58d55..1e6c7da862c 100644 --- a/tests/unit/unittest/testenvironment.h +++ b/tests/unit/unittest/testenvironment.h @@ -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(); - } - - uint hardwareConcurrency() const - { - return 2; - } + TestEnvironment() { temporaryDirectory.setAutoRemove(true); } - static QVector<Utf8String> addPlatformArguments(std::initializer_list<Utf8String> arguments = {}) + Utils::PathString pchBuildDirectory() const override { return temporaryDirectory.path(); } + uint hardwareConcurrency() const { return 2; } + ClangBackEnd::NativeFilePathView preIncludeSearchPath() const override { - 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"}}; }; diff --git a/tests/unit/unittest/token-test.cpp b/tests/unit/unittest/token-test.cpp index 3f7c39ea5f3..f5f8a36e3a9 100644 --- a/tests/unit/unittest/token-test.cpp +++ b/tests/unit/unittest/token-test.cpp @@ -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, diff --git a/tests/unit/unittest/tokenprocessor-test.cpp b/tests/unit/unittest/tokenprocessor-test.cpp index c96650472d0..285c6d3446f 100644 --- a/tests/unit/unittest/tokenprocessor-test.cpp +++ b/tests/unit/unittest/tokenprocessor-test.cpp @@ -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)}), {}, diff --git a/tests/unit/unittest/unittest-utility-functions.h b/tests/unit/unittest/unittest-utility-functions.h index 6d68c1adfcc..5102769e78f 100644 --- a/tests/unit/unittest/unittest-utility-functions.h +++ b/tests/unit/unittest/unittest-utility-functions.h @@ -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 |