From 6360cffc80a4a309f39c1756834a9b76fd4bb9a9 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Thu, 17 Feb 2022 16:27:11 +0100 Subject: [PATCH] Fix passing environment to remote After removing Runnable parameter from DeviceProcess::start() (see 95c9579c58d8cd9dfacbeee70f84920ab9cf87e7) we are now setting the runnable's environment to the remote process directly. This is now used in 2 places: 1. For forming the proper fullCommandLine(), so that the passed environment is expanded to command line arguments 2. For running the remote process itself. Before the mentioned change these two environments were separated (1st was taken from run environment aspect, 2nd was left with its default value - see SshProcess c'tor). After the mentioned change 1 and 2 are equal (i.e. both are env aspect). This affects running app in terminal, as the aspect env is applied to the stub process, so it can't start properly. This change brings the separation back. Amends 95c9579c58d8cd9dfacbeee70f84920ab9cf87e7 Change-Id: I5efe82e19d3fb5608f97e56c2f4b7651643e156a Reviewed-by: hjk Reviewed-by: Qt CI Bot --- src/libs/utils/processinterface.h | 1 + src/libs/utils/qtcprocess.cpp | 10 ++++++++++ src/libs/utils/qtcprocess.h | 3 +++ src/plugins/projectexplorer/applicationlauncher.cpp | 2 +- src/plugins/qnx/qnxdeviceprocess.cpp | 2 +- src/plugins/remotelinux/linuxdeviceprocess.cpp | 2 +- 6 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/libs/utils/processinterface.h b/src/libs/utils/processinterface.h index 2e02c160d15..3b5e360e455 100644 --- a/src/libs/utils/processinterface.h +++ b/src/libs/utils/processinterface.h @@ -45,6 +45,7 @@ public: CommandLine m_commandLine; FilePath m_workingDirectory; Environment m_environment; + Environment m_remoteEnvironment; QByteArray m_writeData; QProcess::ProcessChannelMode m_processChannelMode = QProcess::SeparateChannels; QVariantHash m_extraData; diff --git a/src/libs/utils/qtcprocess.cpp b/src/libs/utils/qtcprocess.cpp index a83b9003ec2..91fa2f84b85 100644 --- a/src/libs/utils/qtcprocess.cpp +++ b/src/libs/utils/qtcprocess.cpp @@ -772,6 +772,16 @@ bool QtcProcess::hasEnvironment() const return d->m_setup.m_haveEnv; } +void QtcProcess::setRemoteEnvironment(const Environment &environment) +{ + d->m_setup.m_remoteEnvironment = environment; +} + +Environment QtcProcess::remoteEnvironment() const +{ + return d->m_setup.m_remoteEnvironment; +} + void QtcProcess::setCommand(const CommandLine &cmdLine) { if (d->m_setup.m_workingDirectory.needsDevice() && cmdLine.executable().needsDevice()) { diff --git a/src/libs/utils/qtcprocess.h b/src/libs/utils/qtcprocess.h index d666a5f3e77..01eb37951a8 100644 --- a/src/libs/utils/qtcprocess.h +++ b/src/libs/utils/qtcprocess.h @@ -102,6 +102,9 @@ public: const Environment &environment() const; bool hasEnvironment() const; + void setRemoteEnvironment(const Environment &env); + Environment remoteEnvironment() const; + void setCommand(const CommandLine &cmdLine); const CommandLine &commandLine() const; diff --git a/src/plugins/projectexplorer/applicationlauncher.cpp b/src/plugins/projectexplorer/applicationlauncher.cpp index 8066955d90e..2aacfd09809 100644 --- a/src/plugins/projectexplorer/applicationlauncher.cpp +++ b/src/plugins/projectexplorer/applicationlauncher.cpp @@ -408,7 +408,7 @@ void ApplicationLauncherPrivate::start(const IDevice::ConstPtr &device, bool loc this, &ApplicationLauncherPrivate::handleApplicationFinished); m_process->setCommand(m_runnable.command); m_process->setWorkingDirectory(m_runnable.workingDirectory); - m_process->setEnvironment(m_runnable.environment); + m_process->setRemoteEnvironment(m_runnable.environment); m_process->setExtraData(m_runnable.extraData); } diff --git a/src/plugins/qnx/qnxdeviceprocess.cpp b/src/plugins/qnx/qnxdeviceprocess.cpp index c04b9dd6d74..3236ba62d24 100644 --- a/src/plugins/qnx/qnxdeviceprocess.cpp +++ b/src/plugins/qnx/qnxdeviceprocess.cpp @@ -59,7 +59,7 @@ QString QnxDeviceProcess::fullCommandLine() const fullCommandLine += QString::fromLatin1("cd %1 ; ").arg( ProcessArgs::quoteArg(workingDirectory().toString())); - const Environment env = environment(); + const Environment env = remoteEnvironment(); for (auto it = env.constBegin(); it != env.constEnd(); ++it) { fullCommandLine += QString::fromLatin1("%1='%2' ") .arg(env.key(it)).arg(env.expandedValueForKey(env.key(it))); diff --git a/src/plugins/remotelinux/linuxdeviceprocess.cpp b/src/plugins/remotelinux/linuxdeviceprocess.cpp index eb2e0742a47..f3da62a53a9 100644 --- a/src/plugins/remotelinux/linuxdeviceprocess.cpp +++ b/src/plugins/remotelinux/linuxdeviceprocess.cpp @@ -99,7 +99,7 @@ QString LinuxDeviceProcess::fullCommandLine() const if (!usesTerminal()) cmd.addArgs(QString("echo ") + pidMarker + "$$" + pidMarker + " && ", CommandLine::Raw); - const Environment &env = environment(); + const Environment &env = remoteEnvironment(); for (auto it = env.constBegin(); it != env.constEnd(); ++it) cmd.addArgs(env.key(it) + "='" + env.expandedValueForKey(env.key(it)) + '\'', CommandLine::Raw);