Process: Use more rawStd{Out,Err} const methods instead of mutable ones

Avoid using readAllStandard{Output,Error} mutable methods if possible.
Use non-mutable methods when we are not connected to
readyReadStandard{Output,Error} signals.

Change-Id: I2e830e571b9eab2177fd856bbe06dfc5137d9c01
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Jarek Kobus
2024-01-21 17:17:46 +01:00
parent 6ed9552be2
commit 290121bc21
25 changed files with 32 additions and 36 deletions

View File

@@ -1035,7 +1035,7 @@ expected_str<QByteArray> UnixDeviceFileAccess::fileContents(const FilePath &file
return make_unexpected(Tr::tr("Failed reading file \"%1\": %2") return make_unexpected(Tr::tr("Failed reading file \"%1\": %2")
.arg(filePath.toUserOutput(), p.readAllStandardError())); .arg(filePath.toUserOutput(), p.readAllStandardError()));
} }
return p.readAllRawStandardOutput(); return p.rawStdOut();
#else #else
return make_unexpected(QString("Not implemented")); return make_unexpected(QString("Not implemented"));
#endif #endif

View File

@@ -90,8 +90,8 @@ RunResult DeviceShell::run(const CommandLine &cmd, const QByteArray &stdInData)
return RunResult{ return RunResult{
proc.exitCode(), proc.exitCode(),
proc.readAllRawStandardOutput(), proc.rawStdOut(),
proc.readAllRawStandardError() proc.rawStdErr()
}; };
} }

View File

@@ -253,7 +253,7 @@ bool AndroidAvdManager::startAvdAsync(const QString &avdName) const
avdProcess->setProcessChannelMode(QProcess::MergedChannels); avdProcess->setProcessChannelMode(QProcess::MergedChannels);
QObject::connect(avdProcess, &Process::done, avdProcess, [avdProcess] { QObject::connect(avdProcess, &Process::done, avdProcess, [avdProcess] {
if (avdProcess->exitCode()) { if (avdProcess->exitCode()) {
const QString errorOutput = QString::fromLatin1(avdProcess->readAllRawStandardOutput()); const QString errorOutput = QString::fromLatin1(avdProcess->rawStdOut());
QMetaObject::invokeMethod(Core::ICore::mainWindow(), [errorOutput] { QMetaObject::invokeMethod(Core::ICore::mainWindow(), [errorOutput] {
const QString title = Tr::tr("AVD Start Error"); const QString title = Tr::tr("AVD Start Error");
QMessageBox::critical(Core::ICore::dialogParent(), title, errorOutput); QMessageBox::critical(Core::ICore::dialogParent(), title, errorOutput);

View File

@@ -1525,7 +1525,7 @@ FilePath AndroidConfig::getJdkPath()
findJdkPathProc.setCommand({"sh", args}); findJdkPathProc.setCommand({"sh", args});
findJdkPathProc.start(); findJdkPathProc.start();
findJdkPathProc.waitForFinished(); findJdkPathProc.waitForFinished();
QByteArray jdkPath = findJdkPathProc.readAllRawStandardOutput().trimmed(); QByteArray jdkPath = findJdkPathProc.rawStdOut().trimmed();
if (HostOsInfo::isMacHost()) { if (HostOsInfo::isMacHost()) {
jdkHome = FilePath::fromUtf8(jdkPath); jdkHome = FilePath::fromUtf8(jdkPath);

View File

@@ -79,9 +79,9 @@ AxivionQueryRunner::AxivionQueryRunner(const AxivionQuery &query, QObject *paren
start(); start();
return; return;
} }
emit resultRetrieved(m_process.readAllRawStandardError()); emit resultRetrieved(m_process.rawStdErr());
} else { } else {
emit resultRetrieved(m_process.readAllRawStandardOutput()); emit resultRetrieved(m_process.rawStdOut());
} }
emit finished(); emit finished();
}); });

View File

@@ -1892,8 +1892,7 @@ void CMakeBuildSystem::runCTest()
m_ctestProcess->setCommand({m_ctestPath, { "-N", "--show-only=json-v1"}}); m_ctestProcess->setCommand({m_ctestPath, { "-N", "--show-only=json-v1"}});
connect(m_ctestProcess.get(), &Process::done, this, [this] { connect(m_ctestProcess.get(), &Process::done, this, [this] {
if (m_ctestProcess->result() == ProcessResult::FinishedWithSuccess) { if (m_ctestProcess->result() == ProcessResult::FinishedWithSuccess) {
const QJsonDocument json const QJsonDocument json = QJsonDocument::fromJson(m_ctestProcess->rawStdOut());
= QJsonDocument::fromJson(m_ctestProcess->readAllRawStandardOutput());
if (!json.isEmpty() && json.isObject()) { if (!json.isEmpty() && json.isObject()) {
const QJsonObject jsonObj = json.object(); const QJsonObject jsonObj = json.object();
const QJsonObject btGraph = jsonObj.value("backtraceGraph").toObject(); const QJsonObject btGraph = jsonObj.value("backtraceGraph").toObject();

View File

@@ -20,7 +20,7 @@ CppcheckRunner::CppcheckRunner(CppcheckTool &tool) : m_tool(tool)
getConf.setCommand({"getconf", {"ARG_MAX"}}); getConf.setCommand({"getconf", {"ARG_MAX"}});
getConf.start(); getConf.start();
getConf.waitForFinished(2000); getConf.waitForFinished(2000);
const QByteArray argMax = getConf.readAllRawStandardOutput().replace("\n", ""); const QByteArray argMax = getConf.rawStdOut().replace("\n", "");
m_maxArgumentsLength = std::max(argMax.toInt(), m_maxArgumentsLength); m_maxArgumentsLength = std::max(argMax.toInt(), m_maxArgumentsLength);
} }

View File

@@ -363,7 +363,7 @@ static FilePath getClangHeadersPathFromClang(const FilePath &clangdFilePath)
if (!clang.waitForFinished()) if (!clang.waitForFinished())
return {}; return {};
const FilePath resourceDir = FilePath::fromUserInput(QString::fromLocal8Bit( const FilePath resourceDir = FilePath::fromUserInput(QString::fromLocal8Bit(
clang.readAllRawStandardOutput().trimmed())); clang.rawStdOut().trimmed()));
if (resourceDir.isEmpty() || !resourceDir.exists()) if (resourceDir.isEmpty() || !resourceDir.exists())
return {}; return {};
const FilePath includeDir = resourceDir.pathAppended("include"); const FilePath includeDir = resourceDir.pathAppended("include");

View File

@@ -475,7 +475,7 @@ void CppModelManager::showPreprocessedFile(bool inNextSplit)
return; return;
} }
if (isMsvc) if (isMsvc)
saveAndOpen(outFilePath, compiler->readAllRawStandardOutput(), inNextSplit); saveAndOpen(outFilePath, compiler->rawStdOut(), inNextSplit);
else else
openEditor(outFilePath, inNextSplit, Core::Constants::K_DEFAULT_TEXT_EDITOR_ID); openEditor(outFilePath, inNextSplit, Core::Constants::K_DEFAULT_TEXT_EDITOR_ID);
}); });

View File

@@ -110,7 +110,7 @@ QueryRunner::QueryRunner(const Query &query, const Id &id, QObject *parent)
} }
VcsBase::VcsOutputWindow::appendError(m_process.exitMessage()); VcsBase::VcsOutputWindow::appendError(m_process.exitMessage());
} else { } else {
emit resultRetrieved(m_process.readAllRawStandardOutput()); emit resultRetrieved(m_process.rawStdOut());
} }
emit finished(); emit finished();
}); });

View File

@@ -42,7 +42,7 @@ inline bool run_meson(const Command &command, QIODevice *output = nullptr)
if (!process.waitForFinished()) if (!process.waitForFinished())
return false; return false;
if (output) { if (output) {
output->write(process.readAllRawStandardOutput()); output->write(process.rawStdOut());
} }
return process.exitCode() == 0; return process.exitCode() == 0;
} }

View File

@@ -165,9 +165,8 @@ void PerfConfigWidget::handleProcessDone()
useTracePointsButton->setEnabled(true); useTracePointsButton->setEnabled(true);
return; return;
} }
const QList<QByteArray> lines = const QList<QByteArray> lines
m_process->readAllRawStandardOutput().append(m_process->readAllRawStandardError()) = m_process->rawStdOut().append(m_process->rawStdErr()).split('\n');
.split('\n');
auto model = eventsView->model(); auto model = eventsView->model();
const int previousRows = model->rowCount(); const int previousRows = model->rowCount();
QHash<QByteArray, QByteArray> tracePoints; QHash<QByteArray, QByteArray> tracePoints;

View File

@@ -88,7 +88,7 @@ void DeviceUsedPortsGatherer::setupUsedPorts()
{ {
d->usedPorts.clear(); d->usedPorts.clear();
const QList<Port> usedPorts = d->portsGatheringMethod.parsePorts( const QList<Port> usedPorts = d->portsGatheringMethod.parsePorts(
d->process->readAllRawStandardOutput()); d->process->rawStdOut());
for (const Port port : usedPorts) { for (const Port port : usedPorts) {
if (d->device->freePorts().contains(port)) if (d->device->freePorts().contains(port))
d->usedPorts << port; d->usedPorts << port;

View File

@@ -235,9 +235,9 @@ QString QbsProfileManager::runQbsConfig(QbsConfigOp op, const QString &key, cons
} else if (qbsConfig.exitCode() != 0) { } else if (qbsConfig.exitCode() != 0) {
Core::MessageManager::writeFlashing( Core::MessageManager::writeFlashing(
Tr::tr("Failed to run qbs config: %1") Tr::tr("Failed to run qbs config: %1")
.arg(QString::fromLocal8Bit(qbsConfig.readAllRawStandardError()))); .arg(QString::fromLocal8Bit(qbsConfig.rawStdErr())));
} }
return QString::fromLocal8Bit(qbsConfig.readAllRawStandardOutput()).trimmed(); return QString::fromLocal8Bit(qbsConfig.rawStdOut()).trimmed();
} }
QVariant fromJSLiteral(const QString &str) QVariant fromJSLiteral(const QString &str)

View File

@@ -37,7 +37,7 @@ static QString getQbsVersion(const FilePath &qbsExe)
qbsProc.start(); qbsProc.start();
if (!qbsProc.waitForFinished(5000) || qbsProc.exitCode() != 0) if (!qbsProc.waitForFinished(5000) || qbsProc.exitCode() != 0)
return {}; return {};
return QString::fromLocal8Bit(qbsProc.readAllRawStandardOutput()).trimmed(); return QString::fromLocal8Bit(qbsProc.rawStdOut()).trimmed();
} }
static bool operator==(const QbsSettingsData &s1, const QbsSettingsData &s2) static bool operator==(const QbsSettingsData &s1, const QbsSettingsData &s2)

View File

@@ -1817,7 +1817,7 @@ static QByteArray runQmakeQuery(const FilePath &binary, const Environment &env,
return {}; return {};
} }
const QByteArray out = process.readAllRawStandardOutput(); const QByteArray out = process.rawStdOut();
if (out.isEmpty()) { if (out.isEmpty()) {
*error = Tr::tr("\"%1\" produced no output: %2.") *error = Tr::tr("\"%1\" produced no output: %2.")
.arg(binary.displayName(), process.cleanedStdErr()); .arg(binary.displayName(), process.cleanedStdErr());

View File

@@ -59,8 +59,8 @@ static void processRunnerCallback(ProcessData *data)
data->exitCode = proc.exitCode(); data->exitCode = proc.exitCode();
data->exitStatus = proc.exitStatus(); data->exitStatus = proc.exitStatus();
data->stdErr = proc.readAllRawStandardError(); data->stdErr = proc.rawStdErr();
data->stdOut = proc.readAllRawStandardOutput(); data->stdOut = proc.rawStdOut();
} }
class QtSupportPlugin final : public ExtensionSystem::IPlugin class QtSupportPlugin final : public ExtensionSystem::IPlugin

View File

@@ -410,7 +410,7 @@ QList<QByteArray> QtVersionManagerImpl::runQtChooser(const QString &qtchooser, c
p.start(); p.start();
p.waitForFinished(); p.waitForFinished();
const bool success = p.exitCode() == 0; const bool success = p.exitCode() == 0;
return success ? p.readAllRawStandardOutput().split('\n') : QList<QByteArray>(); return success ? p.rawStdOut().split('\n') : QList<QByteArray>();
} }
// Asks qtchooser for the qmake path of a given version // Asks qtchooser for the qmake path of a given version

View File

@@ -88,8 +88,7 @@ void RemoteLinuxSignalOperation::runnerDone()
m_errorMessage = m_process->errorString(); m_errorMessage = m_process->errorString();
} else if (m_process->exitCode() != 0) { } else if (m_process->exitCode() != 0) {
m_errorMessage = Tr::tr("Exit code is %1. stderr:").arg(m_process->exitCode()) m_errorMessage = Tr::tr("Exit code is %1. stderr:").arg(m_process->exitCode())
+ QLatin1Char(' ') + QLatin1Char(' ') + QString::fromLatin1(m_process->rawStdErr());
+ QString::fromLatin1(m_process->readAllRawStandardError());
} }
m_process.release()->deleteLater(); m_process.release()->deleteLater();
emit finished(m_errorMessage); emit finished(m_errorMessage);

View File

@@ -118,7 +118,7 @@ void SshKeyCreationDialog::generateKeys()
if (!keygen.waitForFinished()) if (!keygen.waitForFinished())
errorMsg = keygen.errorString(); errorMsg = keygen.errorString();
else if (keygen.exitCode() != 0) else if (keygen.exitCode() != 0)
errorMsg = QString::fromLocal8Bit(keygen.readAllRawStandardError()); errorMsg = QString::fromLocal8Bit(keygen.rawStdErr());
if (!errorMsg.isEmpty()) { if (!errorMsg.isEmpty()) {
showError(Tr::tr("The ssh-keygen tool at \"%1\" failed: %2") showError(Tr::tr("The ssh-keygen tool at \"%1\" failed: %2")
.arg(SshSettings::keygenFilePath().toUserOutput(), errorMsg)); .arg(SshSettings::keygenFilePath().toUserOutput(), errorMsg));

View File

@@ -662,8 +662,7 @@ CropAndTrimDialog::CropAndTrimDialog(const ClipInfo &clip, QWidget *parent)
m_process = new Process(this); m_process = new Process(this);
connect(m_process, &Process::done, this, [this] { connect(m_process, &Process::done, this, [this] {
if (m_process->exitCode() != 0) { if (m_process->exitCode() != 0) {
FFmpegUtils::reportError(m_process->commandLine(), FFmpegUtils::reportError(m_process->commandLine(), m_process->rawStdErr());
m_process->readAllRawStandardError());
return; return;
} }
const QByteArray &imageData = m_process->rawStdOut(); const QByteArray &imageData = m_process->rawStdOut();

View File

@@ -129,7 +129,7 @@ public:
reportFailure(); reportFailure();
return; return;
} }
const QByteArrayList data = m_process->readAllRawStandardOutput().split(' '); const QByteArrayList data = m_process->rawStdOut().split(' ');
if (data.size() != 3) { if (data.size() != 3) {
reportFailure(); reportFailure();
return; return;

View File

@@ -103,7 +103,7 @@ static WebBrowserEntries emrunBrowsers(Target *target)
browserLister.start(); browserLister.start();
if (browserLister.waitForFinished()) if (browserLister.waitForFinished())
result.append(parseEmrunOutput(browserLister.readAllRawStandardOutput())); result.append(parseEmrunOutput(browserLister.rawStdOut()));
} }
return result; return result;
} }

View File

@@ -34,7 +34,7 @@ private:
p.setCommand(cmd); p.setCommand(cmd);
p.setEnvironment(testEnv); p.setEnvironment(testEnv);
p.runBlocking(); p.runBlocking();
return QString::fromUtf8(p.readAllRawStandardOutput()); return QString::fromUtf8(p.rawStdOut());
} }
private slots: private slots:

View File

@@ -114,7 +114,7 @@ private slots:
proc.setCommand({envPath, {}}); proc.setCommand({envPath, {}});
proc.runBlocking(); proc.runBlocking();
QCOMPARE(proc.exitCode(), 0); QCOMPARE(proc.exitCode(), 0);
const QByteArray output = proc.readAllRawStandardOutput() + proc.readAllRawStandardError(); const QByteArray output = proc.rawStdOut() + proc.rawStdErr();
qDebug() << "Process output:" << output; qDebug() << "Process output:" << output;
QCOMPARE(output.size() > 0, qoutput.size() > 0); QCOMPARE(output.size() > 0, qoutput.size() > 0);
@@ -1211,8 +1211,8 @@ void tst_Process::channelForwarding()
process.start(); process.start();
QVERIFY(process.waitForFinished()); QVERIFY(process.waitForFinished());
const QByteArray output = process.readAllRawStandardOutput(); const QByteArray output = process.rawStdOut();
const QByteArray error = process.readAllRawStandardError(); const QByteArray error = process.rawStdErr();
QCOMPARE(output.contains(QByteArray(s_outputData)), outputForwarded); QCOMPARE(output.contains(QByteArray(s_outputData)), outputForwarded);
QCOMPARE(error.contains(QByteArray(s_errorData)), errorForwarded); QCOMPARE(error.contains(QByteArray(s_errorData)), errorForwarded);