diff options
author | Tobias Hunger <tobias.hunger@theqtcompany.com> | 2016-03-03 13:56:05 +0100 |
---|---|---|
committer | Tobias Hunger <tobias.hunger@theqtcompany.com> | 2016-03-11 09:49:25 +0000 |
commit | 972ea4cba0472029786a57004d3b2fe24191cfdf (patch) | |
tree | 7876bf888843b431835e4f0670b99c6991039ad2 /src/plugins/qtsupport/uicgenerator.cpp | |
parent | 119a7dfd201aeaf892f6f4a351911c1f0102be9c (diff) |
ExtraCompiler: Run extra compiler in a thread
and make sure there are not too many of these threads
running at any time. This stops the massive process
startup when loading a project with many UI files, etc.
Task-number: QTCREATORBUG-15795
Change-Id: Icfcddd80d04e36b61ecafbbefe5a1a8b7ea02ec6
Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
Reviewed-by: Ulf Hermann <ulf.hermann@theqtcompany.com>
Diffstat (limited to 'src/plugins/qtsupport/uicgenerator.cpp')
-rw-r--r-- | src/plugins/qtsupport/uicgenerator.cpp | 70 |
1 files changed, 19 insertions, 51 deletions
diff --git a/src/plugins/qtsupport/uicgenerator.cpp b/src/plugins/qtsupport/uicgenerator.cpp index 33818d01b4..7c8fe71e6a 100644 --- a/src/plugins/qtsupport/uicgenerator.cpp +++ b/src/plugins/qtsupport/uicgenerator.cpp @@ -39,43 +39,14 @@ namespace QtSupport { -QLoggingCategory UicGenerator::m_log("qtc.uicgenerator"); - UicGenerator::UicGenerator(const ProjectExplorer::Project *project, const Utils::FileName &source, const Utils::FileNameList &targets, QObject *parent) : - ProjectExplorer::ExtraCompiler(project, source, targets, parent) -{ - connect(&m_process, static_cast<void(QProcess::*)(int)>(&QProcess::finished), - this, &UicGenerator::finishProcess); -} - -void UicGenerator::finishProcess() -{ - if (!m_process.waitForFinished(3000) - && m_process.exitStatus() != QProcess::NormalExit - && m_process.exitCode() != 0) { - - qCDebug(m_log) << "finish process: failed" << m_process.readAllStandardError(); - m_process.kill(); - return; - } - - // 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. - QByteArray normalized = QString::fromLocal8Bit(m_process.readAllStandardOutput()).toUtf8(); - qCDebug(m_log) << "finish process: ok" << normalized.size() << "bytes."; - setCompileTime(QDateTime::currentDateTime()); - setContent(targets()[0], normalized); -} + ProjectExplorer::ProcessExtraCompiler(project, source, targets, parent) +{ } -void UicGenerator::run(const QByteArray &sourceContent) +Utils::FileName UicGenerator::command() const { - if (m_process.state() != QProcess::NotRunning) { - m_process.kill(); - m_process.waitForFinished(3000); - } - - QtSupport::BaseQtVersion *version = 0; + QtSupport::BaseQtVersion *version = nullptr; ProjectExplorer::Target *target; if ((target = project()->activeTarget())) version = QtSupport::QtKitInformation::qtVersion(target->kit()); @@ -83,28 +54,25 @@ void UicGenerator::run(const QByteArray &sourceContent) version = QtSupport::QtKitInformation::qtVersion(ProjectExplorer::KitManager::defaultKit()); if (!version) - return; - - const QString generator = version->uicCommand(); - if (generator.isEmpty()) - return; + return Utils::FileName(); - m_process.setProcessEnvironment(buildEnvironment().toProcessEnvironment()); + return Utils::FileName::fromString(version->uicCommand()); +} - qCDebug(m_log) << " UicGenerator::run " << generator << " on " - << sourceContent.size() << " bytes"; - m_process.start(generator, QStringList(), QIODevice::ReadWrite); - if (!m_process.waitForStarted()) - return; +void UicGenerator::handleProcessStarted(QProcess *process, const QByteArray &sourceContents) +{ + process->write(sourceContents); + process->closeWriteChannel(); +} - m_process.write(sourceContent); - if (!m_process.waitForBytesWritten(3000)) { - qCDebug(m_log) << "failed" << m_process.readAllStandardError(); - m_process.kill(); - return; - } +QList<QByteArray> UicGenerator::handleProcessFinished(QProcess *process) +{ + if (process->exitStatus() != QProcess::NormalExit && process->exitCode() != 0) + return QList<QByteArray>(); - m_process.closeWriteChannel(); + // 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() }; } ProjectExplorer::FileType UicGeneratorFactory::sourceType() const |