forked from qt-creator/qt-creator
ExtraCompiler: Remove stored targets list
Itereate over the hash keys instead. Change-Id: Ib14bef708b74ed1938bcb985b3a5091aca704391 Reviewed-by: Ulf Hermann <ulf.hermann@theqtcompany.com> Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
This commit is contained in:
committed by
Orgad Shaneh
parent
1c483b95a6
commit
ba517fcfab
@@ -122,8 +122,9 @@ void GeneratedCodeModelSupport::update(const QList<ProjectExplorer::ExtraCompile
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
extraCompilerCache.insert(generator);
|
extraCompilerCache.insert(generator);
|
||||||
foreach (const Utils::FileName &generatedFile, generator->targets())
|
generator->forEachTarget([mm, generator](const Utils::FileName &generatedFile) {
|
||||||
new GeneratedCodeModelSupport(mm, generator, generatedFile);
|
new GeneratedCodeModelSupport(mm, generator, generatedFile);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -58,8 +58,7 @@ class ExtraCompilerPrivate
|
|||||||
public:
|
public:
|
||||||
const Project *project;
|
const Project *project;
|
||||||
Utils::FileName source;
|
Utils::FileName source;
|
||||||
QHash<Utils::FileName, QByteArray> contents;
|
FileNameToContentsHash contents;
|
||||||
Utils::FileNameList targets;
|
|
||||||
QList<Task> issues;
|
QList<Task> issues;
|
||||||
QDateTime compileTime;
|
QDateTime compileTime;
|
||||||
Core::IEditor *lastEditor = nullptr;
|
Core::IEditor *lastEditor = nullptr;
|
||||||
@@ -77,7 +76,6 @@ ExtraCompiler::ExtraCompiler(const Project *project, const Utils::FileName &sour
|
|||||||
{
|
{
|
||||||
d->project = project;
|
d->project = project;
|
||||||
d->source = source;
|
d->source = source;
|
||||||
d->targets = targets;
|
|
||||||
foreach (const Utils::FileName &target, targets)
|
foreach (const Utils::FileName &target, targets)
|
||||||
d->contents.insert(target, QByteArray());
|
d->contents.insert(target, QByteArray());
|
||||||
d->timer.setSingleShot(true);
|
d->timer.setSingleShot(true);
|
||||||
@@ -156,7 +154,13 @@ QByteArray ExtraCompiler::content(const Utils::FileName &file) const
|
|||||||
|
|
||||||
Utils::FileNameList ExtraCompiler::targets() const
|
Utils::FileNameList ExtraCompiler::targets() const
|
||||||
{
|
{
|
||||||
return d->targets;
|
return d->contents.keys();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ExtraCompiler::forEachTarget(std::function<void (const Utils::FileName &)> func)
|
||||||
|
{
|
||||||
|
for (auto it = d->contents.constBegin(), end = d->contents.constEnd(); it != end; ++it)
|
||||||
|
func(it.key());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExtraCompiler::setCompileTime(const QDateTime &time)
|
void ExtraCompiler::setCompileTime(const QDateTime &time)
|
||||||
@@ -185,12 +189,12 @@ void ExtraCompiler::onTargetsBuilt(Project *project)
|
|||||||
if (d->compileTime.isValid() && d->compileTime >= sourceTime)
|
if (d->compileTime.isValid() && d->compileTime >= sourceTime)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
foreach (const Utils::FileName &target, d->targets) {
|
forEachTarget([&](const Utils::FileName &target) {
|
||||||
QFileInfo fi(target.toFileInfo());
|
QFileInfo fi(target.toFileInfo());
|
||||||
QDateTime generateTime = fi.exists() ? fi.lastModified() : QDateTime();
|
QDateTime generateTime = fi.exists() ? fi.lastModified() : QDateTime();
|
||||||
if (generateTime.isValid() && (generateTime > sourceTime)) {
|
if (generateTime.isValid() && (generateTime > sourceTime)) {
|
||||||
if (d->compileTime >= generateTime)
|
if (d->compileTime >= generateTime)
|
||||||
continue;
|
return;
|
||||||
|
|
||||||
QFile file(target.toString());
|
QFile file(target.toString());
|
||||||
if (file.open(QFile::ReadOnly | QFile::Text)) {
|
if (file.open(QFile::ReadOnly | QFile::Text)) {
|
||||||
@@ -198,7 +202,7 @@ void ExtraCompiler::onTargetsBuilt(Project *project)
|
|||||||
setContent(target, file.readAll());
|
setContent(target, file.readAll());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExtraCompiler::onEditorChanged(Core::IEditor *editor)
|
void ExtraCompiler::onEditorChanged(Core::IEditor *editor)
|
||||||
@@ -415,8 +419,8 @@ void ProcessExtraCompiler::runImpl(const ContentProvider &provider)
|
|||||||
if (m_watcher)
|
if (m_watcher)
|
||||||
delete m_watcher;
|
delete m_watcher;
|
||||||
|
|
||||||
m_watcher = new QFutureWatcher<QList<QByteArray>>();
|
m_watcher = new QFutureWatcher<FileNameToContentsHash>();
|
||||||
connect(m_watcher, &QFutureWatcher<QList<QByteArray>>::finished,
|
connect(m_watcher, &QFutureWatcher<FileNameToContentsHash>::finished,
|
||||||
this, &ProcessExtraCompiler::cleanUp);
|
this, &ProcessExtraCompiler::cleanUp);
|
||||||
|
|
||||||
m_watcher->setFuture(Utils::runAsync(extraCompilerThreadPool(),
|
m_watcher->setFuture(Utils::runAsync(extraCompilerThreadPool(),
|
||||||
@@ -425,16 +429,17 @@ void ProcessExtraCompiler::runImpl(const ContentProvider &provider)
|
|||||||
buildEnvironment()));
|
buildEnvironment()));
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QByteArray> ProcessExtraCompiler::runInThread(const Utils::FileName &cmd, const Utils::FileName &workDir,
|
FileNameToContentsHash ProcessExtraCompiler::runInThread(
|
||||||
const QStringList &args, const ContentProvider &provider,
|
const Utils::FileName &cmd, const Utils::FileName &workDir,
|
||||||
const Utils::Environment &env)
|
const QStringList &args, const ContentProvider &provider,
|
||||||
|
const Utils::Environment &env)
|
||||||
{
|
{
|
||||||
if (cmd.isEmpty() || !cmd.toFileInfo().isExecutable())
|
if (cmd.isEmpty() || !cmd.toFileInfo().isExecutable())
|
||||||
return QList<QByteArray>();
|
return FileNameToContentsHash();
|
||||||
|
|
||||||
const QByteArray sourceContents = provider();
|
const QByteArray sourceContents = provider();
|
||||||
if (sourceContents.isNull() || !prepareToRun(sourceContents))
|
if (sourceContents.isNull() || !prepareToRun(sourceContents))
|
||||||
return QList<QByteArray>();
|
return FileNameToContentsHash();
|
||||||
|
|
||||||
QProcess process;
|
QProcess process;
|
||||||
|
|
||||||
@@ -444,7 +449,7 @@ QList<QByteArray> ProcessExtraCompiler::runInThread(const Utils::FileName &cmd,
|
|||||||
process.start(cmd.toString(), args, QIODevice::ReadWrite);
|
process.start(cmd.toString(), args, QIODevice::ReadWrite);
|
||||||
if (!process.waitForStarted()) {
|
if (!process.waitForStarted()) {
|
||||||
handleProcessError(&process);
|
handleProcessError(&process);
|
||||||
return QList<QByteArray>();
|
return FileNameToContentsHash();
|
||||||
}
|
}
|
||||||
handleProcessStarted(&process, sourceContents);
|
handleProcessStarted(&process, sourceContents);
|
||||||
process.waitForFinished();
|
process.waitForFinished();
|
||||||
@@ -460,18 +465,15 @@ QList<QByteArray> ProcessExtraCompiler::runInThread(const Utils::FileName &cmd,
|
|||||||
void ProcessExtraCompiler::cleanUp()
|
void ProcessExtraCompiler::cleanUp()
|
||||||
{
|
{
|
||||||
QTC_ASSERT(m_watcher, return);
|
QTC_ASSERT(m_watcher, return);
|
||||||
const QList<QByteArray> data = m_watcher->future().result();
|
const FileNameToContentsHash data = m_watcher->future().result();
|
||||||
delete m_watcher;
|
delete m_watcher;
|
||||||
m_watcher = nullptr;
|
m_watcher = nullptr;
|
||||||
|
|
||||||
if (data.isEmpty())
|
if (data.isEmpty())
|
||||||
return; // There was some kind of error...
|
return; // There was some kind of error...
|
||||||
|
|
||||||
const Utils::FileNameList targetList = targets();
|
for (auto it = data.constBegin(), end = data.constEnd(); it != end; ++it)
|
||||||
QTC_ASSERT(data.count() == targetList.count(), return);
|
setContent(it.key(), it.value());
|
||||||
|
|
||||||
for (int i = 0; i < targetList.count(); ++i)
|
|
||||||
setContent(targetList.at(i), data.at(i));
|
|
||||||
|
|
||||||
setCompileTime(QDateTime::currentDateTime());
|
setCompileTime(QDateTime::currentDateTime());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,14 +35,19 @@
|
|||||||
|
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
#include <QFuture>
|
#include <QFuture>
|
||||||
|
#include <QHash>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
QT_FORWARD_DECLARE_CLASS(QProcess);
|
QT_FORWARD_DECLARE_CLASS(QProcess);
|
||||||
QT_FORWARD_DECLARE_CLASS(QThreadPool);
|
QT_FORWARD_DECLARE_CLASS(QThreadPool);
|
||||||
|
|
||||||
namespace ProjectExplorer {
|
namespace ProjectExplorer {
|
||||||
|
|
||||||
class ExtraCompilerPrivate;
|
class ExtraCompilerPrivate;
|
||||||
|
using FileNameToContentsHash = QHash<Utils::FileName, QByteArray>;
|
||||||
|
|
||||||
class PROJECTEXPLORER_EXPORT ExtraCompiler : public QObject
|
class PROJECTEXPLORER_EXPORT ExtraCompiler : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -61,6 +66,7 @@ public:
|
|||||||
QByteArray content(const Utils::FileName &file) const;
|
QByteArray content(const Utils::FileName &file) const;
|
||||||
|
|
||||||
Utils::FileNameList targets() const;
|
Utils::FileNameList targets() const;
|
||||||
|
void forEachTarget(std::function<void(const Utils::FileName &)> func);
|
||||||
|
|
||||||
void setCompileTime(const QDateTime &time);
|
void setCompileTime(const QDateTime &time);
|
||||||
QDateTime compileTime() const;
|
QDateTime compileTime() const;
|
||||||
@@ -115,19 +121,19 @@ protected:
|
|||||||
virtual void handleProcessError(QProcess *process) { Q_UNUSED(process); }
|
virtual void handleProcessError(QProcess *process) { Q_UNUSED(process); }
|
||||||
virtual void handleProcessStarted(QProcess *process, const QByteArray &sourceContents)
|
virtual void handleProcessStarted(QProcess *process, const QByteArray &sourceContents)
|
||||||
{ Q_UNUSED(process); Q_UNUSED(sourceContents); }
|
{ Q_UNUSED(process); Q_UNUSED(sourceContents); }
|
||||||
virtual QList<QByteArray> handleProcessFinished(QProcess *process) = 0;
|
virtual FileNameToContentsHash handleProcessFinished(QProcess *process) = 0;
|
||||||
|
|
||||||
virtual QList<Task> parseIssues(const QByteArray &stdErr);
|
virtual QList<Task> parseIssues(const QByteArray &stdErr);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using ContentProvider = std::function<QByteArray()>;
|
using ContentProvider = std::function<QByteArray()>;
|
||||||
void runImpl(const ContentProvider &sourceContents);
|
void runImpl(const ContentProvider &sourceContents);
|
||||||
QList<QByteArray> runInThread(const Utils::FileName &cmd, const Utils::FileName &workDir,
|
FileNameToContentsHash runInThread(const Utils::FileName &cmd, const Utils::FileName &workDir,
|
||||||
const QStringList &args, const ContentProvider &provider,
|
const QStringList &args, const ContentProvider &provider,
|
||||||
const Utils::Environment &env);
|
const Utils::Environment &env);
|
||||||
void cleanUp();
|
void cleanUp();
|
||||||
|
|
||||||
QFutureWatcher<QList<QByteArray>> *m_watcher = nullptr;
|
QFutureWatcher<FileNameToContentsHash> *m_watcher = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
class PROJECTEXPLORER_EXPORT ExtraCompilerFactory : public QObject
|
class PROJECTEXPLORER_EXPORT ExtraCompilerFactory : public QObject
|
||||||
|
|||||||
@@ -515,7 +515,7 @@ void QmakeProject::updateCppCodeModel()
|
|||||||
// generated files:
|
// generated files:
|
||||||
QList<ProjectExplorer::ExtraCompiler *> proGenerators = pro->extraCompilers();
|
QList<ProjectExplorer::ExtraCompiler *> proGenerators = pro->extraCompilers();
|
||||||
foreach (ProjectExplorer::ExtraCompiler *ec, proGenerators) {
|
foreach (ProjectExplorer::ExtraCompiler *ec, proGenerators) {
|
||||||
foreach (const FileName &generatedFile, ec->targets()) {
|
ec->forEachTarget([&](const Utils::FileName &generatedFile) {
|
||||||
QString name = generatedFile.toString();
|
QString name = generatedFile.toString();
|
||||||
allFiles << name;
|
allFiles << name;
|
||||||
ProjectFile::Kind kind = ProjectFile::classify(name);
|
ProjectFile::Kind kind = ProjectFile::classify(name);
|
||||||
@@ -535,7 +535,7 @@ void QmakeProject::updateCppCodeModel()
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
generators.append(proGenerators);
|
generators.append(proGenerators);
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,11 @@ QScxmlcGenerator::QScxmlcGenerator(const Project *project,
|
|||||||
const Utils::FileName &source,
|
const Utils::FileName &source,
|
||||||
const Utils::FileNameList &targets, QObject *parent) :
|
const Utils::FileNameList &targets, QObject *parent) :
|
||||||
ProcessExtraCompiler(project, source, targets, parent)
|
ProcessExtraCompiler(project, source, targets, parent)
|
||||||
{ }
|
{
|
||||||
|
QTC_ASSERT(targets.count() == 2, return);
|
||||||
|
m_header = m_tmpdir.path() + QLatin1Char('/') + targets[0].fileName();
|
||||||
|
m_impl = m_tmpdir.path() + QLatin1Char('/') + targets[1].fileName();
|
||||||
|
}
|
||||||
|
|
||||||
QList<Task> QScxmlcGenerator::parseIssues(const QByteArray &processStderr)
|
QList<Task> QScxmlcGenerator::parseIssues(const QByteArray &processStderr)
|
||||||
{
|
{
|
||||||
@@ -84,14 +88,10 @@ Utils::FileName QScxmlcGenerator::command() const
|
|||||||
|
|
||||||
QStringList QScxmlcGenerator::arguments() const
|
QStringList QScxmlcGenerator::arguments() const
|
||||||
{
|
{
|
||||||
QTC_ASSERT(targets().count() == 2, return QStringList());
|
QTC_ASSERT(!m_header.isEmpty(), return QStringList());
|
||||||
|
|
||||||
const Utils::FileName fn = tmpFile();
|
return QStringList({ QLatin1String("--header"), m_header, QLatin1String("--impl"), m_impl,
|
||||||
const QString header = m_tmpdir.path() + QLatin1Char('/') + targets()[0].fileName();
|
tmpFile().fileName() });
|
||||||
const QString impl = m_tmpdir.path() + QLatin1Char('/') + targets()[1].fileName();
|
|
||||||
|
|
||||||
return QStringList({ QLatin1String("--header"), header, QLatin1String("--impl"), impl,
|
|
||||||
fn.fileName() });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils::FileName QScxmlcGenerator::workingDirectory() const
|
Utils::FileName QScxmlcGenerator::workingDirectory() const
|
||||||
@@ -111,19 +111,19 @@ bool QScxmlcGenerator::prepareToRun(const QByteArray &sourceContents)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QByteArray> QScxmlcGenerator::handleProcessFinished(QProcess *process)
|
FileNameToContentsHash QScxmlcGenerator::handleProcessFinished(QProcess *process)
|
||||||
{
|
{
|
||||||
Q_UNUSED(process);
|
Q_UNUSED(process);
|
||||||
const Utils::FileName wd = workingDirectory();
|
const Utils::FileName wd = workingDirectory();
|
||||||
QList<QByteArray> result;
|
FileNameToContentsHash result;
|
||||||
foreach (const Utils::FileName &target, targets()) {
|
forEachTarget([&](const Utils::FileName &target) {
|
||||||
Utils::FileName file = wd;
|
Utils::FileName file = wd;
|
||||||
file.appendPath(target.fileName());
|
file.appendPath(target.fileName());
|
||||||
QFile generated(file.toString());
|
QFile generated(file.toString());
|
||||||
if (!generated.open(QIODevice::ReadOnly))
|
if (!generated.open(QIODevice::ReadOnly))
|
||||||
continue;
|
return;
|
||||||
result << generated.readAll();
|
result[target] = generated.readAll();
|
||||||
}
|
});
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,11 +47,13 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Utils::FileName tmpFile() const;
|
Utils::FileName tmpFile() const;
|
||||||
QList<QByteArray> handleProcessFinished(QProcess *process) override;
|
ProjectExplorer::FileNameToContentsHash handleProcessFinished(QProcess *process) override;
|
||||||
bool prepareToRun(const QByteArray &sourceContents) override;
|
bool prepareToRun(const QByteArray &sourceContents) override;
|
||||||
QList<ProjectExplorer::Task> parseIssues(const QByteArray &processStderr) override;
|
QList<ProjectExplorer::Task> parseIssues(const QByteArray &processStderr) override;
|
||||||
|
|
||||||
QTemporaryDir m_tmpdir;
|
QTemporaryDir m_tmpdir;
|
||||||
|
QString m_header;
|
||||||
|
QString m_impl;
|
||||||
};
|
};
|
||||||
|
|
||||||
class QScxmlcGeneratorFactory : public ProjectExplorer::ExtraCompilerFactory
|
class QScxmlcGeneratorFactory : public ProjectExplorer::ExtraCompilerFactory
|
||||||
|
|||||||
@@ -31,6 +31,8 @@
|
|||||||
#include <projectexplorer/target.h>
|
#include <projectexplorer/target.h>
|
||||||
#include <projectexplorer/buildconfiguration.h>
|
#include <projectexplorer/buildconfiguration.h>
|
||||||
|
|
||||||
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QLoggingCategory>
|
#include <QLoggingCategory>
|
||||||
@@ -44,7 +46,9 @@ namespace QtSupport {
|
|||||||
UicGenerator::UicGenerator(const Project *project, const Utils::FileName &source,
|
UicGenerator::UicGenerator(const Project *project, const Utils::FileName &source,
|
||||||
const Utils::FileNameList &targets, QObject *parent) :
|
const Utils::FileNameList &targets, QObject *parent) :
|
||||||
ProcessExtraCompiler(project, source, targets, parent)
|
ProcessExtraCompiler(project, source, targets, parent)
|
||||||
{ }
|
{
|
||||||
|
QTC_ASSERT(targets.count() == 1, return);
|
||||||
|
}
|
||||||
|
|
||||||
Utils::FileName UicGenerator::command() const
|
Utils::FileName UicGenerator::command() const
|
||||||
{
|
{
|
||||||
@@ -67,14 +71,19 @@ void UicGenerator::handleProcessStarted(QProcess *process, const QByteArray &sou
|
|||||||
process->closeWriteChannel();
|
process->closeWriteChannel();
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QByteArray> UicGenerator::handleProcessFinished(QProcess *process)
|
FileNameToContentsHash UicGenerator::handleProcessFinished(QProcess *process)
|
||||||
{
|
{
|
||||||
|
FileNameToContentsHash result;
|
||||||
if (process->exitStatus() != QProcess::NormalExit && process->exitCode() != 0)
|
if (process->exitStatus() != QProcess::NormalExit && process->exitCode() != 0)
|
||||||
return QList<QByteArray>();
|
return result;
|
||||||
|
|
||||||
|
const Utils::FileNameList targetList = targets();
|
||||||
|
if (targetList.size() != 1)
|
||||||
|
return result;
|
||||||
// As far as I can discover in the UIC sources, it writes out local 8-bit encoding. The
|
// As far as I can discover in the UIC sources, it writes out local 8-bit encoding. The
|
||||||
// conversion below is to normalize both the encoding, and the line terminators.
|
// conversion below is to normalize both the encoding, and the line terminators.
|
||||||
return { QString::fromLocal8Bit(process->readAllStandardOutput()).toUtf8() };
|
result[targetList.first()] = QString::fromLocal8Bit(process->readAllStandardOutput()).toUtf8();
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileType UicGeneratorFactory::sourceType() const
|
FileType UicGeneratorFactory::sourceType() const
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
Utils::FileName command() const override;
|
Utils::FileName command() const override;
|
||||||
void handleProcessStarted(QProcess *process, const QByteArray &sourceContents) override;
|
void handleProcessStarted(QProcess *process, const QByteArray &sourceContents) override;
|
||||||
QList<QByteArray> handleProcessFinished(QProcess *process) override;
|
ProjectExplorer::FileNameToContentsHash handleProcessFinished(QProcess *process) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class UicGeneratorFactory : public ProjectExplorer::ExtraCompilerFactory
|
class UicGeneratorFactory : public ProjectExplorer::ExtraCompilerFactory
|
||||||
|
|||||||
Reference in New Issue
Block a user