forked from qt-creator/qt-creator
Utils: Move SynchronousProcess::normalizeNewlines to QtcProcess
Change-Id: I5ba8ba1061b04b032aafd08382d34ccb62272829 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -29,7 +29,7 @@
|
|||||||
#include "ansiescapecodehandler.h"
|
#include "ansiescapecodehandler.h"
|
||||||
#include "fileinprojectfinder.h"
|
#include "fileinprojectfinder.h"
|
||||||
#include "qtcassert.h"
|
#include "qtcassert.h"
|
||||||
#include "synchronousprocess.h"
|
#include "qtcprocess.h"
|
||||||
#include "theme/theme.h"
|
#include "theme/theme.h"
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
@@ -631,7 +631,7 @@ void OutputFormatter::appendMessage(const QString &text, OutputFormat format)
|
|||||||
d->prependCarriageReturn = false;
|
d->prependCarriageReturn = false;
|
||||||
out.prepend('\r');
|
out.prepend('\r');
|
||||||
}
|
}
|
||||||
out = SynchronousProcess::normalizeNewlines(out);
|
out = QtcProcess::normalizeNewlines(out);
|
||||||
if (out.endsWith('\r')) {
|
if (out.endsWith('\r')) {
|
||||||
d->prependCarriageReturn = true;
|
d->prependCarriageReturn = true;
|
||||||
out.chop(1);
|
out.chop(1);
|
||||||
|
|||||||
@@ -1627,6 +1627,17 @@ bool QtcProcess::ArgIterator::next()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString QtcProcess::normalizeNewlines(const QString &text)
|
||||||
|
{
|
||||||
|
QString res = text;
|
||||||
|
const auto newEnd = std::unique(res.begin(), res.end(), [](const QChar &c1, const QChar &c2) {
|
||||||
|
return c1 == '\r' && c2 == '\r'; // QTCREATORBUG-24556
|
||||||
|
});
|
||||||
|
res.chop(std::distance(newEnd, res.end()));
|
||||||
|
res.replace("\r\n", "\n");
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
void QtcProcess::ArgIterator::deleteArg()
|
void QtcProcess::ArgIterator::deleteArg()
|
||||||
{
|
{
|
||||||
if (!m_prev)
|
if (!m_prev)
|
||||||
|
|||||||
@@ -155,6 +155,8 @@ public:
|
|||||||
bool readDataFromProcess(int timeoutS, QByteArray *stdOut, QByteArray *stdErr,
|
bool readDataFromProcess(int timeoutS, QByteArray *stdOut, QByteArray *stdErr,
|
||||||
bool showTimeOutMessageBox);
|
bool showTimeOutMessageBox);
|
||||||
|
|
||||||
|
static QString normalizeNewlines(const QString &text);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||||
void setupChildProcess() override;
|
void setupChildProcess() override;
|
||||||
|
|||||||
@@ -186,12 +186,12 @@ QString SynchronousProcessResponse::allOutput() const
|
|||||||
|
|
||||||
QString SynchronousProcessResponse::stdOut() const
|
QString SynchronousProcessResponse::stdOut() const
|
||||||
{
|
{
|
||||||
return SynchronousProcess::normalizeNewlines(codec->toUnicode(rawStdOut));
|
return QtcProcess::normalizeNewlines(codec->toUnicode(rawStdOut));
|
||||||
}
|
}
|
||||||
|
|
||||||
QString SynchronousProcessResponse::stdErr() const
|
QString SynchronousProcessResponse::stdErr() const
|
||||||
{
|
{
|
||||||
return SynchronousProcess::normalizeNewlines(codec->toUnicode(rawStdErr));
|
return QtcProcess::normalizeNewlines(codec->toUnicode(rawStdErr));
|
||||||
}
|
}
|
||||||
|
|
||||||
QTCREATOR_UTILS_EXPORT QDebug operator<<(QDebug str, const SynchronousProcessResponse& r)
|
QTCREATOR_UTILS_EXPORT QDebug operator<<(QDebug str, const SynchronousProcessResponse& r)
|
||||||
@@ -257,7 +257,7 @@ QString ChannelBuffer::linesRead()
|
|||||||
return QString();
|
return QString();
|
||||||
|
|
||||||
// Get completed lines and remove them from the incompleteLinesBuffer:
|
// Get completed lines and remove them from the incompleteLinesBuffer:
|
||||||
const QString lines = SynchronousProcess::normalizeNewlines(incompleteLineBuffer.left(lastLineIndex + 1));
|
const QString lines = QtcProcess::normalizeNewlines(incompleteLineBuffer.left(lastLineIndex + 1));
|
||||||
incompleteLineBuffer = incompleteLineBuffer.mid(lastLineIndex + 1);
|
incompleteLineBuffer = incompleteLineBuffer.mid(lastLineIndex + 1);
|
||||||
|
|
||||||
return lines;
|
return lines;
|
||||||
@@ -789,17 +789,6 @@ QString SynchronousProcess::locateBinary(const QString &path, const QString &bin
|
|||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString SynchronousProcess::normalizeNewlines(const QString &text)
|
|
||||||
{
|
|
||||||
QString res = text;
|
|
||||||
const auto newEnd = std::unique(res.begin(), res.end(), [](const QChar &c1, const QChar &c2) {
|
|
||||||
return c1 == '\r' && c2 == '\r'; // QTCREATORBUG-24556
|
|
||||||
});
|
|
||||||
res.chop(std::distance(newEnd, res.end()));
|
|
||||||
res.replace("\r\n", "\n");
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString SynchronousProcess::locateBinary(const QString &binary)
|
QString SynchronousProcess::locateBinary(const QString &binary)
|
||||||
{
|
{
|
||||||
const QByteArray path = qgetenv("PATH");
|
const QByteArray path = qgetenv("PATH");
|
||||||
|
|||||||
@@ -153,8 +153,6 @@ public:
|
|||||||
static QString locateBinary(const QString &binary);
|
static QString locateBinary(const QString &binary);
|
||||||
static QString locateBinary(const QString &path, const QString &binary);
|
static QString locateBinary(const QString &path, const QString &binary);
|
||||||
|
|
||||||
static QString normalizeNewlines(const QString &text);
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void stdOutBuffered(const QString &lines, bool firstTime);
|
void stdOutBuffered(const QString &lines, bool firstTime);
|
||||||
void stdErrBuffered(const QString &lines, bool firstTime);
|
void stdErrBuffered(const QString &lines, bool firstTime);
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ void ClangToolRunner::onProcessFinished(int exitCode, QProcess::ExitStatus exitS
|
|||||||
{
|
{
|
||||||
if (exitStatus == QProcess::NormalExit) {
|
if (exitStatus == QProcess::NormalExit) {
|
||||||
if (exitCode == 0) {
|
if (exitCode == 0) {
|
||||||
qCDebug(LOG).noquote() << "Output:\n" << Utils::SynchronousProcess::normalizeNewlines(
|
qCDebug(LOG).noquote() << "Output:\n" << QtcProcess::normalizeNewlines(
|
||||||
QString::fromLocal8Bit(m_processOutput));
|
QString::fromLocal8Bit(m_processOutput));
|
||||||
emit finishedWithSuccess(m_fileToAnalyze);
|
emit finishedWithSuccess(m_fileToAnalyze);
|
||||||
} else {
|
} else {
|
||||||
@@ -187,7 +187,7 @@ QString ClangToolRunner::commandlineAndOutput() const
|
|||||||
"Output:\n%3")
|
"Output:\n%3")
|
||||||
.arg(m_commandLine.toUserOutput(),
|
.arg(m_commandLine.toUserOutput(),
|
||||||
QString::number(m_process->error()),
|
QString::number(m_process->error()),
|
||||||
Utils::SynchronousProcess::normalizeNewlines(QString::fromLocal8Bit(m_processOutput)));
|
QtcProcess::normalizeNewlines(QString::fromLocal8Bit(m_processOutput)));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
@@ -35,8 +35,6 @@
|
|||||||
|
|
||||||
#include <utils/stringutils.h>
|
#include <utils/stringutils.h>
|
||||||
|
|
||||||
#include <QDir>
|
|
||||||
|
|
||||||
namespace CMakeProjectManager {
|
namespace CMakeProjectManager {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
@@ -44,7 +42,7 @@ using namespace ProjectExplorer;
|
|||||||
|
|
||||||
static QString lineSplit(const QString &rest, const QByteArray &array, std::function<void(const QString &)> f)
|
static QString lineSplit(const QString &rest, const QByteArray &array, std::function<void(const QString &)> f)
|
||||||
{
|
{
|
||||||
QString tmp = rest + Utils::SynchronousProcess::normalizeNewlines(QString::fromLocal8Bit(array));
|
QString tmp = rest + Utils::QtcProcess::normalizeNewlines(QString::fromLocal8Bit(array));
|
||||||
int start = 0;
|
int start = 0;
|
||||||
int end = tmp.indexOf(QLatin1Char('\n'), start);
|
int end = tmp.indexOf(QLatin1Char('\n'), start);
|
||||||
while (end >= 0) {
|
while (end >= 0) {
|
||||||
|
|||||||
@@ -35,6 +35,7 @@
|
|||||||
#include <coreplugin/idocument.h>
|
#include <coreplugin/idocument.h>
|
||||||
|
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
#include <utils/qtcprocess.h>
|
||||||
#include <utils/synchronousprocess.h>
|
#include <utils/synchronousprocess.h>
|
||||||
#include <vcsbase/vcsbaseeditor.h>
|
#include <vcsbase/vcsbaseeditor.h>
|
||||||
#include <vcsbase/vcsoutputwindow.h>
|
#include <vcsbase/vcsoutputwindow.h>
|
||||||
@@ -127,7 +128,7 @@ QProcessEnvironment VcsBaseClientImpl::processEnvironment() const
|
|||||||
|
|
||||||
QString VcsBaseClientImpl::commandOutputFromLocal8Bit(const QByteArray &a)
|
QString VcsBaseClientImpl::commandOutputFromLocal8Bit(const QByteArray &a)
|
||||||
{
|
{
|
||||||
return SynchronousProcess::normalizeNewlines(QString::fromLocal8Bit(a));
|
return QtcProcess::normalizeNewlines(QString::fromLocal8Bit(a));
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList VcsBaseClientImpl::commandOutputLinesFromLocal8Bit(const QByteArray &a)
|
QStringList VcsBaseClientImpl::commandOutputLinesFromLocal8Bit(const QByteArray &a)
|
||||||
|
|||||||
Reference in New Issue
Block a user