forked from qt-creator/qt-creator
Utils/ProjectExplorer: Add IDevice::searchInPath
Change-Id: Ibc7cc7bd6bf3a7776681f7cd2fff051525b19f60 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
|
||||
#include "algorithm.h"
|
||||
#include "commandline.h"
|
||||
#include "environment.h"
|
||||
#include "qtcassert.h"
|
||||
|
||||
#include <QDataStream>
|
||||
@@ -1277,6 +1278,26 @@ FilePath FilePath::onDevice(const FilePath &deviceTemplate) const
|
||||
return res;
|
||||
}
|
||||
|
||||
/*!
|
||||
Searched a binary corresponding to this object in the PATH of
|
||||
the device implied by this object's scheme and host.
|
||||
|
||||
Example usage:
|
||||
\code
|
||||
binary = FilePath::fromUrl("docker://123/./make);
|
||||
fullPath = binary.onDeviceSearchInPath();
|
||||
assert(fullPath == FilePath::fromUrl("docker://123/usr/bin/make"))
|
||||
\endcode
|
||||
*/
|
||||
FilePath FilePath::onDeviceSearchInPath() const
|
||||
{
|
||||
if (needsDevice()) {
|
||||
QTC_ASSERT(s_deviceHooks.searchInPath, return {});
|
||||
return s_deviceHooks.searchInPath(*this);
|
||||
}
|
||||
return Environment::systemEnvironment().searchInPath(path());
|
||||
}
|
||||
|
||||
FilePath FilePath::pathAppended(const QString &path) const
|
||||
{
|
||||
FilePath fn = *this;
|
||||
|
@@ -76,6 +76,7 @@ public:
|
||||
std::function<bool(const FilePath &)> ensureWritableDir;
|
||||
std::function<bool(const FilePath &)> createDir;
|
||||
std::function<bool(const FilePath &)> exists;
|
||||
std::function<FilePath(const FilePath &)> searchInPath;
|
||||
std::function<QList<FilePath>(const FilePath &, const QStringList &, QDir::Filters)> dirEntries;
|
||||
std::function<QByteArray(const FilePath &, int)> fileContents;
|
||||
};
|
||||
@@ -180,6 +181,8 @@ public:
|
||||
|
||||
static void setDeviceFileHooks(const DeviceFileHooks &hooks);
|
||||
|
||||
FilePath onDeviceSearchInPath() const;
|
||||
|
||||
private:
|
||||
friend class ::tst_fileutils;
|
||||
static QString calcRelativePath(const QString &absolutePath, const QString &absoluteAnchorPath);
|
||||
|
@@ -719,6 +719,24 @@ bool DockerDevice::exists(const FilePath &filePath) const
|
||||
return exitCode == 0;
|
||||
}
|
||||
|
||||
FilePath DockerDevice::searchInPath(const FilePath &filePath) const
|
||||
{
|
||||
const QString path = filePath.path();
|
||||
|
||||
CommandLine dcmd{"docker", {"exec", d->m_container, "which", path}};
|
||||
QtcProcess proc;
|
||||
proc.setCommand(dcmd);
|
||||
proc.setWorkingDirectory("/tmp");
|
||||
proc.start();
|
||||
proc.waitForFinished();
|
||||
|
||||
LOG("Run sync:" << dcmd.toUserOutput() << " result: " << proc.exitCode());
|
||||
QTC_ASSERT(proc.exitCode() == 0, return filePath);
|
||||
|
||||
const QString output = proc.stdOut();
|
||||
return mapToGlobalPath(FilePath::fromString(output));
|
||||
}
|
||||
|
||||
QList<FilePath> DockerDevice::directoryEntries(const FilePath &filePath,
|
||||
const QStringList &nameFilters,
|
||||
QDir::Filters filters) const
|
||||
|
@@ -81,6 +81,7 @@ public:
|
||||
bool isWritableDirectory(const Utils::FilePath &filePath) const override;
|
||||
bool createDirectory(const Utils::FilePath &filePath) const override;
|
||||
bool exists(const Utils::FilePath &filePath) const override;
|
||||
Utils::FilePath searchInPath(const Utils::FilePath &filePath) const override;
|
||||
QList<Utils::FilePath> directoryEntries(const Utils::FilePath &filePath,
|
||||
const QStringList &nameFilters,
|
||||
QDir::Filters filters) const override;
|
||||
|
@@ -416,6 +416,12 @@ DeviceManager::DeviceManager(bool isInstance) : d(std::make_unique<DeviceManager
|
||||
return device->exists(filePath);
|
||||
};
|
||||
|
||||
deviceHooks.searchInPath = [](const FilePath &filePath) {
|
||||
auto device = DeviceManager::deviceForPath(filePath);
|
||||
QTC_ASSERT(device, return FilePath{});
|
||||
return device->searchInPath(filePath);
|
||||
};
|
||||
|
||||
deviceHooks.dirEntries = [](const FilePath &filePath,
|
||||
const QStringList &nameFilters, QDir::Filters filters) {
|
||||
auto device = DeviceManager::deviceForPath(filePath);
|
||||
|
@@ -266,6 +266,11 @@ bool IDevice::exists(const Utils::FilePath &filePath) const
|
||||
return false;
|
||||
}
|
||||
|
||||
FilePath IDevice::searchInPath(const FilePath &filePath) const
|
||||
{
|
||||
return Environment::systemEnvironment().searchInPath(filePath.path());
|
||||
}
|
||||
|
||||
QList<FilePath> IDevice::directoryEntries(const FilePath &filePath,
|
||||
const QStringList &nameFilters,
|
||||
QDir::Filters filters) const
|
||||
|
@@ -243,6 +243,7 @@ public:
|
||||
virtual bool ensureWritableDirectory(const Utils::FilePath &filePath) const;
|
||||
virtual bool createDirectory(const Utils::FilePath &filePath) const;
|
||||
virtual bool exists(const Utils::FilePath &filePath) const;
|
||||
virtual Utils::FilePath searchInPath(const Utils::FilePath &filePath) const;
|
||||
virtual QList<Utils::FilePath> directoryEntries(const Utils::FilePath &filePath,
|
||||
const QStringList &nameFilters,
|
||||
QDir::Filters filters) const;
|
||||
|
Reference in New Issue
Block a user