aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Hunger <tobias.hunger@qt.io>2019-06-12 12:48:07 +0200
committerCristian Adam <cristian.adam@qt.io>2019-06-14 09:29:19 +0000
commit6796a5edcd3ccd0d5e0cbaaf6c06ab0e6f9aa544 (patch)
treee5e5c4708461c5b72a67b5f3e8a5b89d1529c528
parent30575d2c76f4eaae8b957f421c9f3e8798a2ddcd (diff)
Extract heuristics to detect framework paths from CppRawProjectPart
Move the code into a separate function of CppRawProjectPart so that it can be used by the project managers to do the framework detection magic as well. Change-Id: I80b9fdadb25005c7e089cb45429c91dd8549eecc Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
-rw-r--r--src/plugins/cpptools/cpprawprojectpart.cpp42
-rw-r--r--src/plugins/cpptools/cpprawprojectpart.h1
2 files changed, 26 insertions, 17 deletions
diff --git a/src/plugins/cpptools/cpprawprojectpart.cpp b/src/plugins/cpptools/cpprawprojectpart.cpp
index ee18166c05..6c29c2bb34 100644
--- a/src/plugins/cpptools/cpprawprojectpart.cpp
+++ b/src/plugins/cpptools/cpprawprojectpart.cpp
@@ -29,6 +29,8 @@
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/kitinformation.h>
+#include <utils/algorithm.h>
+
namespace CppTools {
RawProjectPartFlags::RawProjectPartFlags(const ProjectExplorer::ToolChain *toolChain,
@@ -54,6 +56,25 @@ void RawProjectPart::setFiles(const QStringList &files, const FileClassifier &fi
this->fileClassifier = fileClassifier;
}
+static QString trimTrailingSlashes(const QString &path) {
+ QString p = path;
+ while (p.endsWith('/') && p.count() > 1) {
+ p.chop(1);
+ }
+ return p;
+}
+
+ProjectExplorer::HeaderPath RawProjectPart::frameworkDetectionHeuristic(const ProjectExplorer::HeaderPath &header)
+{
+ QString path = trimTrailingSlashes(header.path);
+
+ if (path.endsWith(".framework")) {
+ path = path.left(path.lastIndexOf(QLatin1Char('/')));
+ return {path, ProjectExplorer::HeaderPathType::Framework};
+ }
+ return header;
+}
+
void RawProjectPart::setProjectFileLocation(const QString &projectFile, int line, int column)
{
this->projectFile = projectFile;
@@ -93,23 +114,10 @@ void RawProjectPart::setHeaderPaths(const ProjectExplorer::HeaderPaths &headerPa
void RawProjectPart::setIncludePaths(const QStringList &includePaths)
{
- headerPaths.clear();
-
- foreach (const QString &includeFile, includePaths) {
- ProjectExplorer::HeaderPath hp(includeFile, ProjectExplorer::HeaderPathType::User);
-
- // The simple project managers are utterly ignorant of frameworks on macOS, and won't report
- // framework paths. The work-around is to check if the include path ends in ".framework",
- // and if so, add the parent directory as framework path.
- if (includeFile.endsWith(QLatin1String(".framework"))) {
- const int slashIdx = includeFile.lastIndexOf(QLatin1Char('/'));
- if (slashIdx != -1) {
- hp = {includeFile.left(slashIdx), ProjectExplorer::HeaderPathType::Framework};
- }
- }
-
- headerPaths.push_back(std::move(hp));
- }
+ this->headerPaths = Utils::transform<QVector>(includePaths, [](const QString &path) {
+ ProjectExplorer::HeaderPath hp(path, ProjectExplorer::HeaderPathType::User);
+ return RawProjectPart::frameworkDetectionHeuristic(hp);
+ });
}
void RawProjectPart::setPreCompiledHeaders(const QStringList &preCompiledHeaders)
diff --git a/src/plugins/cpptools/cpprawprojectpart.h b/src/plugins/cpptools/cpprawprojectpart.h
index 43e3067753..2cddd71bf9 100644
--- a/src/plugins/cpptools/cpprawprojectpart.h
+++ b/src/plugins/cpptools/cpprawprojectpart.h
@@ -61,6 +61,7 @@ public:
// FileClassifier must be thread-safe.
using FileClassifier = std::function<ProjectFile(const QString &filePath)>;
void setFiles(const QStringList &files, const FileClassifier &fileClassifier = FileClassifier());
+ static ProjectExplorer::HeaderPath frameworkDetectionHeuristic(const ProjectExplorer::HeaderPath &header);
void setHeaderPaths(const ProjectExplorer::HeaderPaths &headerPaths);
void setIncludePaths(const QStringList &includePaths);
void setPreCompiledHeaders(const QStringList &preCompiledHeaders);