forked from qt-creator/qt-creator
Docker: Correct environment for docker exec calls
Provide way to clean QtcProcess environment which is needed as e.g. toolchains, build tools, and debugger otherwise run inside a wrong environment when using docker exec for the respective process calls. Change-Id: Ia6de1c90f2134fce260d293a2f6937ab3cfca2ce Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -259,6 +259,12 @@ void QtcProcess::setEnvironment(const Environment &env)
|
|||||||
d->m_haveEnv = true;
|
d->m_haveEnv = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QtcProcess::unsetEnvironment()
|
||||||
|
{
|
||||||
|
d->m_environment = Environment();
|
||||||
|
d->m_haveEnv = false;
|
||||||
|
}
|
||||||
|
|
||||||
const Environment &QtcProcess::environment() const
|
const Environment &QtcProcess::environment() const
|
||||||
{
|
{
|
||||||
return d->m_environment;
|
return d->m_environment;
|
||||||
|
@@ -80,6 +80,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
void setEnvironment(const Environment &env);
|
void setEnvironment(const Environment &env);
|
||||||
|
void unsetEnvironment();
|
||||||
const Environment &environment() const;
|
const Environment &environment() const;
|
||||||
|
|
||||||
void setCommand(const CommandLine &cmdLine);
|
void setCommand(const CommandLine &cmdLine);
|
||||||
|
@@ -1396,12 +1396,24 @@ void DockerDevice::runProcess(QtcProcess &process) const
|
|||||||
|
|
||||||
const FilePath workingDir = process.workingDirectory();
|
const FilePath workingDir = process.workingDirectory();
|
||||||
const CommandLine origCmd = process.commandLine();
|
const CommandLine origCmd = process.commandLine();
|
||||||
|
const Environment env = process.environment();
|
||||||
|
|
||||||
CommandLine cmd{"docker", {"exec"}};
|
CommandLine cmd{"docker", {"exec"}};
|
||||||
if (!workingDir.isEmpty())
|
if (!workingDir.isEmpty())
|
||||||
cmd.addArgs({"-w", workingDir.path()});
|
cmd.addArgs({"-w", workingDir.path()});
|
||||||
if (process.keepsWriteChannelOpen())
|
if (process.keepsWriteChannelOpen())
|
||||||
cmd.addArg("-i");
|
cmd.addArg("-i");
|
||||||
|
if (env.size() != 0 && d->m_accessible != DockerDevicePrivate::Accessible) {
|
||||||
|
process.unsetEnvironment();
|
||||||
|
// FIXME the below would be probably correct if the respective tools would use correct
|
||||||
|
// environment already, but most are using the host environment which usually makes
|
||||||
|
// no sense on the device and may degrade performance
|
||||||
|
// const QStringList envList = env.toStringList();
|
||||||
|
// for (const QString &keyValue : envList) {
|
||||||
|
// cmd.addArg("-e");
|
||||||
|
// cmd.addArg(keyValue);
|
||||||
|
// }
|
||||||
|
}
|
||||||
cmd.addArg(d->m_container);
|
cmd.addArg(d->m_container);
|
||||||
cmd.addArg(origCmd.executable().path()); // Cut off the docker://.../ bits.
|
cmd.addArg(origCmd.executable().path()); // Cut off the docker://.../ bits.
|
||||||
cmd.addArgs(origCmd.splitArguments(osType()));
|
cmd.addArgs(origCmd.splitArguments(osType()));
|
||||||
|
Reference in New Issue
Block a user