forked from qt-creator/qt-creator
QtSuppoer: De-O_OBJECT-ify QScxmlGenerator
Change-Id: I2732aaf838144d6da4c0b51bdfc2c8bb6cc8e21b Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
@@ -6,30 +6,63 @@
|
|||||||
#include <qtsupport/baseqtversion.h>
|
#include <qtsupport/baseqtversion.h>
|
||||||
#include <qtsupport/qtkitinformation.h>
|
#include <qtsupport/qtkitinformation.h>
|
||||||
#include <projectexplorer/target.h>
|
#include <projectexplorer/target.h>
|
||||||
|
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
#include <utils/temporarydirectory.h>
|
||||||
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QLoggingCategory>
|
#include <QLoggingCategory>
|
||||||
#include <QUuid>
|
|
||||||
|
|
||||||
using namespace ProjectExplorer;
|
using namespace ProjectExplorer;
|
||||||
|
using namespace Utils;
|
||||||
|
|
||||||
namespace QtSupport {
|
namespace QtSupport {
|
||||||
|
|
||||||
static QLoggingCategory log("qtc.qscxmlcgenerator", QtWarningMsg);
|
static QLoggingCategory log("qtc.qscxmlcgenerator", QtWarningMsg);
|
||||||
static const char TaskCategory[] = "Task.Category.ExtraCompiler.QScxmlc";
|
|
||||||
|
|
||||||
QScxmlcGenerator::QScxmlcGenerator(const Project *project,
|
const char TaskCategory[] = "Task.Category.ExtraCompiler.QScxmlc";
|
||||||
const Utils::FilePath &source,
|
|
||||||
const Utils::FilePaths &targets, QObject *parent) :
|
class QScxmlcGenerator final : public ProcessExtraCompiler
|
||||||
ProcessExtraCompiler(project, source, targets, parent),
|
{
|
||||||
m_tmpdir("qscxmlgenerator")
|
public:
|
||||||
|
QScxmlcGenerator(const Project *project, const FilePath &source,
|
||||||
|
const FilePaths &targets, QObject *parent)
|
||||||
|
: ProcessExtraCompiler(project, source, targets, parent)
|
||||||
|
, m_tmpdir("qscxmlgenerator")
|
||||||
{
|
{
|
||||||
QTC_ASSERT(targets.count() == 2, return);
|
QTC_ASSERT(targets.count() == 2, return);
|
||||||
m_header = m_tmpdir.filePath(targets[0].fileName()).toString();
|
m_header = m_tmpdir.filePath(targets[0].fileName()).toString();
|
||||||
|
QTC_ASSERT(!m_header.isEmpty(), return);
|
||||||
m_impl = m_tmpdir.filePath(targets[1].fileName()).toString();
|
m_impl = m_tmpdir.filePath(targets[1].fileName()).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
FilePath command() const override;
|
||||||
|
|
||||||
|
QStringList arguments() const override
|
||||||
|
{
|
||||||
|
return {"--header", m_header, "--impl", m_impl, tmpFile().fileName()};
|
||||||
|
}
|
||||||
|
|
||||||
|
FilePath workingDirectory() const override
|
||||||
|
{
|
||||||
|
return m_tmpdir.path();
|
||||||
|
}
|
||||||
|
|
||||||
|
FilePath tmpFile() const
|
||||||
|
{
|
||||||
|
return workingDirectory().pathAppended(source().fileName());
|
||||||
|
}
|
||||||
|
|
||||||
|
FileNameToContentsHash handleProcessFinished(Process *process) override;
|
||||||
|
bool prepareToRun(const QByteArray &sourceContents) override;
|
||||||
|
Tasks parseIssues(const QByteArray &processStderr) override;
|
||||||
|
|
||||||
|
TemporaryDirectory m_tmpdir;
|
||||||
|
QString m_header;
|
||||||
|
QString m_impl;
|
||||||
|
};
|
||||||
|
|
||||||
Tasks QScxmlcGenerator::parseIssues(const QByteArray &processStderr)
|
Tasks QScxmlcGenerator::parseIssues(const QByteArray &processStderr)
|
||||||
{
|
{
|
||||||
Tasks issues;
|
Tasks issues;
|
||||||
@@ -38,7 +71,7 @@ Tasks QScxmlcGenerator::parseIssues(const QByteArray &processStderr)
|
|||||||
QByteArrayList tokens = line.split(':');
|
QByteArrayList tokens = line.split(':');
|
||||||
|
|
||||||
if (tokens.length() > 4) {
|
if (tokens.length() > 4) {
|
||||||
Utils::FilePath file = Utils::FilePath::fromUtf8(tokens[0]);
|
FilePath file = FilePath::fromUtf8(tokens[0]);
|
||||||
int line = tokens[1].toInt();
|
int line = tokens[1].toInt();
|
||||||
// int column = tokens[2].toInt(); <- nice, but not needed for now.
|
// int column = tokens[2].toInt(); <- nice, but not needed for now.
|
||||||
Task::TaskType type = tokens[3].trimmed() == "error" ?
|
Task::TaskType type = tokens[3].trimmed() == "error" ?
|
||||||
@@ -50,8 +83,7 @@ Tasks QScxmlcGenerator::parseIssues(const QByteArray &processStderr)
|
|||||||
return issues;
|
return issues;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FilePath QScxmlcGenerator::command() const
|
||||||
Utils::FilePath QScxmlcGenerator::command() const
|
|
||||||
{
|
{
|
||||||
QtSupport::QtVersion *version = nullptr;
|
QtSupport::QtVersion *version = nullptr;
|
||||||
Target *target;
|
Target *target;
|
||||||
@@ -66,21 +98,9 @@ Utils::FilePath QScxmlcGenerator::command() const
|
|||||||
return version->qscxmlcFilePath();
|
return version->qscxmlcFilePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList QScxmlcGenerator::arguments() const
|
|
||||||
{
|
|
||||||
QTC_ASSERT(!m_header.isEmpty(), return {});
|
|
||||||
|
|
||||||
return {"--header", m_header, "--impl", m_impl, tmpFile().fileName()};
|
|
||||||
}
|
|
||||||
|
|
||||||
Utils::FilePath QScxmlcGenerator::workingDirectory() const
|
|
||||||
{
|
|
||||||
return m_tmpdir.path();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QScxmlcGenerator::prepareToRun(const QByteArray &sourceContents)
|
bool QScxmlcGenerator::prepareToRun(const QByteArray &sourceContents)
|
||||||
{
|
{
|
||||||
const Utils::FilePath fn = tmpFile();
|
const FilePath fn = tmpFile();
|
||||||
QFile input(fn.toString());
|
QFile input(fn.toString());
|
||||||
if (!input.open(QIODevice::WriteOnly))
|
if (!input.open(QIODevice::WriteOnly))
|
||||||
return false;
|
return false;
|
||||||
@@ -90,13 +110,13 @@ bool QScxmlcGenerator::prepareToRun(const QByteArray &sourceContents)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileNameToContentsHash QScxmlcGenerator::handleProcessFinished(Utils::Process *process)
|
FileNameToContentsHash QScxmlcGenerator::handleProcessFinished(Process *process)
|
||||||
{
|
{
|
||||||
Q_UNUSED(process)
|
Q_UNUSED(process)
|
||||||
const Utils::FilePath wd = workingDirectory();
|
const FilePath wd = workingDirectory();
|
||||||
FileNameToContentsHash result;
|
FileNameToContentsHash result;
|
||||||
forEachTarget([&](const Utils::FilePath &target) {
|
forEachTarget([&](const FilePath &target) {
|
||||||
const Utils::FilePath file = wd.pathAppended(target.fileName());
|
const FilePath file = wd.pathAppended(target.fileName());
|
||||||
QFile generated(file.toString());
|
QFile generated(file.toString());
|
||||||
if (!generated.open(QIODevice::ReadOnly))
|
if (!generated.open(QIODevice::ReadOnly))
|
||||||
return;
|
return;
|
||||||
@@ -105,11 +125,6 @@ FileNameToContentsHash QScxmlcGenerator::handleProcessFinished(Utils::Process *p
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils::FilePath QScxmlcGenerator::tmpFile() const
|
|
||||||
{
|
|
||||||
return workingDirectory().pathAppended(source().fileName());
|
|
||||||
}
|
|
||||||
|
|
||||||
FileType QScxmlcGeneratorFactory::sourceType() const
|
FileType QScxmlcGeneratorFactory::sourceType() const
|
||||||
{
|
{
|
||||||
return FileType::StateChart;
|
return FileType::StateChart;
|
||||||
@@ -121,8 +136,8 @@ QString QScxmlcGeneratorFactory::sourceTag() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
ExtraCompiler *QScxmlcGeneratorFactory::create(
|
ExtraCompiler *QScxmlcGeneratorFactory::create(
|
||||||
const Project *project, const Utils::FilePath &source,
|
const Project *project, const FilePath &source,
|
||||||
const Utils::FilePaths &targets)
|
const FilePaths &targets)
|
||||||
{
|
{
|
||||||
return new QScxmlcGenerator(project, source, targets, this);
|
return new QScxmlcGenerator(project, source, targets, this);
|
||||||
}
|
}
|
||||||
|
@@ -4,37 +4,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <projectexplorer/extracompiler.h>
|
#include <projectexplorer/extracompiler.h>
|
||||||
#include <utils/fileutils.h>
|
|
||||||
#include <utils/temporarydirectory.h>
|
#include <utils/filepath.h>
|
||||||
|
|
||||||
namespace QtSupport {
|
namespace QtSupport {
|
||||||
|
|
||||||
class QScxmlcGenerator : public ProjectExplorer::ProcessExtraCompiler
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
QScxmlcGenerator(const ProjectExplorer::Project *project, const Utils::FilePath &source,
|
|
||||||
const Utils::FilePaths &targets, QObject *parent = nullptr);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
Utils::FilePath command() const override;
|
|
||||||
QStringList arguments() const override;
|
|
||||||
Utils::FilePath workingDirectory() const override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
Utils::FilePath tmpFile() const;
|
|
||||||
ProjectExplorer::FileNameToContentsHash handleProcessFinished(Utils::Process *process) override;
|
|
||||||
bool prepareToRun(const QByteArray &sourceContents) override;
|
|
||||||
ProjectExplorer::Tasks parseIssues(const QByteArray &processStderr) override;
|
|
||||||
|
|
||||||
Utils::TemporaryDirectory m_tmpdir;
|
|
||||||
QString m_header;
|
|
||||||
QString m_impl;
|
|
||||||
};
|
|
||||||
|
|
||||||
class QScxmlcGeneratorFactory : public ProjectExplorer::ExtraCompilerFactory
|
class QScxmlcGeneratorFactory : public ProjectExplorer::ExtraCompilerFactory
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
|
||||||
public:
|
public:
|
||||||
QScxmlcGeneratorFactory() = default;
|
QScxmlcGeneratorFactory() = default;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user