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
This commit is contained in:
@@ -164,7 +164,7 @@ std::shared_ptr<Task> SourceGroupCxxCdb::getPreIndexTask(
|
||||
std::shared_ptr<clang::tooling::JSONCompilationDatabase> cdb = IndexerCommandCxx::loadCDB(cdbPath);
|
||||
if (cdb)
|
||||
{
|
||||
const std::set<FilePath>& sourceFilePaths = getAllSourceFilePaths(cdb);
|
||||
const std::set<FilePath> 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<Task> 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<std::string>("-", arg)) &&
|
||||
if ((!compilerFlags.empty() || utility::isPrefix<std::string>("-", arg)) &&
|
||||
FilePath(arg).fileName() != sourcePath.fileName())
|
||||
{
|
||||
compilerFlags.emplace_back(utility::decodeFromUtf8(arg));
|
||||
|
||||
@@ -109,10 +109,21 @@ namespace utility
|
||||
{
|
||||
for (const clang::tooling::CompileCommand& command : cdb->getAllCompileCommands())
|
||||
{
|
||||
if (command.CommandLine.size() != getWithRemoveIncludePchFlag(utility::convert<std::string, std::wstring>(
|
||||
command.CommandLine,
|
||||
[](const std::string& s) {return utility::decodeFromUtf8(s); }
|
||||
)).size())
|
||||
if (containsIncludePchFlag(command.CommandLine))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool containsIncludePchFlag(const std::vector<std::string>& 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;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ namespace utility
|
||||
const SourceGroupSettingsCxx* settings, std::vector<std::wstring> compilerFlags,
|
||||
std::shared_ptr<StorageProvider> storageProvider, std::shared_ptr<DialogView> dialogView);
|
||||
bool containsIncludePchFlags(std::shared_ptr<clang::tooling::JSONCompilationDatabase> cdb);
|
||||
bool containsIncludePchFlag(const std::vector<std::string>& args);
|
||||
std::vector<std::wstring> getWithRemoveIncludePchFlag(const std::vector<std::wstring>& args);
|
||||
void removeIncludePchFlag(std::vector<std::wstring>& args);
|
||||
std::vector<std::wstring> getIncludePchFlags(const SourceGroupSettingsCxx* settings);
|
||||
|
||||
@@ -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.<br />"
|
||||
"If the indexed source code is usually built using precompiled headers, using this option will speed up your indexing performance.<br />"
|
||||
"<br />"
|
||||
"If your source files use precompiled headers via \"#include <pch.h>\", specify \"path/to/pch.h\".<br />"
|
||||
"<br />"
|
||||
"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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user