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(new Internal::SanitizerParser);
|
||||
formatter->addLineParser(Internal::createSanitizerOutputParser());
|
||||
formatter->setForwardStdOutToStdError(buildConfiguration()->parseStdOut());
|
||||
}
|
||||
FileInProjectFinder fileFinder;
|
||||
|
@@ -723,7 +723,6 @@ public:
|
||||
}};
|
||||
|
||||
DeviceCheckBuildStepFactory deviceCheckBuildStepFactory;
|
||||
SanitizerOutputFormatterFactory sanitizerFormatterFactory;
|
||||
};
|
||||
|
||||
static ProjectExplorerPlugin *m_instance = nullptr;
|
||||
@@ -825,6 +824,8 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
|
||||
|
||||
dd = new ProjectExplorerPluginPrivate;
|
||||
|
||||
setupSanitizerOutputParser();
|
||||
|
||||
setupJsonWizardPages();
|
||||
setupJsonWizardFileGenerator();
|
||||
setupJsonWizardScannerGenerator();
|
||||
@@ -1953,8 +1954,9 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
|
||||
|
||||
DeviceManager::instance()->addDevice(IDevice::Ptr(new DesktopDevice));
|
||||
|
||||
if (auto sanitizerTester = SanitizerParser::testCreator())
|
||||
addTestCreator(sanitizerTester.value());
|
||||
#ifdef WITH_TESTS
|
||||
addTestCreator(&createSanitizerOutputParserTest);
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@@ -843,7 +843,7 @@ void RunControlPrivate::showError(const QString &msg)
|
||||
|
||||
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>()) {
|
||||
for (const Id id : std::as_const(customParsersAspect->parsers)) {
|
||||
if (auto parser = createCustomParserFromId(id))
|
||||
@@ -1836,31 +1836,23 @@ void RunWorker::stop()
|
||||
reportStopped();
|
||||
}
|
||||
|
||||
// OutputFormatterFactory
|
||||
// Output parser factories
|
||||
|
||||
static QList<OutputFormatterFactory *> g_outputFormatterFactories;
|
||||
static QList<std::function<OutputLineParser *(Target *)>> g_outputParserFactories;
|
||||
|
||||
OutputFormatterFactory::OutputFormatterFactory()
|
||||
{
|
||||
g_outputFormatterFactories.append(this);
|
||||
}
|
||||
|
||||
OutputFormatterFactory::~OutputFormatterFactory()
|
||||
{
|
||||
g_outputFormatterFactories.removeOne(this);
|
||||
}
|
||||
|
||||
QList<OutputLineParser *> OutputFormatterFactory::createFormatters(Target *target)
|
||||
QList<OutputLineParser *> createOutputParsers(Target *target)
|
||||
{
|
||||
QList<OutputLineParser *> formatters;
|
||||
for (auto factory : std::as_const(g_outputFormatterFactories))
|
||||
formatters << factory->m_creator(target);
|
||||
for (auto factory : std::as_const(g_outputParserFactories)) {
|
||||
if (OutputLineParser *parser = factory(target))
|
||||
formatters << parser;
|
||||
}
|
||||
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
|
||||
|
@@ -289,22 +289,10 @@ public:
|
||||
explicit SimpleTargetRunnerFactory(const QList<Utils::Id> &runConfig);
|
||||
};
|
||||
|
||||
class PROJECTEXPLORER_EXPORT OutputFormatterFactory
|
||||
{
|
||||
protected:
|
||||
OutputFormatterFactory();
|
||||
|
||||
public:
|
||||
virtual ~OutputFormatterFactory();
|
||||
PROJECTEXPLORER_EXPORT
|
||||
void addOutputParserFactory(const std::function<Utils::OutputLineParser *(Target *)> &);
|
||||
|
||||
static QList<Utils::OutputLineParser *> createFormatters(Target *target);
|
||||
|
||||
protected:
|
||||
using FormatterCreator = std::function<QList<Utils::OutputLineParser *>(Target *)>;
|
||||
void setFormatterCreator(const FormatterCreator &creator);
|
||||
|
||||
private:
|
||||
FormatterCreator m_creator;
|
||||
};
|
||||
PROJECTEXPLORER_EXPORT QList<Utils::OutputLineParser *> createOutputParsers(Target *target);
|
||||
|
||||
} // namespace ProjectExplorer
|
||||
|
@@ -3,7 +3,10 @@
|
||||
|
||||
#include "sanitizerparser.h"
|
||||
|
||||
#include "ioutputparser.h"
|
||||
#include "projectexplorerconstants.h"
|
||||
#include "runcontrol.h"
|
||||
#include "task.h"
|
||||
|
||||
#include <QRegularExpression>
|
||||
|
||||
@@ -19,6 +22,20 @@ using namespace Utils;
|
||||
|
||||
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)
|
||||
{
|
||||
if (format != OutputFormat::StdErrFormat)
|
||||
@@ -125,7 +142,22 @@ void SanitizerParser::flush()
|
||||
m_id = 0;
|
||||
}
|
||||
|
||||
OutputLineParser *createSanitizerOutputParser()
|
||||
{
|
||||
return new SanitizerParser;
|
||||
}
|
||||
|
||||
void setupSanitizerOutputParser()
|
||||
{
|
||||
addOutputParserFactory([](Target *) { return new SanitizerParser; });
|
||||
}
|
||||
|
||||
} // namespace ProjectExplorer::Internal
|
||||
|
||||
#ifdef WITH_TESTS
|
||||
|
||||
namespace ProjectExplorer::Internal {
|
||||
|
||||
class SanitizerParserTest : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -214,24 +246,14 @@ SUMMARY: AddressSanitizer: 19 byte(s) leaked in 1 allocation(s).)";
|
||||
testbench.testParsing(input, OutputParserTester::STDERR, tasks, {}, childStdErrLines, {});
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
std::optional<std::function<QObject *()>> SanitizerParser::testCreator()
|
||||
QObject *createSanitizerOutputParserTest()
|
||||
{
|
||||
#ifdef WITH_TESTS
|
||||
return []() -> QObject * { return new SanitizerParserTest; };
|
||||
#else
|
||||
return {};
|
||||
#endif
|
||||
return new SanitizerParserTest;
|
||||
}
|
||||
|
||||
SanitizerOutputFormatterFactory::SanitizerOutputFormatterFactory()
|
||||
{
|
||||
setFormatterCreator([](Target *) -> QList<OutputLineParser *> {return {new SanitizerParser}; });
|
||||
}
|
||||
} // ProjectExplorer::Internal
|
||||
|
||||
} // namespace ProjectExplorer::Internal
|
||||
|
||||
#ifdef WITH_TESTS
|
||||
#include <sanitizerparser.moc>
|
||||
#endif
|
||||
|
||||
#endif // WITH_TESTS
|
||||
|
@@ -3,37 +3,17 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ioutputparser.h"
|
||||
#include "runcontrol.h"
|
||||
#include "task.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QVector>
|
||||
#include <utils/outputformatter.h>
|
||||
|
||||
namespace ProjectExplorer::Internal {
|
||||
|
||||
class SanitizerParser : public OutputTaskParser
|
||||
{
|
||||
public:
|
||||
static std::optional<std::function<QObject *()>> testCreator();
|
||||
Utils::OutputLineParser *createSanitizerOutputParser();
|
||||
|
||||
private:
|
||||
Result handleLine(const QString &line, Utils::OutputFormat format) override;
|
||||
void flush() override;
|
||||
void setupSanitizerOutputParser();
|
||||
|
||||
Result handleContinuation(const QString &line);
|
||||
void addLinkSpecs(const LinkSpecs &linkSpecs);
|
||||
#ifdef WITH_TESTS
|
||||
QObject *createSanitizerOutputParserTest();
|
||||
#endif
|
||||
|
||||
Task m_task;
|
||||
LinkSpecs m_linkSpecs;
|
||||
quint64 m_id = 0;
|
||||
};
|
||||
|
||||
class SanitizerOutputFormatterFactory : public ProjectExplorer::OutputFormatterFactory
|
||||
{
|
||||
public:
|
||||
SanitizerOutputFormatterFactory();
|
||||
};
|
||||
|
||||
} // namespace ProjectExplorer::Internal
|
||||
} // ProjectExplorer::Internal
|
||||
|
||||
|
@@ -43,7 +43,6 @@ QObject *pluginInstance()
|
||||
class PythonPluginPrivate
|
||||
{
|
||||
public:
|
||||
PythonOutputFormatterFactory outputFormatterFactory;
|
||||
PythonRunConfigurationFactory runConfigFactory;
|
||||
PySideBuildStepFactory buildStepFactory;
|
||||
PythonBuildConfigurationFactory buildConfigFactory;
|
||||
@@ -77,6 +76,8 @@ private:
|
||||
|
||||
setupPythonEditorFactory(this);
|
||||
|
||||
setupPythonOutputParser();
|
||||
|
||||
KitManager::setIrrelevantAspects(KitManager::irrelevantAspects()
|
||||
+ QSet<Id>{PythonKitAspect::id()});
|
||||
|
||||
|
@@ -189,12 +189,12 @@ PythonRunConfigurationFactory::PythonRunConfigurationFactory()
|
||||
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)
|
||||
return {new PythonOutputLineParser};
|
||||
return {};
|
||||
return new PythonOutputLineParser;
|
||||
return nullptr;
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -17,10 +17,6 @@ public:
|
||||
PythonRunConfigurationFactory();
|
||||
};
|
||||
|
||||
class PythonOutputFormatterFactory : public ProjectExplorer::OutputFormatterFactory
|
||||
{
|
||||
public:
|
||||
PythonOutputFormatterFactory();
|
||||
};
|
||||
void setupPythonOutputParser();
|
||||
|
||||
} // Python::Internal
|
||||
|
@@ -218,24 +218,18 @@ void QtOutputLineParser::updateProjectFileList()
|
||||
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()
|
||||
{
|
||||
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
|
||||
|
Reference in New Issue
Block a user