Utils: Continue Environment/EnvironmentChange consolidation

Make Environment a stack of changes that gets "expanded" to
a full environment before things are actively accessed.

Later this expansion should be done lazily if possible.

Task-number: QTCREATORBUG-28357
Change-Id: If1c7bfdb9f58b81e71c51ed87ee75d6964a47019
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
hjk
2023-01-26 17:48:36 +01:00
parent ae4e178221
commit 2766b4004b
16 changed files with 261 additions and 206 deletions

View File

@@ -338,9 +338,6 @@ Environment LinuxDevicePrivate::getEnvironment()
QtcProcess getEnvProc;
getEnvProc.setCommand({FilePath("env").onDevice(q->rootPath()), {}});
Environment inEnv;
inEnv.setCombineWithDeviceEnvironment(false);
getEnvProc.setEnvironment(inEnv);
getEnvProc.runBlocking();
const QString remoteOutput = getEnvProc.cleanedStdOut();
@@ -919,16 +916,11 @@ LinuxDevice::LinuxDevice()
d->m_terminals.removeOne(proc);
});
// We recreate the same way that QtcProcess uses to create the actual environment.
const Environment finalEnv = (!env.hasChanges() && env.combineWithDeviceEnvironment())
? d->getEnvironment()
: env;
// If we will not set any environment variables, we can leave out the shell executable
// as the "ssh ..." call will automatically launch the default shell if there are
// no arguments. But if we will set environment variables, we need to explicitly
// specify the shell executable.
const QString shell = finalEnv.hasChanges() ? finalEnv.value_or("SHELL", "/bin/sh")
: QString();
const QString shell = env.hasChanges() ? env.value_or("SHELL", "/bin/sh") : QString();
proc->setCommand({filePath(shell), {}});
proc->setTerminalMode(TerminalMode::On);