From f75593392b7d01c765e9da66c57eb617d52375cd Mon Sep 17 00:00:00 2001 From: mlangkabel Date: Mon, 26 Aug 2019 16:40:26 +0200 Subject: [PATCH] logic: fixes for handling pch flags for cdb source groups * use flags of first source file that specifies an "-include-pch" flag for generating the .pch file * allow to save project settings without specifying input header file if cdb contains -include-pch args --- src/lib_cxx/project/SourceGroupCxxCdb.cpp | 6 ++--- src/lib_cxx/project/utilitySourceGroupCxx.cpp | 19 +++++++++++---- src/lib_cxx/project/utilitySourceGroupCxx.h | 1 + .../path/QtProjectWizardContentPathCxxPch.cpp | 23 +++++++++++++++---- 4 files changed, 38 insertions(+), 11 deletions(-) diff --git a/src/lib_cxx/project/SourceGroupCxxCdb.cpp b/src/lib_cxx/project/SourceGroupCxxCdb.cpp index 5f4bbd98..e2c93e59 100644 --- a/src/lib_cxx/project/SourceGroupCxxCdb.cpp +++ b/src/lib_cxx/project/SourceGroupCxxCdb.cpp @@ -164,7 +164,7 @@ std::shared_ptr SourceGroupCxxCdb::getPreIndexTask( std::shared_ptr cdb = IndexerCommandCxx::loadCDB(cdbPath); if (cdb) { - const std::set& sourceFilePaths = getAllSourceFilePaths(cdb); + const std::set sourceFilePaths = getAllSourceFilePaths(cdb); for (const clang::tooling::CompileCommand& command: cdb->getAllCompileCommands()) { FilePath sourcePath = FilePath(utility::decodeFromUtf8(command.Filename)).makeCanonical(); @@ -177,11 +177,11 @@ std::shared_ptr SourceGroupCxxCdb::getPreIndexTask( } } - if (sourceFilePaths.find(sourcePath) != sourceFilePaths.end()) + if (sourceFilePaths.find(sourcePath) != sourceFilePaths.end() && utility::containsIncludePchFlag(command.CommandLine)) { for (const std::string& arg : command.CommandLine) { - if ((compilerFlags.size() || utility::isPrefix("-", arg)) && + if ((!compilerFlags.empty() || utility::isPrefix("-", arg)) && FilePath(arg).fileName() != sourcePath.fileName()) { compilerFlags.emplace_back(utility::decodeFromUtf8(arg)); diff --git a/src/lib_cxx/project/utilitySourceGroupCxx.cpp b/src/lib_cxx/project/utilitySourceGroupCxx.cpp index d600000e..c5bbcf14 100644 --- a/src/lib_cxx/project/utilitySourceGroupCxx.cpp +++ b/src/lib_cxx/project/utilitySourceGroupCxx.cpp @@ -109,10 +109,21 @@ namespace utility { for (const clang::tooling::CompileCommand& command : cdb->getAllCompileCommands()) { - if (command.CommandLine.size() != getWithRemoveIncludePchFlag(utility::convert( - command.CommandLine, - [](const std::string& s) {return utility::decodeFromUtf8(s); } - )).size()) + if (containsIncludePchFlag(command.CommandLine)) + { + return true; + } + } + return false; + } + + bool containsIncludePchFlag(const std::vector& args) + { + const std::string includePchPrefix = "-include-pch"; + for (size_t i = 0; i < args.size(); i++) + { + const std::string arg = utility::trim(args[i]); + if (utility::isPrefix(includePchPrefix, arg)) { return true; } diff --git a/src/lib_cxx/project/utilitySourceGroupCxx.h b/src/lib_cxx/project/utilitySourceGroupCxx.h index 82d2a190..a2a0ab25 100644 --- a/src/lib_cxx/project/utilitySourceGroupCxx.h +++ b/src/lib_cxx/project/utilitySourceGroupCxx.h @@ -22,6 +22,7 @@ namespace utility const SourceGroupSettingsCxx* settings, std::vector compilerFlags, std::shared_ptr storageProvider, std::shared_ptr dialogView); bool containsIncludePchFlags(std::shared_ptr cdb); + bool containsIncludePchFlag(const std::vector& args); std::vector getWithRemoveIncludePchFlag(const std::vector& args); void removeIncludePchFlag(std::vector& args); std::vector getIncludePchFlags(const SourceGroupSettingsCxx* settings); diff --git a/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPathCxxPch.cpp b/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPathCxxPch.cpp index 2debbcac..7c706cfe 100644 --- a/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPathCxxPch.cpp +++ b/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPathCxxPch.cpp @@ -22,6 +22,9 @@ QtProjectWizardContentPathCxxPch::QtProjectWizardContentPathCxxPch( setHelpString( "Specify the path to the input header file that should be used to generate a precompiled header before indexing.
" "If the indexed source code is usually built using precompiled headers, using this option will speed up your indexing performance.
" + "
" + "If your source files use precompiled headers via \"#include <pch.h>\", specify \"path/to/pch.h\".
" + "
" "Leave blank to disable the use of precompiled headers. You can make use of environment variables with ${ENV_VAR}." ); setAllowEmpty(true); @@ -64,9 +67,18 @@ bool QtProjectWizardContentPathCxxPch::check() if (m_settingsCxxPch->getPchInputFilePath().empty()) { QMessageBox msgBox; - msgBox.setText("The provided compilation database file uses precompiled headers. Please specify a Precompiled Header input file."); + msgBox.setText( + "The provided compilation database file uses precompiled headers. If you want to make use of " + "precompiled headers to speed up your indexer, please specify an input at Precompiled Header File." + ); + QPushButton* cancelButton = msgBox.addButton("Cancel", QMessageBox::ButtonRole::RejectRole); + QPushButton* continueButton = msgBox.addButton("Continue", QMessageBox::ButtonRole::AcceptRole); msgBox.exec(); - return false; + if (msgBox.clickedButton() == cancelButton) + { + return false; + } + return true; } } else @@ -74,9 +86,12 @@ bool QtProjectWizardContentPathCxxPch::check() if (!m_settingsCxxPch->getPchInputFilePath().empty()) { QMessageBox msgBox; - msgBox.setText("The provided compilation database file does not use precompiled headers. Please do not specify a Precompiled Header input file."); + msgBox.setText( + "The provided compilation database file does not use precompiled headers. The specified input file at " + "Precompiled Header File will not be used." + ); msgBox.exec(); - return false; + return true; } } }