aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/projectexplorer/extracompiler.h
diff options
context:
space:
mode:
authorTobias Hunger <tobias.hunger@theqtcompany.com>2016-03-03 13:56:05 +0100
committerTobias Hunger <tobias.hunger@theqtcompany.com>2016-03-11 09:49:25 +0000
commit972ea4cba0472029786a57004d3b2fe24191cfdf (patch)
tree7876bf888843b431835e4f0670b99c6991039ad2 /src/plugins/projectexplorer/extracompiler.h
parent119a7dfd201aeaf892f6f4a351911c1f0102be9c (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/projectexplorer/extracompiler.h')
-rw-r--r--src/plugins/projectexplorer/extracompiler.h59
1 files changed, 56 insertions, 3 deletions
diff --git a/src/plugins/projectexplorer/extracompiler.h b/src/plugins/projectexplorer/extracompiler.h
index eb5e0123d9..6f2ec8bc63 100644
--- a/src/plugins/projectexplorer/extracompiler.h
+++ b/src/plugins/projectexplorer/extracompiler.h
@@ -33,6 +33,13 @@
#include <utils/fileutils.h>
#include <utils/environment.h>
+#include <QByteArray>
+#include <QFuture>
+#include <QList>
+
+QT_FORWARD_DECLARE_CLASS(QProcess);
+QT_FORWARD_DECLARE_CLASS(QThreadPool);
+
namespace ProjectExplorer {
class ExtraCompilerPrivate;
@@ -42,8 +49,8 @@ class PROJECTEXPLORER_EXPORT ExtraCompiler : public QObject
public:
ExtraCompiler(const Project *project, const Utils::FileName &source,
- const Utils::FileNameList &targets, QObject *parent = 0);
- virtual ~ExtraCompiler() override;
+ const Utils::FileNameList &targets, QObject *parent = nullptr);
+ ~ExtraCompiler() override;
const Project *project() const;
Utils::FileName source() const;
@@ -58,6 +65,8 @@ public:
void setCompileTime(const QDateTime &time);
QDateTime compileTime() const;
+ static QThreadPool *extraCompilerThreadPool();
+
signals:
void contentsChanged(const Utils::FileName &file);
@@ -72,16 +81,60 @@ private:
void onActiveTargetChanged();
void onActiveBuildConfigurationChanged();
void setDirty();
+ // This method may not block!
virtual void run(const QByteArray &sourceContent) = 0;
+ virtual void run(const Utils::FileName &file) = 0;
ExtraCompilerPrivate *const d;
};
+class PROJECTEXPLORER_EXPORT ProcessExtraCompiler : public ExtraCompiler
+{
+ Q_OBJECT
+public:
+
+ ProcessExtraCompiler(const Project *project, const Utils::FileName &source,
+ const Utils::FileNameList &targets, QObject *parent = nullptr);
+
+protected:
+ // This will run a process in a thread, if
+ // * command() does not return an empty file name
+ // * command() is exectuable
+ // * prepareToRun returns true
+ // * The process is not yet running
+ void run(const QByteArray &sourceContents) override;
+ void run(const Utils::FileName &fileName) override;
+
+ // Information about the process to run:
+ virtual Utils::FileName workingDirectory() const;
+ virtual Utils::FileName command() const = 0;
+ virtual QStringList arguments() const;
+
+ virtual bool prepareToRun(const QByteArray &sourceContents);
+
+ 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 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,
+ const QStringList &args, const ContentProvider &provider,
+ const Utils::Environment &env);
+ void cleanUp();
+
+ QFutureWatcher<QList<QByteArray>> *m_watcher = nullptr;
+};
+
class PROJECTEXPLORER_EXPORT ExtraCompilerFactory : public QObject
{
Q_OBJECT
public:
- explicit ExtraCompilerFactory(QObject *parent = 0);
+ explicit ExtraCompilerFactory(QObject *parent = nullptr);
virtual FileType sourceType() const = 0;
virtual QString sourceTag() const = 0;