Commit 5d3823ac authored by Tobias Hunger's avatar Tobias Hunger

Use SynchronousProcess::runBlocking

Use SynchronousProcess::runBlocking in favor of SychronousProcess::run.
This avoid nested event loops which can produce really strange crashes
if not use carefully.

This patch only converts those processes that have a timeout of less
than 5 seconds or use the default timeout.

Change-Id: I9de8899dcc946af7049ea357a91972996c0256a1
Reviewed-by: default avatarVikas Pachdha <vikas.pachdha@theqtcompany.com>
Reviewed-by: Tobias Hunger's avatarTobias Hunger <tobias.hunger@qt.io>
parent 17915382
......@@ -43,7 +43,7 @@ QString BuildableHelperLibrary::qtChooserToQmakePath(const QString &path)
const QString toolDir = QLatin1String("QTTOOLDIR=\"");
SynchronousProcess proc;
proc.setTimeoutS(1);
SynchronousProcessResponse response = proc.run(path, QStringList(QLatin1String("-print-env")));
SynchronousProcessResponse response = proc.runBlocking(path, QStringList(QLatin1String("-print-env")));
if (response.result != SynchronousProcessResponse::Finished)
return QString();
const QString output = response.stdOut;
......@@ -104,7 +104,7 @@ QString BuildableHelperLibrary::qtVersionForQMake(const QString &qmakePath)
SynchronousProcess qmake;
qmake.setTimeoutS(5);
SynchronousProcessResponse response = qmake.run(qmakePath, QStringList(QLatin1String("--version")));
SynchronousProcessResponse response = qmake.runBlocking(qmakePath, QStringList(QLatin1String("--version")));
if (response.result != SynchronousProcessResponse::Finished) {
qWarning() << response.exitMessage(qmakePath, 5);
return QString();
......
......@@ -131,7 +131,7 @@ QString BinaryVersionToolTipEventFilter::toolVersion(const QString &binary, cons
return QString();
SynchronousProcess proc;
proc.setTimeoutS(1);
SynchronousProcessResponse response = proc.run(binary, arguments);
SynchronousProcessResponse response = proc.runBlocking(binary, arguments);
if (response.result != SynchronousProcessResponse::Finished)
return QString();
return response.allOutput();
......
......@@ -385,7 +385,8 @@ void AndroidConfig::updateAvailableSdkPlatforms() const
SynchronousProcess proc;
proc.setProcessEnvironment(androidToolEnvironment().toProcessEnvironment());
SynchronousProcessResponse response
= proc.run(androidToolPath().toString(), QStringList() << QLatin1String("list") << QLatin1String("target")); // list avaialbe AVDs
= proc.runBlocking(androidToolPath().toString(),
QStringList() << QLatin1String("list") << QLatin1String("target")); // list avaialbe AVDs
if (response.result != SynchronousProcessResponse::Finished)
return;
......@@ -673,9 +674,9 @@ bool AndroidConfig::removeAVD(const QString &name) const
proc.setTimeoutS(5);
proc.setProcessEnvironment(androidToolEnvironment().toProcessEnvironment());
SynchronousProcessResponse response
= proc.run(androidToolPath().toString(),
QStringList() << QLatin1String("delete") << QLatin1String("avd")
<< QLatin1String("-n") << name);
= proc.runBlocking(androidToolPath().toString(),
QStringList() << QLatin1String("delete") << QLatin1String("avd")
<< QLatin1String("-n") << name);
return response.result == SynchronousProcessResponse::Finished && response.exitCode == 0;
}
......@@ -875,7 +876,7 @@ QString AndroidConfig::getDeviceProperty(const QString &adbToolPath, const QStri
SynchronousProcess adbProc;
adbProc.setTimeoutS(10);
SynchronousProcessResponse response = adbProc.run(adbToolPath, arguments);
SynchronousProcessResponse response = adbProc.runBlocking(adbToolPath, arguments);
if (response.result != SynchronousProcessResponse::Finished)
return QString();
......@@ -1467,7 +1468,7 @@ void AndroidConfigurations::load()
SynchronousProcess proc;
proc.setTimeoutS(2);
proc.setProcessChannelMode(QProcess::MergedChannels);
SynchronousProcessResponse response = proc.run(javaHomeExec.absoluteFilePath(), QStringList());
SynchronousProcessResponse response = proc.runBlocking(javaHomeExec.absoluteFilePath(), QStringList());
if (response.result == SynchronousProcessResponse::Finished) {
const QString &javaHome = response.allOutput().trimmed();
if (!javaHome.isEmpty() && QFileInfo::exists(javaHome))
......
......@@ -173,7 +173,7 @@ AndroidRunner::AndroidRunner(QObject *parent,
Utils::SynchronousProcess psProc;
psProc.setTimeoutS(5);
Utils::SynchronousProcessResponse response
= psProc.run(m_adb, selector() << _("shell") << _("readlink") << _("$(which ps)"));
= psProc.runBlocking(m_adb, selector() << _("shell") << _("readlink") << _("$(which ps)"));
const QString which = response.allOutput();
m_isBusyBox = which.startsWith("busybox");
......
......@@ -80,7 +80,7 @@ static int updateVersionHelper(const QString &command)
{
Utils::SynchronousProcess process;
Utils::SynchronousProcessResponse response
= process.run(command, QStringList() << QLatin1String("--version"));
= process.runBlocking(command, QStringList() << QLatin1String("--version"));
if (response.result != Utils::SynchronousProcessResponse::Finished)
return 0;
......@@ -157,7 +157,7 @@ void ArtisticStyleSettings::createDocumentationFile() const
Utils::SynchronousProcess process;
process.setTimeoutS(2);
Utils::SynchronousProcessResponse response
= process.run(command(), QStringList() << QLatin1String("-h"));
= process.runBlocking(command(), QStringList() << QLatin1String("-h"));
if (response.result != Utils::SynchronousProcessResponse::Finished)
return;
......
......@@ -99,7 +99,7 @@ FormatTask format(FormatTask task)
options.replaceInStrings(QLatin1String("%file"), sourceFile.fileName());
Utils::SynchronousProcess process;
process.setTimeoutS(5);
Utils::SynchronousProcessResponse response = process.run(executable, options);
Utils::SynchronousProcessResponse response = process.runBlocking(executable, options);
if (response.result != Utils::SynchronousProcessResponse::Finished) {
task.error = QObject::tr("Failed to format: %1.").arg(response.exitMessage(executable, 5));
return task;
......
......@@ -129,7 +129,7 @@ void UncrustifySettings::createDocumentationFile() const
Utils::SynchronousProcess process;
process.setTimeoutS(2);
Utils::SynchronousProcessResponse response
= process.run(command(), QStringList() << QLatin1String("--show-config"));
= process.runBlocking(command(), QStringList() << QLatin1String("--show-config"));
if (response.result != Utils::SynchronousProcessResponse::Finished)
return;
......
......@@ -109,7 +109,7 @@ Utils::SynchronousProcessResponse CMakeTool::run(const QString &arg) const
cmake.setProcessEnvironment(env.toProcessEnvironment());
cmake.setTimeOutMessageBoxEnabled(false);
Utils::SynchronousProcessResponse response = cmake.run(m_executable.toString(), QStringList() << arg);
Utils::SynchronousProcessResponse response = cmake.runBlocking(m_executable.toString(), QStringList() << arg);
m_didAttemptToRun = true;
m_didRun = (response.result == Utils::SynchronousProcessResponse::Finished);
return response;
......
......@@ -120,7 +120,7 @@ void DebuggerItem::reinitializeFromFile()
SynchronousProcess proc;
SynchronousProcessResponse response
= proc.run(m_command.toString(), QStringList({ QLatin1String(version) }));
= proc.runBlocking(m_command.toString(), QStringList({ QLatin1String(version) }));
if (response.result != SynchronousProcessResponse::Finished) {
m_engineType = NoEngineType;
return;
......
......@@ -228,8 +228,8 @@ void DebuggerItemManager::autoDetectGdbOrLldbDebuggers()
SynchronousProcess lldbInfo;
lldbInfo.setTimeoutS(2);
SynchronousProcessResponse response
= lldbInfo.run(QLatin1String("xcrun"), QStringList() << QLatin1String("--find")
<< QLatin1String("lldb"));
= lldbInfo.runBlocking(QLatin1String("xcrun"), QStringList() << QLatin1String("--find")
<< QLatin1String("lldb"));
if (response.result == Utils::SynchronousProcessResponse::Finished) {
QString lPath = response.allOutput();
if (!lPath.isEmpty()) {
......
......@@ -140,7 +140,7 @@ GdbCoreEngine::readExecutableNameFromCore(const QString &debuggerCommand, const
QStringList envLang = QProcess::systemEnvironment();
Utils::Environment::setupEnglishOutput(&envLang);
proc.setEnvironment(envLang);
SynchronousProcessResponse response = proc.run(debuggerCommand, args);
SynchronousProcessResponse response = proc.runBlocking(debuggerCommand, args);
if (response.result == SynchronousProcessResponse::Finished) {
QString output = response.stdOut;
......
......@@ -279,7 +279,7 @@ bool AbstractMsvcToolChain::generateEnvironmentSettings(Utils::Environment &env,
if (debug)
qDebug() << "readEnvironmentSetting: " << call << cmdPath << cmdArguments.join(' ')
<< " Env: " << env.size();
Utils::SynchronousProcessResponse response = run.run(cmdPath.toString(), cmdArguments);
Utils::SynchronousProcessResponse response = run.runBlocking(cmdPath.toString(), cmdArguments);
if (response.result != Utils::SynchronousProcessResponse::Finished) {
qWarning() << response.exitMessage(cmdPath.toString(), 10);
return false;
......
......@@ -248,7 +248,7 @@ QByteArray MsvcToolChain::msvcPredefinedMacros(const QStringList cxxflags,
}
arguments << toProcess << QLatin1String("/EP") << QDir::toNativeSeparators(saver.fileName());
Utils::SynchronousProcessResponse response = cpp.run(binary.toString(), arguments);
Utils::SynchronousProcessResponse response = cpp.runBlocking(binary.toString(), arguments);
if (response.result != Utils::SynchronousProcessResponse::Finished ||
response.exitCode != 0)
return predefinedMacros;
......
......@@ -72,7 +72,7 @@ QString findFallbackDefinitionsLocation()
Utils::SynchronousProcess process;
process.setTimeoutS(5);
Utils::SynchronousProcessResponse response
= process.run(program, QStringList(QLatin1String("--prefix")));
= process.runBlocking(program, QStringList(QLatin1String("--prefix")));
if (response.result == Utils::SynchronousProcessResponse::Finished) {
QString output = response.stdOut;
output.remove(QLatin1Char('\n'));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment