QtSuppoer: De-O_OBJECT-ify QScxmlGenerator

Change-Id: I2732aaf838144d6da4c0b51bdfc2c8bb6cc8e21b
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
hjk
2023-08-08 15:15:28 +02:00
parent 1836b50f5d
commit bb6c26cac9
2 changed files with 55 additions and 64 deletions

View File

@@ -6,29 +6,62 @@
#include <qtsupport/baseqtversion.h>
#include <qtsupport/qtkitinformation.h>
#include <projectexplorer/target.h>
#include <utils/qtcassert.h>
#include <utils/temporarydirectory.h>
#include <QDateTime>
#include <QLoggingCategory>
#include <QUuid>
using namespace ProjectExplorer;
using namespace Utils;
namespace QtSupport {
static QLoggingCategory log("qtc.qscxmlcgenerator", QtWarningMsg);
static const char TaskCategory[] = "Task.Category.ExtraCompiler.QScxmlc";
QScxmlcGenerator::QScxmlcGenerator(const Project *project,
const Utils::FilePath &source,
const Utils::FilePaths &targets, QObject *parent) :
ProcessExtraCompiler(project, source, targets, parent),
m_tmpdir("qscxmlgenerator")
const char TaskCategory[] = "Task.Category.ExtraCompiler.QScxmlc";
class QScxmlcGenerator final : public ProcessExtraCompiler
{
QTC_ASSERT(targets.count() == 2, return);
m_header = m_tmpdir.filePath(targets[0].fileName()).toString();
m_impl = m_tmpdir.filePath(targets[1].fileName()).toString();
}
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);
m_header = m_tmpdir.filePath(targets[0].fileName()).toString();
QTC_ASSERT(!m_header.isEmpty(), return);
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)
{
@@ -38,7 +71,7 @@ Tasks QScxmlcGenerator::parseIssues(const QByteArray &processStderr)
QByteArrayList tokens = line.split(':');
if (tokens.length() > 4) {
Utils::FilePath file = Utils::FilePath::fromUtf8(tokens[0]);
FilePath file = FilePath::fromUtf8(tokens[0]);
int line = tokens[1].toInt();
// int column = tokens[2].toInt(); <- nice, but not needed for now.
Task::TaskType type = tokens[3].trimmed() == "error" ?
@@ -50,8 +83,7 @@ Tasks QScxmlcGenerator::parseIssues(const QByteArray &processStderr)
return issues;
}
Utils::FilePath QScxmlcGenerator::command() const
FilePath QScxmlcGenerator::command() const
{
QtSupport::QtVersion *version = nullptr;
Target *target;
@@ -66,21 +98,9 @@ Utils::FilePath QScxmlcGenerator::command() const
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)
{
const Utils::FilePath fn = tmpFile();
const FilePath fn = tmpFile();
QFile input(fn.toString());
if (!input.open(QIODevice::WriteOnly))
return false;
@@ -90,13 +110,13 @@ bool QScxmlcGenerator::prepareToRun(const QByteArray &sourceContents)
return true;
}
FileNameToContentsHash QScxmlcGenerator::handleProcessFinished(Utils::Process *process)
FileNameToContentsHash QScxmlcGenerator::handleProcessFinished(Process *process)
{
Q_UNUSED(process)
const Utils::FilePath wd = workingDirectory();
const FilePath wd = workingDirectory();
FileNameToContentsHash result;
forEachTarget([&](const Utils::FilePath &target) {
const Utils::FilePath file = wd.pathAppended(target.fileName());
forEachTarget([&](const FilePath &target) {
const FilePath file = wd.pathAppended(target.fileName());
QFile generated(file.toString());
if (!generated.open(QIODevice::ReadOnly))
return;
@@ -105,11 +125,6 @@ FileNameToContentsHash QScxmlcGenerator::handleProcessFinished(Utils::Process *p
return result;
}
Utils::FilePath QScxmlcGenerator::tmpFile() const
{
return workingDirectory().pathAppended(source().fileName());
}
FileType QScxmlcGeneratorFactory::sourceType() const
{
return FileType::StateChart;
@@ -121,8 +136,8 @@ QString QScxmlcGeneratorFactory::sourceTag() const
}
ExtraCompiler *QScxmlcGeneratorFactory::create(
const Project *project, const Utils::FilePath &source,
const Utils::FilePaths &targets)
const Project *project, const FilePath &source,
const FilePaths &targets)
{
return new QScxmlcGenerator(project, source, targets, this);
}

View File

@@ -4,37 +4,13 @@
#pragma once
#include <projectexplorer/extracompiler.h>
#include <utils/fileutils.h>
#include <utils/temporarydirectory.h>
#include <utils/filepath.h>
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
{
Q_OBJECT
public:
QScxmlcGeneratorFactory() = default;