2013-08-08 14:05:11 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2013-08-08 14:05:11 +02:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2013-08-08 14:05:11 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2013-08-08 14:05:11 +02:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
2016-01-15 14:57:40 +01:00
|
|
|
|
2013-08-08 14:05:11 +02:00
|
|
|
#include "linuxdeviceprocess.h"
|
|
|
|
|
|
2019-03-13 08:06:08 +01:00
|
|
|
#include <projectexplorer/runcontrol.h>
|
2016-01-27 18:25:13 +01:00
|
|
|
|
2013-08-08 14:05:11 +02:00
|
|
|
#include <utils/environment.h>
|
|
|
|
|
|
2016-01-27 18:25:13 +01:00
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
using namespace Utils;
|
|
|
|
|
|
2013-08-08 14:05:11 +02:00
|
|
|
namespace RemoteLinux {
|
|
|
|
|
|
|
|
|
|
LinuxDeviceProcess::LinuxDeviceProcess(const QSharedPointer<const ProjectExplorer::IDevice> &device,
|
2019-01-09 10:59:42 +01:00
|
|
|
QObject *parent)
|
2016-04-21 11:49:10 +02:00
|
|
|
: ProjectExplorer::SshDeviceProcess(device, parent), m_processId(0)
|
2013-08-08 14:05:11 +02:00
|
|
|
{
|
2016-04-21 11:49:10 +02:00
|
|
|
connect(this, &DeviceProcess::finished, this, [this]() {
|
2019-02-12 11:40:15 +01:00
|
|
|
m_processId = -1;
|
|
|
|
|
});
|
|
|
|
|
connect(this, &DeviceProcess::started, this, [this]() {
|
2016-04-21 11:49:10 +02:00
|
|
|
m_processId = 0;
|
|
|
|
|
});
|
2013-08-08 14:05:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LinuxDeviceProcess::setRcFilesToSource(const QStringList &filePaths)
|
|
|
|
|
{
|
|
|
|
|
m_rcFilesToSource = filePaths;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-21 11:49:10 +02:00
|
|
|
QByteArray LinuxDeviceProcess::readAllStandardOutput()
|
|
|
|
|
{
|
|
|
|
|
QByteArray output = SshDeviceProcess::readAllStandardOutput();
|
2019-01-10 09:21:26 +01:00
|
|
|
if (m_processId != 0 || runInTerminal())
|
2016-04-21 11:49:10 +02:00
|
|
|
return output;
|
|
|
|
|
|
|
|
|
|
m_processIdString.append(output);
|
|
|
|
|
int cut = m_processIdString.indexOf('\n');
|
|
|
|
|
if (cut != -1) {
|
|
|
|
|
m_processId = m_processIdString.left(cut).toLongLong();
|
|
|
|
|
output = m_processIdString.mid(cut + 1);
|
|
|
|
|
m_processIdString.clear();
|
|
|
|
|
return output;
|
|
|
|
|
}
|
|
|
|
|
return QByteArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qint64 LinuxDeviceProcess::processId() const
|
|
|
|
|
{
|
2019-02-12 11:40:15 +01:00
|
|
|
return m_processId < 0 ? 0 : m_processId;
|
2016-04-21 11:49:10 +02:00
|
|
|
}
|
|
|
|
|
|
2018-05-16 13:49:32 +02:00
|
|
|
QString LinuxDeviceProcess::fullCommandLine(const Runnable &runnable) const
|
2013-08-08 14:05:11 +02:00
|
|
|
{
|
2019-06-04 15:59:30 +02:00
|
|
|
CommandLine cmd;
|
2013-08-08 14:05:11 +02:00
|
|
|
|
2019-06-04 15:59:30 +02:00
|
|
|
for (const QString &filePath : rcFilesToSource()) {
|
|
|
|
|
cmd.addArgs({"test", "-f", filePath});
|
2019-06-05 15:35:15 +02:00
|
|
|
cmd.addArgs("&&", CommandLine::Raw);
|
2019-06-04 15:59:30 +02:00
|
|
|
cmd.addArgs({".", filePath});
|
2019-06-05 15:35:15 +02:00
|
|
|
cmd.addArgs(";", CommandLine::Raw);
|
2013-08-08 14:05:11 +02:00
|
|
|
}
|
2019-06-04 15:59:30 +02:00
|
|
|
|
|
|
|
|
if (!runnable.workingDirectory.isEmpty()) {
|
|
|
|
|
cmd.addArgs({"cd", runnable.workingDirectory});
|
2019-06-05 15:35:15 +02:00
|
|
|
cmd.addArgs("&&", CommandLine::Raw);
|
2014-05-06 15:23:24 +02:00
|
|
|
}
|
2019-06-04 15:59:30 +02:00
|
|
|
|
2019-01-10 09:21:26 +01:00
|
|
|
if (!runInTerminal())
|
2019-06-05 15:35:15 +02:00
|
|
|
cmd.addArgs("echo $$ && ", CommandLine::Raw);
|
2019-06-04 15:59:30 +02:00
|
|
|
|
|
|
|
|
const Environment &env = runnable.environment;
|
|
|
|
|
for (auto it = env.constBegin(); it != env.constEnd(); ++it)
|
2019-08-19 14:29:14 +02:00
|
|
|
cmd.addArgs(env.key(it) + "='" + env.expandedValueForKey(env.key(it)) + '\'', CommandLine::Raw);
|
2019-06-04 15:59:30 +02:00
|
|
|
|
2019-01-10 09:21:26 +01:00
|
|
|
if (!runInTerminal())
|
2019-06-04 15:59:30 +02:00
|
|
|
cmd.addArg("exec");
|
|
|
|
|
|
2019-06-20 17:19:12 +02:00
|
|
|
cmd.addArg(runnable.executable.toString());
|
2019-06-05 15:35:15 +02:00
|
|
|
cmd.addArgs(runnable.commandLineArguments, CommandLine::Raw);
|
2019-06-04 15:59:30 +02:00
|
|
|
|
|
|
|
|
return cmd.arguments();
|
2013-08-08 14:05:11 +02:00
|
|
|
}
|
|
|
|
|
|
2019-06-04 15:59:30 +02:00
|
|
|
const QStringList LinuxDeviceProcess::rcFilesToSource() const
|
2013-08-08 14:05:11 +02:00
|
|
|
{
|
|
|
|
|
if (!m_rcFilesToSource.isEmpty())
|
|
|
|
|
return m_rcFilesToSource;
|
2019-06-04 15:59:30 +02:00
|
|
|
return {"/etc/profile", "$HOME/.profile"};
|
2013-08-08 14:05:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace RemoteLinux
|