Docker: Implement DockerDevice::systemEnvironment() function

For synchronous retrieval of the system environment of the device.

Change-Id: I057f9591866b72e37733d495a2a6b203fae91ac4
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2021-05-26 17:18:40 +02:00
parent 523ae2c868
commit e8286088b1
2 changed files with 26 additions and 0 deletions

View File

@@ -294,6 +294,8 @@ public:
QList<ToolChain *> autoDetectToolChains();
void autoDetectCMake();
void fetchSystemEnviroment();
DockerDevice *q;
DockerDeviceData m_data;
@@ -302,6 +304,8 @@ public:
QString m_container;
QString m_mergedDir;
QFileSystemWatcher m_mergedDirWatcher;
Environment m_cachedEnviroment;
};
DockerDevice::DockerDevice(const DockerDeviceData &data)
@@ -730,6 +734,26 @@ void DockerDevice::runProcess(QtcProcess &process) const
process.start();
}
Environment DockerDevice::systemEnvironment() const
{
if (d->m_cachedEnviroment.size() == 0)
d->fetchSystemEnviroment();
QTC_CHECK(d->m_cachedEnviroment.size() != 0);
return d->m_cachedEnviroment;
}
void DockerDevicePrivate::fetchSystemEnviroment()
{
SynchronousProcess proc;
proc.setCommand({"env", {}});
proc.runBlocking();
const QString remoteOutput = proc.stdOut();
m_cachedEnviroment = Environment(remoteOutput.split('\n', Qt::SkipEmptyParts), q->osType());
}
int DockerDevicePrivate::runSynchronously(const CommandLine &cmd) const
{
CommandLine dcmd{"docker", {"exec", m_container}};

View File

@@ -84,6 +84,8 @@ public:
QByteArray fileContents(const Utils::FilePath &filePath, int limit) const override;
void runProcess(Utils::QtcProcess &process) const override;
Utils::Environment systemEnvironment() const override;
const DockerDeviceData &data() const;
void tryCreateLocalFileAccess() const;