Files
qt-creator/src/plugins/cmakeprojectmanager/cmakeprocess.h

58 lines
1.2 KiB
C
Raw Normal View History

// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
#pragma once
#include <utils/outputformatter.h>
#include <QElapsedTimer>
#include <QFutureInterface>
#include <QObject>
#include <QStringList>
#include <memory>
CMakeProcess: Fix stopping the CMake process Calling QtcProcess::terminate() doesn't guarantee that process will be terminated, especially on Windows we may ofter wait for it forever. Replace the call to terminate() with close(). After calling close(), the process will sooner or later be terminated (or finally killed) - that's the job for ProcessReaper. Since the current code relies on receiving the finished() signal after calling a stopping method, we need to call the expected handler (handleProcessDone()) after calling the QtcProcess::close(), as afterwards we can't expect receiving any signal for the possibly running process anymore. Refactor the code so that we connect do QtcProcess::done() signal instead of connecting to QtcProcess::finished() signal. This guarantees that the handler will also be called when process failed to start. Handle this case in done() handler, too. Rename CMakeProcess::terminate() into CMakeProcess::stop() in order to avoid confusion on what method we have chosen to stop the process in fact. That's the implementation detail. Get rid of some QFuture related handlings from public API. Use them directly from inside CMakeProcess d'tor. Get rid of public state() method, as it seems it's unused. Increase the responsiveness of small [x] icon of the running cmake task (reduce the timeout of 500 ms into 50 ms). Fixes: QTCREATORBUG-27518 Change-Id: I15cac3990079ad1cae0bbe22ac2a6e64cfb659a0 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Cristian Adam <cristian.adam@qt.io>
2022-05-13 18:22:03 +02:00
QT_BEGIN_NAMESPACE
template<class T>
class QFutureWatcher;
CMakeProcess: Fix stopping the CMake process Calling QtcProcess::terminate() doesn't guarantee that process will be terminated, especially on Windows we may ofter wait for it forever. Replace the call to terminate() with close(). After calling close(), the process will sooner or later be terminated (or finally killed) - that's the job for ProcessReaper. Since the current code relies on receiving the finished() signal after calling a stopping method, we need to call the expected handler (handleProcessDone()) after calling the QtcProcess::close(), as afterwards we can't expect receiving any signal for the possibly running process anymore. Refactor the code so that we connect do QtcProcess::done() signal instead of connecting to QtcProcess::finished() signal. This guarantees that the handler will also be called when process failed to start. Handle this case in done() handler, too. Rename CMakeProcess::terminate() into CMakeProcess::stop() in order to avoid confusion on what method we have chosen to stop the process in fact. That's the implementation detail. Get rid of some QFuture related handlings from public API. Use them directly from inside CMakeProcess d'tor. Get rid of public state() method, as it seems it's unused. Increase the responsiveness of small [x] icon of the running cmake task (reduce the timeout of 500 ms into 50 ms). Fixes: QTCREATORBUG-27518 Change-Id: I15cac3990079ad1cae0bbe22ac2a6e64cfb659a0 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Cristian Adam <cristian.adam@qt.io>
2022-05-13 18:22:03 +02:00
QT_END_NAMESPACE
namespace Utils {
class ProcessResultData;
class QtcProcess;
}
namespace CMakeProjectManager::Internal {
class BuildDirParameters;
class CMakeProcess : public QObject
{
Q_OBJECT
public:
CMakeProcess();
~CMakeProcess();
void run(const BuildDirParameters &parameters, const QStringList &arguments);
CMakeProcess: Fix stopping the CMake process Calling QtcProcess::terminate() doesn't guarantee that process will be terminated, especially on Windows we may ofter wait for it forever. Replace the call to terminate() with close(). After calling close(), the process will sooner or later be terminated (or finally killed) - that's the job for ProcessReaper. Since the current code relies on receiving the finished() signal after calling a stopping method, we need to call the expected handler (handleProcessDone()) after calling the QtcProcess::close(), as afterwards we can't expect receiving any signal for the possibly running process anymore. Refactor the code so that we connect do QtcProcess::done() signal instead of connecting to QtcProcess::finished() signal. This guarantees that the handler will also be called when process failed to start. Handle this case in done() handler, too. Rename CMakeProcess::terminate() into CMakeProcess::stop() in order to avoid confusion on what method we have chosen to stop the process in fact. That's the implementation detail. Get rid of some QFuture related handlings from public API. Use them directly from inside CMakeProcess d'tor. Get rid of public state() method, as it seems it's unused. Increase the responsiveness of small [x] icon of the running cmake task (reduce the timeout of 500 ms into 50 ms). Fixes: QTCREATORBUG-27518 Change-Id: I15cac3990079ad1cae0bbe22ac2a6e64cfb659a0 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Cristian Adam <cristian.adam@qt.io>
2022-05-13 18:22:03 +02:00
void stop();
int lastExitCode() const { return m_lastExitCode; }
signals:
void started();
void finished();
private:
CMakeProcess: Fix stopping the CMake process Calling QtcProcess::terminate() doesn't guarantee that process will be terminated, especially on Windows we may ofter wait for it forever. Replace the call to terminate() with close(). After calling close(), the process will sooner or later be terminated (or finally killed) - that's the job for ProcessReaper. Since the current code relies on receiving the finished() signal after calling a stopping method, we need to call the expected handler (handleProcessDone()) after calling the QtcProcess::close(), as afterwards we can't expect receiving any signal for the possibly running process anymore. Refactor the code so that we connect do QtcProcess::done() signal instead of connecting to QtcProcess::finished() signal. This guarantees that the handler will also be called when process failed to start. Handle this case in done() handler, too. Rename CMakeProcess::terminate() into CMakeProcess::stop() in order to avoid confusion on what method we have chosen to stop the process in fact. That's the implementation detail. Get rid of some QFuture related handlings from public API. Use them directly from inside CMakeProcess d'tor. Get rid of public state() method, as it seems it's unused. Increase the responsiveness of small [x] icon of the running cmake task (reduce the timeout of 500 ms into 50 ms). Fixes: QTCREATORBUG-27518 Change-Id: I15cac3990079ad1cae0bbe22ac2a6e64cfb659a0 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Cristian Adam <cristian.adam@qt.io>
2022-05-13 18:22:03 +02:00
void handleProcessDone(const Utils::ProcessResultData &resultData);
std::unique_ptr<Utils::QtcProcess> m_process;
Utils::OutputFormatter m_parser;
QFutureInterface<void> m_futureInterface;
std::unique_ptr<QFutureWatcher<void>> m_futureWatcher;
QElapsedTimer m_elapsed;
int m_lastExitCode = 0;
};
} // CMakeProjectManager::Internal