QtcProcess: Extract QtcProcess specific enums into separate header

Change-Id: Ib3498f189000fd8f5501130c0d280b0f5ae83849
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2022-02-18 00:56:14 +01:00
parent 0ee07255f5
commit 48960b5cfc
19 changed files with 102 additions and 65 deletions

View File

@@ -121,6 +121,7 @@ add_qtc_library(Utils
porting.h
portlist.cpp portlist.h
predicates.h
processenums.h
processhandle.cpp processhandle.h
processreaper.cpp processreaper.h
processutils.cpp processutils.h

View File

@@ -28,7 +28,6 @@
#include "utils_global.h"
#include "processreaper.h"
#include "processutils.h"
#include "singleton.h"
#include <QThread>

View File

@@ -25,7 +25,7 @@
#pragma once
#include "processutils.h"
#include "processenums.h"
#include <QDataStream>
#include <QProcess>

View File

@@ -28,7 +28,6 @@
#include "environment.h"
#include "filepath.h"
#include "launcherpackets.h"
#include "processutils.h"
#include "qtcprocess.h"
#include <QDeadlineTimer>

View File

@@ -0,0 +1,55 @@
/****************************************************************************
**
** Copyright (C) 2022 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** 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
** 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.
**
** 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.
**
****************************************************************************/
#pragma once
#include <QMetaType>
namespace Utils {
enum class ProcessMode {
Reader, // This opens in ReadOnly mode if no write data or in ReadWrite mode otherwise,
// closes the write channel afterwards.
Writer // This opens in ReadWrite mode and doesn't close the write channel
};
enum class ProcessImpl {
QProcess,
ProcessLauncher,
Default // Defaults to ProcessLauncherImpl, if QTC_USE_QPROCESS env var is set
// it equals to QProcessImpl.
};
enum class TerminalMode {
Off,
Run,
Debug,
Suspend,
On = Run // Default mode for terminal set to on
};
} // namespace Utils
Q_DECLARE_METATYPE(Utils::ProcessMode);

View File

@@ -25,17 +25,13 @@
#pragma once
#include "processenums.h"
#include <QIODevice>
#include <QProcess>
namespace Utils {
enum class ProcessMode {
Reader, // This opens in ReadOnly mode if no write data or in ReadWrite mode otherwise,
// closes the write channel afterwards
Writer // This opens in ReadWrite mode and doesn't close the write channel
};
class ProcessStartHandler {
public:
ProcessStartHandler(QProcess *process) : m_process(process) {}
@@ -83,5 +79,3 @@ private:
};
} // namespace Utils
Q_DECLARE_METATYPE(Utils::ProcessMode);

View File

@@ -32,6 +32,7 @@
#include "launcherpackets.h"
#include "launchersocket.h"
#include "processreaper.h"
#include "processutils.h"
#include "stringutils.h"
#include "terminalprocess_p.h"
@@ -217,8 +218,7 @@ public:
class TerminalImpl : public ProcessInterface
{
public:
TerminalImpl(QObject *parent, QtcProcess::ProcessImpl processImpl,
QtcProcess::TerminalMode terminalMode)
TerminalImpl(QObject *parent, ProcessImpl processImpl, TerminalMode terminalMode)
: ProcessInterface(parent)
, m_terminal(this, processImpl, terminalMode)
{
@@ -431,11 +431,11 @@ void ProcessLauncherImpl::cancel()
m_handle->cancel();
}
static QtcProcess::ProcessImpl defaultProcessImpl()
static ProcessImpl defaultProcessImpl()
{
if (qEnvironmentVariableIsSet("QTC_USE_QPROCESS"))
return QtcProcess::QProcessImpl;
return QtcProcess::ProcessLauncherImpl;
return ProcessImpl::QProcess;
return ProcessImpl::ProcessLauncher;
}
class QtcProcessPrivate : public QObject
@@ -454,12 +454,12 @@ public:
ProcessInterface *createProcessInterface()
{
const QtcProcess::ProcessImpl impl = m_setup.m_processImpl == QtcProcess::DefaultImpl
const ProcessImpl impl = m_setup.m_processImpl == ProcessImpl::Default
? defaultProcessImpl() : m_setup.m_processImpl;
if (m_setup.m_terminalMode != QtcProcess::TerminalOff)
if (m_setup.m_terminalMode != TerminalMode::Off)
return new TerminalImpl(parent(), impl, m_setup.m_terminalMode);
else if (impl == QtcProcess::QProcessImpl)
else if (impl == ProcessImpl::QProcess)
return new QProcessImpl(parent());
return new ProcessLauncherImpl(parent());
}
@@ -717,7 +717,7 @@ void QtcProcess::setTerminalMode(TerminalMode mode)
d->m_setup.m_terminalMode = mode;
}
QtcProcess::TerminalMode QtcProcess::terminalMode() const
TerminalMode QtcProcess::terminalMode() const
{
return d->m_setup.m_terminalMode;
}

View File

@@ -29,7 +29,7 @@
#include "environment.h"
#include "commandline.h"
#include "processutils.h"
#include "processenums.h"
#include "qtcassert.h"
#include <QProcess>
@@ -63,20 +63,6 @@ public:
QtcProcess(QObject *parent = nullptr);
~QtcProcess();
enum ProcessImpl {
QProcessImpl,
ProcessLauncherImpl,
DefaultImpl,
};
enum TerminalMode {
TerminalOff,
TerminalRun,
TerminalDebug,
TerminalSuspend,
TerminalOn = TerminalRun // default mode for ON
};
void setProcessInterface(ProcessInterface *interface);
// ProcessInterface related
@@ -113,7 +99,7 @@ public:
void setTerminalMode(TerminalMode mode);
TerminalMode terminalMode() const;
bool usesTerminal() const { return terminalMode() != TerminalOff; }
bool usesTerminal() const { return terminalMode() != TerminalMode::Off; }
void setProcessMode(ProcessMode processMode);
ProcessMode processMode() const;
@@ -253,9 +239,9 @@ private:
class QTCREATOR_UTILS_EXPORT ProcessSetupData
{
public:
QtcProcess::ProcessImpl m_processImpl = QtcProcess::DefaultImpl;
ProcessImpl m_processImpl = ProcessImpl::Default;
ProcessMode m_processMode = ProcessMode::Reader;
QtcProcess::TerminalMode m_terminalMode = QtcProcess::TerminalOff;
TerminalMode m_terminalMode = TerminalMode::Off;
CommandLine m_commandLine;
FilePath m_workingDirectory;

View File

@@ -63,16 +63,16 @@
namespace Utils {
namespace Internal {
static QString modeOption(QtcProcess::TerminalMode m)
static QString modeOption(TerminalMode m)
{
switch (m) {
case QtcProcess::TerminalRun:
case TerminalMode::Run:
return QLatin1String("run");
case QtcProcess::TerminalDebug:
case TerminalMode::Debug:
return QLatin1String("debug");
case QtcProcess::TerminalSuspend:
case TerminalMode::Suspend:
return QLatin1String("suspend");
case QtcProcess::TerminalOff:
case TerminalMode::Off:
QTC_CHECK(false);
break;
}
@@ -123,15 +123,14 @@ static QString msgCannotExecute(const QString & p, const QString &why)
class TerminalProcessPrivate
{
public:
TerminalProcessPrivate(QObject *parent, QtcProcess::ProcessImpl processImpl,
QtcProcess::TerminalMode terminalMode)
TerminalProcessPrivate(QObject *parent, ProcessImpl processImpl, TerminalMode terminalMode)
: m_terminalMode(terminalMode)
, m_process(parent)
{
m_process.setProcessImpl(processImpl);
}
const QtcProcess::TerminalMode m_terminalMode;
const TerminalMode m_terminalMode;
FilePath m_workingDir;
Environment m_environment;
qint64 m_processId = 0;
@@ -161,9 +160,9 @@ public:
#endif
};
TerminalProcess::TerminalProcess(QObject *parent, QtcProcess::ProcessImpl processImpl,
QtcProcess::TerminalMode terminalMode) :
QObject(parent), d(new TerminalProcessPrivate(this, processImpl, terminalMode))
TerminalProcess::TerminalProcess(QObject *parent, ProcessImpl processImpl,
TerminalMode terminalMode)
: QObject(parent), d(new TerminalProcessPrivate(this, processImpl, terminalMode))
{
connect(&d->m_stubServer, &QLocalServer::newConnection,
this, &TerminalProcess::stubConnectionAvailable);
@@ -211,7 +210,7 @@ void TerminalProcess::start()
QString pcmd;
QString pargs;
if (d->m_terminalMode != QtcProcess::TerminalRun) { // The debugger engines already pre-process the arguments.
if (d->m_terminalMode != TerminalMode::Run) { // The debugger engines already pre-process the arguments.
pcmd = d->m_commandLine.executable().toString();
pargs = d->m_commandLine.arguments();
} else {
@@ -376,7 +375,7 @@ void TerminalProcess::start()
emitError(QProcess::FailedToStart, tr("Quoting error in command."));
return;
}
if (d->m_terminalMode == QtcProcess::TerminalDebug) {
if (d->m_terminalMode == TerminalMode::Debug) {
// FIXME: QTCREATORBUG-2809
emitError(QProcess::FailedToStart, tr("Debugging complex shell commands in a terminal"
" is currently not supported."));

View File

@@ -25,7 +25,9 @@
#pragma once
#include "qtcprocess.h"
#include "processenums.h"
#include <QProcess>
namespace Utils {
@@ -39,8 +41,7 @@ class TerminalProcess : public QObject
{
Q_OBJECT
public:
explicit TerminalProcess(QObject *parent, QtcProcess::ProcessImpl processImpl,
QtcProcess::TerminalMode terminalMode);
explicit TerminalProcess(QObject *parent, ProcessImpl processImpl, TerminalMode terminalMode);
~TerminalProcess() override;
void setCommand(const CommandLine &command);

View File

@@ -218,6 +218,7 @@ Project {
"porting.h",
"portlist.cpp",
"portlist.h",
"processenums.h",
"processhandle.cpp",
"processhandle.h",
"processreaper.cpp",

View File

@@ -196,7 +196,7 @@ void TerminalRunner::start()
m_stubProc = new QtcProcess(this);
m_stubProc->setTerminalMode(HostOsInfo::isWindowsHost()
? QtcProcess::TerminalSuspend : QtcProcess::TerminalDebug);
? TerminalMode::Suspend : TerminalMode::Debug);
connect(m_stubProc, &QtcProcess::errorOccurred,
this, &TerminalRunner::stubError);

View File

@@ -534,7 +534,7 @@ DockerDevice::DockerDevice(const DockerDeviceData &data)
}
QtcProcess *proc = new QtcProcess;
proc->setTerminalMode(QtcProcess::TerminalOn);
proc->setTerminalMode(TerminalMode::On);
QObject::connect(proc, &QtcProcess::finished, proc, &QObject::deleteLater);

View File

@@ -190,7 +190,7 @@ void ApplicationLauncherPrivate::stop()
return;
m_stopRequested = true;
emit q->appendMessage(ApplicationLauncher::tr("User requested stop. Shutting down..."),
Utils::NormalMessageFormat);
NormalMessageFormat);
switch (m_state) {
case Run:
m_process->terminate();
@@ -439,7 +439,7 @@ void ApplicationLauncherPrivate::start(const IDevice::ConstPtr &device, bool loc
this, &ApplicationLauncherPrivate::handleStandardOutput);
}
m_process->setTerminalMode(m_useTerminal ? QtcProcess::TerminalOn : QtcProcess::TerminalOff);
m_process->setTerminalMode(m_useTerminal ? Utils::TerminalMode::On : Utils::TerminalMode::Off);
m_process->start();
}

View File

@@ -1680,7 +1680,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
if (tmp < 0 || tmp > int(StopBeforeBuild::SameApp))
tmp = int(defaultSettings.stopBeforeBuild);
dd->m_projectExplorerSettings.stopBeforeBuild = StopBeforeBuild(tmp);
dd->m_projectExplorerSettings.terminalMode = static_cast<TerminalMode>(
dd->m_projectExplorerSettings.terminalMode = static_cast<Internal::TerminalMode>(
s->value(Constants::TERMINAL_MODE_SETTINGS_KEY, int(defaultSettings.terminalMode)).toInt());
dd->m_projectExplorerSettings.closeSourceFilesWithProject
= s->value(Constants::CLOSE_FILES_WITH_PROJECT_SETTINGS_KEY,

View File

@@ -108,7 +108,7 @@ void openPythonRepl(QObject *parent, const FilePath &file, ReplType type)
const auto args = QStringList{"-i"} + replImportArgs(file, type);
auto process = new QtcProcess(parent);
process->setTerminalMode(QtcProcess::TerminalOn);
process->setTerminalMode(TerminalMode::On);
const FilePath pythonCommand = detectPython(file);
process->setCommand({pythonCommand, args});
process->setWorkingDirectory(workingDir(file));

View File

@@ -287,7 +287,7 @@ public:
~LinuxDevicePrivate();
CommandLine fullLocalCommandLine(const CommandLine &remoteCommand,
QtcProcess::TerminalMode terminalMode,
TerminalMode terminalMode,
bool hasDisplay) const;
bool setupShell();
bool runInShell(const CommandLine &cmd, const QByteArray &data = {});
@@ -335,7 +335,7 @@ LinuxDevice::LinuxDevice()
if (env.size() > 0)
proc->setCommand({"/bin/sh", {}});
proc->setTerminalMode(QtcProcess::TerminalOn);
proc->setTerminalMode(TerminalMode::On);
proc->setEnvironment(env);
proc->setWorkingDirectory(workingDir);
proc->start();
@@ -438,7 +438,7 @@ bool LinuxDevice::handlesFile(const FilePath &filePath) const
}
CommandLine LinuxDevicePrivate::fullLocalCommandLine(const CommandLine &remoteCommand,
QtcProcess::TerminalMode terminalMode,
TerminalMode terminalMode,
bool hasDisplay) const
{
Utils::CommandLine cmd{SshSettings::sshFilePath()};
@@ -446,7 +446,7 @@ CommandLine LinuxDevicePrivate::fullLocalCommandLine(const CommandLine &remoteCo
if (hasDisplay)
cmd.addArg("-X");
if (terminalMode != QtcProcess::TerminalOff)
if (terminalMode != TerminalMode::Off)
cmd.addArg("-tt");
cmd.addArg("-q");

View File

@@ -12,6 +12,7 @@ add_qtc_executable(qtcreator_processlauncher
processlauncher-main.cpp
${UTILSDIR}/launcherpackets.cpp
${UTILSDIR}/launcherpackets.h
${UTILSDIR}/processenums.h
${UTILSDIR}/processreaper.cpp
${UTILSDIR}/processreaper.h
${UTILSDIR}/processutils.cpp

View File

@@ -29,6 +29,7 @@ QtcTool {
files: [
"launcherpackets.cpp",
"launcherpackets.h",
"processenums.h",
"processreaper.cpp",
"processreaper.h",
"processutils.cpp",