forked from qt-creator/qt-creator
Utils: Replace FilePath part setters
... by a combined version. This will make it easier to store the parts in one QString object. Change-Id: Ie85a77e3957c78a30e49998fe2e617af35a8ad17 Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io> Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -503,15 +503,14 @@ void Snapshot::insertLibraryInfo(const Utils::FilePath &path, const LibraryInfo
|
||||
break;
|
||||
ImportKey iKey(ImportType::Library, QStringList(myPath.mid(iPath)).join(QLatin1Char('.')),
|
||||
importKey.majorVersion, importKey.minorVersion);
|
||||
Utils::FilePath newP(path);
|
||||
newP.setPath((iPath == 1)
|
||||
Utils::FilePath newP = path.withNewPath(
|
||||
(iPath == 1)
|
||||
? QLatin1String("/")
|
||||
: QStringList(myPath.mid(0, iPath)).join(QLatin1Char('/')));
|
||||
cImport.addPossibleExport(Export(iKey, newP, true));
|
||||
}
|
||||
} else {
|
||||
Utils::FilePath requiredPath(path);
|
||||
requiredPath.setPath(
|
||||
Utils::FilePath requiredPath = path.withNewPath(
|
||||
QStringList(splitPath.mid(0, splitPath.size() - importKey.splitPath.size()))
|
||||
.join(QLatin1String("/")));
|
||||
cImport.addPossibleExport(Export(importKey, requiredPath, true));
|
||||
@@ -549,8 +548,8 @@ void Snapshot::insertLibraryInfo(const Utils::FilePath &path, const LibraryInfo
|
||||
break;
|
||||
ImportKey iKey(ImportType::Library, QStringList(splitPath.mid(iPath)).join(QLatin1Char('.')),
|
||||
majorVersion, minorVersion);
|
||||
Utils::FilePath newP(path);
|
||||
newP.setPath((iPath == 1)
|
||||
Utils::FilePath newP = path.withNewPath(
|
||||
iPath == 1
|
||||
? QLatin1String("/")
|
||||
: QStringList(splitPath.mid(0, iPath)).join(QLatin1Char('/')));
|
||||
cImport.addPossibleExport(Export(iKey, newP, true));
|
||||
|
@@ -1200,7 +1200,7 @@ static QList<Utils::FilePath> minimalPrefixPaths(const QList<Utils::FilePath> &p
|
||||
// find minimal prefix, ensure '/' at end
|
||||
for (Utils::FilePath path : qAsConst(paths)) {
|
||||
if (!path.endsWith("/"))
|
||||
path.setPath(QString(path.path() + "/"));
|
||||
path = path.withNewPath(path.path() + "/");
|
||||
if (path.path().length() > 1)
|
||||
sortedPaths.append(path);
|
||||
}
|
||||
|
@@ -37,9 +37,7 @@ FilePath BuildableHelperLibrary::qtChooserToQmakePath(const FilePath &qtChooser)
|
||||
if (end == -1)
|
||||
return {};
|
||||
|
||||
FilePath qmake = qtChooser;
|
||||
qmake.setPath(QString(output.mid(pos, end - pos) + "/qmake"));
|
||||
return qmake;
|
||||
return qtChooser.withNewPath(output.mid(pos, end - pos) + "/qmake");
|
||||
}
|
||||
|
||||
static bool isQmake(FilePath path)
|
||||
|
@@ -150,11 +150,14 @@ QFileInfo FilePath::toFileInfo() const
|
||||
|
||||
FilePath FilePath::fromUrl(const QUrl &url)
|
||||
{
|
||||
FilePath fn;
|
||||
fn.m_scheme = url.scheme();
|
||||
fn.m_host = url.host();
|
||||
fn.setRootAndPath(url.path(), HostOsInfo::hostOs());
|
||||
return fn;
|
||||
return FilePath::fromParts(url.scheme(), url.host(), url.path());
|
||||
}
|
||||
|
||||
FilePath FilePath::fromParts(const QStringView scheme, const QStringView host, const QStringView path)
|
||||
{
|
||||
FilePath result;
|
||||
result.setParts(scheme, host, path);
|
||||
return result;
|
||||
}
|
||||
|
||||
FilePath FilePath::currentWorkingPath()
|
||||
@@ -318,22 +321,6 @@ QString FilePath::completeSuffix() const
|
||||
return {};
|
||||
}
|
||||
|
||||
void FilePath::setScheme(const QStringView scheme)
|
||||
{
|
||||
QTC_CHECK(!scheme.contains('/'));
|
||||
m_scheme = scheme.toString();
|
||||
}
|
||||
|
||||
void FilePath::setHost(const QStringView host)
|
||||
{
|
||||
m_host = host.toString();
|
||||
}
|
||||
|
||||
void FilePath::setPath(const QStringView path)
|
||||
{
|
||||
setRootAndPath(path, HostOsInfo::hostOs());
|
||||
}
|
||||
|
||||
QStringView FilePath::scheme() const
|
||||
{
|
||||
return m_scheme;
|
||||
@@ -354,9 +341,12 @@ QStringView FilePath::root() const
|
||||
return m_root;
|
||||
}
|
||||
|
||||
void FilePath::setRoot(const QStringView root)
|
||||
void FilePath::setParts(const QStringView scheme, const QStringView host, const QStringView path)
|
||||
{
|
||||
m_root = root.toString();
|
||||
QTC_CHECK(!m_scheme.contains('/'));
|
||||
m_scheme = scheme.toString();
|
||||
m_host = host.toString();
|
||||
setRootAndPath(path, HostOsInfo::hostOs());
|
||||
}
|
||||
|
||||
/// \returns a bool indicating whether a file with this
|
||||
@@ -629,9 +619,7 @@ QString FilePath::mapToDevicePath() const
|
||||
|
||||
FilePath FilePath::withExecutableSuffix() const
|
||||
{
|
||||
FilePath res = *this;
|
||||
res.setPath(OsSpecificAspects::withExecutableSuffix(osType(), path()));
|
||||
return res;
|
||||
return withNewPath(OsSpecificAspects::withExecutableSuffix(osType(), path()));
|
||||
}
|
||||
|
||||
/// Find the parent directory of a given directory.
|
||||
@@ -655,9 +643,7 @@ FilePath FilePath::parentDir() const
|
||||
const QString parent = doCleanPath(path);
|
||||
QTC_ASSERT(parent != path, return FilePath());
|
||||
|
||||
FilePath result = *this;
|
||||
result.setPath(parent);
|
||||
return result;
|
||||
return withNewPath(parent);
|
||||
}
|
||||
|
||||
FilePath FilePath::absolutePath() const
|
||||
@@ -1568,7 +1554,7 @@ void FilePath::clear()
|
||||
*/
|
||||
bool FilePath::isEmpty() const
|
||||
{
|
||||
return m_root.isEmpty() && m_path.isEmpty();
|
||||
return root().isEmpty() && path().isEmpty();
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -1596,7 +1582,7 @@ QString FilePath::shortNativePath() const
|
||||
*/
|
||||
bool FilePath::isRelativePath() const
|
||||
{
|
||||
return m_root.isEmpty();
|
||||
return root().isEmpty();
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -1606,9 +1592,9 @@ bool FilePath::isRelativePath() const
|
||||
*/
|
||||
FilePath FilePath::resolvePath(const FilePath &tail) const
|
||||
{
|
||||
if (!tail.m_root.isEmpty())
|
||||
if (!tail.root().isEmpty())
|
||||
return tail;
|
||||
return pathAppended(tail.m_path);
|
||||
return pathAppended(tail.path());
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -1624,9 +1610,7 @@ FilePath FilePath::resolvePath(const QString &tail) const
|
||||
|
||||
FilePath FilePath::cleanPath() const
|
||||
{
|
||||
FilePath result = *this;
|
||||
result.setPath(doCleanPath(result.path()));
|
||||
return result;
|
||||
return withNewPath(doCleanPath(path()));
|
||||
}
|
||||
|
||||
QTextStream &operator<<(QTextStream &s, const FilePath &fn)
|
||||
|
@@ -56,11 +56,11 @@ public:
|
||||
[[nodiscard]] static FilePath fromUtf8(const char *filepath, int filepathSize = -1);
|
||||
[[nodiscard]] static FilePath fromVariant(const QVariant &variant);
|
||||
[[nodiscard]] static FilePath fromUrl(const QUrl &url);
|
||||
[[nodiscard]] static FilePath fromParts(const QStringView scheme, const QStringView host, const QStringView path);
|
||||
|
||||
[[nodiscard]] static FilePath currentWorkingPath();
|
||||
[[nodiscard]] static FilePath rootPath();
|
||||
|
||||
|
||||
QString toUserOutput() const;
|
||||
QString toString() const;
|
||||
QString toFSPathString() const;
|
||||
@@ -68,16 +68,11 @@ public:
|
||||
QUrl toUrl() const;
|
||||
|
||||
QStringView scheme() const;
|
||||
void setScheme(const QStringView scheme);
|
||||
|
||||
QStringView host() const;
|
||||
void setHost(const QStringView host);
|
||||
|
||||
QString path() const;
|
||||
void setPath(const QStringView path);
|
||||
|
||||
QStringView root() const;
|
||||
void setRoot(const QStringView root);
|
||||
|
||||
void setParts(const QStringView scheme, const QStringView host, const QStringView path);
|
||||
|
||||
QString fileName() const;
|
||||
QString fileNameWithPathComponents(int pathComponents) const;
|
||||
|
@@ -392,7 +392,7 @@ FilePath FileUtils::commonPath(const FilePaths &paths)
|
||||
};
|
||||
if (!allOf(others, sameScheme))
|
||||
return result;
|
||||
result.setScheme(commonScheme);
|
||||
result.setParts(commonScheme, {}, {});
|
||||
|
||||
// Common host
|
||||
const QStringView commonHost = first.host();
|
||||
@@ -401,7 +401,7 @@ FilePath FileUtils::commonPath(const FilePaths &paths)
|
||||
};
|
||||
if (!allOf(others, sameHost))
|
||||
return result;
|
||||
result.setHost(commonHost);
|
||||
result.setParts(commonScheme, commonHost, {});
|
||||
|
||||
// Common path
|
||||
QString commonPath;
|
||||
@@ -413,7 +413,7 @@ FilePath FileUtils::commonPath(const FilePaths &paths)
|
||||
commonPath += segment + '/';
|
||||
if (!allOf(others, sameBasePath))
|
||||
return result;
|
||||
result.setPath(commonPath.chopped(1));
|
||||
result.setParts(commonScheme, commonHost, commonPath.chopped(1));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@@ -271,11 +271,10 @@ QString MacroExpander::expand(const QString &stringWithVariables) const
|
||||
|
||||
FilePath MacroExpander::expand(const FilePath &fileNameWithVariables) const
|
||||
{
|
||||
FilePath result = fileNameWithVariables;
|
||||
result.setPath(expand(result.path()));
|
||||
result.setHost(expand(result.host().toString()));
|
||||
result.setScheme(expand(result.scheme().toString()));
|
||||
return result;
|
||||
return FilePath::fromParts(
|
||||
expand(fileNameWithVariables.scheme().toString()),
|
||||
expand(fileNameWithVariables.host().toString()),
|
||||
expand(fileNameWithVariables.path()));
|
||||
}
|
||||
|
||||
QByteArray MacroExpander::expand(const QByteArray &stringWithVariables) const
|
||||
|
@@ -1439,9 +1439,8 @@ FilePath CMakeBuildConfiguration::shadowBuildDirectory(const FilePath &projectFi
|
||||
bcName, buildType, "cmake");
|
||||
|
||||
if (CMakeGeneratorKitAspect::isMultiConfigGenerator(k)) {
|
||||
QString path = buildPath.path();
|
||||
path = path.left(path.lastIndexOf(QString("-%1").arg(bcName)));
|
||||
buildPath.setPath(path);
|
||||
const QString path = buildPath.path();
|
||||
buildPath = buildPath.withNewPath(path.left(path.lastIndexOf(QString("-%1").arg(bcName))));
|
||||
}
|
||||
|
||||
return buildPath;
|
||||
|
@@ -167,7 +167,7 @@ void StackFrame::fixQrcFrame(const DebuggerRunParameters &rp)
|
||||
relativePath = relativePath.right(relativePath.size() - 5);
|
||||
while (relativePath.startsWith('/'))
|
||||
relativePath = relativePath.mid(1);
|
||||
relativeFile.setPath(relativePath);
|
||||
relativeFile = relativeFile.withNewPath(relativePath);
|
||||
|
||||
FilePath absFile = findFile(rp.projectSourceDirectory, relativeFile);
|
||||
if (absFile.isEmpty())
|
||||
|
@@ -590,10 +590,7 @@ FilePath DockerDevice::mapToGlobalPath(const FilePath &pathOnDevice) const
|
||||
return pathOnDevice;
|
||||
}
|
||||
|
||||
FilePath result;
|
||||
result.setPath(pathOnDevice.path());
|
||||
result.setScheme(Constants::DOCKER_DEVICE_SCHEME);
|
||||
result.setHost(d->m_data.repoAndTag());
|
||||
return FilePath::fromParts(Constants::DOCKER_DEVICE_SCHEME, d->m_data.repoAndTag(), pathOnDevice.path());
|
||||
|
||||
// The following would work, but gives no hint on repo and tag
|
||||
// result.setScheme("docker");
|
||||
@@ -602,8 +599,6 @@ FilePath DockerDevice::mapToGlobalPath(const FilePath &pathOnDevice) const
|
||||
// The following would work, but gives no hint on repo, tag and imageid
|
||||
// result.setScheme("device");
|
||||
// result.setHost(id().toString());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
QString DockerDevice::mapToDevicePath(const Utils::FilePath &globalPath) const
|
||||
@@ -621,11 +616,7 @@ QString DockerDevice::mapToDevicePath(const Utils::FilePath &globalPath) const
|
||||
|
||||
Utils::FilePath DockerDevice::rootPath() const
|
||||
{
|
||||
FilePath root;
|
||||
root.setScheme(Constants::DOCKER_DEVICE_SCHEME);
|
||||
root.setHost(d->m_data.repoAndTag());
|
||||
root.setPath(u"/");
|
||||
return root;
|
||||
return FilePath::fromParts(Constants::DOCKER_DEVICE_SCHEME, d->m_data.repoAndTag(), u"/");
|
||||
}
|
||||
|
||||
bool DockerDevice::handlesFile(const FilePath &filePath) const
|
||||
|
@@ -196,11 +196,7 @@ FilePath IDevice::mapToGlobalPath(const FilePath &pathOnDevice) const
|
||||
return pathOnDevice;
|
||||
}
|
||||
// match DeviceManager::deviceForPath
|
||||
FilePath result;
|
||||
result.setPath(pathOnDevice.path());
|
||||
result.setScheme(u"device");
|
||||
result.setHost(id().toString());
|
||||
return result;
|
||||
return FilePath::fromParts(u"device", id().toString(), pathOnDevice.path());
|
||||
}
|
||||
|
||||
QString IDevice::mapToDevicePath(const FilePath &globalPath) const
|
||||
@@ -758,11 +754,7 @@ void IDevice::setMachineType(MachineType machineType)
|
||||
|
||||
FilePath IDevice::rootPath() const
|
||||
{
|
||||
FilePath root;
|
||||
root.setScheme(u"device");
|
||||
root.setHost(id().toString());
|
||||
root.setPath(u"/");
|
||||
return root;
|
||||
return FilePath::fromParts(u"device", id().toString(), u"/");
|
||||
}
|
||||
|
||||
FilePath IDevice::debugServerPath() const
|
||||
|
@@ -82,7 +82,8 @@ FilePath ProcessParameters::effectiveWorkingDirectory() const
|
||||
QString path = m_workingDirectory.path();
|
||||
if (m_macroExpander)
|
||||
path = m_macroExpander->expand(path);
|
||||
m_effectiveWorkingDirectory.setPath(QDir::cleanPath(m_environment.expandVariables(path)));
|
||||
m_effectiveWorkingDirectory =
|
||||
m_effectiveWorkingDirectory.withNewPath(QDir::cleanPath(m_environment.expandVariables(path)));
|
||||
}
|
||||
return m_effectiveWorkingDirectory;
|
||||
}
|
||||
|
@@ -233,12 +233,10 @@ FilePath WorkingDirectoryAspect::workingDirectory() const
|
||||
{
|
||||
const Environment env = m_envAspect ? m_envAspect->environment()
|
||||
: Environment::systemEnvironment();
|
||||
FilePath res = m_workingDirectory;
|
||||
QString workingDir = m_workingDirectory.path();
|
||||
if (m_macroExpander)
|
||||
workingDir = m_macroExpander->expandProcessArgs(workingDir);
|
||||
res.setPath(PathChooser::expandedDirectory(workingDir, env, QString()));
|
||||
return res;
|
||||
return m_workingDirectory.withNewPath(PathChooser::expandedDirectory(workingDir, env, QString()));
|
||||
}
|
||||
|
||||
FilePath WorkingDirectoryAspect::defaultWorkingDirectory() const
|
||||
|
@@ -780,8 +780,7 @@ FilePath QmakeBuildSystem::buildDir(const FilePath &proFilePath) const
|
||||
? projectDirectory()
|
||||
: buildConfigBuildDir;
|
||||
// FIXME: Convoluted.
|
||||
buildDir.setPath(QDir::cleanPath(QDir(buildDir.path()).absoluteFilePath(relativeDir)));
|
||||
return buildDir;
|
||||
return buildDir.withNewPath(QDir::cleanPath(QDir(buildDir.path()).absoluteFilePath(relativeDir)));
|
||||
}
|
||||
|
||||
void QmakeBuildSystem::proFileParseError(const QString &errorMessage, const FilePath &filePath)
|
||||
|
@@ -716,7 +716,7 @@ void QtVersion::fromMap(const QVariantMap &map)
|
||||
QString string = d->m_qmakeCommand.path();
|
||||
if (string.startsWith('~'))
|
||||
string.remove(0, 1).prepend(QDir::homePath());
|
||||
qmake.setPath(string);
|
||||
qmake = qmake.withNewPath(string);
|
||||
if (!d->m_qmakeCommand.needsDevice()) {
|
||||
if (BuildableHelperLibrary::isQtChooser(qmake)) {
|
||||
// we don't want to treat qtchooser as a normal qmake
|
||||
|
@@ -730,8 +730,7 @@ CommandLine SshProcessInterfacePrivate::fullLocalCommandLine() const
|
||||
cmd.addArgs(options);
|
||||
|
||||
CommandLine remoteWithLocalPath = q->m_setup.m_commandLine;
|
||||
FilePath executable;
|
||||
executable.setPath(remoteWithLocalPath.executable().path());
|
||||
FilePath executable = FilePath::fromParts({}, {}, remoteWithLocalPath.executable().path());
|
||||
remoteWithLocalPath.setExecutable(executable);
|
||||
|
||||
cmd.addArg(q->fullCommandLine(remoteWithLocalPath));
|
||||
@@ -1028,11 +1027,7 @@ QString LinuxDevice::userAtHost() const
|
||||
|
||||
FilePath LinuxDevice::rootPath() const
|
||||
{
|
||||
FilePath root;
|
||||
root.setScheme(u"ssh");
|
||||
root.setHost(userAtHost());
|
||||
root.setPath(u"/");
|
||||
return root;
|
||||
return FilePath::fromParts(u"ssh", userAtHost(), u"/");
|
||||
}
|
||||
|
||||
bool LinuxDevice::handlesFile(const FilePath &filePath) const
|
||||
@@ -1515,7 +1510,8 @@ private:
|
||||
m_batchFile->write("-rm " + ProcessArgs::quoteArgUnix(
|
||||
file.m_target.path()).toLocal8Bit() + '\n');
|
||||
// see QTBUG-5817.
|
||||
sourceFileOrLinkTarget.setPath(fi.dir().relativeFilePath(fi.symLinkTarget()));
|
||||
sourceFileOrLinkTarget =
|
||||
sourceFileOrLinkTarget.withNewPath(fi.dir().relativeFilePath(fi.symLinkTarget()));
|
||||
}
|
||||
}
|
||||
m_batchFile->write(transferCommand(direction(), link) + ' '
|
||||
@@ -1597,8 +1593,10 @@ private:
|
||||
}
|
||||
|
||||
FileToTransfer fixedFile = file;
|
||||
(direction() == FileTransferDirection::Upload) ? fixedFile.m_source.setPath(localFilePath)
|
||||
: fixedFile.m_target.setPath(localFilePath);
|
||||
if (direction() == FileTransferDirection::Upload)
|
||||
fixedFile.m_source = fixedFile.m_source.withNewPath(localFilePath);
|
||||
else
|
||||
fixedFile.m_target = fixedFile.m_target.withNewPath(localFilePath);
|
||||
return fixedFile;
|
||||
}
|
||||
|
||||
|
@@ -771,7 +771,7 @@ void MemcheckToolPrivate::heobAction()
|
||||
QString executablePath = executable.path();
|
||||
if (executablePath.startsWith(wdSlashed, Qt::CaseInsensitive)) {
|
||||
executablePath.remove(0, wdSlashed.size());
|
||||
executable.setPath(executablePath);
|
||||
executable = executable.withNewPath(executablePath);
|
||||
}
|
||||
|
||||
// heob arguments
|
||||
|
@@ -314,11 +314,7 @@ void tst_fileutils::toString()
|
||||
QFETCH(QString, result);
|
||||
QFETCH(QString, userResult);
|
||||
|
||||
FilePath filePath;
|
||||
filePath.setScheme(scheme);
|
||||
filePath.setHost(host);
|
||||
filePath.setPath(path);
|
||||
|
||||
FilePath filePath = FilePath::fromParts(scheme, host, path);
|
||||
QCOMPARE(filePath.toString(), result);
|
||||
QString cleanedOutput = filePath.needsDevice() ? filePath.toUserOutput() : QDir::cleanPath(filePath.toUserOutput());
|
||||
QCOMPARE(cleanedOutput, userResult);
|
||||
@@ -428,15 +424,7 @@ void tst_fileutils::fromToString()
|
||||
QCOMPARE(filePath.host(), host);
|
||||
QCOMPARE(filePath.path(), path);
|
||||
|
||||
|
||||
FilePath copy = filePath;
|
||||
copy.setHost(host);
|
||||
QCOMPARE(copy.toString(), full);
|
||||
|
||||
copy.setScheme(scheme);
|
||||
QCOMPARE(copy.toString(), full);
|
||||
|
||||
copy.setPath(path);
|
||||
FilePath copy = FilePath::fromParts(scheme, host, path);
|
||||
QCOMPARE(copy.toString(), full);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user