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;
|
||||
|
||||
extraCompilerCache.insert(generator);
|
||||
foreach (const Utils::FileName &generatedFile, generator->targets())
|
||||
generator->forEachTarget([mm, generator](const Utils::FileName &generatedFile) {
|
||||
new GeneratedCodeModelSupport(mm, generator, generatedFile);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -58,8 +58,7 @@ class ExtraCompilerPrivate
|
||||
public:
|
||||
const Project *project;
|
||||
Utils::FileName source;
|
||||
QHash<Utils::FileName, QByteArray> contents;
|
||||
Utils::FileNameList targets;
|
||||
FileNameToContentsHash contents;
|
||||
QList<Task> issues;
|
||||
QDateTime compileTime;
|
||||
Core::IEditor *lastEditor = nullptr;
|
||||
@@ -77,7 +76,6 @@ ExtraCompiler::ExtraCompiler(const Project *project, const Utils::FileName &sour
|
||||
{
|
||||
d->project = project;
|
||||
d->source = source;
|
||||
d->targets = targets;
|
||||
foreach (const Utils::FileName &target, targets)
|
||||
d->contents.insert(target, QByteArray());
|
||||
d->timer.setSingleShot(true);
|
||||
@@ -156,7 +154,13 @@ QByteArray ExtraCompiler::content(const Utils::FileName &file) 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)
|
||||
@@ -185,12 +189,12 @@ void ExtraCompiler::onTargetsBuilt(Project *project)
|
||||
if (d->compileTime.isValid() && d->compileTime >= sourceTime)
|
||||
return;
|
||||
|
||||
foreach (const Utils::FileName &target, d->targets) {
|
||||
forEachTarget([&](const Utils::FileName &target) {
|
||||
QFileInfo fi(target.toFileInfo());
|
||||
QDateTime generateTime = fi.exists() ? fi.lastModified() : QDateTime();
|
||||
if (generateTime.isValid() && (generateTime > sourceTime)) {
|
||||
if (d->compileTime >= generateTime)
|
||||
continue;
|
||||
return;
|
||||
|
||||
QFile file(target.toString());
|
||||
if (file.open(QFile::ReadOnly | QFile::Text)) {
|
||||
@@ -198,7 +202,7 @@ void ExtraCompiler::onTargetsBuilt(Project *project)
|
||||
setContent(target, file.readAll());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void ExtraCompiler::onEditorChanged(Core::IEditor *editor)
|
||||
@@ -415,8 +419,8 @@ void ProcessExtraCompiler::runImpl(const ContentProvider &provider)
|
||||
if (m_watcher)
|
||||
delete m_watcher;
|
||||
|
||||
m_watcher = new QFutureWatcher<QList<QByteArray>>();
|
||||
connect(m_watcher, &QFutureWatcher<QList<QByteArray>>::finished,
|
||||
m_watcher = new QFutureWatcher<FileNameToContentsHash>();
|
||||
connect(m_watcher, &QFutureWatcher<FileNameToContentsHash>::finished,
|
||||
this, &ProcessExtraCompiler::cleanUp);
|
||||
|
||||
m_watcher->setFuture(Utils::runAsync(extraCompilerThreadPool(),
|
||||
@@ -425,16 +429,17 @@ void ProcessExtraCompiler::runImpl(const ContentProvider &provider)
|
||||
buildEnvironment()));
|
||||
}
|
||||
|
||||
QList<QByteArray> ProcessExtraCompiler::runInThread(const Utils::FileName &cmd, const Utils::FileName &workDir,
|
||||
FileNameToContentsHash ProcessExtraCompiler::runInThread(
|
||||
const Utils::FileName &cmd, const Utils::FileName &workDir,
|
||||
const QStringList &args, const ContentProvider &provider,
|
||||
const Utils::Environment &env)
|
||||
{
|
||||
if (cmd.isEmpty() || !cmd.toFileInfo().isExecutable())
|
||||
return QList<QByteArray>();
|
||||
return FileNameToContentsHash();
|
||||
|
||||
const QByteArray sourceContents = provider();
|
||||
if (sourceContents.isNull() || !prepareToRun(sourceContents))
|
||||
return QList<QByteArray>();
|
||||
return FileNameToContentsHash();
|
||||
|
||||
QProcess process;
|
||||
|
||||
@@ -444,7 +449,7 @@ QList<QByteArray> ProcessExtraCompiler::runInThread(const Utils::FileName &cmd,
|
||||
process.start(cmd.toString(), args, QIODevice::ReadWrite);
|
||||
if (!process.waitForStarted()) {
|
||||
handleProcessError(&process);
|
||||
return QList<QByteArray>();
|
||||
return FileNameToContentsHash();
|
||||
}
|
||||
handleProcessStarted(&process, sourceContents);
|
||||
process.waitForFinished();
|
||||
@@ -460,18 +465,15 @@ QList<QByteArray> ProcessExtraCompiler::runInThread(const Utils::FileName &cmd,
|
||||
void ProcessExtraCompiler::cleanUp()
|
||||
{
|
||||
QTC_ASSERT(m_watcher, return);
|
||||
const QList<QByteArray> data = m_watcher->future().result();
|
||||
const FileNameToContentsHash data = m_watcher->future().result();
|
||||
delete m_watcher;
|
||||
m_watcher = nullptr;
|
||||
|
||||
if (data.isEmpty())
|
||||
return; // There was some kind of error...
|
||||
|
||||
const Utils::FileNameList targetList = targets();
|
||||
QTC_ASSERT(data.count() == targetList.count(), return);
|
||||
|
||||
for (int i = 0; i < targetList.count(); ++i)
|
||||
setContent(targetList.at(i), data.at(i));
|
||||
for (auto it = data.constBegin(), end = data.constEnd(); it != end; ++it)
|
||||
setContent(it.key(), it.value());
|
||||
|
||||
setCompileTime(QDateTime::currentDateTime());
|
||||
}
|
||||
|
||||
@@ -35,14 +35,19 @@
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QFuture>
|
||||
#include <QHash>
|
||||
#include <QList>
|
||||
|
||||
#include <functional>
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QProcess);
|
||||
QT_FORWARD_DECLARE_CLASS(QThreadPool);
|
||||
|
||||
namespace ProjectExplorer {
|
||||
|
||||
class ExtraCompilerPrivate;
|
||||
using FileNameToContentsHash = QHash<Utils::FileName, QByteArray>;
|
||||
|
||||
class PROJECTEXPLORER_EXPORT ExtraCompiler : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -61,6 +66,7 @@ public:
|
||||
QByteArray content(const Utils::FileName &file) const;
|
||||
|
||||
Utils::FileNameList targets() const;
|
||||
void forEachTarget(std::function<void(const Utils::FileName &)> func);
|
||||
|
||||
void setCompileTime(const QDateTime &time);
|
||||
QDateTime compileTime() const;
|
||||
@@ -115,19 +121,19 @@ protected:
|
||||
virtual void handleProcessError(QProcess *process) { Q_UNUSED(process); }
|
||||
virtual void handleProcessStarted(QProcess *process, const QByteArray &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);
|
||||
|
||||
private:
|
||||
using ContentProvider = std::function<QByteArray()>;
|
||||
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 Utils::Environment &env);
|
||||
void cleanUp();
|
||||
|
||||
QFutureWatcher<QList<QByteArray>> *m_watcher = nullptr;
|
||||
QFutureWatcher<FileNameToContentsHash> *m_watcher = nullptr;
|
||||
};
|
||||
|
||||
class PROJECTEXPLORER_EXPORT ExtraCompilerFactory : public QObject
|
||||
|
||||
@@ -515,7 +515,7 @@ void QmakeProject::updateCppCodeModel()
|
||||
// generated files:
|
||||
QList<ProjectExplorer::ExtraCompiler *> proGenerators = pro->extraCompilers();
|
||||
foreach (ProjectExplorer::ExtraCompiler *ec, proGenerators) {
|
||||
foreach (const FileName &generatedFile, ec->targets()) {
|
||||
ec->forEachTarget([&](const Utils::FileName &generatedFile) {
|
||||
QString name = generatedFile.toString();
|
||||
allFiles << name;
|
||||
ProjectFile::Kind kind = ProjectFile::classify(name);
|
||||
@@ -535,7 +535,7 @@ void QmakeProject::updateCppCodeModel()
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
generators.append(proGenerators);
|
||||
|
||||
|
||||
@@ -45,7 +45,11 @@ QScxmlcGenerator::QScxmlcGenerator(const Project *project,
|
||||
const Utils::FileName &source,
|
||||
const Utils::FileNameList &targets, QObject *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)
|
||||
{
|
||||
@@ -84,14 +88,10 @@ Utils::FileName QScxmlcGenerator::command() const
|
||||
|
||||
QStringList QScxmlcGenerator::arguments() const
|
||||
{
|
||||
QTC_ASSERT(targets().count() == 2, return QStringList());
|
||||
QTC_ASSERT(!m_header.isEmpty(), return QStringList());
|
||||
|
||||
const Utils::FileName fn = tmpFile();
|
||||
const QString header = m_tmpdir.path() + QLatin1Char('/') + targets()[0].fileName();
|
||||
const QString impl = m_tmpdir.path() + QLatin1Char('/') + targets()[1].fileName();
|
||||
|
||||
return QStringList({ QLatin1String("--header"), header, QLatin1String("--impl"), impl,
|
||||
fn.fileName() });
|
||||
return QStringList({ QLatin1String("--header"), m_header, QLatin1String("--impl"), m_impl,
|
||||
tmpFile().fileName() });
|
||||
}
|
||||
|
||||
Utils::FileName QScxmlcGenerator::workingDirectory() const
|
||||
@@ -111,19 +111,19 @@ bool QScxmlcGenerator::prepareToRun(const QByteArray &sourceContents)
|
||||
return true;
|
||||
}
|
||||
|
||||
QList<QByteArray> QScxmlcGenerator::handleProcessFinished(QProcess *process)
|
||||
FileNameToContentsHash QScxmlcGenerator::handleProcessFinished(QProcess *process)
|
||||
{
|
||||
Q_UNUSED(process);
|
||||
const Utils::FileName wd = workingDirectory();
|
||||
QList<QByteArray> result;
|
||||
foreach (const Utils::FileName &target, targets()) {
|
||||
FileNameToContentsHash result;
|
||||
forEachTarget([&](const Utils::FileName &target) {
|
||||
Utils::FileName file = wd;
|
||||
file.appendPath(target.fileName());
|
||||
QFile generated(file.toString());
|
||||
if (!generated.open(QIODevice::ReadOnly))
|
||||
continue;
|
||||
result << generated.readAll();
|
||||
}
|
||||
return;
|
||||
result[target] = generated.readAll();
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -47,11 +47,13 @@ protected:
|
||||
|
||||
private:
|
||||
Utils::FileName tmpFile() const;
|
||||
QList<QByteArray> handleProcessFinished(QProcess *process) override;
|
||||
ProjectExplorer::FileNameToContentsHash handleProcessFinished(QProcess *process) override;
|
||||
bool prepareToRun(const QByteArray &sourceContents) override;
|
||||
QList<ProjectExplorer::Task> parseIssues(const QByteArray &processStderr) override;
|
||||
|
||||
QTemporaryDir m_tmpdir;
|
||||
QString m_header;
|
||||
QString m_impl;
|
||||
};
|
||||
|
||||
class QScxmlcGeneratorFactory : public ProjectExplorer::ExtraCompilerFactory
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
#include <projectexplorer/target.h>
|
||||
#include <projectexplorer/buildconfiguration.h>
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
#include <QLoggingCategory>
|
||||
@@ -44,7 +46,9 @@ namespace QtSupport {
|
||||
UicGenerator::UicGenerator(const Project *project, const Utils::FileName &source,
|
||||
const Utils::FileNameList &targets, QObject *parent) :
|
||||
ProcessExtraCompiler(project, source, targets, parent)
|
||||
{ }
|
||||
{
|
||||
QTC_ASSERT(targets.count() == 1, return);
|
||||
}
|
||||
|
||||
Utils::FileName UicGenerator::command() const
|
||||
{
|
||||
@@ -67,14 +71,19 @@ void UicGenerator::handleProcessStarted(QProcess *process, const QByteArray &sou
|
||||
process->closeWriteChannel();
|
||||
}
|
||||
|
||||
QList<QByteArray> UicGenerator::handleProcessFinished(QProcess *process)
|
||||
FileNameToContentsHash UicGenerator::handleProcessFinished(QProcess *process)
|
||||
{
|
||||
FileNameToContentsHash result;
|
||||
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
|
||||
// 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
|
||||
|
||||
@@ -43,7 +43,7 @@ public:
|
||||
protected:
|
||||
Utils::FileName command() const 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
|
||||
|
||||
Reference in New Issue
Block a user