forked from qt-creator/qt-creator
RemoteLinux: Use Util::CommandLine to construct device process commands
Change-Id: I194b5225f56cabd92e1de7d3df2e74b515aa476e Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -28,15 +28,12 @@
|
|||||||
#include <projectexplorer/runcontrol.h>
|
#include <projectexplorer/runcontrol.h>
|
||||||
|
|
||||||
#include <utils/environment.h>
|
#include <utils/environment.h>
|
||||||
#include <utils/qtcprocess.h>
|
|
||||||
|
|
||||||
using namespace ProjectExplorer;
|
using namespace ProjectExplorer;
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
namespace RemoteLinux {
|
namespace RemoteLinux {
|
||||||
|
|
||||||
static QString quote(const QString &s) { return Utils::QtcProcess::quoteArgUnix(s); }
|
|
||||||
|
|
||||||
LinuxDeviceProcess::LinuxDeviceProcess(const QSharedPointer<const ProjectExplorer::IDevice> &device,
|
LinuxDeviceProcess::LinuxDeviceProcess(const QSharedPointer<const ProjectExplorer::IDevice> &device,
|
||||||
QObject *parent)
|
QObject *parent)
|
||||||
: ProjectExplorer::SshDeviceProcess(device, parent), m_processId(0)
|
: ProjectExplorer::SshDeviceProcess(device, parent), m_processId(0)
|
||||||
@@ -78,42 +75,41 @@ qint64 LinuxDeviceProcess::processId() const
|
|||||||
|
|
||||||
QString LinuxDeviceProcess::fullCommandLine(const Runnable &runnable) const
|
QString LinuxDeviceProcess::fullCommandLine(const Runnable &runnable) const
|
||||||
{
|
{
|
||||||
const Environment env = runnable.environment;
|
CommandLine cmd;
|
||||||
|
|
||||||
|
for (const QString &filePath : rcFilesToSource()) {
|
||||||
|
cmd.addArgs({"test", "-f", filePath});
|
||||||
|
cmd.addArgs("&&");
|
||||||
|
cmd.addArgs({".", filePath});
|
||||||
|
cmd.addArgs(";");
|
||||||
|
}
|
||||||
|
|
||||||
QString fullCommandLine;
|
|
||||||
foreach (const QString &filePath, rcFilesToSource())
|
|
||||||
fullCommandLine += QString::fromLatin1("test -f %1 && . %1;").arg(filePath);
|
|
||||||
if (!runnable.workingDirectory.isEmpty()) {
|
if (!runnable.workingDirectory.isEmpty()) {
|
||||||
fullCommandLine.append(QLatin1String("cd ")).append(quote(runnable.workingDirectory))
|
cmd.addArgs({"cd", runnable.workingDirectory});
|
||||||
.append(QLatin1String(" && "));
|
cmd.addArgs("&&");
|
||||||
}
|
|
||||||
QString envString;
|
|
||||||
for (auto it = env.constBegin(); it != env.constEnd(); ++it) {
|
|
||||||
if (!envString.isEmpty())
|
|
||||||
envString += QLatin1Char(' ');
|
|
||||||
envString.append(env.key(it)).append(QLatin1String("='")).append(env.value(it))
|
|
||||||
.append(QLatin1Char('\''));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!runInTerminal())
|
if (!runInTerminal())
|
||||||
fullCommandLine.append("echo $$ && ");
|
cmd.addArgs("echo $$ && ");
|
||||||
if (!envString.isEmpty())
|
|
||||||
fullCommandLine.append(envString);
|
const Environment &env = runnable.environment;
|
||||||
|
for (auto it = env.constBegin(); it != env.constEnd(); ++it)
|
||||||
|
cmd.addArgs(env.key(it) + "='" + env.value(it) + '\'');
|
||||||
|
|
||||||
if (!runInTerminal())
|
if (!runInTerminal())
|
||||||
fullCommandLine.append(" exec");
|
cmd.addArg("exec");
|
||||||
fullCommandLine.append(' ');
|
|
||||||
fullCommandLine.append(quote(runnable.executable));
|
cmd.addArg(runnable.executable);
|
||||||
if (!runnable.commandLineArguments.isEmpty()) {
|
cmd.addArgs(runnable.commandLineArguments);
|
||||||
fullCommandLine.append(QLatin1Char(' '));
|
|
||||||
fullCommandLine.append(runnable.commandLineArguments);
|
return cmd.arguments();
|
||||||
}
|
|
||||||
return fullCommandLine;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList LinuxDeviceProcess::rcFilesToSource() const
|
const QStringList LinuxDeviceProcess::rcFilesToSource() const
|
||||||
{
|
{
|
||||||
if (!m_rcFilesToSource.isEmpty())
|
if (!m_rcFilesToSource.isEmpty())
|
||||||
return m_rcFilesToSource;
|
return m_rcFilesToSource;
|
||||||
return QStringList() << QLatin1String("/etc/profile") << QLatin1String("$HOME/.profile");
|
return {"/etc/profile", "$HOME/.profile"};
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace RemoteLinux
|
} // namespace RemoteLinux
|
||||||
|
@@ -49,7 +49,7 @@ private:
|
|||||||
QString fullCommandLine(const ProjectExplorer::Runnable &) const override;
|
QString fullCommandLine(const ProjectExplorer::Runnable &) const override;
|
||||||
qint64 processId() const override;
|
qint64 processId() const override;
|
||||||
|
|
||||||
QStringList rcFilesToSource() const;
|
const QStringList rcFilesToSource() const;
|
||||||
|
|
||||||
QStringList m_rcFilesToSource;
|
QStringList m_rcFilesToSource;
|
||||||
QByteArray m_processIdString;
|
QByteArray m_processIdString;
|
||||||
|
Reference in New Issue
Block a user