ProjectExplorer: Merge IDevice::{filePath,mapToGlobalPath}

They were doing practically the same. Keep the 'filePath' name for
now until something more fitting comes up.

Change-Id: I96ca4da4b30b7b463583e002f2c19d6e6c5541e6
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
hjk
2022-12-14 17:26:30 +01:00
parent 67c2570d74
commit 5787a22f69
9 changed files with 15 additions and 35 deletions

View File

@@ -773,17 +773,11 @@ bool DockerDevice::usableAsBuildDevice() const
return true;
}
FilePath DockerDevice::mapToGlobalPath(const FilePath &pathOnDevice) const
FilePath DockerDevice::filePath(const QString &pathOnDevice) const
{
if (pathOnDevice.needsDevice()) {
// Already correct form, only sanity check it's ours...
QTC_CHECK(handlesFile(pathOnDevice));
return pathOnDevice;
}
return FilePath::fromParts(Constants::DOCKER_DEVICE_SCHEME,
d->repoAndTagEncoded(),
pathOnDevice.path());
pathOnDevice);
// The following would work, but gives no hint on repo and tag
// result.setScheme("docker");

View File

@@ -81,9 +81,8 @@ public:
ProjectExplorer::DeviceTester *createDeviceTester() const override;
bool usableAsBuildDevice() const override;
Utils::FilePath mapToGlobalPath(const Utils::FilePath &pathOnDevice) const override;
Utils::FilePath rootPath() const override;
Utils::FilePath filePath(const QString &pathOnDevice) const override;
bool handlesFile(const Utils::FilePath &filePath) const override;
bool ensureReachable(const Utils::FilePath &other) const override;

View File

@@ -167,7 +167,7 @@ DockerDeviceWidget::DockerDeviceWidget(const IDevice::Ptr &device)
paths.append(FilePath::fromString(path.trimmed()));
}
paths = Utils::transform(paths, [dockerDevice](const FilePath &path) {
return dockerDevice->mapToGlobalPath(path);
return dockerDevice->filePath(path.path());
});
return paths;
};

View File

@@ -139,10 +139,9 @@ bool DesktopDevice::handlesFile(const FilePath &filePath) const
return !filePath.needsDevice();
}
FilePath DesktopDevice::mapToGlobalPath(const Utils::FilePath &pathOnDevice) const
FilePath DesktopDevice::filePath(const QString &pathOnDevice) const
{
QTC_CHECK(!pathOnDevice.needsDevice());
return pathOnDevice;
return FilePath::fromParts({}, {}, pathOnDevice);
}
Environment DesktopDevice::systemEnvironment() const

View File

@@ -34,9 +34,9 @@ public:
bool handlesFile(const Utils::FilePath &filePath) const override;
Utils::Environment systemEnvironment() const override;
Utils::FilePath mapToGlobalPath(const Utils::FilePath &pathOnDevice) const override;
Utils::FilePath rootPath() const override;
Utils::FilePath filePath(const QString &pathOnDevice) const override;
protected:
DesktopDevice();

View File

@@ -200,20 +200,10 @@ DeviceFileAccess *IDevice::fileAccess() const
return d->fileAccess;
}
FilePath IDevice::mapToGlobalPath(const FilePath &pathOnDevice) const
{
if (pathOnDevice.needsDevice()) {
// Already correct form, only sanity check it's ours...
QTC_CHECK(handlesFile(pathOnDevice));
return pathOnDevice;
}
// match DeviceManager::deviceForPath
return FilePath::fromParts(u"device", id().toString(), pathOnDevice.path());
}
FilePath IDevice::filePath(const QString &pathOnDevice) const
{
return mapToGlobalPath(FilePath::fromString(pathOnDevice));
// match DeviceManager::deviceForPath
return FilePath::fromParts(u"device", id().toString(), pathOnDevice);
}
bool IDevice::handlesFile(const FilePath &filePath) const
@@ -226,8 +216,8 @@ bool IDevice::handlesFile(const FilePath &filePath) const
FilePath IDevice::searchExecutableInPath(const QString &fileName) const
{
FilePaths paths;
for (const FilePath &path : systemEnvironment().path())
paths.append(mapToGlobalPath(path));
for (const FilePath &pathEntry : systemEnvironment().path())
paths.append(filePath(pathEntry.path()));
return searchExecutable(fileName, paths);
}
@@ -235,7 +225,7 @@ FilePath IDevice::searchExecutable(const QString &fileName, const FilePaths &dir
{
for (FilePath dir : dirs) {
if (!handlesFile(dir)) // Allow device-local dirs to be used.
dir = mapToGlobalPath(dir);
dir = filePath(dir.path());
QTC_CHECK(handlesFile(dir));
const FilePath candidate = dir / fileName;
if (candidate.isExecutableFile())

View File

@@ -189,7 +189,7 @@ public:
void setMachineType(MachineType machineType);
virtual Utils::FilePath rootPath() const;
Utils::FilePath filePath(const QString &pathOnDevice) const;
virtual Utils::FilePath filePath(const QString &pathOnDevice) const;
Utils::FilePath debugServerPath() const;
void setDebugServerPath(const Utils::FilePath &path);
@@ -219,8 +219,6 @@ public:
Utils::DeviceFileAccess *fileAccess() const;
virtual bool handlesFile(const Utils::FilePath &filePath) const;
virtual Utils::FilePath mapToGlobalPath(const Utils::FilePath &pathOnDevice) const;
virtual Utils::FilePath searchExecutableInPath(const QString &fileName) const;
virtual Utils::FilePath searchExecutable(const QString &fileName,
const Utils::FilePaths &dirs) const;

View File

@@ -1120,7 +1120,7 @@ static FilePaths findCompilerCandidates(const ToolchainDetector &detector,
compilerPaths << candidate;
return true;
};
const FilePath globalDir = device->mapToGlobalPath(deviceDir);
const FilePath globalDir = device->filePath(deviceDir.path());
globalDir.iterateDirectory(callBack, {nameFilters, QDir::Files | QDir::Executable});
}
} else {

View File

@@ -119,7 +119,7 @@ FilePath ProjectConfiguration::mapFromBuildDeviceToGlobalPath(const FilePath &pa
{
IDevice::ConstPtr dev = BuildDeviceKitAspect::device(kit());
QTC_ASSERT(dev, return path);
return dev->mapToGlobalPath(path);
return dev->filePath(path.path());
}
Id ProjectExplorer::idFromMap(const QVariantMap &map)