2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2016-01-15 16:12:54 +01:00
|
|
|
|
|
|
|
|
#include "extracompiler.h"
|
2016-03-03 13:56:05 +01:00
|
|
|
|
2016-01-15 16:12:54 +01:00
|
|
|
#include "buildmanager.h"
|
2016-03-03 13:56:05 +01:00
|
|
|
#include "kitinformation.h"
|
2023-02-14 15:47:22 +01:00
|
|
|
#include "projectmanager.h"
|
2016-01-15 16:12:54 +01:00
|
|
|
#include "target.h"
|
|
|
|
|
|
2016-03-03 13:56:05 +01:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
|
|
|
|
#include <coreplugin/idocument.h>
|
|
|
|
|
|
2023-01-04 11:25:23 +01:00
|
|
|
#include <utils/asynctask.h>
|
2022-11-24 08:52:47 +01:00
|
|
|
#include <utils/expected.h>
|
2023-01-16 17:03:26 +01:00
|
|
|
#include <utils/guard.h>
|
2021-08-31 11:04:35 +02:00
|
|
|
#include <utils/qtcprocess.h>
|
2016-01-15 16:12:54 +01:00
|
|
|
|
|
|
|
|
#include <QDateTime>
|
2023-01-16 17:03:26 +01:00
|
|
|
#include <QLoggingCategory>
|
2016-03-03 13:56:05 +01:00
|
|
|
#include <QThreadPool>
|
2016-01-15 16:12:54 +01:00
|
|
|
#include <QTimer>
|
|
|
|
|
|
2023-02-12 01:00:58 +01:00
|
|
|
using namespace Core;
|
2021-08-31 11:04:35 +02:00
|
|
|
using namespace Utils;
|
|
|
|
|
|
2016-01-15 16:12:54 +01:00
|
|
|
namespace ProjectExplorer {
|
|
|
|
|
|
2016-03-03 13:56:05 +01:00
|
|
|
Q_GLOBAL_STATIC(QThreadPool, s_extraCompilerThreadPool);
|
2016-01-15 16:12:54 +01:00
|
|
|
Q_GLOBAL_STATIC(QList<ExtraCompilerFactory *>, factories);
|
2023-01-16 17:03:26 +01:00
|
|
|
Q_LOGGING_CATEGORY(log, "qtc.projectexplorer.extracompiler", QtWarningMsg);
|
2021-06-28 11:57:08 +02:00
|
|
|
|
2016-01-15 16:12:54 +01:00
|
|
|
class ExtraCompilerPrivate
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
const Project *project;
|
2021-08-31 11:04:35 +02:00
|
|
|
FilePath source;
|
2016-03-11 15:18:20 +02:00
|
|
|
FileNameToContentsHash contents;
|
2016-01-15 16:12:54 +01:00
|
|
|
QDateTime compileTime;
|
2023-02-12 01:00:58 +01:00
|
|
|
IEditor *lastEditor = nullptr;
|
2016-01-15 16:12:54 +01:00
|
|
|
QMetaObject::Connection activeBuildConfigConnection;
|
|
|
|
|
QMetaObject::Connection activeEnvironmentConnection;
|
2023-02-12 01:00:58 +01:00
|
|
|
Guard lock;
|
2016-01-15 16:12:54 +01:00
|
|
|
bool dirty = false;
|
|
|
|
|
|
|
|
|
|
QTimer timer;
|
2023-01-04 11:25:23 +01:00
|
|
|
|
|
|
|
|
FutureSynchronizer m_futureSynchronizer;
|
|
|
|
|
std::unique_ptr<TaskTree> m_taskTree;
|
2016-01-15 16:12:54 +01:00
|
|
|
};
|
|
|
|
|
|
2021-08-31 11:04:35 +02:00
|
|
|
ExtraCompiler::ExtraCompiler(const Project *project, const FilePath &source,
|
|
|
|
|
const FilePaths &targets, QObject *parent) :
|
2018-07-16 13:59:39 +02:00
|
|
|
QObject(parent), d(std::make_unique<ExtraCompilerPrivate>())
|
2016-01-15 16:12:54 +01:00
|
|
|
{
|
|
|
|
|
d->project = project;
|
|
|
|
|
d->source = source;
|
2021-08-31 11:04:35 +02:00
|
|
|
for (const FilePath &target : targets)
|
2016-02-17 23:47:26 +02:00
|
|
|
d->contents.insert(target, QByteArray());
|
2016-01-15 16:12:54 +01:00
|
|
|
d->timer.setSingleShot(true);
|
|
|
|
|
|
2023-01-16 17:03:26 +01:00
|
|
|
connect(&d->timer, &QTimer::timeout, this, &ExtraCompiler::compileIfDirty);
|
2016-01-15 16:12:54 +01:00
|
|
|
connect(BuildManager::instance(), &BuildManager::buildStateChanged,
|
|
|
|
|
this, &ExtraCompiler::onTargetsBuilt);
|
|
|
|
|
|
2023-02-14 15:47:22 +01:00
|
|
|
connect(ProjectManager::instance(), &ProjectManager::projectRemoved,
|
2016-01-15 16:12:54 +01:00
|
|
|
this, [this](Project *project) {
|
|
|
|
|
if (project == d->project)
|
|
|
|
|
deleteLater();
|
|
|
|
|
});
|
|
|
|
|
|
2023-02-12 01:00:58 +01:00
|
|
|
EditorManager *editorManager = EditorManager::instance();
|
|
|
|
|
connect(editorManager, &EditorManager::currentEditorChanged,
|
2016-01-15 16:12:54 +01:00
|
|
|
this, &ExtraCompiler::onEditorChanged);
|
2023-02-12 01:00:58 +01:00
|
|
|
connect(editorManager, &EditorManager::editorAboutToClose,
|
2016-01-15 16:12:54 +01:00
|
|
|
this, &ExtraCompiler::onEditorAboutToClose);
|
|
|
|
|
|
|
|
|
|
// Use existing target files, where possible. Otherwise run the compiler.
|
2021-06-17 17:25:38 +02:00
|
|
|
QDateTime sourceTime = d->source.lastModified();
|
2021-08-31 11:04:35 +02:00
|
|
|
for (const FilePath &target : targets) {
|
2022-11-23 12:21:23 +01:00
|
|
|
if (!target.exists()) {
|
2016-01-15 16:12:54 +01:00
|
|
|
d->dirty = true;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-23 12:21:23 +01:00
|
|
|
QDateTime lastModified = target.lastModified();
|
2016-01-15 16:12:54 +01:00
|
|
|
if (lastModified < sourceTime)
|
|
|
|
|
d->dirty = true;
|
|
|
|
|
|
|
|
|
|
if (!d->compileTime.isValid() || d->compileTime > lastModified)
|
|
|
|
|
d->compileTime = lastModified;
|
|
|
|
|
|
2022-11-24 08:52:47 +01:00
|
|
|
const expected_str<QByteArray> contents = target.fileContents();
|
|
|
|
|
QTC_ASSERT_EXPECTED(contents, return);
|
|
|
|
|
|
|
|
|
|
setContent(target, *contents);
|
2016-01-15 16:12:54 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-16 13:59:39 +02:00
|
|
|
ExtraCompiler::~ExtraCompiler() = default;
|
2016-01-15 16:12:54 +01:00
|
|
|
|
|
|
|
|
const Project *ExtraCompiler::project() const
|
|
|
|
|
{
|
|
|
|
|
return d->project;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-31 11:04:35 +02:00
|
|
|
FilePath ExtraCompiler::source() const
|
2016-01-15 16:12:54 +01:00
|
|
|
{
|
|
|
|
|
return d->source;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-31 11:04:35 +02:00
|
|
|
QByteArray ExtraCompiler::content(const FilePath &file) const
|
2016-01-15 16:12:54 +01:00
|
|
|
{
|
2016-02-17 23:47:26 +02:00
|
|
|
return d->contents.value(file);
|
2016-01-15 16:12:54 +01:00
|
|
|
}
|
|
|
|
|
|
2021-08-31 11:04:35 +02:00
|
|
|
FilePaths ExtraCompiler::targets() const
|
2016-01-15 16:12:54 +01:00
|
|
|
{
|
2016-03-11 15:18:20 +02:00
|
|
|
return d->contents.keys();
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-04 11:25:23 +01:00
|
|
|
void ExtraCompiler::forEachTarget(std::function<void (const FilePath &)> func) const
|
2016-03-11 15:18:20 +02:00
|
|
|
{
|
|
|
|
|
for (auto it = d->contents.constBegin(), end = d->contents.constEnd(); it != end; ++it)
|
|
|
|
|
func(it.key());
|
2016-01-15 16:12:54 +01:00
|
|
|
}
|
|
|
|
|
|
2023-01-03 15:12:25 +01:00
|
|
|
void ExtraCompiler::updateCompileTime()
|
2016-01-15 16:12:54 +01:00
|
|
|
{
|
2023-01-03 15:12:25 +01:00
|
|
|
d->compileTime = QDateTime::currentDateTime();
|
2016-01-15 16:12:54 +01:00
|
|
|
}
|
|
|
|
|
|
2016-03-03 13:56:05 +01:00
|
|
|
QThreadPool *ExtraCompiler::extraCompilerThreadPool()
|
|
|
|
|
{
|
|
|
|
|
return s_extraCompilerThreadPool();
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-04 11:25:23 +01:00
|
|
|
Tasking::TaskItem ExtraCompiler::compileFileItem()
|
|
|
|
|
{
|
|
|
|
|
return taskItemImpl(fromFileProvider());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ExtraCompiler::compileFile()
|
|
|
|
|
{
|
|
|
|
|
compileImpl(fromFileProvider());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ExtraCompiler::compileContent(const QByteArray &content)
|
|
|
|
|
{
|
|
|
|
|
compileImpl([content] { return content; });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ExtraCompiler::compileImpl(const ContentProvider &provider)
|
|
|
|
|
{
|
|
|
|
|
const auto finalize = [=] {
|
|
|
|
|
d->m_taskTree.release()->deleteLater();
|
|
|
|
|
};
|
|
|
|
|
d->m_taskTree.reset(new TaskTree({taskItemImpl(provider)}));
|
|
|
|
|
connect(d->m_taskTree.get(), &TaskTree::done, this, finalize);
|
|
|
|
|
connect(d->m_taskTree.get(), &TaskTree::errorOccurred, this, finalize);
|
2023-01-17 13:00:43 +01:00
|
|
|
d->m_taskTree->start();
|
2023-01-04 11:25:23 +01:00
|
|
|
}
|
|
|
|
|
|
2023-01-16 17:03:26 +01:00
|
|
|
void ExtraCompiler::compileIfDirty()
|
|
|
|
|
{
|
|
|
|
|
qCDebug(log) << Q_FUNC_INFO;
|
|
|
|
|
if (!d->lock.isLocked() && d->dirty && d->lastEditor) {
|
|
|
|
|
qCDebug(log) << '\t' << "about to compile";
|
|
|
|
|
d->dirty = false;
|
|
|
|
|
compileContent(d->lastEditor->document()->contents());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-04 11:25:23 +01:00
|
|
|
ExtraCompiler::ContentProvider ExtraCompiler::fromFileProvider() const
|
|
|
|
|
{
|
|
|
|
|
const auto provider = [fileName = source()] {
|
|
|
|
|
QFile file(fileName.toString());
|
|
|
|
|
if (!file.open(QFile::ReadOnly | QFile::Text))
|
|
|
|
|
return QByteArray();
|
|
|
|
|
return file.readAll();
|
|
|
|
|
};
|
|
|
|
|
return provider;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-29 15:26:23 +02:00
|
|
|
bool ExtraCompiler::isDirty() const
|
|
|
|
|
{
|
|
|
|
|
return d->dirty;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-16 17:03:26 +01:00
|
|
|
void ExtraCompiler::block()
|
|
|
|
|
{
|
|
|
|
|
qCDebug(log) << Q_FUNC_INFO;
|
|
|
|
|
d->lock.lock();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ExtraCompiler::unblock()
|
|
|
|
|
{
|
|
|
|
|
qCDebug(log) << Q_FUNC_INFO;
|
|
|
|
|
d->lock.unlock();
|
|
|
|
|
if (!d->lock.isLocked() && !d->timer.isActive())
|
|
|
|
|
d->timer.start();
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-15 16:12:54 +01:00
|
|
|
void ExtraCompiler::onTargetsBuilt(Project *project)
|
|
|
|
|
{
|
|
|
|
|
if (project != d->project || BuildManager::isBuilding(project))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// This is mostly a fall back for the cases when the generator couldn't be run.
|
|
|
|
|
// It pays special attention to the case where a source file was newly created
|
2021-06-17 17:25:38 +02:00
|
|
|
const QDateTime sourceTime = d->source.lastModified();
|
2016-01-15 16:12:54 +01:00
|
|
|
if (d->compileTime.isValid() && d->compileTime >= sourceTime)
|
|
|
|
|
return;
|
|
|
|
|
|
2021-08-31 11:04:35 +02:00
|
|
|
forEachTarget([&](const FilePath &target) {
|
2016-01-15 16:12:54 +01:00
|
|
|
QFileInfo fi(target.toFileInfo());
|
|
|
|
|
QDateTime generateTime = fi.exists() ? fi.lastModified() : QDateTime();
|
|
|
|
|
if (generateTime.isValid() && (generateTime > sourceTime)) {
|
|
|
|
|
if (d->compileTime >= generateTime)
|
2016-03-11 15:18:20 +02:00
|
|
|
return;
|
2016-01-15 16:12:54 +01:00
|
|
|
|
2022-11-24 08:52:47 +01:00
|
|
|
const expected_str<QByteArray> contents = target.fileContents();
|
|
|
|
|
QTC_ASSERT_EXPECTED(contents, return);
|
|
|
|
|
|
|
|
|
|
d->compileTime = generateTime;
|
|
|
|
|
setContent(target, *contents);
|
2016-01-15 16:12:54 +01:00
|
|
|
}
|
2016-03-11 15:18:20 +02:00
|
|
|
});
|
2016-01-15 16:12:54 +01:00
|
|
|
}
|
|
|
|
|
|
2023-02-12 01:00:58 +01:00
|
|
|
void ExtraCompiler::onEditorChanged(IEditor *editor)
|
2016-01-15 16:12:54 +01:00
|
|
|
{
|
|
|
|
|
// Handle old editor
|
|
|
|
|
if (d->lastEditor) {
|
2023-02-12 01:00:58 +01:00
|
|
|
IDocument *doc = d->lastEditor->document();
|
|
|
|
|
disconnect(doc, &IDocument::contentsChanged,
|
2016-01-15 16:12:54 +01:00
|
|
|
this, &ExtraCompiler::setDirty);
|
|
|
|
|
|
|
|
|
|
if (d->dirty) {
|
|
|
|
|
d->dirty = false;
|
2023-01-04 11:25:23 +01:00
|
|
|
compileContent(doc->contents());
|
2016-01-15 16:12:54 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (editor && editor->document()->filePath() == d->source) {
|
|
|
|
|
d->lastEditor = editor;
|
|
|
|
|
|
|
|
|
|
// Handle new editor
|
2023-02-12 01:00:58 +01:00
|
|
|
connect(d->lastEditor->document(), &IDocument::contentsChanged,
|
2016-01-15 16:12:54 +01:00
|
|
|
this, &ExtraCompiler::setDirty);
|
|
|
|
|
} else {
|
2016-03-03 13:56:05 +01:00
|
|
|
d->lastEditor = nullptr;
|
2016-01-15 16:12:54 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ExtraCompiler::setDirty()
|
|
|
|
|
{
|
|
|
|
|
d->dirty = true;
|
|
|
|
|
d->timer.start(1000);
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-12 01:00:58 +01:00
|
|
|
void ExtraCompiler::onEditorAboutToClose(IEditor *editor)
|
2016-01-15 16:12:54 +01:00
|
|
|
{
|
|
|
|
|
if (d->lastEditor != editor)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Oh no our editor is going to be closed
|
|
|
|
|
// get the content first
|
2023-02-12 01:00:58 +01:00
|
|
|
IDocument *doc = d->lastEditor->document();
|
|
|
|
|
disconnect(doc, &IDocument::contentsChanged,
|
2016-01-15 16:12:54 +01:00
|
|
|
this, &ExtraCompiler::setDirty);
|
|
|
|
|
if (d->dirty) {
|
|
|
|
|
d->dirty = false;
|
2023-01-04 11:25:23 +01:00
|
|
|
compileContent(doc->contents());
|
2016-01-15 16:12:54 +01:00
|
|
|
}
|
2016-03-03 13:56:05 +01:00
|
|
|
d->lastEditor = nullptr;
|
2016-01-15 16:12:54 +01:00
|
|
|
}
|
|
|
|
|
|
2021-08-31 11:04:35 +02:00
|
|
|
Environment ExtraCompiler::buildEnvironment() const
|
2016-01-15 16:12:54 +01:00
|
|
|
{
|
2023-02-12 01:00:58 +01:00
|
|
|
Target *target = project()->activeTarget();
|
|
|
|
|
if (!target)
|
|
|
|
|
return Environment::systemEnvironment();
|
|
|
|
|
|
|
|
|
|
if (BuildConfiguration *bc = target->activeBuildConfiguration())
|
|
|
|
|
return bc->environment();
|
2016-01-15 16:12:54 +01:00
|
|
|
|
2023-02-12 01:00:58 +01:00
|
|
|
const EnvironmentItems changes = EnvironmentKitAspect::environmentChanges(target->kit());
|
|
|
|
|
Environment env = Environment::systemEnvironment();
|
|
|
|
|
env.modify(changes);
|
|
|
|
|
return env;
|
2016-01-15 16:12:54 +01:00
|
|
|
}
|
|
|
|
|
|
2023-02-12 01:00:58 +01:00
|
|
|
FutureSynchronizer *ExtraCompiler::futureSynchronizer() const
|
2023-01-04 11:25:23 +01:00
|
|
|
{
|
|
|
|
|
return &d->m_futureSynchronizer;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-31 11:04:35 +02:00
|
|
|
void ExtraCompiler::setContent(const FilePath &file, const QByteArray &contents)
|
2016-01-15 16:12:54 +01:00
|
|
|
{
|
2023-01-16 17:03:26 +01:00
|
|
|
qCDebug(log).noquote() << Q_FUNC_INFO << contents;
|
2016-02-17 23:47:26 +02:00
|
|
|
auto it = d->contents.find(file);
|
|
|
|
|
if (it != d->contents.end()) {
|
|
|
|
|
if (it.value() != contents) {
|
|
|
|
|
it.value() = contents;
|
|
|
|
|
emit contentsChanged(file);
|
2016-01-15 16:12:54 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-12 19:49:38 +01:00
|
|
|
ExtraCompilerFactory::ExtraCompilerFactory(QObject *parent)
|
|
|
|
|
: QObject(parent)
|
2016-01-15 16:12:54 +01:00
|
|
|
{
|
2017-01-31 17:37:13 +01:00
|
|
|
factories->append(this);
|
2016-01-15 16:12:54 +01:00
|
|
|
}
|
|
|
|
|
|
2017-01-31 17:37:13 +01:00
|
|
|
ExtraCompilerFactory::~ExtraCompilerFactory()
|
2016-01-15 16:12:54 +01:00
|
|
|
{
|
2017-01-31 17:37:13 +01:00
|
|
|
factories->removeAll(this);
|
2016-01-15 16:12:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<ExtraCompilerFactory *> ExtraCompilerFactory::extraCompilerFactories()
|
|
|
|
|
{
|
|
|
|
|
return *factories();
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-31 11:04:35 +02:00
|
|
|
ProcessExtraCompiler::ProcessExtraCompiler(const Project *project, const FilePath &source,
|
|
|
|
|
const FilePaths &targets, QObject *parent) :
|
2016-03-03 13:56:05 +01:00
|
|
|
ExtraCompiler(project, source, targets, parent)
|
|
|
|
|
{ }
|
|
|
|
|
|
2023-01-04 11:25:23 +01:00
|
|
|
Tasking::TaskItem ProcessExtraCompiler::taskItemImpl(const ContentProvider &provider)
|
2016-04-03 11:54:31 +03:00
|
|
|
{
|
2023-01-04 11:25:23 +01:00
|
|
|
const auto setupTask = [=](AsyncTask<FileNameToContentsHash> &async) {
|
|
|
|
|
async.setThreadPool(extraCompilerThreadPool());
|
2023-02-12 01:00:58 +01:00
|
|
|
async.setConcurrentCallData(&ProcessExtraCompiler::runInThread, this, command(),
|
|
|
|
|
workingDirectory(), arguments(), provider, buildEnvironment());
|
2023-01-04 11:25:23 +01:00
|
|
|
async.setFutureSynchronizer(futureSynchronizer());
|
|
|
|
|
};
|
|
|
|
|
const auto taskDone = [=](const AsyncTask<FileNameToContentsHash> &async) {
|
2023-02-02 23:32:26 +01:00
|
|
|
if (!async.isResultAvailable())
|
2023-01-04 11:25:23 +01:00
|
|
|
return;
|
|
|
|
|
const FileNameToContentsHash data = async.result();
|
|
|
|
|
if (data.isEmpty())
|
|
|
|
|
return; // There was some kind of error...
|
|
|
|
|
for (auto it = data.constBegin(), end = data.constEnd(); it != end; ++it)
|
|
|
|
|
setContent(it.key(), it.value());
|
|
|
|
|
updateCompileTime();
|
2016-03-03 13:56:05 +01:00
|
|
|
};
|
2023-01-04 11:25:23 +01:00
|
|
|
return Tasking::Async<FileNameToContentsHash>(setupTask, taskDone);
|
2016-03-03 13:56:05 +01:00
|
|
|
}
|
|
|
|
|
|
2021-08-31 11:04:35 +02:00
|
|
|
FilePath ProcessExtraCompiler::workingDirectory() const
|
2016-03-03 13:56:05 +01:00
|
|
|
{
|
2021-08-31 11:04:35 +02:00
|
|
|
return FilePath();
|
2016-03-03 13:56:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList ProcessExtraCompiler::arguments() const
|
|
|
|
|
{
|
|
|
|
|
return QStringList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ProcessExtraCompiler::prepareToRun(const QByteArray &sourceContents)
|
|
|
|
|
{
|
2019-07-23 10:58:00 +02:00
|
|
|
Q_UNUSED(sourceContents)
|
2016-03-03 13:56:05 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-27 16:09:44 +02:00
|
|
|
Tasks ProcessExtraCompiler::parseIssues(const QByteArray &stdErr)
|
2016-03-03 13:56:05 +01:00
|
|
|
{
|
2019-07-23 10:58:00 +02:00
|
|
|
Q_UNUSED(stdErr)
|
2019-05-27 16:09:44 +02:00
|
|
|
return {};
|
2016-03-03 13:56:05 +01:00
|
|
|
}
|
|
|
|
|
|
2023-02-12 01:00:58 +01:00
|
|
|
void ProcessExtraCompiler::runInThread(QPromise<FileNameToContentsHash> &promise,
|
2023-01-04 11:25:23 +01:00
|
|
|
const FilePath &cmd, const FilePath &workDir,
|
|
|
|
|
const QStringList &args, const ContentProvider &provider,
|
|
|
|
|
const Environment &env)
|
2016-03-03 13:56:05 +01:00
|
|
|
{
|
|
|
|
|
if (cmd.isEmpty() || !cmd.toFileInfo().isExecutable())
|
2016-04-03 11:54:31 +03:00
|
|
|
return;
|
2016-03-03 13:56:05 +01:00
|
|
|
|
|
|
|
|
const QByteArray sourceContents = provider();
|
|
|
|
|
if (sourceContents.isNull() || !prepareToRun(sourceContents))
|
2016-04-03 11:54:31 +03:00
|
|
|
return;
|
2016-03-03 13:56:05 +01:00
|
|
|
|
2021-08-31 11:04:35 +02:00
|
|
|
QtcProcess process;
|
2016-03-03 13:56:05 +01:00
|
|
|
|
2021-08-31 11:04:35 +02:00
|
|
|
process.setEnvironment(env);
|
2016-03-03 13:56:05 +01:00
|
|
|
if (!workDir.isEmpty())
|
2022-01-18 17:40:19 +01:00
|
|
|
process.setWorkingDirectory(workDir);
|
2021-08-31 11:04:35 +02:00
|
|
|
process.setCommand({ cmd, args });
|
|
|
|
|
process.setWriteData(sourceContents);
|
|
|
|
|
process.start();
|
|
|
|
|
if (!process.waitForStarted())
|
2016-04-03 11:54:31 +03:00
|
|
|
return;
|
2016-03-03 13:56:05 +01:00
|
|
|
|
2023-02-12 01:00:58 +01:00
|
|
|
while (!promise.isCanceled()) {
|
2021-08-31 11:04:35 +02:00
|
|
|
if (process.waitForFinished(200))
|
|
|
|
|
break;
|
2023-01-04 11:25:23 +01:00
|
|
|
}
|
2021-08-31 11:04:35 +02:00
|
|
|
|
2023-02-12 01:00:58 +01:00
|
|
|
if (promise.isCanceled())
|
2016-04-03 11:54:31 +03:00
|
|
|
return;
|
2016-03-03 13:56:05 +01:00
|
|
|
|
2023-02-12 01:00:58 +01:00
|
|
|
promise.addResult(handleProcessFinished(&process));
|
2016-03-03 13:56:05 +01:00
|
|
|
}
|
|
|
|
|
|
2016-01-15 16:12:54 +01:00
|
|
|
} // namespace ProjectExplorer
|