forked from qt-creator/qt-creator
Utils: Change semantics of FilePath::onDeviceSearchInPath()
... and rename it to searchOnDevice(). We need to handle additional search directories anyways, so its more uniform to always pass a list all of them. Change-Id: I46c7860b51d11c26db58045ff3ab922148af021f Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -1374,17 +1374,17 @@ FilePath FilePath::onDevice(const FilePath &deviceTemplate) const
|
|||||||
Example usage:
|
Example usage:
|
||||||
\code
|
\code
|
||||||
binary = FilePath::fromUrl("docker://123/./make);
|
binary = FilePath::fromUrl("docker://123/./make);
|
||||||
fullPath = binary.onDeviceSearchInPath();
|
fullPath = binary.searchOnDevice();
|
||||||
assert(fullPath == FilePath::fromUrl("docker://123/usr/bin/make"))
|
assert(fullPath == FilePath::fromUrl("docker://123/usr/bin/make"))
|
||||||
\endcode
|
\endcode
|
||||||
*/
|
*/
|
||||||
FilePath FilePath::onDeviceSearchInPath(const FilePaths &additionalDirs) const
|
FilePath FilePath::searchOnDevice(const FilePaths &dirs) const
|
||||||
{
|
{
|
||||||
if (needsDevice()) {
|
if (needsDevice()) {
|
||||||
QTC_ASSERT(s_deviceHooks.searchInPath, return {});
|
QTC_ASSERT(s_deviceHooks.searchInPath, return {});
|
||||||
return s_deviceHooks.searchInPath(*this, additionalDirs);
|
return s_deviceHooks.searchInPath(*this, dirs);
|
||||||
}
|
}
|
||||||
return Environment::systemEnvironment().searchInPath(path(), additionalDirs);
|
return Environment::systemEnvironment().searchInPath(path(), dirs);
|
||||||
}
|
}
|
||||||
|
|
||||||
Environment FilePath::deviceEnvironment() const
|
Environment FilePath::deviceEnvironment() const
|
||||||
|
|||||||
@@ -216,7 +216,7 @@ public:
|
|||||||
|
|
||||||
static void setDeviceFileHooks(const DeviceFileHooks &hooks);
|
static void setDeviceFileHooks(const DeviceFileHooks &hooks);
|
||||||
|
|
||||||
FilePath onDeviceSearchInPath(const QList<FilePath> &additionalDirs = {}) const;
|
FilePath searchOnDevice(const QList<FilePath> &dirs) const;
|
||||||
Environment deviceEnvironment() const;
|
Environment deviceEnvironment() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -500,7 +500,7 @@ QList<BaseQtVersion *> KitDetectorPrivate::autoDetectQtVersions() const
|
|||||||
emit q->logOutput('\n' + tr("Searching Qt installations..."));
|
emit q->logOutput('\n' + tr("Searching Qt installations..."));
|
||||||
for (const QString &candidate : candidates) {
|
for (const QString &candidate : candidates) {
|
||||||
emit q->logOutput(tr("Searching for %1 executable...").arg(candidate));
|
emit q->logOutput(tr("Searching for %1 executable...").arg(candidate));
|
||||||
const FilePath qmake = m_device->searchInPath(FilePath::fromString(candidate));
|
const FilePath qmake = m_device->searchExecutableInPath(candidate);
|
||||||
if (qmake.isEmpty())
|
if (qmake.isEmpty())
|
||||||
continue;
|
continue;
|
||||||
BaseQtVersion *qtVersion = QtVersionFactory::createQtVersionFromQMakePath(qmake, false, m_sharedId, &error);
|
BaseQtVersion *qtVersion = QtVersionFactory::createQtVersionFromQMakePath(qmake, false, m_sharedId, &error);
|
||||||
@@ -546,8 +546,8 @@ void KitDetectorPrivate::autoDetectCMake()
|
|||||||
QString error;
|
QString error;
|
||||||
const QStringList candidates = {"cmake"};
|
const QStringList candidates = {"cmake"};
|
||||||
for (const QString &candidate : candidates) {
|
for (const QString &candidate : candidates) {
|
||||||
const FilePath cmake = m_device->searchInPath(FilePath::fromString(candidate));
|
const FilePath cmake = m_device->searchExecutableInPath(candidate);
|
||||||
if (cmake.isExecutableFile()) {
|
if (!cmake.isEmpty()) {
|
||||||
emit q->logOutput(tr("Found CMake binary: %1").arg(cmake.toUserOutput()));
|
emit q->logOutput(tr("Found CMake binary: %1").arg(cmake.toUserOutput()));
|
||||||
const bool res = QMetaObject::invokeMethod(cmakeManager,
|
const bool res = QMetaObject::invokeMethod(cmakeManager,
|
||||||
"registerCMakeByPath",
|
"registerCMakeByPath",
|
||||||
@@ -1046,35 +1046,6 @@ FilePath DockerDevice::symLinkTarget(const FilePath &filePath) const
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
FilePath DockerDevice::searchInPath(const FilePath &filePath, const FilePaths &additionalDirs) const
|
|
||||||
{
|
|
||||||
QTC_ASSERT(handlesFile(filePath), return {});
|
|
||||||
tryCreateLocalFileAccess();
|
|
||||||
|
|
||||||
const QString path = filePath.path();
|
|
||||||
|
|
||||||
// FIXME: Check whether local search via deviceEnvironment/PATH is faster?
|
|
||||||
CommandLine dcmd{"docker", {"exec", d->m_container, "which", path}};
|
|
||||||
QtcProcess proc;
|
|
||||||
proc.setCommand(dcmd);
|
|
||||||
proc.start();
|
|
||||||
proc.waitForFinished();
|
|
||||||
|
|
||||||
LOG("Run sync:" << dcmd.toUserOutput() << " result: " << proc.exitCode());
|
|
||||||
if (proc.exitCode() == 0) {
|
|
||||||
const QString output = proc.stdOut().trimmed();
|
|
||||||
return mapToGlobalPath(FilePath::fromString(output));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const FilePath &dir : additionalDirs) {
|
|
||||||
const FilePath candidate = dir / filePath.path();
|
|
||||||
if (candidate.exists())
|
|
||||||
return candidate;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
FilePaths DockerDevice::directoryEntries(const FilePath &filePath,
|
FilePaths DockerDevice::directoryEntries(const FilePath &filePath,
|
||||||
const QStringList &nameFilters,
|
const QStringList &nameFilters,
|
||||||
QDir::Filters filters,
|
QDir::Filters filters,
|
||||||
|
|||||||
@@ -88,8 +88,6 @@ public:
|
|||||||
bool removeRecursively(const Utils::FilePath &filePath) const override;
|
bool removeRecursively(const Utils::FilePath &filePath) const override;
|
||||||
bool copyFile(const Utils::FilePath &filePath, const Utils::FilePath &target) const override;
|
bool copyFile(const Utils::FilePath &filePath, const Utils::FilePath &target) const override;
|
||||||
bool renameFile(const Utils::FilePath &filePath, const Utils::FilePath &target) const override;
|
bool renameFile(const Utils::FilePath &filePath, const Utils::FilePath &target) const override;
|
||||||
Utils::FilePath searchInPath(const Utils::FilePath &filePath,
|
|
||||||
const Utils::FilePaths &additionalDirs) const override;
|
|
||||||
Utils::FilePath symLinkTarget(const Utils::FilePath &filePath) const override;
|
Utils::FilePath symLinkTarget(const Utils::FilePath &filePath) const override;
|
||||||
QList<Utils::FilePath> directoryEntries(const Utils::FilePath &filePath,
|
QList<Utils::FilePath> directoryEntries(const Utils::FilePath &filePath,
|
||||||
const QStringList &nameFilters,
|
const QStringList &nameFilters,
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ QList<ToolChain *> NimToolChainFactory::autoDetect(const QList<ToolChain *> &alr
|
|||||||
QList<ToolChain *> result;
|
QList<ToolChain *> result;
|
||||||
|
|
||||||
IDevice::ConstPtr dev = device ? device : DeviceManager::defaultDesktopDevice();
|
IDevice::ConstPtr dev = device ? device : DeviceManager::defaultDesktopDevice();
|
||||||
const FilePath compilerPath = dev->searchInPath(FilePath::fromString("nim"));
|
const FilePath compilerPath = dev->searchExecutableInPath("nim");
|
||||||
if (compilerPath.isEmpty())
|
if (compilerPath.isEmpty())
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
|
|||||||
@@ -458,10 +458,10 @@ DeviceManager::DeviceManager(bool isInstance) : d(std::make_unique<DeviceManager
|
|||||||
return device->renameFile(filePath, target);
|
return device->renameFile(filePath, target);
|
||||||
};
|
};
|
||||||
|
|
||||||
deviceHooks.searchInPath = [](const FilePath &filePath, const FilePaths &additionalDirs) {
|
deviceHooks.searchInPath = [](const FilePath &filePath, const FilePaths &dirs) {
|
||||||
auto device = DeviceManager::deviceForPath(filePath);
|
auto device = DeviceManager::deviceForPath(filePath);
|
||||||
QTC_ASSERT(device, return FilePath{});
|
QTC_ASSERT(device, return FilePath{});
|
||||||
return device->searchInPath(filePath, additionalDirs);
|
return device->searchExecutable(filePath.path(), dirs);
|
||||||
};
|
};
|
||||||
|
|
||||||
deviceHooks.symLinkTarget = [](const FilePath &filePath) {
|
deviceHooks.symLinkTarget = [](const FilePath &filePath) {
|
||||||
|
|||||||
@@ -311,9 +311,24 @@ bool IDevice::renameFile(const FilePath &filePath, const FilePath &target) const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
FilePath IDevice::searchInPath(const FilePath &filePath, const FilePaths &additionalDirs) const
|
FilePath IDevice::searchExecutableInPath(const QString &fileName) const
|
||||||
{
|
{
|
||||||
return Environment::systemEnvironment().searchInPath(filePath.path());
|
FilePaths paths;
|
||||||
|
for (const FilePath &path : systemEnvironment().path())
|
||||||
|
paths.append(mapToGlobalPath(path));
|
||||||
|
return searchExecutable(fileName, paths);
|
||||||
|
}
|
||||||
|
|
||||||
|
FilePath IDevice::searchExecutable(const QString &fileName, const FilePaths &dirs) const
|
||||||
|
{
|
||||||
|
for (const FilePath &dir : dirs) {
|
||||||
|
QTC_CHECK(handlesFile(dir));
|
||||||
|
const FilePath candidate = dir / fileName;
|
||||||
|
if (isExecutableFile(candidate))
|
||||||
|
return candidate;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
FilePath IDevice::symLinkTarget(const FilePath &filePath) const
|
FilePath IDevice::symLinkTarget(const FilePath &filePath) const
|
||||||
|
|||||||
@@ -249,8 +249,9 @@ public:
|
|||||||
virtual bool removeRecursively(const Utils::FilePath &filePath) const;
|
virtual bool removeRecursively(const Utils::FilePath &filePath) const;
|
||||||
virtual bool copyFile(const Utils::FilePath &filePath, const Utils::FilePath &target) const;
|
virtual bool copyFile(const Utils::FilePath &filePath, const Utils::FilePath &target) const;
|
||||||
virtual bool renameFile(const Utils::FilePath &filePath, const Utils::FilePath &target) const;
|
virtual bool renameFile(const Utils::FilePath &filePath, const Utils::FilePath &target) const;
|
||||||
virtual Utils::FilePath searchInPath(const Utils::FilePath &filePath,
|
virtual Utils::FilePath searchExecutableInPath(const QString &fileName) const;
|
||||||
const QList<Utils::FilePath> &additionalDirs = {}) const;
|
virtual Utils::FilePath searchExecutable(const QString &fileName,
|
||||||
|
const QList<Utils::FilePath> &dirs) const;
|
||||||
virtual Utils::FilePath symLinkTarget(const Utils::FilePath &filePath) const;
|
virtual Utils::FilePath symLinkTarget(const Utils::FilePath &filePath) const;
|
||||||
virtual QList<Utils::FilePath> directoryEntries(const Utils::FilePath &filePath,
|
virtual QList<Utils::FilePath> directoryEntries(const Utils::FilePath &filePath,
|
||||||
const QStringList &nameFilters,
|
const QStringList &nameFilters,
|
||||||
|
|||||||
Reference in New Issue
Block a user