forked from qt-creator/qt-creator
ProjectExplorer: Remove OutputFormatterFactory hierarchy
It never gained traction, was only used in thee places, and the class(-hierarchy) is not really needed and only complicates the code when the formatter creation is handled in free functions. Also adapt the users. Change-Id: Ieef7199f5a36f244b2f38cffef71a5fe0606065c Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -216,7 +216,7 @@ void BuildStep::setupOutputFormatter(OutputFormatter *formatter)
|
|||||||
formatter->addLineParser(parser);
|
formatter->addLineParser(parser);
|
||||||
}
|
}
|
||||||
|
|
||||||
formatter->addLineParser(new Internal::SanitizerParser);
|
formatter->addLineParser(Internal::createSanitizerOutputParser());
|
||||||
formatter->setForwardStdOutToStdError(buildConfiguration()->parseStdOut());
|
formatter->setForwardStdOutToStdError(buildConfiguration()->parseStdOut());
|
||||||
}
|
}
|
||||||
FileInProjectFinder fileFinder;
|
FileInProjectFinder fileFinder;
|
||||||
|
@@ -723,7 +723,6 @@ public:
|
|||||||
}};
|
}};
|
||||||
|
|
||||||
DeviceCheckBuildStepFactory deviceCheckBuildStepFactory;
|
DeviceCheckBuildStepFactory deviceCheckBuildStepFactory;
|
||||||
SanitizerOutputFormatterFactory sanitizerFormatterFactory;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static ProjectExplorerPlugin *m_instance = nullptr;
|
static ProjectExplorerPlugin *m_instance = nullptr;
|
||||||
@@ -825,6 +824,8 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
|
|||||||
|
|
||||||
dd = new ProjectExplorerPluginPrivate;
|
dd = new ProjectExplorerPluginPrivate;
|
||||||
|
|
||||||
|
setupSanitizerOutputParser();
|
||||||
|
|
||||||
setupJsonWizardPages();
|
setupJsonWizardPages();
|
||||||
setupJsonWizardFileGenerator();
|
setupJsonWizardFileGenerator();
|
||||||
setupJsonWizardScannerGenerator();
|
setupJsonWizardScannerGenerator();
|
||||||
@@ -1953,8 +1954,9 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
|
|||||||
|
|
||||||
DeviceManager::instance()->addDevice(IDevice::Ptr(new DesktopDevice));
|
DeviceManager::instance()->addDevice(IDevice::Ptr(new DesktopDevice));
|
||||||
|
|
||||||
if (auto sanitizerTester = SanitizerParser::testCreator())
|
#ifdef WITH_TESTS
|
||||||
addTestCreator(sanitizerTester.value());
|
addTestCreator(&createSanitizerOutputParserTest);
|
||||||
|
#endif
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -843,7 +843,7 @@ void RunControlPrivate::showError(const QString &msg)
|
|||||||
|
|
||||||
void RunControl::setupFormatter(OutputFormatter *formatter) const
|
void RunControl::setupFormatter(OutputFormatter *formatter) const
|
||||||
{
|
{
|
||||||
QList<Utils::OutputLineParser *> parsers = OutputFormatterFactory::createFormatters(target());
|
QList<Utils::OutputLineParser *> parsers = createOutputParsers(target());
|
||||||
if (const auto customParsersAspect = aspect<CustomParsersAspect>()) {
|
if (const auto customParsersAspect = aspect<CustomParsersAspect>()) {
|
||||||
for (const Id id : std::as_const(customParsersAspect->parsers)) {
|
for (const Id id : std::as_const(customParsersAspect->parsers)) {
|
||||||
if (auto parser = createCustomParserFromId(id))
|
if (auto parser = createCustomParserFromId(id))
|
||||||
@@ -1836,31 +1836,23 @@ void RunWorker::stop()
|
|||||||
reportStopped();
|
reportStopped();
|
||||||
}
|
}
|
||||||
|
|
||||||
// OutputFormatterFactory
|
// Output parser factories
|
||||||
|
|
||||||
static QList<OutputFormatterFactory *> g_outputFormatterFactories;
|
static QList<std::function<OutputLineParser *(Target *)>> g_outputParserFactories;
|
||||||
|
|
||||||
OutputFormatterFactory::OutputFormatterFactory()
|
QList<OutputLineParser *> createOutputParsers(Target *target)
|
||||||
{
|
|
||||||
g_outputFormatterFactories.append(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
OutputFormatterFactory::~OutputFormatterFactory()
|
|
||||||
{
|
|
||||||
g_outputFormatterFactories.removeOne(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<OutputLineParser *> OutputFormatterFactory::createFormatters(Target *target)
|
|
||||||
{
|
{
|
||||||
QList<OutputLineParser *> formatters;
|
QList<OutputLineParser *> formatters;
|
||||||
for (auto factory : std::as_const(g_outputFormatterFactories))
|
for (auto factory : std::as_const(g_outputParserFactories)) {
|
||||||
formatters << factory->m_creator(target);
|
if (OutputLineParser *parser = factory(target))
|
||||||
|
formatters << parser;
|
||||||
|
}
|
||||||
return formatters;
|
return formatters;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OutputFormatterFactory::setFormatterCreator(const FormatterCreator &creator)
|
void addOutputParserFactory(const std::function<Utils::OutputLineParser *(Target *)> &factory)
|
||||||
{
|
{
|
||||||
m_creator = creator;
|
g_outputParserFactories.append(factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
// SimpleTargetRunnerFactory
|
// SimpleTargetRunnerFactory
|
||||||
|
@@ -289,22 +289,10 @@ public:
|
|||||||
explicit SimpleTargetRunnerFactory(const QList<Utils::Id> &runConfig);
|
explicit SimpleTargetRunnerFactory(const QList<Utils::Id> &runConfig);
|
||||||
};
|
};
|
||||||
|
|
||||||
class PROJECTEXPLORER_EXPORT OutputFormatterFactory
|
|
||||||
{
|
|
||||||
protected:
|
|
||||||
OutputFormatterFactory();
|
|
||||||
|
|
||||||
public:
|
PROJECTEXPLORER_EXPORT
|
||||||
virtual ~OutputFormatterFactory();
|
void addOutputParserFactory(const std::function<Utils::OutputLineParser *(Target *)> &);
|
||||||
|
|
||||||
static QList<Utils::OutputLineParser *> createFormatters(Target *target);
|
PROJECTEXPLORER_EXPORT QList<Utils::OutputLineParser *> createOutputParsers(Target *target);
|
||||||
|
|
||||||
protected:
|
|
||||||
using FormatterCreator = std::function<QList<Utils::OutputLineParser *>(Target *)>;
|
|
||||||
void setFormatterCreator(const FormatterCreator &creator);
|
|
||||||
|
|
||||||
private:
|
|
||||||
FormatterCreator m_creator;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace ProjectExplorer
|
} // namespace ProjectExplorer
|
||||||
|
@@ -3,7 +3,10 @@
|
|||||||
|
|
||||||
#include "sanitizerparser.h"
|
#include "sanitizerparser.h"
|
||||||
|
|
||||||
|
#include "ioutputparser.h"
|
||||||
#include "projectexplorerconstants.h"
|
#include "projectexplorerconstants.h"
|
||||||
|
#include "runcontrol.h"
|
||||||
|
#include "task.h"
|
||||||
|
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
|
|
||||||
@@ -19,6 +22,20 @@ using namespace Utils;
|
|||||||
|
|
||||||
namespace ProjectExplorer::Internal {
|
namespace ProjectExplorer::Internal {
|
||||||
|
|
||||||
|
class SanitizerParser final : public OutputTaskParser
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
Result handleLine(const QString &line, OutputFormat format) final;
|
||||||
|
void flush() final;
|
||||||
|
|
||||||
|
Result handleContinuation(const QString &line);
|
||||||
|
void addLinkSpecs(const LinkSpecs &linkSpecs);
|
||||||
|
|
||||||
|
Task m_task;
|
||||||
|
LinkSpecs m_linkSpecs;
|
||||||
|
quint64 m_id = 0;
|
||||||
|
};
|
||||||
|
|
||||||
OutputLineParser::Result SanitizerParser::handleLine(const QString &line, OutputFormat format)
|
OutputLineParser::Result SanitizerParser::handleLine(const QString &line, OutputFormat format)
|
||||||
{
|
{
|
||||||
if (format != OutputFormat::StdErrFormat)
|
if (format != OutputFormat::StdErrFormat)
|
||||||
@@ -125,7 +142,22 @@ void SanitizerParser::flush()
|
|||||||
m_id = 0;
|
m_id = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OutputLineParser *createSanitizerOutputParser()
|
||||||
|
{
|
||||||
|
return new SanitizerParser;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setupSanitizerOutputParser()
|
||||||
|
{
|
||||||
|
addOutputParserFactory([](Target *) { return new SanitizerParser; });
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace ProjectExplorer::Internal
|
||||||
|
|
||||||
#ifdef WITH_TESTS
|
#ifdef WITH_TESTS
|
||||||
|
|
||||||
|
namespace ProjectExplorer::Internal {
|
||||||
|
|
||||||
class SanitizerParserTest : public QObject
|
class SanitizerParserTest : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -214,24 +246,14 @@ SUMMARY: AddressSanitizer: 19 byte(s) leaked in 1 allocation(s).)";
|
|||||||
testbench.testParsing(input, OutputParserTester::STDERR, tasks, {}, childStdErrLines, {});
|
testbench.testParsing(input, OutputParserTester::STDERR, tasks, {}, childStdErrLines, {});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
#endif
|
|
||||||
|
|
||||||
std::optional<std::function<QObject *()>> SanitizerParser::testCreator()
|
QObject *createSanitizerOutputParserTest()
|
||||||
{
|
{
|
||||||
#ifdef WITH_TESTS
|
return new SanitizerParserTest;
|
||||||
return []() -> QObject * { return new SanitizerParserTest; };
|
|
||||||
#else
|
|
||||||
return {};
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SanitizerOutputFormatterFactory::SanitizerOutputFormatterFactory()
|
} // ProjectExplorer::Internal
|
||||||
{
|
|
||||||
setFormatterCreator([](Target *) -> QList<OutputLineParser *> {return {new SanitizerParser}; });
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace ProjectExplorer::Internal
|
|
||||||
|
|
||||||
#ifdef WITH_TESTS
|
|
||||||
#include <sanitizerparser.moc>
|
#include <sanitizerparser.moc>
|
||||||
#endif
|
|
||||||
|
#endif // WITH_TESTS
|
||||||
|
@@ -3,37 +3,17 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "ioutputparser.h"
|
#include <utils/outputformatter.h>
|
||||||
#include "runcontrol.h"
|
|
||||||
#include "task.h"
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QVector>
|
|
||||||
|
|
||||||
namespace ProjectExplorer::Internal {
|
namespace ProjectExplorer::Internal {
|
||||||
|
|
||||||
class SanitizerParser : public OutputTaskParser
|
Utils::OutputLineParser *createSanitizerOutputParser();
|
||||||
{
|
|
||||||
public:
|
|
||||||
static std::optional<std::function<QObject *()>> testCreator();
|
|
||||||
|
|
||||||
private:
|
void setupSanitizerOutputParser();
|
||||||
Result handleLine(const QString &line, Utils::OutputFormat format) override;
|
|
||||||
void flush() override;
|
|
||||||
|
|
||||||
Result handleContinuation(const QString &line);
|
#ifdef WITH_TESTS
|
||||||
void addLinkSpecs(const LinkSpecs &linkSpecs);
|
QObject *createSanitizerOutputParserTest();
|
||||||
|
#endif
|
||||||
|
|
||||||
Task m_task;
|
} // ProjectExplorer::Internal
|
||||||
LinkSpecs m_linkSpecs;
|
|
||||||
quint64 m_id = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
class SanitizerOutputFormatterFactory : public ProjectExplorer::OutputFormatterFactory
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
SanitizerOutputFormatterFactory();
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace ProjectExplorer::Internal
|
|
||||||
|
|
||||||
|
@@ -43,7 +43,6 @@ QObject *pluginInstance()
|
|||||||
class PythonPluginPrivate
|
class PythonPluginPrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PythonOutputFormatterFactory outputFormatterFactory;
|
|
||||||
PythonRunConfigurationFactory runConfigFactory;
|
PythonRunConfigurationFactory runConfigFactory;
|
||||||
PySideBuildStepFactory buildStepFactory;
|
PySideBuildStepFactory buildStepFactory;
|
||||||
PythonBuildConfigurationFactory buildConfigFactory;
|
PythonBuildConfigurationFactory buildConfigFactory;
|
||||||
@@ -77,6 +76,8 @@ private:
|
|||||||
|
|
||||||
setupPythonEditorFactory(this);
|
setupPythonEditorFactory(this);
|
||||||
|
|
||||||
|
setupPythonOutputParser();
|
||||||
|
|
||||||
KitManager::setIrrelevantAspects(KitManager::irrelevantAspects()
|
KitManager::setIrrelevantAspects(KitManager::irrelevantAspects()
|
||||||
+ QSet<Id>{PythonKitAspect::id()});
|
+ QSet<Id>{PythonKitAspect::id()});
|
||||||
|
|
||||||
|
@@ -189,12 +189,12 @@ PythonRunConfigurationFactory::PythonRunConfigurationFactory()
|
|||||||
addSupportedProjectType(PythonProjectId);
|
addSupportedProjectType(PythonProjectId);
|
||||||
}
|
}
|
||||||
|
|
||||||
PythonOutputFormatterFactory::PythonOutputFormatterFactory()
|
void setupPythonOutputParser()
|
||||||
{
|
{
|
||||||
setFormatterCreator([](Target *t) -> QList<OutputLineParser *> {
|
addOutputParserFactory([](Target *t) -> OutputLineParser * {
|
||||||
if (t && t->project()->mimeType() == Constants::C_PY_PROJECT_MIME_TYPE)
|
if (t && t->project()->mimeType() == Constants::C_PY_PROJECT_MIME_TYPE)
|
||||||
return {new PythonOutputLineParser};
|
return new PythonOutputLineParser;
|
||||||
return {};
|
return nullptr;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -17,10 +17,6 @@ public:
|
|||||||
PythonRunConfigurationFactory();
|
PythonRunConfigurationFactory();
|
||||||
};
|
};
|
||||||
|
|
||||||
class PythonOutputFormatterFactory : public ProjectExplorer::OutputFormatterFactory
|
void setupPythonOutputParser();
|
||||||
{
|
|
||||||
public:
|
|
||||||
PythonOutputFormatterFactory();
|
|
||||||
};
|
|
||||||
|
|
||||||
} // Python::Internal
|
} // Python::Internal
|
||||||
|
@@ -218,24 +218,18 @@ void QtOutputLineParser::updateProjectFileList()
|
|||||||
d->projectFinder.setProjectFiles(d->project->files(Project::SourceFiles));
|
d->projectFinder.setProjectFiles(d->project->files(Project::SourceFiles));
|
||||||
}
|
}
|
||||||
|
|
||||||
// QtOutputFormatterFactory
|
|
||||||
|
|
||||||
class QtOutputFormatterFactory final : public OutputFormatterFactory
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
QtOutputFormatterFactory()
|
|
||||||
{
|
|
||||||
setFormatterCreator([](Target *t) -> QList<OutputLineParser *> {
|
|
||||||
if (QtKitAspect::qtVersion(t ? t->kit() : nullptr))
|
|
||||||
return {new QtTestParser, new QtOutputLineParser(t)};
|
|
||||||
return {};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
void setupQtOutputFormatter()
|
void setupQtOutputFormatter()
|
||||||
{
|
{
|
||||||
static QtOutputFormatterFactory theQtOutputFormatterFactory;
|
addOutputParserFactory([](Target *t) -> OutputLineParser * {
|
||||||
|
if (QtKitAspect::qtVersion(t ? t->kit() : nullptr))
|
||||||
|
return new QtTestParser;
|
||||||
|
return nullptr;
|
||||||
|
});
|
||||||
|
addOutputParserFactory([](Target *t) -> OutputLineParser * {
|
||||||
|
if (QtKitAspect::qtVersion(t ? t->kit() : nullptr))
|
||||||
|
return new QtOutputLineParser(t);
|
||||||
|
return nullptr;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
} // QtSupport::Internal
|
} // QtSupport::Internal
|
||||||
|
Reference in New Issue
Block a user