logic: Don't store CxxCompilerHeaderPath in Global Include Paths

* show path in Global Include Paths preferences
* add to CXX indexer commands
* add migration to remove from app settings
This commit is contained in:
Eberhard Graether
2019-05-27 16:11:19 +02:00
parent 581b1894f2
commit b6a39a2d66
18 changed files with 1071 additions and 137 deletions
@@ -8,6 +8,8 @@ SourceFilePath: "src/Test.c"
CompilerFlag: "header_search/local"
CompilerFlag: "-isystem"
CompilerFlag: "test/header/search/path"
CompilerFlag: "-isystem"
CompilerFlag: "data/cxx/include/"
CompilerFlag: "-iframework"
CompilerFlag: "framework_search/local"
CompilerFlag: "-iframework"
@@ -16,6 +16,8 @@ SourceFilePath: "src/Test.cpp"
CompilerFlag: "header_search/local"
CompilerFlag: "-isystem"
CompilerFlag: "test/header/search/path"
CompilerFlag: "-isystem"
CompilerFlag: "data/cxx/include/"
CompilerFlag: "-iframework"
CompilerFlag: "framework_search/local"
CompilerFlag: "-iframework"
@@ -3,11 +3,15 @@ SourceFilePath: "src/Test.cpp"
IndexedPath: "test/indexed/header/path"
CompilerFlag: "-isystem"
CompilerFlag: "src/header/search/path/from/cbp"
CompilerFlag: "-isystem"
CompilerFlag: "data/cxx/include/"
CompilerFlag: "-DDEFINE_FROM_CBP"
CompilerFlag: "-isystem"
CompilerFlag: "header_search/local"
CompilerFlag: "-isystem"
CompilerFlag: "test/header/search/path"
CompilerFlag: "-isystem"
CompilerFlag: "data/cxx/include/"
CompilerFlag: "-iframework"
CompilerFlag: "framework_search/local"
CompilerFlag: "-iframework"
@@ -10,6 +10,8 @@ SourceFilePath: "src/Test.cpp"
CompilerFlag: "header_search/local"
CompilerFlag: "-isystem"
CompilerFlag: "test/header/search/path"
CompilerFlag: "-isystem"
CompilerFlag: "data/cxx/include/"
CompilerFlag: "-iframework"
CompilerFlag: "framework_search/local"
CompilerFlag: "-iframework"
@@ -7,6 +7,8 @@ SourceFilePath: "tictactoe/src/artificial_player.cpp"
CompilerFlag: "-std=c++17"
CompilerFlag: "-isystem"
CompilerFlag: "test/header/search/path"
CompilerFlag: "-isystem"
CompilerFlag: "data/cxx/include/"
CompilerFlag: "-iframework"
CompilerFlag: "test/framework/search/path"
CompilerFlag: "tictactoe/src/artificial_player.cpp"
@@ -19,6 +21,8 @@ SourceFilePath: "tictactoe/src/field.cpp"
CompilerFlag: "-std=c++17"
CompilerFlag: "-isystem"
CompilerFlag: "test/header/search/path"
CompilerFlag: "-isystem"
CompilerFlag: "data/cxx/include/"
CompilerFlag: "-iframework"
CompilerFlag: "test/framework/search/path"
CompilerFlag: "tictactoe/src/field.cpp"
@@ -31,6 +35,8 @@ SourceFilePath: "tictactoe/src/human_player.cc"
CompilerFlag: "-std=c++17"
CompilerFlag: "-isystem"
CompilerFlag: "test/header/search/path"
CompilerFlag: "-isystem"
CompilerFlag: "data/cxx/include/"
CompilerFlag: "-iframework"
CompilerFlag: "test/framework/search/path"
CompilerFlag: "tictactoe/src/human_player.cc"
@@ -43,6 +49,8 @@ SourceFilePath: "tictactoe/src/io.cpp"
CompilerFlag: "-std=c++17"
CompilerFlag: "-isystem"
CompilerFlag: "test/header/search/path"
CompilerFlag: "-isystem"
CompilerFlag: "data/cxx/include/"
CompilerFlag: "-iframework"
CompilerFlag: "test/framework/search/path"
CompilerFlag: "tictactoe/src/io.cpp"
@@ -55,6 +63,8 @@ SourceFilePath: "tictactoe/src/main.cpp"
CompilerFlag: "-std=c++17"
CompilerFlag: "-isystem"
CompilerFlag: "test/header/search/path"
CompilerFlag: "-isystem"
CompilerFlag: "data/cxx/include/"
CompilerFlag: "-iframework"
CompilerFlag: "test/framework/search/path"
CompilerFlag: "tictactoe/src/main.cpp"
@@ -67,6 +77,8 @@ SourceFilePath: "tictactoe/src/player.cpp"
CompilerFlag: "-std=c++17"
CompilerFlag: "-isystem"
CompilerFlag: "test/header/search/path"
CompilerFlag: "-isystem"
CompilerFlag: "data/cxx/include/"
CompilerFlag: "-iframework"
CompilerFlag: "test/framework/search/path"
CompilerFlag: "tictactoe/src/player.cpp"
@@ -79,6 +91,8 @@ SourceFilePath: "tictactoe/src/tictactoe.cpp"
CompilerFlag: "-std=c++17"
CompilerFlag: "-isystem"
CompilerFlag: "test/header/search/path"
CompilerFlag: "-isystem"
CompilerFlag: "data/cxx/include/"
CompilerFlag: "-iframework"
CompilerFlag: "test/framework/search/path"
CompilerFlag: "tictactoe/src/tictactoe.cpp"
-4
View File
@@ -31,7 +31,6 @@
#include "UserPaths.h"
#include "utility.h"
#include "utilityApp.h"
#include "utilityCxx.h"
#include "utilityPathDetection.h"
#include "Version.h"
#include "productVersion.h"
@@ -135,9 +134,6 @@ void prefillCxxHeaderPaths()
LOG_INFO("Prefilling header search paths");
std::shared_ptr<CombinedPathDetector> cxxHeaderDetector = utility::getCxxHeaderPathDetector();
std::vector<FilePath> paths = cxxHeaderDetector->getPaths();
paths = utility::replaceOrAddCxxCompilerHeaderPath(paths);
if (!paths.empty())
{
MessageStatus(L"Ran C/C++ header path detection, found " + std::to_wstring(paths.size()) + L" path" +
-2
View File
@@ -640,8 +640,6 @@ add_files(
utility/UserPaths.h
utility/utility.cpp
utility/utility.h
utility/utilityCxx.cpp
utility/utilityCxx.h
utility/utilityFile.cpp
utility/utilityFile.h
utility/utilityLibrary.h
+28 -18
View File
@@ -9,11 +9,10 @@
#include "Status.h"
#include "TimeStamp.h"
#include "utility.h"
#include "utilityCxx.h"
#include "UserPaths.h"
#include "Version.h"
const size_t ApplicationSettings::VERSION = 7;
const size_t ApplicationSettings::VERSION = 8;
std::shared_ptr<ApplicationSettings> ApplicationSettings::s_instance;
@@ -64,22 +63,6 @@ bool ApplicationSettings::load(const FilePath& filePath, bool readOnly)
}
}
));
migrator.addMigration(6, std::make_shared<SettingsMigrationLambda>(
[](const SettingsMigration* migration, Settings* settings)
{
std::vector<FilePath> cxxHeaderSearchPaths = migration->getValuesFromSettings(
settings, "indexing/cxx/header_search_paths/header_search_path", std::vector<FilePath>());
cxxHeaderSearchPaths = utility::replaceOrAddCxxCompilerHeaderPath(cxxHeaderSearchPaths);
migration->setValuesInSettings(settings, "indexing/cxx/header_search_paths/header_search_path", cxxHeaderSearchPaths);
if (cxxHeaderSearchPaths.size() == 1)
{
migration->setValueInSettings(settings, "indexing/cxx/has_prefilled_header_search_paths", false);
}
}
));
migrator.addMigration(7, std::make_shared<SettingsMigrationLambda>(
[](const SettingsMigration* migration, Settings* settings)
{
@@ -99,6 +82,33 @@ bool ApplicationSettings::load(const FilePath& filePath, bool readOnly)
migration->setValuesInSettings(settings, "user/recent_projects/recent_project", recentProjects);
}
));
migrator.addMigration(8, std::make_shared<SettingsMigrationLambda>(
[](const SettingsMigration* migration, Settings* settings)
{
std::vector<FilePath> cxxHeaderSearchPaths = migration->getValuesFromSettings(
settings, "indexing/cxx/header_search_paths/header_search_path", std::vector<FilePath>());
std::vector<FilePath> newCxxHeaderSearchPaths;
for (const FilePath& path : cxxHeaderSearchPaths)
{
if (path.getCanonical().getConcatenated(L"/stdarg.h").exists() &&
path.str().find("data/cxx/include") != std::string::npos)
{
continue;
}
newCxxHeaderSearchPaths.push_back(path);
}
migration->setValuesInSettings(
settings, "indexing/cxx/header_search_paths/header_search_path", newCxxHeaderSearchPaths);
if (newCxxHeaderSearchPaths.size() == 0)
{
migration->setValueInSettings(settings, "indexing/cxx/has_prefilled_header_search_paths", false);
}
}
));
bool migrated = migrator.migrate(this, ApplicationSettings::VERSION);
if (migrated)
{
-23
View File
@@ -1,23 +0,0 @@
#include "utilityCxx.h"
#include "ResourcePaths.h"
namespace utility
{
std::vector<FilePath> replaceOrAddCxxCompilerHeaderPath(const std::vector<FilePath>& headerSearchPaths)
{
std::vector<FilePath> newHeaderSearchPaths;
const FilePath cxxCompilerHeaderPath = ResourcePaths::getCxxCompilerHeaderPath();
for (const FilePath& path : headerSearchPaths)
{
if (path != cxxCompilerHeaderPath)
{
newHeaderSearchPaths.push_back(path);
}
}
newHeaderSearchPaths.push_back(cxxCompilerHeaderPath);
return newHeaderSearchPaths;
}
}
-13
View File
@@ -1,13 +0,0 @@
#ifndef UTILITY_CXX_H
#define UTILITY_CXX_H
#include <vector>
#include <utility/file/FilePath.h>
namespace utility
{
std::vector<FilePath> replaceOrAddCxxCompilerHeaderPath(const std::vector<FilePath>& headerSearchPaths);
}
#endif // UTILITY_CXX_H
+7 -18
View File
@@ -61,31 +61,20 @@ std::vector<std::wstring> IndexerCommandCxx::getCompilerFlagsForSystemHeaderSear
std::vector<std::wstring> compilerFlags;
compilerFlags.reserve(systemHeaderSearchPaths.size() * 2);
bool hasCxxCompilerHeaderPath = false;
for (const FilePath& path : systemHeaderSearchPaths)
{
if (path == ResourcePaths::getCxxCompilerHeaderPath())
{
hasCxxCompilerHeaderPath = true;
}
else
{
compilerFlags.push_back(L"-isystem");
compilerFlags.push_back(path.wstr());
}
compilerFlags.push_back(L"-isystem");
compilerFlags.push_back(path.wstr());
}
if (hasCxxCompilerHeaderPath)
{
#ifdef _WIN32
// prepend clang system includes on windows
compilerFlags = utility::concat({ L"-isystem", ResourcePaths::getCxxCompilerHeaderPath().wstr() }, compilerFlags);
// prepend clang system includes on windows
compilerFlags = utility::concat({ L"-isystem", ResourcePaths::getCxxCompilerHeaderPath().wstr() }, compilerFlags);
#else
// append otherwise
compilerFlags.push_back(L"-isystem");
compilerFlags.push_back(ResourcePaths::getCxxCompilerHeaderPath().wstr());
// append otherwise
compilerFlags.push_back(L"-isystem");
compilerFlags.push_back(ResourcePaths::getCxxCompilerHeaderPath().wstr());
#endif
}
return compilerFlags;
}
+4 -4
View File
@@ -89,11 +89,11 @@ std::shared_ptr<IndexerCommandProvider> SourceGroupCxxCdb::getIndexerCommandProv
std::vector<std::wstring> compilerFlags;
{
utility::append(compilerFlags, IndexerCommandCxx::getCompilerFlagsForSystemHeaderSearchPaths(m_settings->getHeaderSearchPathsExpandedAndAbsolute()));
utility::append(compilerFlags, IndexerCommandCxx::getCompilerFlagsForSystemHeaderSearchPaths(appSettings->getHeaderSearchPathsExpanded()));
utility::append(compilerFlags, IndexerCommandCxx::getCompilerFlagsForSystemHeaderSearchPaths(
utility::concat(m_settings->getHeaderSearchPathsExpandedAndAbsolute(), appSettings->getHeaderSearchPathsExpanded())));
utility::append(compilerFlags, IndexerCommandCxx::getCompilerFlagsForFrameworkSearchPaths(m_settings->getFrameworkSearchPathsExpandedAndAbsolute()));
utility::append(compilerFlags, IndexerCommandCxx::getCompilerFlagsForFrameworkSearchPaths(appSettings->getFrameworkSearchPathsExpanded()));
utility::append(compilerFlags, IndexerCommandCxx::getCompilerFlagsForFrameworkSearchPaths(
utility::concat(m_settings->getFrameworkSearchPathsExpandedAndAbsolute(), appSettings->getFrameworkSearchPathsExpanded())));
utility::append(compilerFlags, m_settings->getCompilerFlags());
}
+4 -5
View File
@@ -133,13 +133,12 @@ std::shared_ptr<IndexerCommandProvider> SourceGroupCxxEmpty::getIndexerCommandPr
}
}
utility::append(compilerFlags, IndexerCommandCxx::getCompilerFlagsForSystemHeaderSearchPaths(indexedDirectoryPaths));
utility::append(compilerFlags, IndexerCommandCxx::getCompilerFlagsForSystemHeaderSearchPaths(m_settings->getHeaderSearchPathsExpandedAndAbsolute()));
utility::append(compilerFlags, IndexerCommandCxx::getCompilerFlagsForSystemHeaderSearchPaths(appSettings->getHeaderSearchPathsExpanded()));
utility::append(compilerFlags, IndexerCommandCxx::getCompilerFlagsForSystemHeaderSearchPaths(
utility::concat(indexedDirectoryPaths, utility::concat(m_settings->getHeaderSearchPathsExpandedAndAbsolute(), appSettings->getHeaderSearchPathsExpanded()))));
}
{
utility::append(compilerFlags, IndexerCommandCxx::getCompilerFlagsForFrameworkSearchPaths(m_settings->getFrameworkSearchPathsExpandedAndAbsolute()));
utility::append(compilerFlags, IndexerCommandCxx::getCompilerFlagsForFrameworkSearchPaths(appSettings->getFrameworkSearchPathsExpanded()));
utility::append(compilerFlags, IndexerCommandCxx::getCompilerFlagsForFrameworkSearchPaths(
utility::concat(m_settings->getFrameworkSearchPathsExpandedAndAbsolute(), appSettings->getFrameworkSearchPathsExpanded())));
}
utility::append(compilerFlags, m_settings->getCompilerFlags());
@@ -38,7 +38,6 @@
#include "ScopedFunctor.h"
#include "utility.h"
#include "utilityApp.h"
#include "utilityCxx.h"
#include "utilityFile.h"
#include "utilityPathDetection.h"
#include "utilityString.h"
@@ -1029,46 +1028,38 @@ void QtProjectWizzardContentPathsHeaderSearchGlobal::load()
void QtProjectWizzardContentPathsHeaderSearchGlobal::save()
{
ApplicationSettings::getInstance()->setHeaderSearchPaths(m_list->getPathsAsDisplayed());
std::vector<FilePath> paths;
for (const FilePath& headerPath : m_list->getPathsAsDisplayed())
{
if (headerPath != ResourcePaths::getCxxCompilerHeaderPath())
{
paths.push_back(headerPath);
}
}
ApplicationSettings::getInstance()->setHeaderSearchPaths(paths);
ApplicationSettings::getInstance()->save();
}
bool QtProjectWizzardContentPathsHeaderSearchGlobal::check()
{
bool hasCompilerHeaderPath = false;
if (utility::getOsType() == OS_WINDOWS)
{
return QtProjectWizzardContentPaths::check();
}
bool hasOtherCompilerConfig = false;
for (const FilePath& headerPath : m_list->getPathsAsDisplayed())
{
if (headerPath == ResourcePaths::getCxxCompilerHeaderPath())
{
hasCompilerHeaderPath = true;
}
else if (headerPath.getCanonical().getConcatenated(L"/stdarg.h").exists())
if (headerPath != ResourcePaths::getCxxCompilerHeaderPath() &&
headerPath.getCanonical().getConcatenated(L"/stdarg.h").exists())
{
hasOtherCompilerConfig = true;
break;
}
}
if (!hasCompilerHeaderPath)
{
QMessageBox msgBox;
msgBox.setText("Compiler Header Path missing");
msgBox.setInformativeText("Your Global Include Paths do not contain the path to the compiler headers of "
"Sourcetrail's C/C++ indexer. This can cause a lot of errors during indexing. Do you want to add the "
"path to the list?");
msgBox.addButton("Add", QMessageBox::ButtonRole::YesRole);
msgBox.addButton("Skip", QMessageBox::ButtonRole::NoRole);
msgBox.setIcon(QMessageBox::Icon::Question);
int ret = msgBox.exec();
if (ret == 0) // QMessageBox::Yes
{
m_list->addPaths({ ResourcePaths::getCxxCompilerHeaderPath() }, true);
hasCompilerHeaderPath = true;
}
}
if (utility::getOsType() != OS_WINDOWS && hasOtherCompilerConfig && hasCompilerHeaderPath)
if (hasOtherCompilerConfig)
{
QMessageBox msgBox;
msgBox.setText("Multiple Compiler Headers");
@@ -1086,11 +1077,12 @@ bool QtProjectWizzardContentPathsHeaderSearchGlobal::check()
std::vector<FilePath> paths;
for (const FilePath& headerPath : m_list->getPathsAsDisplayed())
{
if (headerPath == ResourcePaths::getCxxCompilerHeaderPath() ||
!headerPath.getCanonical().getConcatenated(L"/stdarg.h").exists())
if (headerPath != ResourcePaths::getCxxCompilerHeaderPath() &&
headerPath.getCanonical().getConcatenated(L"/stdarg.h").exists())
{
paths.push_back(headerPath);
continue;
}
paths.push_back(headerPath);
}
setPaths(paths);
}
@@ -1101,27 +1093,22 @@ bool QtProjectWizzardContentPathsHeaderSearchGlobal::check()
void QtProjectWizzardContentPathsHeaderSearchGlobal::detectedPaths(const std::vector<FilePath>& paths)
{
setPaths(paths);
std::vector<FilePath> headerPaths;
for (const FilePath& headerPath : paths)
{
if (headerPath != ResourcePaths::getCxxCompilerHeaderPath())
{
headerPaths.push_back(headerPath);
}
}
setPaths(headerPaths);
}
void QtProjectWizzardContentPathsHeaderSearchGlobal::setPaths(const std::vector<FilePath>& paths)
{
m_list->setPaths({});
std::vector<FilePath> nonCxxCompilerHeaderPaths;
for (const FilePath& headerPath : paths)
{
if (headerPath == ResourcePaths::getCxxCompilerHeaderPath())
{
m_list->addPaths({ headerPath }, true);
}
else
{
nonCxxCompilerHeaderPaths.push_back(headerPath);
}
}
m_list->addPaths(nonCxxCompilerHeaderPaths);
m_list->addPaths({ ResourcePaths::getCxxCompilerHeaderPath() }, true);
m_list->addPaths(paths);
}
@@ -3,7 +3,6 @@
#include "FilePath.h"
#include "utilityCxxHeaderDetection.h"
#include "utilityString.h"
#include "utilityCxx.h"
CxxHeaderPathDetector::CxxHeaderPathDetector(const std::string& compilerName)
: PathDetector(compilerName)
@@ -8,7 +8,6 @@
#include "FilePath.h"
#include "utilityCxxHeaderDetection.h"
#include "utility.h"
#include "utilityCxx.h"
CxxVs10To14HeaderPathDetector::CxxVs10To14HeaderPathDetector(VisualStudioType type, bool isExpress, ApplicationArchitectureType architecture)
: PathDetector(visualStudioTypeToString(type) + (isExpress ? " Express" : "") + (architecture == APPLICATION_ARCHITECTURE_X86_64 ? " 64 Bit" : ""))
@@ -7,7 +7,6 @@
#include "utilityCxxHeaderDetection.h"
#include "utility.h"
#include "utilityApp.h"
#include "utilityCxx.h"
CxxVs15HeaderPathDetector::CxxVs15HeaderPathDetector()
: PathDetector("Visual Studio 2017")