Utils: Move FileUtils::resolvePath to FilePath

In line with the general move toward use of FilePath nowadays.

Change-Id: I1c50e1479f7d9100ff8ded3ce3c22dd82b7fe6aa
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2019-12-04 13:36:04 +01:00
parent fa2c95f221
commit d3b2c01c11
8 changed files with 19 additions and 20 deletions

View File

@@ -398,13 +398,13 @@ bool FileUtils::isRelativePath(const QString &path)
return true; return true;
} }
QString FileUtils::resolvePath(const QString &baseDir, const QString &fileName) FilePath FilePath::resolvePath(const QString &fileName) const
{ {
if (fileName.isEmpty()) if (fileName.isEmpty())
return QString(); return {}; // FIXME: Isn't this odd?
if (isAbsolutePath(fileName)) if (FileUtils::isAbsolutePath(fileName))
return QDir::cleanPath(fileName); return FilePath::fromString(QDir::cleanPath(fileName));
return QDir::cleanPath(baseDir + QLatin1Char('/') + fileName); return FilePath::fromString(QDir::cleanPath(toString() + QLatin1Char('/') + fileName));
} }
FilePath FileUtils::commonPath(const FilePath &oldCommonPath, const FilePath &filePath) FilePath FileUtils::commonPath(const FilePath &oldCommonPath, const FilePath &filePath)

View File

@@ -107,6 +107,7 @@ public:
FilePath relativeChildPath(const FilePath &parent) const; FilePath relativeChildPath(const FilePath &parent) const;
FilePath pathAppended(const QString &str) const; FilePath pathAppended(const QString &str) const;
FilePath stringAppended(const QString &str) const; FilePath stringAppended(const QString &str) const;
FilePath resolvePath(const QString &fileName) const;
FilePath canonicalPath() const; FilePath canonicalPath() const;
@@ -172,7 +173,6 @@ public:
static bool isRelativePath(const QString &fileName); static bool isRelativePath(const QString &fileName);
static bool isAbsolutePath(const QString &fileName) { return !isRelativePath(fileName); } static bool isAbsolutePath(const QString &fileName) { return !isRelativePath(fileName); }
static QString resolvePath(const QString &baseDir, const QString &fileName);
static FilePath commonPath(const FilePath &oldCommonPath, const FilePath &fileName); static FilePath commonPath(const FilePath &oldCommonPath, const FilePath &fileName);
static QByteArray fileId(const FilePath &fileName); static QByteArray fileId(const FilePath &fileName);
}; };

View File

@@ -4700,8 +4700,8 @@ static QString findExecutableFromName(const QString &fileNameFromCore, const QSt
absPath = fileNameFromCore; absPath = fileNameFromCore;
} else { } else {
QFileInfo coreInfo(coreFile); QFileInfo coreInfo(coreFile);
QDir coreDir = coreInfo.dir(); FilePath coreDir = FilePath::fromString(coreInfo.dir().absolutePath());
absPath = FileUtils::resolvePath(coreDir.absolutePath(), fileNameFromCore); absPath = coreDir.resolvePath(fileNameFromCore).toString();
} }
if (QFileInfo(absPath).isFile() || absPath.isEmpty()) if (QFileInfo(absPath).isFile() || absPath.isEmpty())
return absPath; return absPath;

View File

@@ -155,7 +155,7 @@ FilePath CustomParser::absoluteFilePath(const QString &filePath) const
if (m_workingDirectory.isEmpty()) if (m_workingDirectory.isEmpty())
return FilePath::fromUserInput(filePath); return FilePath::fromUserInput(filePath);
return FilePath::fromString(FileUtils::resolvePath(m_workingDirectory, filePath)); return FilePath::fromString(m_workingDirectory).resolvePath(filePath);
} }
bool CustomParser::hasMatch(const QString &line, CustomParserExpression::CustomParserChannel channel, bool CustomParser::hasMatch(const QString &line, CustomParserExpression::CustomParserChannel channel,

View File

@@ -66,9 +66,9 @@ static FilePath defaultBuildDirectory(const FilePath &projectFilePath, const Kit
{ {
const QString projectName = projectFilePath.toFileInfo().completeBaseName(); const QString projectName = projectFilePath.toFileInfo().completeBaseName();
ProjectMacroExpander expander(projectFilePath, projectName, k, bcName, buildType); ProjectMacroExpander expander(projectFilePath, projectName, k, bcName, buildType);
QString projectDir = Project::projectDirectory(projectFilePath).toString(); FilePath projectDir = Project::projectDirectory(projectFilePath);
QString buildPath = expander.expand(ProjectExplorerPlugin::buildDirectoryTemplate()); QString buildPath = expander.expand(ProjectExplorerPlugin::buildDirectoryTemplate());
return FilePath::fromString(FileUtils::resolvePath(projectDir, buildPath)); return projectDir.resolvePath(buildPath);
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------

View File

@@ -86,14 +86,14 @@ QbsProjectImporter::QbsProjectImporter(const FilePath &path) : QtProjectImporter
{ {
} }
static QString buildDir(const FilePath &projectFilePath, const Kit *k) static FilePath buildDir(const FilePath &projectFilePath, const Kit *k)
{ {
const QString projectName = projectFilePath.toFileInfo().completeBaseName(); const QString projectName = projectFilePath.toFileInfo().completeBaseName();
ProjectMacroExpander expander(projectFilePath, projectName, k, QString(), ProjectMacroExpander expander(projectFilePath, projectName, k, QString(),
BuildConfiguration::Unknown); BuildConfiguration::Unknown);
const QString projectDir = Project::projectDirectory(projectFilePath).toString(); const FilePath projectDir = Project::projectDirectory(projectFilePath);
const QString buildPath = expander.expand(ProjectExplorerPlugin::buildDirectoryTemplate()); const QString buildPath = expander.expand(ProjectExplorerPlugin::buildDirectoryTemplate());
return FileUtils::resolvePath(projectDir, buildPath); return projectDir.resolvePath(buildPath);
} }
static bool hasBuildGraph(const QString &dir) static bool hasBuildGraph(const QString &dir)
@@ -123,7 +123,7 @@ QStringList QbsProjectImporter::importCandidates()
seenCandidates.insert(projectDir); seenCandidates.insert(projectDir);
const auto &kits = KitManager::kits(); const auto &kits = KitManager::kits();
for (Kit * const k : kits) { for (Kit * const k : kits) {
QFileInfo fi(buildDir(projectFilePath(), k)); QFileInfo fi = buildDir(projectFilePath(), k).toFileInfo();
const QString candidate = fi.absolutePath(); const QString candidate = fi.absolutePath();
if (!seenCandidates.contains(candidate)) { if (!seenCandidates.contains(candidate)) {
seenCandidates.insert(candidate); seenCandidates.insert(candidate);

View File

@@ -86,9 +86,9 @@ FilePath QmakeBuildConfiguration::shadowBuildDirectory(const FilePath &proFilePa
const QString projectName = proFilePath.toFileInfo().completeBaseName(); const QString projectName = proFilePath.toFileInfo().completeBaseName();
ProjectMacroExpander expander(proFilePath, projectName, k, suffix, buildType); ProjectMacroExpander expander(proFilePath, projectName, k, suffix, buildType);
QString projectDir = Project::projectDirectory(proFilePath).toString(); FilePath projectDir = Project::projectDirectory(proFilePath);
QString buildPath = expander.expand(ProjectExplorerPlugin::buildDirectoryTemplate()); QString buildPath = expander.expand(ProjectExplorerPlugin::buildDirectoryTemplate());
return FilePath::fromString(FileUtils::resolvePath(projectDir, buildPath)); return projectDir.resolvePath(buildPath);
} }
const char BUILD_CONFIGURATION_KEY[] = "Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration"; const char BUILD_CONFIGURATION_KEY[] = "Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration";

View File

@@ -91,8 +91,7 @@ bool WinRtPackageDeploymentStep::init()
if (!qt) if (!qt)
return false; return false;
const QString windeployqtPath = FileUtils::resolvePath(qt->hostBinPath().toString(), const FilePath windeployqtPath = qt->hostBinPath().resolvePath("windeployqt.exe");
"windeployqt.exe");
CommandLine windeployqt{windeployqtPath}; CommandLine windeployqt{windeployqtPath};
windeployqt.addArg(QDir::toNativeSeparators(m_targetFilePath)); windeployqt.addArg(QDir::toNativeSeparators(m_targetFilePath));
@@ -104,7 +103,7 @@ bool WinRtPackageDeploymentStep::init()
} }
ProcessParameters *params = processParameters(); ProcessParameters *params = processParameters();
if (!QFile::exists(windeployqtPath)) { if (!windeployqtPath.exists()) {
raiseError(tr("Cannot find windeployqt.exe in \"%1\".") raiseError(tr("Cannot find windeployqt.exe in \"%1\".")
.arg(QDir::toNativeSeparators(qt->hostBinPath().toString()))); .arg(QDir::toNativeSeparators(qt->hostBinPath().toString())));
return false; return false;