forked from qt-creator/qt-creator
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>
This commit is contained in:
committed by
Cristian Adam
parent
30575d2c76
commit
6796a5edcd
@@ -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)
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user