LinuxDevice: Implement runProcess()

Change-Id: I5300d36119ffb9fdd82a2ba7e02f76edc0fe2eda
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2022-02-03 13:20:15 +01:00
parent 9a5cb5896e
commit f5b946abbe
5 changed files with 71 additions and 12 deletions

View File

@@ -286,6 +286,9 @@ public:
explicit LinuxDevicePrivate(LinuxDevice *parent);
~LinuxDevicePrivate();
CommandLine fullLocalCommandLine(const CommandLine &remoteCommand,
QtcProcess::TerminalMode terminalMode,
bool hasDisplay) const;
bool setupShell();
bool runInShell(const CommandLine &cmd, const QByteArray &data = {});
QString outputForRunInShell(const QString &cmd);
@@ -414,9 +417,7 @@ DeviceEnvironmentFetcher::Ptr LinuxDevice::environmentFetcher() const
QString LinuxDevice::userAtHost() const
{
if (sshParameters().userName().isEmpty())
return sshParameters().host();
return sshParameters().userName() + '@' + sshParameters().host();
return sshParameters().userAtHost();
}
FilePath LinuxDevice::mapToGlobalPath(const FilePath &pathOnDevice) const
@@ -438,9 +439,53 @@ bool LinuxDevice::handlesFile(const FilePath &filePath) const
return filePath.scheme() == "ssh" && filePath.host() == userAtHost();
}
void LinuxDevice::runProcess(QtcProcess &) const
CommandLine LinuxDevicePrivate::fullLocalCommandLine(const CommandLine &remoteCommand,
QtcProcess::TerminalMode terminalMode,
bool hasDisplay) const
{
QTC_CHECK(false); // FIXME: Implement
Utils::CommandLine cmd{SshSettings::sshFilePath()};
const SshConnectionParameters parameters = q->sshParameters();
if (hasDisplay)
cmd.addArg("-X");
if (terminalMode != QtcProcess::TerminalOff)
cmd.addArg("-tt");
cmd.addArg("-q");
// TODO: currently this drops shared connection (-o ControlPath=socketFilePath)
cmd.addArgs(parameters.connectionOptions(SshSettings::sshFilePath()) << parameters.host());
CommandLine remoteWithLocalPath = remoteCommand;
FilePath executable = remoteWithLocalPath.executable();
executable.setScheme({});
executable.setHost({});
remoteWithLocalPath.setExecutable(executable);
cmd.addArg(remoteWithLocalPath.toUserOutput());
return cmd;
}
void LinuxDevice::runProcess(QtcProcess &process) const
{
QTC_ASSERT(!process.isRunning(), return);
Utils::Environment env = process.hasEnvironment() ? process.environment()
: Utils::Environment::systemEnvironment();
const bool hasDisplay = env.hasKey("DISPLAY") && (env.value("DISPLAY") != QString(":0"));
if (SshSettings::askpassFilePath().exists()) {
env.set("SSH_ASKPASS", SshSettings::askpassFilePath().toUserOutput());
// OpenSSH only uses the askpass program if DISPLAY is set, regardless of the platform.
if (!env.hasKey("DISPLAY"))
env.set("DISPLAY", ":0");
}
process.setEnvironment(env);
// Otherwise, ssh will ignore SSH_ASKPASS and read from /dev/tty directly.
process.setDisableUnixTerminal();
process.setCommand(d->fullLocalCommandLine(process.commandLine(), process.terminalMode(),
hasDisplay));
process.start();
}
LinuxDevicePrivate::LinuxDevicePrivate(LinuxDevice *parent)