ProjectExplorer: Proliferate FilePath a bit

Change-Id: Ia671a1de17b9e58764375c5f64cc47b053b0725a
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2022-11-25 14:06:47 +01:00
parent 4d325522e0
commit 2704f8ff0b
17 changed files with 54 additions and 61 deletions

View File

@@ -148,8 +148,8 @@ void addDriverModeFlagIfNeeded(const ToolChain *toolchain,
RawProjectPart makeRawProjectPart(const Utils::FilePath &projectFile,
Kit *kit,
ProjectExplorer::KitInfo &kitInfo,
const QString &workingDir,
const Utils::FilePath &fileName,
const FilePath &workingDir,
const FilePath &filePath,
QStringList flags)
{
HeaderPaths headerPaths;
@@ -157,7 +157,7 @@ RawProjectPart makeRawProjectPart(const Utils::FilePath &projectFile,
CppEditor::ProjectFile::Kind fileKind = CppEditor::ProjectFile::Unclassified;
const QStringList originalFlags = flags;
filteredFlags(fileName.fileName(),
filteredFlags(filePath,
workingDir,
flags,
headerPaths,
@@ -166,10 +166,12 @@ RawProjectPart makeRawProjectPart(const Utils::FilePath &projectFile,
kitInfo.sysRootPath);
RawProjectPart rpp;
rpp.setProjectFileLocation(projectFile.toString());
rpp.setBuildSystemTarget(workingDir);
rpp.setDisplayName(fileName.fileName());
rpp.setFiles({fileName.toString()});
rpp.setBuildSystemTarget(workingDir.path());
rpp.setDisplayName(filePath.fileName());
rpp.setFiles({filePath.toFSPathString()});
rpp.setHeaderPaths(headerPaths);
rpp.setMacros(macros);

View File

@@ -92,7 +92,9 @@ public:
QStringList getFilteredFlags()
{
filteredFlags(fileName, workingDir, flags, headerPaths, macros, fileKind, sysRoot);
filteredFlags(FilePath::fromString(fileName),
FilePath::fromString(workingDir),
flags, headerPaths, macros, fileKind, sysRoot);
return flags;
}

View File

@@ -22,15 +22,6 @@ using namespace Utils;
namespace CompilationDatabaseProjectManager {
namespace Internal {
static QString updatedPathFlag(const QString &pathStr, const QString &workingDir)
{
QString result = pathStr;
if (QDir(pathStr).isRelative())
result = workingDir + "/" + pathStr;
return result;
}
static CppEditor::ProjectFile::Kind fileKindFromString(QString flag)
{
using namespace CppEditor;
@@ -86,13 +77,13 @@ QStringList filterFromFileName(const QStringList &flags, QString fileName)
return result;
}
void filteredFlags(const QString &fileName,
const QString &workingDir,
void filteredFlags(const FilePath &filePath,
const FilePath &workingDir,
QStringList &flags,
HeaderPaths &headerPaths,
Macros &macros,
CppEditor::ProjectFile::Kind &fileKind,
Utils::FilePath &sysRoot)
FilePath &sysRoot)
{
if (flags.empty())
return;
@@ -113,7 +104,7 @@ void filteredFlags(const QString &fileName,
}
if (includePathType) {
const QString pathStr = updatedPathFlag(flag, workingDir);
const QString pathStr = workingDir.resolvePath(flag).toString();
headerPaths.append({pathStr, includePathType.value()});
includePathType.reset();
continue;
@@ -152,7 +143,7 @@ void filteredFlags(const QString &fileName,
return flag.startsWith(opt) && flag != opt;
});
if (!includeOpt.isEmpty()) {
const QString pathStr = updatedPathFlag(flag.mid(includeOpt.length()), workingDir);
const QString pathStr = workingDir.resolvePath(flag.mid(includeOpt.length())).toString();
headerPaths.append({pathStr, userIncludeFlags.contains(includeOpt)
? HeaderPathType::User : HeaderPathType::System});
continue;
@@ -182,14 +173,14 @@ void filteredFlags(const QString &fileName,
if (flag.startsWith("--sysroot=")) {
if (sysRoot.isEmpty())
sysRoot = FilePath::fromUserInput(updatedPathFlag(flag.mid(10), workingDir));
sysRoot = workingDir.resolvePath(flag.mid(10));
continue;
}
if ((flag.startsWith("-std=") || flag.startsWith("/std:"))
&& fileKind == CppEditor::ProjectFile::Unclassified) {
const bool cpp = (flag.contains("c++") || flag.contains("gnu++"));
if (CppEditor::ProjectFile::isHeader(CppEditor::ProjectFile::classify(fileName)))
if (CppEditor::ProjectFile::isHeader(CppEditor::ProjectFile::classify(filePath.path())))
fileKind = cpp ? CppEditor::ProjectFile::CXXHeader : CppEditor::ProjectFile::CHeader;
else
fileKind = cpp ? CppEditor::ProjectFile::CXXSource : CppEditor::ProjectFile::CSource;
@@ -203,7 +194,7 @@ void filteredFlags(const QString &fileName,
}
if (fileKind == CppEditor::ProjectFile::Unclassified)
fileKind = CppEditor::ProjectFile::classify(fileName);
fileKind = CppEditor::ProjectFile::classify(filePath.path());
flags = filtered;
}

View File

@@ -4,10 +4,8 @@
#pragma once
#include <cppeditor/cppprojectfile.h>
#include <utils/filepath.h>
#include <QHash>
#include <QStringList>
namespace ProjectExplorer {
class HeaderPath;
@@ -21,7 +19,7 @@ class DbEntry {
public:
QStringList flags;
Utils::FilePath fileName;
QString workingDir;
Utils::FilePath workingDir;
};
class DbContents {
@@ -35,8 +33,8 @@ using MimeBinaryCache = QHash<QString, bool>;
QStringList filterFromFileName(const QStringList &flags, QString baseName);
void filteredFlags(const QString &fileName,
const QString &workingDir,
void filteredFlags(const Utils::FilePath &filePath,
const Utils::FilePath &workingDir,
QStringList &flags,
QVector<ProjectExplorer::HeaderPath> &headerPaths,
QVector<ProjectExplorer::Macro> &macros,

View File

@@ -182,7 +182,7 @@ std::vector<DbEntry> CompilationDbParser::readJsonObjects() const
const Utils::FilePath filePath = jsonObjectFilePath(object);
const QStringList flags = filterFromFileName(jsonObjectFlags(object, flagsCache),
filePath.fileName());
result.push_back({flags, filePath, object["directory"].toString()});
result.push_back({flags, filePath, FilePath::fromUserInput(object["directory"].toString())});
objectStart = m_projectFileContents.indexOf('{', objectEnd + 1);
objectEnd = m_projectFileContents.indexOf('}', objectStart + 1);