forked from qt-creator/qt-creator
QNX: Prepare for RecipeRunner split
Change-Id: I78841372cab1acd50d2e62f7555450abfa762de8 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -11,84 +11,100 @@
|
|||||||
#include <utils/qtcprocess.h>
|
#include <utils/qtcprocess.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
|
#include <QDateTime>
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
|
|
||||||
using namespace ProjectExplorer;
|
using namespace ProjectExplorer;
|
||||||
|
using namespace Tasking;
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
namespace Qnx::Internal {
|
namespace Qnx::Internal {
|
||||||
|
|
||||||
Slog2InfoRunner::Slog2InfoRunner(RunControl *runControl)
|
struct SlogData
|
||||||
: RunWorker(runControl)
|
|
||||||
{
|
{
|
||||||
setId("Slog2InfoRunner");
|
RunWorker *m_worker = nullptr;
|
||||||
m_applicationId = runControl->aspectData<ExecutableAspect>()->executable.fileName();
|
QString m_applicationId;
|
||||||
|
QDateTime m_launchDateTime = {};
|
||||||
|
bool m_currentLogs = false;
|
||||||
|
QString m_remainingData = {};
|
||||||
|
|
||||||
|
void processLogLine(const QString &line);
|
||||||
|
void processRemainingLogData();
|
||||||
|
void processLogInput(const QString &input);
|
||||||
|
};
|
||||||
|
|
||||||
|
static Group recipe(RunWorker *worker)
|
||||||
|
{
|
||||||
|
RunControl *runControl = worker->runControl();
|
||||||
|
QString applicationId = runControl->aspectData<ExecutableAspect>()->executable.fileName();
|
||||||
// See QTCREATORBUG-10712 for details.
|
// See QTCREATORBUG-10712 for details.
|
||||||
// We need to limit length of ApplicationId to 63 otherwise it would not match one in slog2info.
|
// We need to limit length of ApplicationId to 63 otherwise it would not match one in slog2info.
|
||||||
m_applicationId.truncate(63);
|
applicationId.truncate(63);
|
||||||
}
|
|
||||||
|
|
||||||
void Slog2InfoRunner::start()
|
const Storage<SlogData> storage({worker, applicationId});
|
||||||
{
|
|
||||||
using namespace Tasking;
|
|
||||||
QTC_CHECK(!m_taskTreeRunner.isRunning());
|
|
||||||
|
|
||||||
const auto onTestSetup = [this](Process &process) {
|
const auto onTestSetup = [runControl](Process &process) {
|
||||||
process.setCommand(CommandLine{runControl()->device()->filePath("slog2info")});
|
process.setCommand(CommandLine{runControl->device()->filePath("slog2info")});
|
||||||
};
|
};
|
||||||
const auto onTestDone = [this] {
|
const auto onTestDone = [storage] {
|
||||||
appendMessage(Tr::tr("Warning: \"slog2info\" is not found on the device, "
|
storage->m_worker->appendMessage(Tr::tr("Warning: \"slog2info\" is not found on the device, "
|
||||||
"debug output not available."), ErrorMessageFormat);
|
"debug output not available."), ErrorMessageFormat);
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto onLaunchTimeSetup = [this](Process &process) {
|
const auto onLaunchTimeSetup = [runControl](Process &process) {
|
||||||
process.setCommand({runControl()->device()->filePath("date"), "+\"%d %H:%M:%S\"", CommandLine::Raw});
|
process.setCommand({runControl->device()->filePath("date"), "+\"%d %H:%M:%S\"", CommandLine::Raw});
|
||||||
};
|
};
|
||||||
const auto onLaunchTimeDone = [this](const Process &process) {
|
const auto onLaunchTimeDone = [applicationId, storage](const Process &process) {
|
||||||
QTC_CHECK(!m_applicationId.isEmpty());
|
QTC_CHECK(!applicationId.isEmpty());
|
||||||
m_launchDateTime = QDateTime::fromString(process.cleanedStdOut().trimmed(), "dd HH:mm:ss");
|
storage->m_launchDateTime = QDateTime::fromString(process.cleanedStdOut().trimmed(),
|
||||||
|
"dd HH:mm:ss");
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto onLogSetup = [this](Process &process) {
|
const auto onLogSetup = [storage, worker, runControl](Process &process) {
|
||||||
process.setCommand({runControl()->device()->filePath("slog2info"), {"-w"}});
|
process.setCommand({runControl->device()->filePath("slog2info"), {"-w"}});
|
||||||
connect(&process, &Process::readyReadStandardOutput, this, [this, processPtr = &process] {
|
SlogData *slogData = storage.activeStorage();
|
||||||
processLogInput(QString::fromLatin1(processPtr->readAllRawStandardOutput()));
|
QObject::connect(&process, &Process::readyReadStandardOutput, worker,
|
||||||
});
|
[slogData, processPtr = &process] {
|
||||||
connect(&process, &Process::readyReadStandardError, this, [this, processPtr = &process] {
|
slogData->processLogInput(QString::fromLatin1(processPtr->readAllRawStandardOutput()));
|
||||||
appendMessage(QString::fromLatin1(processPtr->readAllRawStandardError()), StdErrFormat);
|
});
|
||||||
|
QObject::connect(&process, &Process::readyReadStandardError, worker, [worker, processPtr = &process] {
|
||||||
|
worker->appendMessage(QString::fromLatin1(processPtr->readAllRawStandardError()), StdErrFormat);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
const auto onLogError = [this](const Process &process) {
|
const auto onLogError = [worker](const Process &process) {
|
||||||
appendMessage(Tr::tr("Cannot show slog2info output. Error: %1").arg(process.errorString()),
|
worker->appendMessage(Tr::tr("Cannot show slog2info output. Error: %1")
|
||||||
StdErrFormat);
|
.arg(process.errorString()), StdErrFormat);
|
||||||
};
|
};
|
||||||
|
|
||||||
const Group root {
|
const auto onCanceled = [storage](DoneWith result) {
|
||||||
|
if (result == DoneWith::Cancel)
|
||||||
|
storage->processRemainingLogData();
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
storage,
|
||||||
ProcessTask(onTestSetup, onTestDone, CallDoneIf::Error),
|
ProcessTask(onTestSetup, onTestDone, CallDoneIf::Error),
|
||||||
ProcessTask(onLaunchTimeSetup, onLaunchTimeDone, CallDoneIf::Success),
|
ProcessTask(onLaunchTimeSetup, onLaunchTimeDone, CallDoneIf::Success),
|
||||||
ProcessTask(onLogSetup, onLogError, CallDoneIf::Error)
|
ProcessTask(onLogSetup, onLogError, CallDoneIf::Error),
|
||||||
|
onGroupDone(onCanceled, CallDoneIf::Error)
|
||||||
};
|
};
|
||||||
|
|
||||||
m_taskTreeRunner.start(root);
|
|
||||||
reportStarted();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Slog2InfoRunner::stop()
|
Slog2InfoRunner::Slog2InfoRunner(RunControl *runControl)
|
||||||
|
: RunWorker(runControl)
|
||||||
|
, m_recipe(recipe(this))
|
||||||
{
|
{
|
||||||
m_taskTreeRunner.reset();
|
setId("Slog2InfoRunner");
|
||||||
processRemainingLogData();
|
|
||||||
reportStopped();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Slog2InfoRunner::processRemainingLogData()
|
void SlogData::processRemainingLogData()
|
||||||
{
|
{
|
||||||
if (!m_remainingData.isEmpty())
|
if (!m_remainingData.isEmpty())
|
||||||
processLogLine(m_remainingData);
|
processLogLine(m_remainingData);
|
||||||
m_remainingData.clear();
|
m_remainingData.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Slog2InfoRunner::processLogInput(const QString &input)
|
void SlogData::processLogInput(const QString &input)
|
||||||
{
|
{
|
||||||
QStringList lines = input.split(QLatin1Char('\n'));
|
QStringList lines = input.split(QLatin1Char('\n'));
|
||||||
if (lines.isEmpty())
|
if (lines.isEmpty())
|
||||||
@@ -99,7 +115,7 @@ void Slog2InfoRunner::processLogInput(const QString &input)
|
|||||||
processLogLine(line);
|
processLogLine(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Slog2InfoRunner::processLogLine(const QString &line)
|
void SlogData::processLogLine(const QString &line)
|
||||||
{
|
{
|
||||||
// The "(\\s+\\S+)?" represents a named buffer. If message has noname (aka empty) buffer
|
// The "(\\s+\\S+)?" represents a named buffer. If message has noname (aka empty) buffer
|
||||||
// then the message might get cut for the first number in the message.
|
// then the message might get cut for the first number in the message.
|
||||||
@@ -117,25 +133,44 @@ void Slog2InfoRunner::processLogLine(const QString &line)
|
|||||||
if (!m_launchDateTime.isNull()) {
|
if (!m_launchDateTime.isNull()) {
|
||||||
// Check if logs are from the recent launch
|
// Check if logs are from the recent launch
|
||||||
if (!m_currentLogs) {
|
if (!m_currentLogs) {
|
||||||
QDateTime dateTime = QDateTime::fromString(match.captured(1),
|
const QDateTime dateTime = QDateTime::fromString(match.captured(1),
|
||||||
QLatin1String("dd HH:mm:ss.zzz"));
|
QLatin1String("dd HH:mm:ss.zzz"));
|
||||||
m_currentLogs = dateTime >= m_launchDateTime;
|
m_currentLogs = dateTime >= m_launchDateTime;
|
||||||
if (!m_currentLogs)
|
if (!m_currentLogs)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString applicationId = match.captured(2);
|
const QString applicationId = match.captured(2);
|
||||||
if (!applicationId.startsWith(m_applicationId))
|
if (!applicationId.startsWith(m_applicationId))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QString bufferName = match.captured(4);
|
const QString bufferName = match.captured(4);
|
||||||
int bufferId = match.captured(5).toInt();
|
int bufferId = match.captured(5).toInt();
|
||||||
// filtering out standard BB10 messages
|
// filtering out standard BB10 messages
|
||||||
if (bufferName == QLatin1String("default") && bufferId == 8900)
|
if (bufferName == QLatin1String("default") && bufferId == 8900)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
appendMessage(match.captured(6).trimmed() + '\n', StdOutFormat);
|
m_worker->appendMessage(match.captured(6).trimmed() + '\n', StdOutFormat);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Slog2InfoRunner::start()
|
||||||
|
{
|
||||||
|
QTC_CHECK(!m_taskTreeRunner.isRunning());
|
||||||
|
|
||||||
|
m_taskTreeRunner.start(m_recipe, {}, [this](DoneWith result) {
|
||||||
|
if (result == DoneWith::Success)
|
||||||
|
reportStopped();
|
||||||
|
else
|
||||||
|
reportFailure();
|
||||||
|
});
|
||||||
|
reportStarted();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Slog2InfoRunner::stop()
|
||||||
|
{
|
||||||
|
m_taskTreeRunner.cancel();
|
||||||
|
reportStopped();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // Qnx::Internal
|
} // Qnx::Internal
|
||||||
|
@@ -7,8 +7,6 @@
|
|||||||
|
|
||||||
#include <solutions/tasking/tasktreerunner.h>
|
#include <solutions/tasking/tasktreerunner.h>
|
||||||
|
|
||||||
#include <QDateTime>
|
|
||||||
|
|
||||||
namespace Qnx::Internal {
|
namespace Qnx::Internal {
|
||||||
|
|
||||||
class Slog2InfoRunner : public ProjectExplorer::RunWorker
|
class Slog2InfoRunner : public ProjectExplorer::RunWorker
|
||||||
@@ -20,15 +18,8 @@ public:
|
|||||||
void stop() override;
|
void stop() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void processRemainingLogData();
|
|
||||||
void processLogInput(const QString &input);
|
|
||||||
void processLogLine(const QString &line);
|
|
||||||
|
|
||||||
QString m_applicationId;
|
|
||||||
QDateTime m_launchDateTime;
|
|
||||||
bool m_currentLogs = false;
|
|
||||||
QString m_remainingData;
|
|
||||||
Tasking::TaskTreeRunner m_taskTreeRunner;
|
Tasking::TaskTreeRunner m_taskTreeRunner;
|
||||||
|
Tasking::Group m_recipe;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // Qnx::Internal
|
} // Qnx::Internal
|
||||||
|
Reference in New Issue
Block a user