diff --git a/CMakeLists.txt b/CMakeLists.txt index 8bc5ba30..3a466084 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -365,7 +365,24 @@ target_include_directories(${LIB_CXX_PROJECT_NAME} SYSTEM ) link_directories(${LLVM_LIBRARY_DIRS} ${CLANG_LIBRARY_DIRS} ${Boost_LIBRARY_DIRS}) -llvm_map_components_to_libnames(REQ_LLVM_LIBS support core libdriver passes x86asmparser x86codegen) +llvm_map_components_to_libnames(REQ_LLVM_LIBS + support core libdriver passes + x86asmparser x86codegen + aarch64asmparser aarch64codegen + amdgpuasmparser amdgpucodegen + armasmparser armcodegen + bpfasmparser bpfcodegen + hexagonasmparser hexagoncodegen + lanaiasmparser lanaicodegen + mipsasmparser mipscodegen + msp430asmparser msp430codegen + nvptxcodegen + powerpcasmparser powerpccodegen + sparcasmparser sparccodegen + systemzasmparser systemzcodegen + webassemblyasmparser webassemblycodegen + xcorecodegen +) target_link_libraries(${LIB_CXX_PROJECT_NAME} ${LIB_UTILITY_PROJECT_NAME} ${CLANG_LIBRARIES} ${REQ_LLVM_LIBS}) diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index f43dd12c..875106a0 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -380,6 +380,8 @@ add_files( settings/SourceGroupSettingsWithIndexedHeaderPaths.h settings/SourceGroupSettingsWithJavaStandard.cpp settings/SourceGroupSettingsWithJavaStandard.h + settings/SourceGroupSettingsWithCxxPchOptions.cpp + settings/SourceGroupSettingsWithCxxPchOptions.h settings/SourceGroupSettingsWithSonargraphProjectPath.cpp settings/SourceGroupSettingsWithSonargraphProjectPath.h settings/SourceGroupSettingsWithSourceExtensions.cpp diff --git a/src/lib/project/Project.cpp b/src/lib/project/Project.cpp index 2f808342..9b7879e8 100644 --- a/src/lib/project/Project.cpp +++ b/src/lib/project/Project.cpp @@ -542,6 +542,16 @@ void Project::buildIndex(RefreshInfo info, std::shared_ptr dialogVie taskSequential->addTask(std::make_shared>("indexer_command_queue_started", false)); taskSequential->addTask(std::make_shared>("indexer_command_queue_stopped", false)); + std::shared_ptr preIndexTasks = std::make_shared(); + taskSequential->addTask(preIndexTasks); + for (const std::shared_ptr& sourceGroup : m_sourceGroups) + { + if (sourceGroup->getStatus() == SOURCE_GROUP_STATUS_ENABLED) + { + preIndexTasks->addTask(sourceGroup->getPreIndexTask(dialogView)); + } + } + std::shared_ptr taskParserWrapper = std::make_shared(tempStorage, dialogView); taskSequential->addTask(taskParserWrapper); diff --git a/src/lib/project/SourceGroup.cpp b/src/lib/project/SourceGroup.cpp index d0b3e419..bf6216fa 100644 --- a/src/lib/project/SourceGroup.cpp +++ b/src/lib/project/SourceGroup.cpp @@ -1,15 +1,22 @@ #include "SourceGroup.h" -#include "MemoryIndexerCommandProvider.h" -#include "SourceGroupSettings.h" #include "FilePath.h" #include "FilePathFilter.h" +#include "MemoryIndexerCommandProvider.h" +#include "ProjectSettings.h" +#include "SourceGroupSettings.h" +#include "TaskLambda.h" std::shared_ptr SourceGroup::getIndexerCommandProvider(const std::set& filesToIndex) const { return std::make_shared(getIndexerCommands(filesToIndex)); } +std::shared_ptr SourceGroup::getPreIndexTask(std::shared_ptr dialogView) const +{ + return std::make_shared([]() {}); +} + SourceGroupType SourceGroup::getType() const { return getSourceGroupSettings()->getType(); diff --git a/src/lib/project/SourceGroup.h b/src/lib/project/SourceGroup.h index 181b6313..8c06bfc3 100644 --- a/src/lib/project/SourceGroup.h +++ b/src/lib/project/SourceGroup.h @@ -9,11 +9,13 @@ #include "SourceGroupStatusType.h" #include "SourceGroupType.h" -class IndexerCommand; -class IndexerCommandProvider; +class DialogView; class FilePath; class FilePathFilter; +class IndexerCommand; +class IndexerCommandProvider; class SourceGroupSettings; +class Task; class SourceGroup { @@ -27,6 +29,7 @@ public: virtual std::set getAllSourceFilePaths() const = 0; virtual std::shared_ptr getIndexerCommandProvider(const std::set& filesToIndex) const; virtual std::vector> getIndexerCommands(const std::set& filesToIndex) const = 0; + virtual std::shared_ptr getPreIndexTask(std::shared_ptr dialogView) const; SourceGroupType getType() const; LanguageType getLanguage() const; diff --git a/src/lib/settings/ApplicationSettings.cpp b/src/lib/settings/ApplicationSettings.cpp index 34ae3c30..a7d2a1d9 100644 --- a/src/lib/settings/ApplicationSettings.cpp +++ b/src/lib/settings/ApplicationSettings.cpp @@ -8,8 +8,9 @@ #include "ResourcePaths.h" #include "Status.h" #include "TimeStamp.h" -#include "utility.h" #include "UserPaths.h" +#include "utility.h" +#include "utilityFile.h" #include "Version.h" const size_t ApplicationSettings::VERSION = 8; @@ -390,7 +391,7 @@ std::vector ApplicationSettings::getJreSystemLibraryPaths() const std::vector ApplicationSettings::getJreSystemLibraryPathsExpanded() const { - return expandPaths(getJreSystemLibraryPaths()); + return utility::getExpandedPaths(getJreSystemLibraryPaths()); } bool ApplicationSettings::setJreSystemLibraryPaths(const std::vector& jreSystemLibraryPaths) @@ -445,7 +446,7 @@ std::vector ApplicationSettings::getHeaderSearchPaths() const std::vector ApplicationSettings::getHeaderSearchPathsExpanded() const { - return expandPaths(getHeaderSearchPaths()); + return utility::getExpandedPaths(getHeaderSearchPaths()); } bool ApplicationSettings::setHeaderSearchPaths(const std::vector& headerSearchPaths) @@ -470,7 +471,7 @@ std::vector ApplicationSettings::getFrameworkSearchPaths() const std::vector ApplicationSettings::getFrameworkSearchPathsExpanded() const { - return expandPaths(getFrameworkSearchPaths()); + return utility::getExpandedPaths(getFrameworkSearchPaths()); } bool ApplicationSettings::setFrameworkSearchPaths(const std::vector& frameworkSearchPaths) diff --git a/src/lib/settings/ProjectSettings.cpp b/src/lib/settings/ProjectSettings.cpp index da50169d..d54d4978 100644 --- a/src/lib/settings/ProjectSettings.cpp +++ b/src/lib/settings/ProjectSettings.cpp @@ -15,6 +15,7 @@ #include "SourceGroupSettingsJavaSonargraph.h" #include "SourceGroupSettingsPythonEmpty.h" #include "logging.h" +#include "utilityFile.h" #include "utilityString.h" #include "utilityUuid.h" @@ -128,6 +129,11 @@ void ProjectSettings::setProjectFilePath(std::wstring projectName, const FilePat setFilePath(projectFileLocation.getConcatenated(L"/" + projectName + PROJECT_FILE_EXTENSION)); } +FilePath ProjectSettings::getDependenciesDirectoryPath() const +{ + return getProjectDirectoryPath().concatenate(L"sourcetrail_dependencies"); +} + FilePath ProjectSettings::getDBFilePath() const { return getFilePath().replaceExtension(INDEX_DB_FILE_EXTENSION); @@ -240,7 +246,7 @@ void ProjectSettings::setAllSourceGroupSettings(const std::vector ProjectSettings::makePathsExpandedAndAbsolute(const std::vector& paths) const { - std::vector p = expandPaths(paths); + std::vector p = utility::getExpandedPaths(paths); std::vector absPaths; const FilePath basePath = getProjectDirectoryPath(); @@ -261,14 +267,7 @@ std::vector ProjectSettings::makePathsExpandedAndAbsolute(const std::v FilePath ProjectSettings::makePathExpandedAndAbsolute(const FilePath& path) const { - FilePath p = expandPath(path); - - if (p.empty() || p.isAbsolute()) - { - return p; - } - - return getProjectDirectoryPath().concatenate(p).makeCanonical(); + return utility::getExpandedAndAbsolutePath(path, getProjectDirectoryPath()); } SettingsMigrator ProjectSettings::getMigrations() const diff --git a/src/lib/settings/ProjectSettings.h b/src/lib/settings/ProjectSettings.h index eabca933..a7e6969f 100644 --- a/src/lib/settings/ProjectSettings.h +++ b/src/lib/settings/ProjectSettings.h @@ -35,6 +35,7 @@ public: FilePath getProjectFilePath() const; void setProjectFilePath(std::wstring projectName, const FilePath& projectFileLocation); + FilePath getDependenciesDirectoryPath() const; FilePath getDBFilePath() const; FilePath getTempDBFilePath() const; diff --git a/src/lib/settings/Settings.cpp b/src/lib/settings/Settings.cpp index 45f7917a..e4764075 100644 --- a/src/lib/settings/Settings.cpp +++ b/src/lib/settings/Settings.cpp @@ -98,33 +98,6 @@ void Settings::setVersion(size_t version) setValue("version", version); } -FilePath Settings::expandPath(const FilePath& path) -{ - std::vector paths = path.expandEnvironmentVariables(); - if (!paths.empty()) - { - if (paths.size() > 1) - { - LOG_WARNING( - L"Environment variable in path \"" + path.wstr() + L"\" has been expanded to " + std::to_wstring(paths.size()) + - L"paths, but only \"" + paths.front().wstr() + L"\" will be used." - ); - } - return paths.front(); - } - return FilePath(); -} - -std::vector Settings::expandPaths(const std::vector& paths) -{ - std::vector expanedPaths; - for (const FilePath& path : paths) - { - utility::append(expanedPaths, path.expandEnvironmentVariables()); - } - return expanedPaths; -} - Settings::Settings() { clear(); diff --git a/src/lib/settings/Settings.h b/src/lib/settings/Settings.h index d53baf35..c97b46ce 100644 --- a/src/lib/settings/Settings.h +++ b/src/lib/settings/Settings.h @@ -29,9 +29,6 @@ public: size_t getVersion() const; void setVersion(size_t version); - static FilePath expandPath(const FilePath& path); - static std::vector expandPaths(const std::vector& paths); - protected: Settings(); diff --git a/src/lib/settings/SourceGroupSettings.cpp b/src/lib/settings/SourceGroupSettings.cpp index 79727c9e..441e6525 100644 --- a/src/lib/settings/SourceGroupSettings.cpp +++ b/src/lib/settings/SourceGroupSettings.cpp @@ -1,7 +1,8 @@ #include "SourceGroupSettings.h" -#include "ProjectSettings.h" #include "ConfigManager.h" +#include "ProjectSettings.h" +#include "utilityString.h" const size_t SourceGroupSettings::s_version = 1; const std::string SourceGroupSettings::s_keyPrefix = "source_groups/source_group_"; @@ -93,16 +94,16 @@ const ProjectSettings* SourceGroupSettings::getProjectSettings() const return m_projectSettings; } +FilePath SourceGroupSettings::getSourceGroupDependenciesDirectoryPath() const +{ + return getProjectSettings()->getDependenciesDirectoryPath().concatenate(utility::decodeFromUtf8(getId())); +} + FilePath SourceGroupSettings::getProjectDirectoryPath() const { return m_projectSettings->getProjectDirectoryPath(); } -FilePath SourceGroupSettings::makePathExpandedAndAbsolute(const FilePath& path) const -{ - return m_projectSettings->makePathExpandedAndAbsolute(path); -} - std::vector SourceGroupSettings::makePathsExpandedAndAbsolute(const std::vector& paths) const { return m_projectSettings->makePathsExpandedAndAbsolute(paths); diff --git a/src/lib/settings/SourceGroupSettings.h b/src/lib/settings/SourceGroupSettings.h index 0f0152fb..cebf5fdc 100644 --- a/src/lib/settings/SourceGroupSettings.h +++ b/src/lib/settings/SourceGroupSettings.h @@ -42,9 +42,9 @@ public: void setStatus(SourceGroupStatusType status); const ProjectSettings* getProjectSettings() const override; + FilePath getSourceGroupDependenciesDirectoryPath() const override; FilePath getProjectDirectoryPath() const; - FilePath makePathExpandedAndAbsolute(const FilePath& path) const; std::vector makePathsExpandedAndAbsolute(const std::vector& paths) const; protected: diff --git a/src/lib/settings/SourceGroupSettingsBase.h b/src/lib/settings/SourceGroupSettingsBase.h index 4d2f2ef7..cd3e0170 100644 --- a/src/lib/settings/SourceGroupSettingsBase.h +++ b/src/lib/settings/SourceGroupSettingsBase.h @@ -1,6 +1,7 @@ #ifndef SOURCE_GROUP_SETTINGS_BASE_H #define SOURCE_GROUP_SETTINGS_BASE_H +class FilePath; class ProjectSettings; class SourceGroupSettingsBase @@ -9,6 +10,7 @@ public: virtual ~SourceGroupSettingsBase() = default; virtual const ProjectSettings* getProjectSettings() const = 0; + virtual FilePath getSourceGroupDependenciesDirectoryPath() const = 0; }; #endif // SOURCE_GROUP_SETTINGS_BASE_H diff --git a/src/lib/settings/SourceGroupSettingsCEmpty.cpp b/src/lib/settings/SourceGroupSettingsCEmpty.cpp index 1163bc1d..a44f5910 100644 --- a/src/lib/settings/SourceGroupSettingsCEmpty.cpp +++ b/src/lib/settings/SourceGroupSettingsCEmpty.cpp @@ -19,6 +19,7 @@ void SourceGroupSettingsCEmpty::load(std::shared_ptr config SourceGroupSettingsWithCStandard::load(config, key); SourceGroupSettingsWithCxxCrossCompilationOptions::load(config, key); SourceGroupSettingsWithSourceExtensions::load(config, key); + SourceGroupSettingsWithCxxPchOptions::load(config, key); SourceGroupSettingsWithSourcePaths::load(config, key); SourceGroupSettingsWithExcludeFilters::load(config, key); } @@ -32,6 +33,7 @@ void SourceGroupSettingsCEmpty::save(std::shared_ptr config) SourceGroupSettingsWithCStandard::save(config, key); SourceGroupSettingsWithCxxCrossCompilationOptions::save(config, key); SourceGroupSettingsWithSourceExtensions::save(config, key); + SourceGroupSettingsWithCxxPchOptions::save(config, key); SourceGroupSettingsWithSourcePaths::save(config, key); SourceGroupSettingsWithExcludeFilters::save(config, key); } @@ -46,6 +48,7 @@ bool SourceGroupSettingsCEmpty::equals(std::shared_ptr othe SourceGroupSettingsWithCStandard::equals(otherCxxEmpty) && SourceGroupSettingsWithCxxCrossCompilationOptions::equals(otherCxxEmpty) && SourceGroupSettingsWithSourceExtensions::equals(otherCxxEmpty) && + SourceGroupSettingsWithCxxPchOptions::equals(otherCxxEmpty) && SourceGroupSettingsWithSourcePaths::equals(otherCxxEmpty) && SourceGroupSettingsWithExcludeFilters::equals(otherCxxEmpty) ); diff --git a/src/lib/settings/SourceGroupSettingsCEmpty.h b/src/lib/settings/SourceGroupSettingsCEmpty.h index b406709e..fc14d6d0 100644 --- a/src/lib/settings/SourceGroupSettingsCEmpty.h +++ b/src/lib/settings/SourceGroupSettingsCEmpty.h @@ -5,6 +5,7 @@ #include "SourceGroupSettingsWithCStandard.h" #include "SourceGroupSettingsWithCxxCrossCompilationOptions.h" #include "SourceGroupSettingsWithExcludeFilters.h" +#include "SourceGroupSettingsWithCxxPchOptions.h" #include "SourceGroupSettingsWithSourceExtensions.h" #include "SourceGroupSettingsWithSourcePaths.h" @@ -13,6 +14,7 @@ class SourceGroupSettingsCEmpty , public SourceGroupSettingsWithCStandard , public SourceGroupSettingsWithCxxCrossCompilationOptions , public SourceGroupSettingsWithExcludeFilters + , public SourceGroupSettingsWithCxxPchOptions , public SourceGroupSettingsWithSourceExtensions , public SourceGroupSettingsWithSourcePaths { diff --git a/src/lib/settings/SourceGroupSettingsCppEmpty.cpp b/src/lib/settings/SourceGroupSettingsCppEmpty.cpp index be9280a7..8243befe 100644 --- a/src/lib/settings/SourceGroupSettingsCppEmpty.cpp +++ b/src/lib/settings/SourceGroupSettingsCppEmpty.cpp @@ -19,6 +19,7 @@ void SourceGroupSettingsCppEmpty::load(std::shared_ptr conf SourceGroupSettingsWithCppStandard::load(config, key); SourceGroupSettingsWithCxxCrossCompilationOptions::load(config, key); SourceGroupSettingsWithSourceExtensions::load(config, key); + SourceGroupSettingsWithCxxPchOptions::load(config, key); SourceGroupSettingsWithSourcePaths::load(config, key); SourceGroupSettingsWithExcludeFilters::load(config, key); } @@ -32,6 +33,7 @@ void SourceGroupSettingsCppEmpty::save(std::shared_ptr config) SourceGroupSettingsWithCppStandard::save(config, key); SourceGroupSettingsWithCxxCrossCompilationOptions::save(config, key); SourceGroupSettingsWithSourceExtensions::save(config, key); + SourceGroupSettingsWithCxxPchOptions::save(config, key); SourceGroupSettingsWithSourcePaths::save(config, key); SourceGroupSettingsWithExcludeFilters::save(config, key); } @@ -46,6 +48,7 @@ bool SourceGroupSettingsCppEmpty::equals(std::shared_ptr ot SourceGroupSettingsWithCppStandard::equals(otherCxxEmpty) && SourceGroupSettingsWithCxxCrossCompilationOptions::equals(otherCxxEmpty) && SourceGroupSettingsWithSourceExtensions::equals(otherCxxEmpty) && + SourceGroupSettingsWithCxxPchOptions::equals(otherCxxEmpty) && SourceGroupSettingsWithSourcePaths::equals(otherCxxEmpty) && SourceGroupSettingsWithExcludeFilters::equals(otherCxxEmpty) ); diff --git a/src/lib/settings/SourceGroupSettingsCppEmpty.h b/src/lib/settings/SourceGroupSettingsCppEmpty.h index a62c5b74..cca290ac 100644 --- a/src/lib/settings/SourceGroupSettingsCppEmpty.h +++ b/src/lib/settings/SourceGroupSettingsCppEmpty.h @@ -5,6 +5,7 @@ #include "SourceGroupSettingsWithCppStandard.h" #include "SourceGroupSettingsWithCxxCrossCompilationOptions.h" #include "SourceGroupSettingsWithExcludeFilters.h" +#include "SourceGroupSettingsWithCxxPchOptions.h" #include "SourceGroupSettingsWithSourceExtensions.h" #include "SourceGroupSettingsWithSourcePaths.h" @@ -13,6 +14,7 @@ class SourceGroupSettingsCppEmpty , public SourceGroupSettingsWithCppStandard , public SourceGroupSettingsWithCxxCrossCompilationOptions , public SourceGroupSettingsWithExcludeFilters + , public SourceGroupSettingsWithCxxPchOptions , public SourceGroupSettingsWithSourceExtensions , public SourceGroupSettingsWithSourcePaths { diff --git a/src/lib/settings/SourceGroupSettingsCxxCdb.cpp b/src/lib/settings/SourceGroupSettingsCxxCdb.cpp index 478fbd62..af4c0af5 100644 --- a/src/lib/settings/SourceGroupSettingsCxxCdb.cpp +++ b/src/lib/settings/SourceGroupSettingsCxxCdb.cpp @@ -1,7 +1,8 @@ #include "SourceGroupSettingsCxxCdb.h" -#include "ProjectSettings.h" #include "ConfigManager.h" +#include "ProjectSettings.h" +#include "utilityFile.h" SourceGroupSettingsCxxCdb::SourceGroupSettingsCxxCdb(const std::string& id, const ProjectSettings* projectSettings) : SourceGroupSettingsCxx(id, SOURCE_GROUP_CXX_CDB, projectSettings) @@ -58,7 +59,7 @@ FilePath SourceGroupSettingsCxxCdb::getCompilationDatabasePath() const FilePath SourceGroupSettingsCxxCdb::getCompilationDatabasePathExpandedAndAbsolute() const { - return m_projectSettings->makePathExpandedAndAbsolute(getCompilationDatabasePath()); + return utility::getExpandedAndAbsolutePath(getCompilationDatabasePath(), m_projectSettings->getProjectDirectoryPath()); } void SourceGroupSettingsCxxCdb::setCompilationDatabasePath(const FilePath& compilationDatabasePath) diff --git a/src/lib/settings/SourceGroupSettingsCxxCodeblocks.cpp b/src/lib/settings/SourceGroupSettingsCxxCodeblocks.cpp index af974c70..26d8024c 100644 --- a/src/lib/settings/SourceGroupSettingsCxxCodeblocks.cpp +++ b/src/lib/settings/SourceGroupSettingsCxxCodeblocks.cpp @@ -2,6 +2,7 @@ #include "ConfigManager.h" #include "ProjectSettings.h" +#include "utilityFile.h" SourceGroupSettingsCxxCodeblocks::SourceGroupSettingsCxxCodeblocks(const std::string& id, const ProjectSettings* projectSettings) : SourceGroupSettingsCxx(id, SOURCE_GROUP_CXX_CODEBLOCKS, projectSettings) @@ -66,7 +67,7 @@ FilePath SourceGroupSettingsCxxCodeblocks::getCodeblocksProjectPath() const FilePath SourceGroupSettingsCxxCodeblocks::getCodeblocksProjectPathExpandedAndAbsolute() const { - return m_projectSettings->makePathExpandedAndAbsolute(getCodeblocksProjectPath()); + return utility::getExpandedAndAbsolutePath(getCodeblocksProjectPath(), m_projectSettings->getProjectDirectoryPath()); } void SourceGroupSettingsCxxCodeblocks::setCodeblocksProjectPath(const FilePath& compilationDatabasePath) diff --git a/src/lib/settings/SourceGroupSettingsJavaGradle.cpp b/src/lib/settings/SourceGroupSettingsJavaGradle.cpp index 2e0cadf3..99b1f4bd 100644 --- a/src/lib/settings/SourceGroupSettingsJavaGradle.cpp +++ b/src/lib/settings/SourceGroupSettingsJavaGradle.cpp @@ -1,12 +1,12 @@ #include "SourceGroupSettingsJavaGradle.h" -#include "ProjectSettings.h" #include "ConfigManager.h" +#include "ProjectSettings.h" +#include "utilityFile.h" SourceGroupSettingsJavaGradle::SourceGroupSettingsJavaGradle(const std::string& id, const ProjectSettings* projectSettings) : SourceGroupSettingsJava(id, SOURCE_GROUP_JAVA_GRADLE, projectSettings) , m_gradleProjectFilePath(FilePath()) - , m_gradleDependenciesDirectory(FilePath()) , m_shouldIndexGradleTests(false) { } @@ -23,7 +23,6 @@ void SourceGroupSettingsJavaGradle::load(std::shared_ptr co const std::string key = s_keyPrefix + getId(); setGradleProjectFilePath(config->getValueOrDefault(key + "/gradle/project_file_path", FilePath(L""))); - setGradleDependenciesDirectory(config->getValueOrDefault(key + "/gradle/dependencies_directory", FilePath(L""))); setShouldIndexGradleTests(config->getValueOrDefault(key + "/gradle/should_index_tests", false)); } @@ -34,7 +33,6 @@ void SourceGroupSettingsJavaGradle::save(std::shared_ptr config) const std::string key = s_keyPrefix + getId(); config->setValue(key + "/gradle/project_file_path", getGradleProjectFilePath().wstr()); - config->setValue(key + "/gradle/dependencies_directory", getGradleDependenciesDirectory().wstr()); config->setValue(key + "/gradle/should_index_tests", getShouldIndexGradleTests()); } @@ -46,11 +44,15 @@ bool SourceGroupSettingsJavaGradle::equals(std::shared_ptr otherJavaGradle && SourceGroupSettingsJava::equals(other) && m_gradleProjectFilePath == otherJavaGradle->m_gradleProjectFilePath && - m_gradleDependenciesDirectory == otherJavaGradle->m_gradleDependenciesDirectory && m_shouldIndexGradleTests == otherJavaGradle->m_shouldIndexGradleTests ); } +FilePath SourceGroupSettingsJavaGradle::getGradleDependenciesDirectoryPath() const +{ + return getSourceGroupDependenciesDirectoryPath().concatenate(L"gradle"); +} + FilePath SourceGroupSettingsJavaGradle::getGradleProjectFilePath() const { return m_gradleProjectFilePath; @@ -58,7 +60,7 @@ FilePath SourceGroupSettingsJavaGradle::getGradleProjectFilePath() const FilePath SourceGroupSettingsJavaGradle::getGradleProjectFilePathExpandedAndAbsolute() const { - return m_projectSettings->makePathExpandedAndAbsolute(getGradleProjectFilePath()); + return utility::getExpandedAndAbsolutePath(getGradleProjectFilePath(), getProjectSettings()->getProjectDirectoryPath()); } void SourceGroupSettingsJavaGradle::setGradleProjectFilePath(const FilePath& path) @@ -66,21 +68,6 @@ void SourceGroupSettingsJavaGradle::setGradleProjectFilePath(const FilePath& pat m_gradleProjectFilePath = path; } -FilePath SourceGroupSettingsJavaGradle::getGradleDependenciesDirectory() const -{ - return m_gradleDependenciesDirectory; -} - -FilePath SourceGroupSettingsJavaGradle::getGradleDependenciesDirectoryExpandedAndAbsolute() const -{ - return m_projectSettings->makePathExpandedAndAbsolute(getGradleDependenciesDirectory()); -} - -void SourceGroupSettingsJavaGradle::setGradleDependenciesDirectory(const FilePath& path) -{ - m_gradleDependenciesDirectory = path; -} - bool SourceGroupSettingsJavaGradle::getShouldIndexGradleTests() const { return m_shouldIndexGradleTests; diff --git a/src/lib/settings/SourceGroupSettingsJavaGradle.h b/src/lib/settings/SourceGroupSettingsJavaGradle.h index 69ac07b2..a0f7199f 100644 --- a/src/lib/settings/SourceGroupSettingsJavaGradle.h +++ b/src/lib/settings/SourceGroupSettingsJavaGradle.h @@ -16,21 +16,18 @@ public: void save(std::shared_ptr config) override; bool equals(std::shared_ptr other) const override; - + + FilePath getGradleDependenciesDirectoryPath() const; + FilePath getGradleProjectFilePath() const; FilePath getGradleProjectFilePathExpandedAndAbsolute() const; void setGradleProjectFilePath(const FilePath& path); - FilePath getGradleDependenciesDirectory() const; - FilePath getGradleDependenciesDirectoryExpandedAndAbsolute() const; - void setGradleDependenciesDirectory(const FilePath& path); - bool getShouldIndexGradleTests() const; void setShouldIndexGradleTests(bool value); private: FilePath m_gradleProjectFilePath; - FilePath m_gradleDependenciesDirectory; bool m_shouldIndexGradleTests; }; diff --git a/src/lib/settings/SourceGroupSettingsJavaMaven.cpp b/src/lib/settings/SourceGroupSettingsJavaMaven.cpp index 7aaf683d..a3089af6 100644 --- a/src/lib/settings/SourceGroupSettingsJavaMaven.cpp +++ b/src/lib/settings/SourceGroupSettingsJavaMaven.cpp @@ -1,12 +1,12 @@ #include "SourceGroupSettingsJavaMaven.h" -#include "ProjectSettings.h" #include "ConfigManager.h" +#include "ProjectSettings.h" +#include "utilityFile.h" SourceGroupSettingsJavaMaven::SourceGroupSettingsJavaMaven(const std::string& id, const ProjectSettings* projectSettings) : SourceGroupSettingsJava(id, SOURCE_GROUP_JAVA_MAVEN, projectSettings) , m_mavenProjectFilePath(FilePath()) - , m_mavenDependenciesDirectory(FilePath()) , m_shouldIndexMavenTests(false) { } @@ -23,7 +23,6 @@ void SourceGroupSettingsJavaMaven::load(std::shared_ptr con const std::string key = s_keyPrefix + getId(); setMavenProjectFilePath(config->getValueOrDefault(key + "/maven/project_file_path", FilePath(L""))); - setMavenDependenciesDirectory(config->getValueOrDefault(key + "/maven/dependencies_directory", FilePath(L""))); setShouldIndexMavenTests(config->getValueOrDefault(key + "/maven/should_index_tests", false)); } @@ -34,7 +33,6 @@ void SourceGroupSettingsJavaMaven::save(std::shared_ptr config) const std::string key = s_keyPrefix + getId(); config->setValue(key + "/maven/project_file_path", getMavenProjectFilePath().wstr()); - config->setValue(key + "/maven/dependencies_directory", getMavenDependenciesDirectory().wstr()); config->setValue(key + "/maven/should_index_tests", getShouldIndexMavenTests()); } @@ -46,11 +44,15 @@ bool SourceGroupSettingsJavaMaven::equals(std::shared_ptr o otherJavaMaven && SourceGroupSettingsJava::equals(other) && m_mavenProjectFilePath == otherJavaMaven->m_mavenProjectFilePath && - m_mavenDependenciesDirectory == otherJavaMaven->m_mavenDependenciesDirectory && m_shouldIndexMavenTests == otherJavaMaven->m_shouldIndexMavenTests ); } +FilePath SourceGroupSettingsJavaMaven::getMavenDependenciesDirectoryPath() const +{ + return getSourceGroupDependenciesDirectoryPath().concatenate(L"maven"); +} + FilePath SourceGroupSettingsJavaMaven::getMavenProjectFilePath() const { return m_mavenProjectFilePath; @@ -58,7 +60,7 @@ FilePath SourceGroupSettingsJavaMaven::getMavenProjectFilePath() const FilePath SourceGroupSettingsJavaMaven::getMavenProjectFilePathExpandedAndAbsolute() const { - return m_projectSettings->makePathExpandedAndAbsolute(getMavenProjectFilePath()); + return utility::getExpandedAndAbsolutePath(getMavenProjectFilePath(), getProjectSettings()->getProjectDirectoryPath()); } void SourceGroupSettingsJavaMaven::setMavenProjectFilePath(const FilePath& path) @@ -66,21 +68,6 @@ void SourceGroupSettingsJavaMaven::setMavenProjectFilePath(const FilePath& path) m_mavenProjectFilePath = path; } -FilePath SourceGroupSettingsJavaMaven::getMavenDependenciesDirectory() const -{ - return m_mavenDependenciesDirectory; -} - -FilePath SourceGroupSettingsJavaMaven::getMavenDependenciesDirectoryExpandedAndAbsolute() const -{ - return m_projectSettings->makePathExpandedAndAbsolute(getMavenDependenciesDirectory()); -} - -void SourceGroupSettingsJavaMaven::setMavenDependenciesDirectory(const FilePath& path) -{ - m_mavenDependenciesDirectory = path; -} - bool SourceGroupSettingsJavaMaven::getShouldIndexMavenTests() const { return m_shouldIndexMavenTests; diff --git a/src/lib/settings/SourceGroupSettingsJavaMaven.h b/src/lib/settings/SourceGroupSettingsJavaMaven.h index 9483719c..556339db 100644 --- a/src/lib/settings/SourceGroupSettingsJavaMaven.h +++ b/src/lib/settings/SourceGroupSettingsJavaMaven.h @@ -17,20 +17,17 @@ public: bool equals(std::shared_ptr other) const override; + FilePath getMavenDependenciesDirectoryPath() const; + FilePath getMavenProjectFilePath() const; FilePath getMavenProjectFilePathExpandedAndAbsolute() const; void setMavenProjectFilePath(const FilePath& path); - FilePath getMavenDependenciesDirectory() const; - FilePath getMavenDependenciesDirectoryExpandedAndAbsolute() const; - void setMavenDependenciesDirectory(const FilePath& path); - bool getShouldIndexMavenTests() const; void setShouldIndexMavenTests(bool value); private: FilePath m_mavenProjectFilePath; - FilePath m_mavenDependenciesDirectory; bool m_shouldIndexMavenTests; }; diff --git a/src/lib/settings/SourceGroupSettingsPythonEmpty.cpp b/src/lib/settings/SourceGroupSettingsPythonEmpty.cpp index 4a618495..58868466 100644 --- a/src/lib/settings/SourceGroupSettingsPythonEmpty.cpp +++ b/src/lib/settings/SourceGroupSettingsPythonEmpty.cpp @@ -2,6 +2,7 @@ #include "FilePath.h" #include "ProjectSettings.h" +#include "utilityFile.h" SourceGroupSettingsPythonEmpty::SourceGroupSettingsPythonEmpty(const std::string& id, const ProjectSettings* projectSettings) : SourceGroupSettings(id, SOURCE_GROUP_PYTHON_EMPTY, projectSettings) @@ -60,7 +61,7 @@ FilePath SourceGroupSettingsPythonEmpty::getEnvironmentPath() const FilePath SourceGroupSettingsPythonEmpty::getEnvironmentPathExpandedAndAbsolute() const { - return m_projectSettings->makePathExpandedAndAbsolute(getEnvironmentPath()); + return utility::getExpandedAndAbsolutePath(getEnvironmentPath(), m_projectSettings->getProjectDirectoryPath()); } void SourceGroupSettingsPythonEmpty::setEnvironmentPath(const FilePath& environmentPath) diff --git a/src/lib/settings/SourceGroupSettingsWithCxxPchOptions.cpp b/src/lib/settings/SourceGroupSettingsWithCxxPchOptions.cpp new file mode 100644 index 00000000..95dc43b1 --- /dev/null +++ b/src/lib/settings/SourceGroupSettingsWithCxxPchOptions.cpp @@ -0,0 +1,42 @@ +#include "SourceGroupSettingsWithCxxPchOptions.h" + +#include "ProjectSettings.h" +#include "utilityFile.h" + +bool SourceGroupSettingsWithCxxPchOptions::equals(std::shared_ptr other) const +{ + return ( + other && + m_pchInputFilePath == other->m_pchInputFilePath + ); +} + +void SourceGroupSettingsWithCxxPchOptions::load(std::shared_ptr config, const std::string& key) +{ + setPchInputFilePathFilePath(config->getValueOrDefault(key + "/pch_input_file_path", FilePath(L""))); +} + +void SourceGroupSettingsWithCxxPchOptions::save(std::shared_ptr config, const std::string& key) +{ + config->setValue(key + "/pch_input_file_path", getPchInputFilePath().wstr()); +} + +FilePath SourceGroupSettingsWithCxxPchOptions::getPchDependenciesDirectoryPath() const +{ + return getSourceGroupDependenciesDirectoryPath().concatenate(L"pch"); +} + +FilePath SourceGroupSettingsWithCxxPchOptions::getPchInputFilePath() const +{ + return m_pchInputFilePath; +} + +FilePath SourceGroupSettingsWithCxxPchOptions::getPchInputFilePathExpandedAndAbsolute() const +{ + return utility::getExpandedAndAbsolutePath(getPchInputFilePath(), getProjectSettings()->getProjectDirectoryPath()); +} + +void SourceGroupSettingsWithCxxPchOptions::setPchInputFilePathFilePath(const FilePath& path) +{ + m_pchInputFilePath = path; +} diff --git a/src/lib/settings/SourceGroupSettingsWithCxxPchOptions.h b/src/lib/settings/SourceGroupSettingsWithCxxPchOptions.h new file mode 100644 index 00000000..98592b0a --- /dev/null +++ b/src/lib/settings/SourceGroupSettingsWithCxxPchOptions.h @@ -0,0 +1,35 @@ +#ifndef SOURCE_GROUP_SETTINGS_WITH_CXX_PCH_OPTIONS_H +#define SOURCE_GROUP_SETTINGS_WITH_CXX_PCH_OPTIONS_H + +#include +#include + +#include "FilePath.h" +#include "SourceGroupSettingsBase.h" + +class ConfigManager; + +class SourceGroupSettingsWithCxxPchOptions + : virtual public SourceGroupSettingsBase +{ +public: + SourceGroupSettingsWithCxxPchOptions() = default; + virtual ~SourceGroupSettingsWithCxxPchOptions() = default; + + bool equals(std::shared_ptr other) const; + + FilePath getPchDependenciesDirectoryPath() const; + + FilePath getPchInputFilePath() const; + FilePath getPchInputFilePathExpandedAndAbsolute() const; + void setPchInputFilePathFilePath(const FilePath& path); + +protected: + void load(std::shared_ptr config, const std::string& key); + void save(std::shared_ptr config, const std::string& key); + +private: + FilePath m_pchInputFilePath; +}; + +#endif // SOURCE_GROUP_SETTINGS_WITH_CXX_PCH_OPTIONS_H diff --git a/src/lib/settings/SourceGroupSettingsWithExcludeFilters.cpp b/src/lib/settings/SourceGroupSettingsWithExcludeFilters.cpp index a4015779..1ca67d08 100644 --- a/src/lib/settings/SourceGroupSettingsWithExcludeFilters.cpp +++ b/src/lib/settings/SourceGroupSettingsWithExcludeFilters.cpp @@ -4,6 +4,7 @@ #include "FilePathFilter.h" #include "FileSystem.h" #include "utility.h" +#include "utilityFile.h" SourceGroupSettingsWithExcludeFilters::SourceGroupSettingsWithExcludeFilters() : m_excludeFilters(std::vector()) @@ -45,6 +46,8 @@ void SourceGroupSettingsWithExcludeFilters::setExcludeFilterStrings(const std::v std::vector SourceGroupSettingsWithExcludeFilters::getFiltersExpandedAndAbsolute(const std::vector& filterStrings) const { + const FilePath projectDirectoryPath = getProjectSettings()->getProjectDirectoryPath(); + std::vector result; for (const std::wstring& filterString : filterStrings) @@ -58,7 +61,7 @@ std::vector SourceGroupSettingsWithExcludeFilters::getFiltersExp if (std::regex_search(filterString, match, std::wregex(L"[\\\\/]")) && !match.empty() && match.position(0) < int(wildcardPos)) { - const FilePath p = getProjectSettings()->makePathExpandedAndAbsolute(FilePath(match.prefix().str())); + const FilePath p = utility::getExpandedAndAbsolutePath(FilePath(match.prefix().str()), projectDirectoryPath); std::set symLinkPaths = FileSystem::getSymLinkedDirectories(p); symLinkPaths.insert(p); @@ -79,7 +82,7 @@ std::vector SourceGroupSettingsWithExcludeFilters::getFiltersExp } else { - const FilePath p = getProjectSettings()->makePathExpandedAndAbsolute(FilePath(filterString)); + const FilePath p = utility::getExpandedAndAbsolutePath(FilePath(filterString), projectDirectoryPath); const bool isFile = p.exists() && !p.isDirectory(); std::set symLinkPaths = FileSystem::getSymLinkedDirectories(p); diff --git a/src/lib/settings/SourceGroupSettingsWithSonargraphProjectPath.cpp b/src/lib/settings/SourceGroupSettingsWithSonargraphProjectPath.cpp index b72d06a2..ee2ddd02 100644 --- a/src/lib/settings/SourceGroupSettingsWithSonargraphProjectPath.cpp +++ b/src/lib/settings/SourceGroupSettingsWithSonargraphProjectPath.cpp @@ -1,6 +1,7 @@ #include "SourceGroupSettingsWithSonargraphProjectPath.h" #include "ProjectSettings.h" +#include "utilityFile.h" SourceGroupSettingsWithSonargraphProjectPath::SourceGroupSettingsWithSonargraphProjectPath() { @@ -31,7 +32,7 @@ FilePath SourceGroupSettingsWithSonargraphProjectPath::getSonargraphProjectPath( FilePath SourceGroupSettingsWithSonargraphProjectPath::getSonargraphProjectPathExpandedAndAbsolute() const { - return getProjectSettings()->makePathExpandedAndAbsolute(getSonargraphProjectPath()); + return utility::getExpandedAndAbsolutePath(getSonargraphProjectPath(), getProjectSettings()->getProjectDirectoryPath()); } void SourceGroupSettingsWithSonargraphProjectPath::setSonargraphProjectPath(const FilePath& sonargraphProjectPath) diff --git a/src/lib/utility/utilityFile.cpp b/src/lib/utility/utilityFile.cpp index 95d6c166..a9657bee 100644 --- a/src/lib/utility/utilityFile.cpp +++ b/src/lib/utility/utilityFile.cpp @@ -66,6 +66,45 @@ std::vector utility::getTopLevelPaths(const std::set& paths) return topLevelPaths; } +FilePath utility::getExpandedPath(const FilePath& path) +{ + std::vector paths = path.expandEnvironmentVariables(); + if (!paths.empty()) + { + if (paths.size() > 1) + { + LOG_WARNING( + L"Environment variable in path \"" + path.wstr() + L"\" has been expanded to " + std::to_wstring(paths.size()) + + L"paths, but only \"" + paths.front().wstr() + L"\" will be used." + ); + } + return paths.front(); + } + return FilePath(); +} + +std::vector utility::getExpandedPaths(const std::vector& paths) +{ + std::vector expanedPaths; + for (const FilePath& path : paths) + { + utility::append(expanedPaths, path.expandEnvironmentVariables()); + } + return expanedPaths; +} + +FilePath utility::getExpandedAndAbsolutePath(const FilePath& path, const FilePath& baseDirectory) +{ + FilePath p = getExpandedPath(path); + + if (p.empty() || p.isAbsolute()) + { + return p; + } + + return baseDirectory.getConcatenated(p).makeCanonical(); +} + FilePath utility::getAsRelativeIfShorter(const FilePath& absolutePath, const FilePath& baseDirectory) { if (!baseDirectory.empty()) diff --git a/src/lib/utility/utilityFile.h b/src/lib/utility/utilityFile.h index df78b541..98bcbe8e 100644 --- a/src/lib/utility/utilityFile.h +++ b/src/lib/utility/utilityFile.h @@ -13,6 +13,9 @@ namespace utility std::vector getTopLevelPaths(const std::vector& paths); std::vector getTopLevelPaths(const std::set& paths); + FilePath getExpandedPath(const FilePath& path); + std::vector getExpandedPaths(const std::vector& paths); + FilePath getExpandedAndAbsolutePath(const FilePath& path, const FilePath& baseDirectory); FilePath getAsRelativeIfShorter(const FilePath& absolutePath, const FilePath& baseDirectory); std::vector getAsRelativeIfShorter(const std::vector& absolutePaths, const FilePath& baseDirectory); } diff --git a/src/lib_cxx/CMakeLists.txt b/src/lib_cxx/CMakeLists.txt index d323f881..b7e230f8 100644 --- a/src/lib_cxx/CMakeLists.txt +++ b/src/lib_cxx/CMakeLists.txt @@ -37,9 +37,8 @@ add_files( data/parser/cxx/name_resolver/CxxTypeNameResolver.cpp data/parser/cxx/name_resolver/CxxTypeNameResolver.h + data/parser/cxx/ASTAction.cpp data/parser/cxx/ASTAction.h - data/parser/cxx/ASTActionFactory.cpp - data/parser/cxx/ASTActionFactory.h data/parser/cxx/ASTConsumer.cpp data/parser/cxx/ASTConsumer.h data/parser/cxx/CanonicalFilePathCache.cpp @@ -72,8 +71,12 @@ add_files( data/parser/cxx/CxxParser.h data/parser/cxx/CxxVerboseAstVisitor.cpp data/parser/cxx/CxxVerboseAstVisitor.h + data/parser/cxx/GeneratePCHAction.cpp + data/parser/cxx/GeneratePCHAction.h data/parser/cxx/PreprocessorCallbacks.cpp data/parser/cxx/PreprocessorCallbacks.h + data/parser/cxx/SingleFrontendActionFactory.cpp + data/parser/cxx/SingleFrontendActionFactory.h data/parser/cxx/utilityClang.cpp data/parser/cxx/utilityClang.h diff --git a/src/lib_cxx/data/parser/cxx/ASTAction.cpp b/src/lib_cxx/data/parser/cxx/ASTAction.cpp new file mode 100644 index 00000000..22a28df4 --- /dev/null +++ b/src/lib_cxx/data/parser/cxx/ASTAction.cpp @@ -0,0 +1,34 @@ +#include "ASTAction.h" + +#include + +#include "ASTConsumer.h" +#include "PreprocessorCallbacks.h" + +ASTAction::ASTAction( + std::shared_ptr client, + std::shared_ptr canonicalFilePathCache, + std::shared_ptr indexerStateInfo +) + : m_client(client) + , m_canonicalFilePathCache(canonicalFilePathCache) + , m_indexerStateInfo(indexerStateInfo) + , m_commentHandler(client, canonicalFilePathCache) +{} + +std::unique_ptr ASTAction::CreateASTConsumer(clang::CompilerInstance& compiler, llvm::StringRef inFile) +{ + return std::unique_ptr(new ASTConsumer( + &compiler.getASTContext(), &compiler.getPreprocessor(), m_client, m_canonicalFilePathCache, m_indexerStateInfo + )); +} + +bool ASTAction::BeginSourceFileAction(clang::CompilerInstance& compiler) +{ + clang::Preprocessor& preprocessor = compiler.getPreprocessor(); + preprocessor.addPPCallbacks(llvm::make_unique( + compiler.getSourceManager(), m_client, m_canonicalFilePathCache + )); + preprocessor.addCommentHandler(&m_commentHandler); + return true; +} diff --git a/src/lib_cxx/data/parser/cxx/ASTAction.h b/src/lib_cxx/data/parser/cxx/ASTAction.h index e8a73d22..929b79d8 100644 --- a/src/lib_cxx/data/parser/cxx/ASTAction.h +++ b/src/lib_cxx/data/parser/cxx/ASTAction.h @@ -3,47 +3,26 @@ #include -#include #include -#include -#include "ASTConsumer.h" #include "CommentHandler.h" -#include "PreprocessorCallbacks.h" -template -class ASTAction - : public ASTActionBase +class ParserClient; +class CanonicalFilePathCache; +struct IndexerStateInfo; + +class ASTAction : public clang::ASTFrontendAction { public: explicit ASTAction( std::shared_ptr client, std::shared_ptr canonicalFilePathCache, std::shared_ptr indexerStateInfo - ) - : m_client(client) - , m_canonicalFilePathCache(canonicalFilePathCache) - , m_indexerStateInfo(indexerStateInfo) - , m_commentHandler(client, canonicalFilePathCache) - {} - - virtual ~ASTAction() {} + ); protected: - virtual std::unique_ptr CreateASTConsumer(clang::CompilerInstance& compiler, llvm::StringRef inFile) override - { - return std::unique_ptr( - new ASTConsumer(&compiler.getASTContext(), &compiler.getPreprocessor(), m_client, m_canonicalFilePathCache, m_indexerStateInfo)); - } - - virtual bool BeginSourceFileAction(clang::CompilerInstance& compiler) override - { - clang::Preprocessor& preprocessor = compiler.getPreprocessor(); - preprocessor.addPPCallbacks( - llvm::make_unique(compiler.getSourceManager(), m_client, m_canonicalFilePathCache)); - preprocessor.addCommentHandler(&m_commentHandler); - return true; - } + std::unique_ptr CreateASTConsumer(clang::CompilerInstance& compiler, llvm::StringRef inFile) override; + bool BeginSourceFileAction(clang::CompilerInstance& compiler) override; private: std::shared_ptr m_client; diff --git a/src/lib_cxx/data/parser/cxx/ASTActionFactory.cpp b/src/lib_cxx/data/parser/cxx/ASTActionFactory.cpp deleted file mode 100644 index a4f32443..00000000 --- a/src/lib_cxx/data/parser/cxx/ASTActionFactory.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include "ASTActionFactory.h" - -#include - -#include "ASTAction.h" - -ASTActionFactory::ASTActionFactory( - std::shared_ptr client, - std::shared_ptr canonicalFilePathCache, - std::shared_ptr indexerStateInfo -) - : m_client(client) - , m_canonicalFilePathCache(canonicalFilePathCache) - , m_indexerStateInfo(indexerStateInfo) -{ -} - -ASTActionFactory::~ASTActionFactory() -{ -} - -clang::FrontendAction* ASTActionFactory::create() -{ - return new ASTAction(m_client, m_canonicalFilePathCache, m_indexerStateInfo); -} diff --git a/src/lib_cxx/data/parser/cxx/ASTActionFactory.h b/src/lib_cxx/data/parser/cxx/ASTActionFactory.h deleted file mode 100644 index a798edaa..00000000 --- a/src/lib_cxx/data/parser/cxx/ASTActionFactory.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef AST_ACTION_FACTORY -#define AST_ACTION_FACTORY - -#include - -#include - -#include "IndexerStateInfo.h" - -class CanonicalFilePathCache; -class ParserClient; - -class ASTActionFactory - : public clang::tooling::FrontendActionFactory -{ -public: - explicit ASTActionFactory( - std::shared_ptr client, - std::shared_ptr canonicalFilePathCache, - std::shared_ptr indexerStateInfo - ); - - virtual ~ASTActionFactory(); - - virtual clang::FrontendAction* create() override; - -private: - std::shared_ptr m_client; - std::shared_ptr m_canonicalFilePathCache; - std::shared_ptr m_indexerStateInfo; -}; - -#endif // AST_ACTION_FACTORY diff --git a/src/lib_cxx/data/parser/cxx/CxxParser.cpp b/src/lib_cxx/data/parser/cxx/CxxParser.cpp index 3b80b6c0..b1fc04e1 100644 --- a/src/lib_cxx/data/parser/cxx/CxxParser.cpp +++ b/src/lib_cxx/data/parser/cxx/CxxParser.cpp @@ -10,7 +10,7 @@ #include #include "ApplicationSettings.h" -#include "ASTActionFactory.h" +#include "ASTAction.h" #include "CanonicalFilePathCache.h" #include "CxxCompilationDatabaseSingle.h" #include "CxxDiagnosticConsumer.h" @@ -20,6 +20,7 @@ #include "logging.h" #include "ParserClient.h" #include "ResourcePaths.h" +#include "SingleFrontendActionFactory.h" #include "TextAccess.h" #include "utilityString.h" #include "utility.h" @@ -114,6 +115,8 @@ namespace const clang::tooling::FileContentMappings &VirtualMappedFiles = clang::tooling::FileContentMappings() ) { + CxxParser::initializeLLVM(); + llvm::SmallString<16> FileNameStorage; llvm::StringRef FileNameRef = FileName.toNullTerminatedStringRef(FileNameStorage); @@ -136,6 +139,47 @@ namespace } } +std::vector CxxParser::getCommandlineArgumentsEssential(const std::vector& compilerFlags) +{ + std::vector args; + + // The option -fno-delayed-template-parsing signals that templates that there should + // be AST elements for unused template functions as well. + args.push_back("-fno-delayed-template-parsing"); + + // The option -fexceptions signals that clang should watch out for exception-related code during indexing. + args.push_back("-fexceptions"); + + // The option -c signals that no executable is built. + args.push_back("-c"); + + // The option -w disables all warnings. + args.push_back("-w"); + + // This option tells clang just to continue parsing no matter how manny errors have been thrown. + args.push_back("-ferror-limit=0"); + + for (const std::wstring& compilerFlag : compilerFlags) + { + args.push_back(utility::encodeToUtf8(compilerFlag)); + } + + return args; +} + +void CxxParser::initializeLLVM() +{ + static bool intialized = false; + if (!intialized) + { + llvm::InitializeAllTargets(); + llvm::InitializeAllTargetMCs(); + llvm::InitializeAllAsmPrinters(); + llvm::InitializeAllAsmParsers(); + intialized = true; + } +} + CxxParser::CxxParser( std::shared_ptr client, std::shared_ptr fileRegister, @@ -172,13 +216,13 @@ void CxxParser::buildIndex(const std::wstring& fileName, std::shared_ptr(m_fileRegister); std::shared_ptr diagnostics = getDiagnostics(FilePath(), canonicalFilePathCache, false); - ASTActionFactory actionFactory(m_client, canonicalFilePathCache, m_indexerStateInfo); + clang::ASTFrontendAction* action = new ASTAction(m_client, canonicalFilePathCache, m_indexerStateInfo); std::vector args = getCommandlineArgumentsEssential(compilerFlags); runToolOnCodeWithArgs( diagnostics.get(), - actionFactory.create(), + action, fileContent->getText(), args, utility::encodeToUtf8(fileName) @@ -187,6 +231,8 @@ void CxxParser::buildIndex(const std::wstring& fileName, std::shared_ptr(1, utility::encodeToUtf8(sourceFilePath.wstr()))); std::shared_ptr canonicalFilePathCache = std::make_shared(m_fileRegister); @@ -207,8 +253,8 @@ void CxxParser::runTool(clang::tooling::CompilationDatabase* compilationDatabase } } - ASTActionFactory actionFactory(m_client, canonicalFilePathCache, m_indexerStateInfo); - tool.run(&actionFactory); + clang::ASTFrontendAction* action = new ASTAction(m_client, canonicalFilePathCache, m_indexerStateInfo); + tool.run(new SingleFrontendActionFactory(action)); if (!m_client->hasContent()) { @@ -231,34 +277,6 @@ void CxxParser::runTool(clang::tooling::CompilationDatabase* compilationDatabase } } -std::vector CxxParser::getCommandlineArgumentsEssential(const std::vector& compilerFlags) const -{ - std::vector args; - - // The option -fno-delayed-template-parsing signals that templates that there should - // be AST elements for unused template functions as well. - args.push_back("-fno-delayed-template-parsing"); - - // The option -fexceptions signals that clang should watch out for exception-related code during indexing. - args.push_back("-fexceptions"); - - // The option -c signals that no executable is built. - args.push_back("-c"); - - // The option -w disables all warnings. - args.push_back("-w"); - - // This option tells clang just to continue parsing no matter how manny errors have been thrown. - args.push_back("-ferror-limit=0"); - - for (const std::wstring& compilerFlag: compilerFlags) - { - args.push_back(utility::encodeToUtf8(compilerFlag)); - } - - return args; -} - std::shared_ptr CxxParser::getDiagnostics(const FilePath& sourceFilePath, std::shared_ptr canonicalFilePathCache, bool logErrors) const { llvm::IntrusiveRefCntPtr options = new clang::DiagnosticOptions(); diff --git a/src/lib_cxx/data/parser/cxx/CxxParser.h b/src/lib_cxx/data/parser/cxx/CxxParser.h index a253c750..ce5604a3 100644 --- a/src/lib_cxx/data/parser/cxx/CxxParser.h +++ b/src/lib_cxx/data/parser/cxx/CxxParser.h @@ -26,6 +26,9 @@ struct IndexerStateInfo; class CxxParser: public Parser { public: + static std::vector getCommandlineArgumentsEssential(const std::vector& compilerFlags); + static void CxxParser::initializeLLVM(); + CxxParser(std::shared_ptr client, std::shared_ptr fileRegister, std::shared_ptr indexerStateInfo); void buildIndex(std::shared_ptr indexerCommand); @@ -34,8 +37,6 @@ public: private: void runTool(clang::tooling::CompilationDatabase* compilationDatabase, const FilePath& sourceFilePath); - std::vector getCommandlineArgumentsEssential(const std::vector& compilerFlags) const; - std::shared_ptr getDiagnostics( const FilePath& sourceFilePath, std::shared_ptr canonicalFilePathCache, bool logErrors) const; diff --git a/src/lib_cxx/data/parser/cxx/GeneratePCHAction.cpp b/src/lib_cxx/data/parser/cxx/GeneratePCHAction.cpp new file mode 100644 index 00000000..6e9b170b --- /dev/null +++ b/src/lib_cxx/data/parser/cxx/GeneratePCHAction.cpp @@ -0,0 +1,39 @@ +#include "GeneratePCHAction.h" + +#include "clang/Frontend/CompilerInstance.h" +#include "clang/Serialization/ASTWriter.h" +#include "clang/Frontend/MultiplexConsumer.h" + +bool GeneratePCHAction::shouldEraseOutputFiles() +{ + return false; +} + +std::unique_ptr GeneratePCHAction::CreateASTConsumer(clang::CompilerInstance &CI, llvm::StringRef InFile) +{ + std::string Sysroot; + if (!ComputeASTConsumerArguments(CI, /*ref*/ Sysroot)) + return nullptr; + + std::string OutputFile; + std::unique_ptr OS = + CreateOutputFile(CI, InFile, /*ref*/ OutputFile); + if (!OS) + return nullptr; + + if (!CI.getFrontendOpts().RelocatablePCH) + Sysroot.clear(); + + const auto &FrontendOpts = CI.getFrontendOpts(); + auto Buffer = std::make_shared(); + std::vector> Consumers; + Consumers.push_back(llvm::make_unique( + CI.getPreprocessor(), OutputFile, Sysroot, + Buffer, FrontendOpts.ModuleFileExtensions, + true, + FrontendOpts.IncludeTimestamps)); + Consumers.push_back(CI.getPCHContainerWriter().CreatePCHContainerGenerator( + CI, InFile, OutputFile, std::move(OS), Buffer)); + + return llvm::make_unique(std::move(Consumers)); +} diff --git a/src/lib_cxx/data/parser/cxx/GeneratePCHAction.h b/src/lib_cxx/data/parser/cxx/GeneratePCHAction.h new file mode 100644 index 00000000..121e806e --- /dev/null +++ b/src/lib_cxx/data/parser/cxx/GeneratePCHAction.h @@ -0,0 +1,16 @@ +#ifndef GENERATE_PCH_ACTION_H +#define GENERATE_PCH_ACTION_H + +#include "clang/Frontend/FrontendActions.h" + +class GeneratePCHAction : public clang::GeneratePCHAction +{ +protected: + // this method has been overridden to prevent erasing output file independently of provided flags + bool shouldEraseOutputFiles() override; + + // this method has been overridden to always set "AllowASTWithErrors" of the PCHGenerator to "true" + std::unique_ptr CreateASTConsumer(clang::CompilerInstance &CI, llvm::StringRef InFile) override; +}; + +#endif // GENERATE_PCH_ACTION_H diff --git a/src/lib_cxx/data/parser/cxx/SingleFrontendActionFactory.cpp b/src/lib_cxx/data/parser/cxx/SingleFrontendActionFactory.cpp new file mode 100644 index 00000000..4cca8d2b --- /dev/null +++ b/src/lib_cxx/data/parser/cxx/SingleFrontendActionFactory.cpp @@ -0,0 +1,10 @@ +#include "SingleFrontendActionFactory.h" + +SingleFrontendActionFactory::SingleFrontendActionFactory(clang::FrontendAction* action) + : m_action(action) +{} + +clang::FrontendAction* SingleFrontendActionFactory::create() +{ + return m_action; +} diff --git a/src/lib_cxx/data/parser/cxx/SingleFrontendActionFactory.h b/src/lib_cxx/data/parser/cxx/SingleFrontendActionFactory.h new file mode 100644 index 00000000..1f40186c --- /dev/null +++ b/src/lib_cxx/data/parser/cxx/SingleFrontendActionFactory.h @@ -0,0 +1,16 @@ +#ifndef SINGLE_FRONTEND_ACTION_FACTORY +#define SINGLE_FRONTEND_ACTION_FACTORY + +#include "clang/Tooling/Tooling.h" + +class SingleFrontendActionFactory : public clang::tooling::FrontendActionFactory +{ +public: + SingleFrontendActionFactory(clang::FrontendAction* action); + clang::FrontendAction* create() override; + +private: + clang::FrontendAction* m_action; +}; + +#endif // SINGLE_FRONTEND_ACTION_FACTORY diff --git a/src/lib_cxx/project/SourceGroupCxxEmpty.cpp b/src/lib_cxx/project/SourceGroupCxxEmpty.cpp index 1cd09a66..5df6eba0 100644 --- a/src/lib_cxx/project/SourceGroupCxxEmpty.cpp +++ b/src/lib_cxx/project/SourceGroupCxxEmpty.cpp @@ -1,13 +1,20 @@ #include "SourceGroupCxxEmpty.h" #include "ApplicationSettings.h" +#include "CxxCompilationDatabaseSingle.h" #include "CxxIndexerCommandProvider.h" +#include "CxxParser.h" +#include "DialogView.h" #include "FileManager.h" +#include "FileSystem.h" +#include "GeneratePCHAction.h" #include "IndexerCommandCxx.h" +#include "SingleFrontendActionFactory.h" #include "SourceGroupSettingsCEmpty.h" #include "SourceGroupSettingsCppEmpty.h" #include "SourceGroupSettingsWithCppStandard.h" #include "SourceGroupSettingsWithCStandard.h" +#include "TaskLambda.h" #include "utility.h" SourceGroupCxxEmpty::SourceGroupCxxEmpty(std::shared_ptr settings) @@ -67,55 +74,173 @@ std::set SourceGroupCxxEmpty::getAllSourceFilePaths() const std::shared_ptr SourceGroupCxxEmpty::getIndexerCommandProvider(const std::set& filesToIndex) const { - std::shared_ptr appSettings = ApplicationSettings::getInstance(); - - std::set indexedPaths; std::set excludeFilters; - std::wstring targetFlag; + FilePath pchInputFilePath; + FilePath pchDependenciesDirectoryPath; if (std::shared_ptr settings = std::dynamic_pointer_cast(m_settings)) { indexedPaths = utility::toSet(settings->getSourcePathsExpandedAndAbsolute()); excludeFilters = utility::toSet(settings->getExcludeFiltersExpandedAndAbsolute()); - targetFlag = settings->getTargetFlag(); + pchInputFilePath = settings->getPchInputFilePathExpandedAndAbsolute(); + pchDependenciesDirectoryPath = settings->getPchDependenciesDirectoryPath(); } else if (std::shared_ptr settings = std::dynamic_pointer_cast(m_settings)) { indexedPaths = utility::toSet(settings->getSourcePathsExpandedAndAbsolute()); excludeFilters = utility::toSet(settings->getExcludeFiltersExpandedAndAbsolute()); - targetFlag = settings->getTargetFlag(); + pchInputFilePath = settings->getPchInputFilePathExpandedAndAbsolute(); + pchDependenciesDirectoryPath = settings->getPchDependenciesDirectoryPath(); } + std::vector compilerFlags = getCompilerFlags(); + + if (!pchInputFilePath.empty() && !pchDependenciesDirectoryPath.empty()) + { + const FilePath pchOutputFilePath = pchDependenciesDirectoryPath.getConcatenated(pchInputFilePath.fileName()).replaceExtension(L"pch"); + compilerFlags.push_back(L"-fallow-pch-with-compiler-errors"); + compilerFlags.push_back(L"-include-pch"); + compilerFlags.push_back(pchOutputFilePath.wstr()); + } + + std::shared_ptr provider = std::make_shared(); + for (const FilePath& sourcePath: getAllSourceFilePaths()) + { + if (filesToIndex.find(sourcePath) != filesToIndex.end()) + { + provider->addCommand(std::make_shared( + sourcePath, + indexedPaths, + excludeFilters, + std::set(), + m_settings->getProjectDirectoryPath(), + utility::concat(compilerFlags, sourcePath.wstr()) + )); + } + } + + return provider; +} + +std::vector> SourceGroupCxxEmpty::getIndexerCommands(const std::set& filesToIndex) const +{ + return getIndexerCommandProvider(filesToIndex)->consumeAllCommands(); +} + +std::shared_ptr SourceGroupCxxEmpty::getPreIndexTask(std::shared_ptr dialogView) const +{ + FilePath pchInputFilePath; + FilePath pchDependenciesDirectoryPath; + if (std::shared_ptr settings = + std::dynamic_pointer_cast(m_settings)) + { + pchInputFilePath = settings->getPchInputFilePathExpandedAndAbsolute(); + pchDependenciesDirectoryPath = settings->getPchDependenciesDirectoryPath(); + } + else if (std::shared_ptr settings = + std::dynamic_pointer_cast(m_settings)) + { + pchInputFilePath = settings->getPchInputFilePathExpandedAndAbsolute(); + pchDependenciesDirectoryPath = settings->getPchDependenciesDirectoryPath(); + } + + if (pchInputFilePath.empty() || pchDependenciesDirectoryPath.empty()) + { + return std::make_shared([]() {}); + } + + if (!pchInputFilePath.exists()) + { + LOG_ERROR(L"Precompiled header input file \"" + pchInputFilePath.wstr() + L"\" does not exist."); + return std::make_shared([]() {}); + } + + const FilePath pchOutputFilePath = pchDependenciesDirectoryPath.getConcatenated(pchInputFilePath.fileName()).replaceExtension(L"pch"); + + std::vector compilerFlags = getCompilerFlags(); + compilerFlags.push_back(pchInputFilePath.wstr()); + compilerFlags.push_back(L"-emit-pch"); + compilerFlags.push_back(L"-o"); + compilerFlags.push_back(pchOutputFilePath.wstr()); + + return std::make_shared( + [dialogView, pchInputFilePath, pchOutputFilePath, compilerFlags]() + { + dialogView->showUnknownProgressDialog(L"Preparing Indexing", L"Processing Precompiled Headers"); + LOG_INFO( + L"Generating precompiled header output for input file \"" + pchInputFilePath.wstr() + + L"\" at location \"" + pchOutputFilePath.wstr() + L"\"" + ); + + CxxParser::initializeLLVM(); + + if (!pchOutputFilePath.getParentDirectory().exists()) + { + FileSystem::createDirectory(pchOutputFilePath.getParentDirectory()); + } + + clang::tooling::CompileCommand pchCommand; + pchCommand.Filename = utility::encodeToUtf8(pchInputFilePath.fileName()); + pchCommand.Directory = pchOutputFilePath.getParentDirectory().str(); + // DON'T use "-fsyntax-only" here because it will cause the output file to be erased + pchCommand.CommandLine = utility::concat({ "clang-tool" }, CxxParser::getCommandlineArgumentsEssential(compilerFlags)); + + CxxCompilationDatabaseSingle compilationDatabase(pchCommand); + clang::tooling::ClangTool tool(compilationDatabase, std::vector(1, utility::encodeToUtf8(pchInputFilePath.wstr()))); + GeneratePCHAction* action = new GeneratePCHAction(); + tool.clearArgumentsAdjusters(); + tool.run(new SingleFrontendActionFactory(action)); + } + ); +} + +std::shared_ptr SourceGroupCxxEmpty::getSourceGroupSettings() +{ + return m_settings; +} + +std::shared_ptr SourceGroupCxxEmpty::getSourceGroupSettings() const +{ + return m_settings; +} + +std::vector SourceGroupCxxEmpty::getCompilerFlags() const +{ std::vector compilerFlags; + + std::shared_ptr appSettings = ApplicationSettings::getInstance(); + std::set indexedPaths; + std::wstring targetFlag; + std::wstring languageStandard = SourceGroupSettingsWithCppStandard::getDefaultCppStandardStatic(); + + if (std::shared_ptr settings = + std::dynamic_pointer_cast(m_settings)) { - if (!targetFlag.empty()) - { - compilerFlags.push_back(targetFlag); - } + indexedPaths = utility::toSet(settings->getSourcePathsExpandedAndAbsolute()); + targetFlag = settings->getTargetFlag(); + languageStandard = settings->getCStandard(); + } + else if (std::shared_ptr settings = + std::dynamic_pointer_cast(m_settings)) + { + indexedPaths = utility::toSet(settings->getSourcePathsExpandedAndAbsolute()); + targetFlag = settings->getTargetFlag(); + languageStandard = settings->getCppStandard(); + } + else + { + LOG_ERROR(L"Source group doesn't specify language standard. Falling back to \"" + languageStandard + L"\"."); } + if (!targetFlag.empty()) { - std::wstring languageStandard = SourceGroupSettingsWithCppStandard::getDefaultCppStandardStatic(); - if (std::shared_ptr cSettings = - std::dynamic_pointer_cast(m_settings)) - { - languageStandard = cSettings->getCStandard(); - } - else if (std::shared_ptr cppSettings = - std::dynamic_pointer_cast(m_settings)) - { - languageStandard = cppSettings->getCppStandard(); - } - else - { - LOG_ERROR(L"Source group doesn't specify language standard. Falling back to \"" + languageStandard + L"\"."); - } - - compilerFlags.push_back(IndexerCommandCxx::getCompilerFlagLanguageStandard(languageStandard)); + compilerFlags.push_back(targetFlag); } + compilerFlags.push_back(IndexerCommandCxx::getCompilerFlagLanguageStandard(languageStandard)); + if (std::dynamic_pointer_cast(m_settings)) { compilerFlags.push_back(L"-x"); @@ -143,36 +268,6 @@ std::shared_ptr SourceGroupCxxEmpty::getIndexerCommandPr utility::append(compilerFlags, m_settings->getCompilerFlags()); - std::shared_ptr provider = std::make_shared(); - for (const FilePath& sourcePath: getAllSourceFilePaths()) - { - if (filesToIndex.find(sourcePath) != filesToIndex.end()) - { - provider->addCommand(std::make_shared( - sourcePath, - indexedPaths, - excludeFilters, - std::set(), - m_settings->getProjectDirectoryPath(), - utility::concat(compilerFlags, sourcePath.wstr()) - )); - } - } - - return provider; + return compilerFlags; } -std::vector> SourceGroupCxxEmpty::getIndexerCommands(const std::set& filesToIndex) const -{ - return getIndexerCommandProvider(filesToIndex)->consumeAllCommands(); -} - -std::shared_ptr SourceGroupCxxEmpty::getSourceGroupSettings() -{ - return m_settings; -} - -std::shared_ptr SourceGroupCxxEmpty::getSourceGroupSettings() const -{ - return m_settings; -} diff --git a/src/lib_cxx/project/SourceGroupCxxEmpty.h b/src/lib_cxx/project/SourceGroupCxxEmpty.h index af3a0bc0..156bcf5f 100644 --- a/src/lib_cxx/project/SourceGroupCxxEmpty.h +++ b/src/lib_cxx/project/SourceGroupCxxEmpty.h @@ -17,10 +17,12 @@ public: std::set getAllSourceFilePaths() const override; std::shared_ptr getIndexerCommandProvider(const std::set& filesToIndex) const override; std::vector> getIndexerCommands(const std::set& filesToIndex) const override; + std::shared_ptr getPreIndexTask(std::shared_ptr dialogView) const override; private: std::shared_ptr getSourceGroupSettings() override; std::shared_ptr getSourceGroupSettings() const override; + std::vector getCompilerFlags() const; std::shared_ptr m_settings; }; diff --git a/src/lib_gui/CMakeLists.txt b/src/lib_gui/CMakeLists.txt index ce507bec..a9c172db 100644 --- a/src/lib_gui/CMakeLists.txt +++ b/src/lib_gui/CMakeLists.txt @@ -150,10 +150,8 @@ add_files( qt/project_wizard/content/path/QtProjectWizardContentPathCDB.h qt/project_wizard/content/path/QtProjectWizardContentPathCodeblocksProject.cpp qt/project_wizard/content/path/QtProjectWizardContentPathCodeblocksProject.h - qt/project_wizard/content/path/QtProjectWizardContentPathDependenciesGradle.cpp - qt/project_wizard/content/path/QtProjectWizardContentPathDependenciesGradle.h - qt/project_wizard/content/path/QtProjectWizardContentPathDependenciesMaven.cpp - qt/project_wizard/content/path/QtProjectWizardContentPathDependenciesMaven.h + qt/project_wizard/content/path/QtProjectWizardContentPathCxxPch.cpp + qt/project_wizard/content/path/QtProjectWizardContentPathCxxPch.h qt/project_wizard/content/path/QtProjectWizardContentPathPythonEnvironment.cpp qt/project_wizard/content/path/QtProjectWizardContentPathPythonEnvironment.h qt/project_wizard/content/path/QtProjectWizardContentPathSonargraphProject.cpp diff --git a/src/lib_gui/qt/project_wizard/QtProjectWizard.cpp b/src/lib_gui/qt/project_wizard/QtProjectWizard.cpp index e9fb2d93..e07af1c7 100644 --- a/src/lib_gui/qt/project_wizard/QtProjectWizard.cpp +++ b/src/lib_gui/qt/project_wizard/QtProjectWizard.cpp @@ -19,8 +19,7 @@ #include "QtProjectWizardContentPath.h" #include "QtProjectWizardContentPathCDB.h" #include "QtProjectWizardContentPathCodeblocksProject.h" -#include "QtProjectWizardContentPathDependenciesGradle.h" -#include "QtProjectWizardContentPathDependenciesMaven.h" +#include "QtProjectWizardContentPathCxxPch.h" #include "QtProjectWizardContentPathPythonEnvironment.h" #include "QtProjectWizardContentPathSonargraphProject.h" #include "QtProjectWizardContentPathSourceGradle.h" @@ -141,6 +140,13 @@ namespace { QtSourceGroupWizardPage page("Advanced (optional)"); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); + page.addContentCreator( + WIZARD_CONTENT_CONTEXT_ALL, + [](std::shared_ptr settings, QtProjectWizardWindow* window) + { + return new QtProjectWizardContentPathCxxPch(settings, settings, window); + } + ); pages.push_back(page); } @@ -180,6 +186,13 @@ namespace { QtSourceGroupWizardPage page("Advanced (optional)"); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); + page.addContentCreator( + WIZARD_CONTENT_CONTEXT_ALL, + [](std::shared_ptr settings, QtProjectWizardWindow* window) + { + return new QtProjectWizardContentPathCxxPch(settings, settings, window); + } + ); pages.push_back(page); } @@ -362,7 +375,6 @@ namespace QtSourceGroupWizardPage page("Indexed Paths"); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); - page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); pages.push_back(page); } { @@ -383,7 +395,6 @@ namespace QtSourceGroupWizardPage page("Indexed Paths"); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); - page.addContentCreatorWithSettings(WIZARD_CONTENT_CONTEXT_ALL); pages.push_back(page); } { @@ -1107,28 +1118,12 @@ void QtProjectWizard::selectedProjectType(SourceGroupType sourceGroupType) case SOURCE_GROUP_JAVA_MAVEN: { std::shared_ptr settings = std::make_shared(sourceGroupId, m_projectSettings.get()); - settings->setMavenDependenciesDirectory( - FilePath( - L"./sourcetrail_dependencies/" + utility::replace(m_projectSettings->getProjectName(), L" ", L"_") + - L"/" + - utility::decodeFromUtf8(settings->getId()) + - L"/maven" - ) - ); executeSourceGroupSetup(settings); } break; case SOURCE_GROUP_JAVA_GRADLE: { std::shared_ptr settings = std::make_shared(sourceGroupId, m_projectSettings.get()); - settings->setGradleDependenciesDirectory( - FilePath( - L"./sourcetrail_dependencies/" + utility::replace(m_projectSettings->getProjectName(), L" ", L"_") + - L"/" + - utility::decodeFromUtf8(settings->getId()) + - L"/gradle" - ) - ); executeSourceGroupSetup(settings); } break; diff --git a/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPath.cpp b/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPath.cpp index e6ed45ad..e6d3df5b 100644 --- a/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPath.cpp +++ b/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPath.cpp @@ -3,10 +3,10 @@ #include #include "SourceGroupSettings.h" +#include "utilityFile.h" QtProjectWizardContentPath::QtProjectWizardContentPath(QtProjectWizardWindow* window) : QtProjectWizardContent(window) - , m_makePathRelativeToProjectFileLocation(true) , m_allowEmpty(false) { } @@ -25,10 +25,7 @@ void QtProjectWizardContentPath::populate(QGridLayout* layout, int& row) m_picker->setPickDirectory(true); m_picker->setPlaceholderText(m_placeholderString); - if (m_makePathRelativeToProjectFileLocation) - { - m_picker->setRelativeRootDirectory(getSourceGroupSettings()->getProjectDirectoryPath()); - } + m_picker->setRelativeRootDirectory(getSourceGroupSettings()->getProjectDirectoryPath()); layout->addWidget(m_picker, row, QtProjectWizardWindow::BACK_COL); row++; @@ -53,7 +50,7 @@ bool QtProjectWizardContentPath::check() } } - FilePath path = getSourceGroupSettings()->makePathExpandedAndAbsolute(FilePath(m_picker->getText().toStdWString())); + FilePath path = utility::getExpandedAndAbsolutePath(FilePath(m_picker->getText().toStdWString()), getSourceGroupSettings()->getProjectDirectoryPath()); if (m_picker->pickDirectory()) { @@ -66,7 +63,7 @@ bool QtProjectWizardContentPath::check() break; } - if (m_fileEndings.find(path.extension()) == m_fileEndings.end()) + if (!m_fileEndings.empty() && m_fileEndings.find(path.extension()) == m_fileEndings.end()) { error = "The entered path does have a correct file ending at \"" + m_titleString + "\"."; break; diff --git a/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPath.h b/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPath.h index 6fa209ff..a0822da6 100644 --- a/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPath.h +++ b/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPath.h @@ -31,8 +31,6 @@ protected: QtLocationPicker* m_picker; - bool m_makePathRelativeToProjectFileLocation; - private: virtual std::shared_ptr getSourceGroupSettings() = 0; diff --git a/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPathCxxPch.cpp b/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPathCxxPch.cpp new file mode 100644 index 00000000..706e9a4b --- /dev/null +++ b/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPathCxxPch.cpp @@ -0,0 +1,46 @@ +#include "QtProjectWizardContentPathCxxPch.h" + +#include "SourceGroupSettingsWithCxxPchOptions.h" +#include "utility.h" +#include "utilityFile.h" + +QtProjectWizardContentPathCxxPch::QtProjectWizardContentPathCxxPch( + std::shared_ptr settings, + std::shared_ptr settingsCxxPch, + QtProjectWizardWindow* window +) + : QtProjectWizardContentPath(window) + , m_settings(settings) + , m_settingsCxxPch(settingsCxxPch) +{ + setTitleString("Precompiled Header File"); + setHelpString( + "Specify the path to the input header file that should be used to generate a precompiled header during indexing.
" + "If the indexed source code is usually built using precompiled headers, using this option will speed up your indexing performance.
" + "Leave blank to disable the use of precompiled headers. You can make use of environment variables with ${ENV_VAR}." + ); + setAllowEmpty(true); + setPlaceholderString("Not Using Precompiled Headers"); +} + +void QtProjectWizardContentPathCxxPch::populate(QGridLayout* layout, int& row) +{ + QtProjectWizardContentPath::populate(layout, row); + + m_picker->setPickDirectory(false); +} + +void QtProjectWizardContentPathCxxPch::load() +{ + m_picker->setText(QString::fromStdWString(m_settingsCxxPch->getPchInputFilePath().wstr())); +} + +void QtProjectWizardContentPathCxxPch::save() +{ + m_settingsCxxPch->setPchInputFilePathFilePath(FilePath(m_picker->getText().toStdWString())); +} + +std::shared_ptr QtProjectWizardContentPathCxxPch::getSourceGroupSettings() +{ + return m_settings; +} diff --git a/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPathCxxPch.h b/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPathCxxPch.h new file mode 100644 index 00000000..91fc5f12 --- /dev/null +++ b/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPathCxxPch.h @@ -0,0 +1,33 @@ +#ifndef QT_PROJECT_WIZARD_CONTENT_PATH_CXX_PCH_H +#define QT_PROJECT_WIZARD_CONTENT_PATH_CXX_PCH_H + +#include "QtProjectWizardContentPath.h" +#include "SingleValueCache.h" + +class SourceGroupSettingsWithCxxPchOptions; + +class QtProjectWizardContentPathCxxPch + : public QtProjectWizardContentPath +{ + Q_OBJECT + +public: + QtProjectWizardContentPathCxxPch( + std::shared_ptr settings, + std::shared_ptr settingsCxxPch, + QtProjectWizardWindow* window); + + // QtProjectWizardContent implementation + void populate(QGridLayout* layout, int& row) override; + + void load() override; + void save() override; + +private: + std::shared_ptr getSourceGroupSettings() override; + + std::shared_ptr m_settings; + std::shared_ptr m_settingsCxxPch; +}; + +#endif // QT_PROJECT_WIZARD_CONTENT_PATH_CXX_PCH_H diff --git a/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPathDependenciesGradle.cpp b/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPathDependenciesGradle.cpp deleted file mode 100644 index 1a978433..00000000 --- a/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPathDependenciesGradle.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include "QtProjectWizardContentPathDependenciesGradle.h" - -#include "SourceGroupSettingsJavaGradle.h" - -QtProjectWizardContentPathDependenciesGradle::QtProjectWizardContentPathDependenciesGradle( - std::shared_ptr settings, QtProjectWizardWindow* window -) - : QtProjectWizardContentPath(window) - , m_settings(settings) -{ - setTitleString("Intermediate Dependencies Directory"); - setHelpString( - "This directory is used to temporarily download and store the dependencies (e.g. .jar files) of the Gradle " - "project while it is indexed.
" - "
" - "You can make use of environment variables with ${ENV_VAR}." - ); -} - -void QtProjectWizardContentPathDependenciesGradle::load() -{ - m_picker->setText(QString::fromStdWString(m_settings->getGradleDependenciesDirectory().wstr())); -} - -void QtProjectWizardContentPathDependenciesGradle::save() -{ - m_settings->setGradleDependenciesDirectory(FilePath(m_picker->getText().toStdWString())); -} - -std::shared_ptr QtProjectWizardContentPathDependenciesGradle::getSourceGroupSettings() -{ - return m_settings; -} diff --git a/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPathDependenciesGradle.h b/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPathDependenciesGradle.h deleted file mode 100644 index f7032b9d..00000000 --- a/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPathDependenciesGradle.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef QT_PROJECT_WIZARD_CONTENT_PATH_DEPENDENCIES_GRADLE_H -#define QT_PROJECT_WIZARD_CONTENT_PATH_DEPENDENCIES_GRADLE_H - -#include "QtProjectWizardContentPath.h" - -class SourceGroupSettingsJavaGradle; - -class QtProjectWizardContentPathDependenciesGradle - : public QtProjectWizardContentPath -{ - Q_OBJECT - -public: - QtProjectWizardContentPathDependenciesGradle( - std::shared_ptr settings, QtProjectWizardWindow* window); - - // QtProjectWizardContent implementation - void load() override; - void save() override; - -private: - std::shared_ptr getSourceGroupSettings() override; - - std::shared_ptr m_settings; -}; - -#endif // QT_PROJECT_WIZARD_CONTENT_PATH_DEPENDENCIES_GRADLE_H diff --git a/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPathDependenciesMaven.cpp b/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPathDependenciesMaven.cpp deleted file mode 100644 index 72792905..00000000 --- a/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPathDependenciesMaven.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include "QtProjectWizardContentPathDependenciesMaven.h" - -#include "SourceGroupSettingsJavaMaven.h" - -QtProjectWizardContentPathDependenciesMaven::QtProjectWizardContentPathDependenciesMaven( - std::shared_ptr settings, QtProjectWizardWindow* window -) - : QtProjectWizardContentPath(window) - , m_settings(settings) -{ - setTitleString("Intermediate Dependencies Directory"); - setHelpString( - "This directory is used to temporarily download and store the dependencies (e.g. .jar files) of the Maven project while it is indexed.
" - "
" - "You can make use of environment variables with ${ENV_VAR}." - ); -} - -void QtProjectWizardContentPathDependenciesMaven::load() -{ - m_picker->setText(QString::fromStdWString(m_settings->getMavenDependenciesDirectory().wstr())); -} - -void QtProjectWizardContentPathDependenciesMaven::save() -{ - m_settings->setMavenDependenciesDirectory(FilePath(m_picker->getText().toStdWString())); -} - -std::shared_ptr QtProjectWizardContentPathDependenciesMaven::getSourceGroupSettings() -{ - return m_settings; -} diff --git a/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPathDependenciesMaven.h b/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPathDependenciesMaven.h deleted file mode 100644 index 7569f28a..00000000 --- a/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPathDependenciesMaven.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef QT_PROJECT_WIZARD_CONTENT_PATH_DEPENDENCIES_MAVEN_H -#define QT_PROJECT_WIZARD_CONTENT_PATH_DEPENDENCIES_MAVEN_H - -#include "QtProjectWizardContentPath.h" - -class SourceGroupSettingsJavaMaven; - -class QtProjectWizardContentPathDependenciesMaven - : public QtProjectWizardContentPath -{ - Q_OBJECT -public: - QtProjectWizardContentPathDependenciesMaven( - std::shared_ptr settings, QtProjectWizardWindow* window); - - // QtProjectWizardContent implementation - void load() override; - void save() override; - -private: - std::shared_ptr getSourceGroupSettings() override; - - std::shared_ptr m_settings; -}; - -#endif // QT_PROJECT_WIZARD_CONTENT_PATH_DEPENDENCIES_MAVEN_H diff --git a/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPathPythonEnvironment.cpp b/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPathPythonEnvironment.cpp index a6ad6685..22b123bb 100644 --- a/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPathPythonEnvironment.cpp +++ b/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPathPythonEnvironment.cpp @@ -3,6 +3,7 @@ #include "ResourcePaths.h" #include "SourceGroupSettingsPythonEmpty.h" #include "utilityApp.h" +#include "utilityFile.h" QtProjectWizardContentPathPythonEnvironment::QtProjectWizardContentPathPythonEnvironment( std::shared_ptr settings, QtProjectWizardWindow* window @@ -63,7 +64,7 @@ void QtProjectWizardContentPathPythonEnvironment::onTextChanged(const QString& t std::thread([=]() { std::pair out = utility::executeProcess( "\"" + ResourcePaths::getPythonPath().str() + "SourcetrailPythonIndexer\" check-environment " + - "--environment-path \"" + m_settings->makePathExpandedAndAbsolute(FilePath(text.toStdWString())).str() + "\"", + "--environment-path \"" + utility::getExpandedAndAbsolutePath(FilePath(text.toStdWString()), m_settings->getProjectDirectoryPath()).str() + "\"", FilePath(), 5000 ); diff --git a/src/lib_java/project/SourceGroupJavaGradle.cpp b/src/lib_java/project/SourceGroupJavaGradle.cpp index ae950578..ba7c3f6d 100644 --- a/src/lib_java/project/SourceGroupJavaGradle.cpp +++ b/src/lib_java/project/SourceGroupJavaGradle.cpp @@ -53,10 +53,10 @@ std::vector SourceGroupJavaGradle::doGetClassPath() const { std::vector classPath = utility::getClassPath({}, true, getAllSourceFilePaths()); - if (m_settings->getGradleDependenciesDirectoryExpandedAndAbsolute().exists()) + if (m_settings->getGradleDependenciesDirectoryPath().exists()) { std::vector gradleJarPaths = FileSystem::getFilePathsFromDirectory( - m_settings->getGradleDependenciesDirectoryExpandedAndAbsolute(), + m_settings->getGradleDependenciesDirectoryPath(), { L".jar" } ); @@ -97,7 +97,7 @@ bool SourceGroupJavaGradle::prepareGradleData() bool success = utility::gradleCopyDependencies( projectRootPath, - m_settings->getGradleDependenciesDirectoryExpandedAndAbsolute(), + m_settings->getGradleDependenciesDirectoryPath(), m_settings->getShouldIndexGradleTests() ); diff --git a/src/lib_java/project/SourceGroupJavaMaven.cpp b/src/lib_java/project/SourceGroupJavaMaven.cpp index 3956a072..48f98b6b 100644 --- a/src/lib_java/project/SourceGroupJavaMaven.cpp +++ b/src/lib_java/project/SourceGroupJavaMaven.cpp @@ -52,10 +52,10 @@ std::vector SourceGroupJavaMaven::doGetClassPath() const { std::vector classPath = utility::getClassPath({}, true, getAllSourceFilePaths()); - if (m_settings && m_settings->getMavenDependenciesDirectoryExpandedAndAbsolute().exists()) + if (m_settings && m_settings->getMavenDependenciesDirectoryPath().exists()) { std::vector mavenJarPaths = FileSystem::getFilePathsFromDirectory( - m_settings->getMavenDependenciesDirectoryExpandedAndAbsolute(), + m_settings->getMavenDependenciesDirectoryPath(), { L".jar" } ); @@ -105,7 +105,7 @@ bool SourceGroupJavaMaven::prepareMavenData() dialogView->showUnknownProgressDialog(L"Preparing Project", L"Maven\nExporting Dependencies"); bool success = utility::mavenCopyDependencies( - mavenPath, projectRootPath, m_settings->getMavenDependenciesDirectoryExpandedAndAbsolute() + mavenPath, projectRootPath, m_settings->getMavenDependenciesDirectoryPath() ); return success; diff --git a/src/test/SourceGroupTestSuite.h b/src/test/SourceGroupTestSuite.h index 39293540..952bf8ad 100644 --- a/src/test/SourceGroupTestSuite.h +++ b/src/test/SourceGroupTestSuite.h @@ -313,7 +313,6 @@ public: sourceGroupSettings->setJavaStandard({ L"10" }); sourceGroupSettings->setGradleProjectFilePath({ getInputDirectoryPath(projectName).concatenate(L"build.gradle") }); sourceGroupSettings->setShouldIndexGradleTests(true); - sourceGroupSettings->setGradleDependenciesDirectory(getInputDirectoryPath(projectName).concatenate(L"gradle_dependencies")); std::shared_ptr applicationSettings = ApplicationSettings::getInstance(); @@ -353,7 +352,6 @@ public: sourceGroupSettings->setJavaStandard({ L"10" }); sourceGroupSettings->setMavenProjectFilePath({ getInputDirectoryPath(projectName).concatenate(L"my-app/pom.xml") }); sourceGroupSettings->setShouldIndexMavenTests(true); - sourceGroupSettings->setMavenDependenciesDirectory(getInputDirectoryPath(projectName).concatenate(L"maven_dependencies")); std::shared_ptr applicationSettings = ApplicationSettings::getInstance();