forked from qt-creator/qt-creator
MesonProcess: Connect to done() signal
Instead of connecting to errorOccurred() and finished() signals. Change-Id: I94b5b55795110ea4bdc90fd5da88585bd28f1b32 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -52,7 +52,7 @@ MesonProcess::MesonProcess()
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool MesonProcess::run(const Command &command,
|
bool MesonProcess::run(const Command &command,
|
||||||
const Utils::Environment env,
|
const Environment &env,
|
||||||
const QString &projectName,
|
const QString &projectName,
|
||||||
bool captureStdo)
|
bool captureStdo)
|
||||||
{
|
{
|
||||||
@@ -97,58 +97,25 @@ void MesonProcess::setProgressValue(int p)
|
|||||||
m_future.setProgressValue(p);
|
m_future.setProgressValue(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MesonProcess::handleProcessFinished(int code, QProcess::ExitStatus status)
|
void MesonProcess::handleProcessDone()
|
||||||
{
|
{
|
||||||
|
if (m_process->result() != ProcessResult::FinishedWithSuccess) {
|
||||||
|
ProjectExplorer::TaskHub::addTask(ProjectExplorer::BuildSystemTask{
|
||||||
|
ProjectExplorer::Task::TaskType::Error, m_process->exitMessage()});
|
||||||
|
}
|
||||||
m_cancelTimer.stop();
|
m_cancelTimer.stop();
|
||||||
m_stdo = m_process->readAllStandardOutput();
|
m_stdo = m_process->readAllStandardOutput();
|
||||||
m_stderr = m_process->readAllStandardError();
|
m_stderr = m_process->readAllStandardError();
|
||||||
if (status == QProcess::NormalExit) {
|
if (m_process->exitStatus() == QProcess::NormalExit) {
|
||||||
m_future.setProgressValue(1);
|
m_future.setProgressValue(1);
|
||||||
m_future.reportFinished();
|
m_future.reportFinished();
|
||||||
} else {
|
} else {
|
||||||
m_future.reportCanceled();
|
m_future.reportCanceled();
|
||||||
m_future.reportFinished();
|
m_future.reportFinished();
|
||||||
}
|
}
|
||||||
const QString elapsedTime = Utils::formatElapsedTime(m_elapsed.elapsed());
|
const QString elapsedTime = formatElapsedTime(m_elapsed.elapsed());
|
||||||
Core::MessageManager::writeSilently(elapsedTime);
|
Core::MessageManager::writeSilently(elapsedTime);
|
||||||
emit finished(code, status);
|
emit finished(m_process->exitCode(), m_process->exitStatus());
|
||||||
}
|
|
||||||
|
|
||||||
void MesonProcess::handleProcessError(QProcess::ProcessError error)
|
|
||||||
{
|
|
||||||
QString message;
|
|
||||||
QString commandStr = m_currentCommand.toUserOutput();
|
|
||||||
switch (error) {
|
|
||||||
case QProcess::FailedToStart:
|
|
||||||
message = tr("The process failed to start.")
|
|
||||||
+ tr("Either the "
|
|
||||||
"invoked program \"%1\" is missing, or you may have insufficient "
|
|
||||||
"permissions to invoke the program.")
|
|
||||||
.arg(m_currentCommand.executable().toUserOutput());
|
|
||||||
break;
|
|
||||||
case QProcess::Crashed:
|
|
||||||
message = tr("The process was ended forcefully.");
|
|
||||||
break;
|
|
||||||
case QProcess::Timedout:
|
|
||||||
message = tr("Process timed out.");
|
|
||||||
break;
|
|
||||||
case QProcess::WriteError:
|
|
||||||
message = tr("An error occurred when attempting to write "
|
|
||||||
"to the process. For example, the process may not be running, "
|
|
||||||
"or it may have closed its input channel.");
|
|
||||||
break;
|
|
||||||
case QProcess::ReadError:
|
|
||||||
message = tr("An error occurred when attempting to read from "
|
|
||||||
"the process. For example, the process may not be running.");
|
|
||||||
break;
|
|
||||||
case QProcess::UnknownError:
|
|
||||||
message = tr("An unknown error in the process occurred.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
ProjectExplorer::TaskHub::addTask(
|
|
||||||
ProjectExplorer::BuildSystemTask{ProjectExplorer::Task::TaskType::Error,
|
|
||||||
QString("%1\n%2").arg(message).arg(commandStr)});
|
|
||||||
handleProcessFinished(-1, QProcess::CrashExit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MesonProcess::checkForCancelled()
|
void MesonProcess::checkForCancelled()
|
||||||
@@ -161,26 +128,16 @@ void MesonProcess::checkForCancelled()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MesonProcess::setupProcess(const Command &command,
|
void MesonProcess::setupProcess(const Command &command,
|
||||||
const Utils::Environment env,
|
const Environment env,
|
||||||
bool captureStdo)
|
bool captureStdo)
|
||||||
{
|
{
|
||||||
if (m_process)
|
m_process.reset(new QtcProcess);
|
||||||
disconnect(m_process.get());
|
connect(m_process.get(), &QtcProcess::done, this, &MesonProcess::handleProcessDone);
|
||||||
m_process = std::make_unique<Utils::QtcProcess>();
|
|
||||||
connect(m_process.get(), &QtcProcess::finished, this, [this] {
|
|
||||||
handleProcessFinished(m_process->exitCode(), m_process->exitStatus());
|
|
||||||
});
|
|
||||||
connect(m_process.get(), &QtcProcess::errorOccurred, this, &MesonProcess::handleProcessError);
|
|
||||||
if (!captureStdo) {
|
if (!captureStdo) {
|
||||||
connect(m_process.get(),
|
connect(m_process.get(), &QtcProcess::readyReadStandardOutput,
|
||||||
&QtcProcess::readyReadStandardOutput,
|
this, &MesonProcess::processStandardOutput);
|
||||||
this,
|
connect(m_process.get(), &QtcProcess::readyReadStandardError,
|
||||||
&MesonProcess::processStandardOutput);
|
this, &MesonProcess::processStandardError);
|
||||||
|
|
||||||
connect(m_process.get(),
|
|
||||||
&QtcProcess::readyReadStandardError,
|
|
||||||
this,
|
|
||||||
&MesonProcess::processStandardError);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_process->setWorkingDirectory(command.workDir());
|
m_process->setWorkingDirectory(command.workDir());
|
||||||
@@ -213,17 +170,15 @@ bool MesonProcess::sanityCheck(const Command &command) const
|
|||||||
|
|
||||||
void MesonProcess::processStandardOutput()
|
void MesonProcess::processStandardOutput()
|
||||||
{
|
{
|
||||||
QTC_ASSERT(m_process, return );
|
const auto data = m_process->readAllStandardOutput();
|
||||||
auto data = m_process->readAllStandardOutput();
|
|
||||||
Core::MessageManager::writeSilently(QString::fromLocal8Bit(data));
|
Core::MessageManager::writeSilently(QString::fromLocal8Bit(data));
|
||||||
emit readyReadStandardOutput(data);
|
emit readyReadStandardOutput(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MesonProcess::processStandardError()
|
void MesonProcess::processStandardError()
|
||||||
{
|
{
|
||||||
QTC_ASSERT(m_process, return );
|
|
||||||
|
|
||||||
Core::MessageManager::writeSilently(QString::fromLocal8Bit(m_process->readAllStandardError()));
|
Core::MessageManager::writeSilently(QString::fromLocal8Bit(m_process->readAllStandardError()));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace MesonProjectManager
|
} // namespace MesonProjectManager
|
||||||
|
@@ -47,7 +47,7 @@ class MesonProcess final : public QObject
|
|||||||
public:
|
public:
|
||||||
MesonProcess();
|
MesonProcess();
|
||||||
bool run(const Command &command,
|
bool run(const Command &command,
|
||||||
const Utils::Environment env,
|
const Utils::Environment &env,
|
||||||
const QString &projectName,
|
const QString &projectName,
|
||||||
bool captureStdo = false);
|
bool captureStdo = false);
|
||||||
|
|
||||||
@@ -66,8 +66,7 @@ signals:
|
|||||||
void readyReadStandardOutput(const QByteArray &data);
|
void readyReadStandardOutput(const QByteArray &data);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void handleProcessFinished(int code, QProcess::ExitStatus status);
|
void handleProcessDone();
|
||||||
void handleProcessError(QProcess::ProcessError error);
|
|
||||||
void checkForCancelled();
|
void checkForCancelled();
|
||||||
void setupProcess(const Command &command, const Utils::Environment env, bool captureStdo);
|
void setupProcess(const Command &command, const Utils::Environment env, bool captureStdo);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user