forked from qt-creator/qt-creator
Fix up QProcess::waitForFinished()
waitForFinish returns false if the process is no longer running at the time of the call. Handle that throughout the codebase. Change-Id: Ia7194095454e82efbd4eb88f2d55926bdd09e094 Reviewed-by: hjk <hjk@theqtcompany.com>
This commit is contained in:
@@ -43,10 +43,11 @@
|
||||
|
||||
#include <qtsupport/qtkitinformation.h>
|
||||
|
||||
#include <utils/qtcprocess.h>
|
||||
#include <utils/synchronousprocess.h>
|
||||
|
||||
#include <QInputDialog>
|
||||
#include <QMessageBox>
|
||||
#include <QProcess>
|
||||
|
||||
namespace Android {
|
||||
using namespace Internal;
|
||||
@@ -279,29 +280,32 @@ bool AndroidBuildApkStep::verboseOutput() const
|
||||
QAbstractItemModel *AndroidBuildApkStep::keystoreCertificates()
|
||||
{
|
||||
QString rawCerts;
|
||||
QProcess keytoolProc;
|
||||
while (!rawCerts.length() || !m_keystorePasswd.length()) {
|
||||
QStringList params;
|
||||
params << QLatin1String("-list") << QLatin1String("-v") << QLatin1String("-keystore") << m_keystorePath.toUserOutput() << QLatin1String("-storepass");
|
||||
QStringList params
|
||||
= { QLatin1String("-list"), QLatin1String("-v"), QLatin1String("-keystore"),
|
||||
m_keystorePath.toUserOutput(), QLatin1String("-storepass") };
|
||||
if (!m_keystorePasswd.length())
|
||||
keystorePassword();
|
||||
if (!m_keystorePasswd.length())
|
||||
return 0;
|
||||
return nullptr;
|
||||
params << m_keystorePasswd;
|
||||
params << QLatin1String("-J-Duser.language=en");
|
||||
keytoolProc.start(AndroidConfigurations::currentConfig().keytoolPath().toString(), params);
|
||||
if (!keytoolProc.waitForStarted() || !keytoolProc.waitForFinished()) {
|
||||
|
||||
Utils::SynchronousProcess keytoolProc;
|
||||
keytoolProc.setTimeoutS(30);
|
||||
const Utils::SynchronousProcessResponse response
|
||||
= keytoolProc.run(AndroidConfigurations::currentConfig().keytoolPath().toString(), params);
|
||||
if (response.result != Utils::SynchronousProcessResponse::Finished) {
|
||||
QMessageBox::critical(0, tr("Error"),
|
||||
tr("Failed to run keytool."));
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (keytoolProc.exitCode()) {
|
||||
QMessageBox::critical(0, tr("Error"),
|
||||
tr("Invalid password."));
|
||||
if (response.exitCode != 0) {
|
||||
QMessageBox::critical(0, tr("Error"), tr("Invalid password."));
|
||||
m_keystorePasswd.clear();
|
||||
}
|
||||
rawCerts = QString::fromLatin1(keytoolProc.readAllStandardOutput());
|
||||
rawCerts = response.stdOut;
|
||||
}
|
||||
return new CertificatesModel(rawCerts, this);
|
||||
}
|
||||
|
||||
@@ -49,8 +49,10 @@
|
||||
#include <qtsupport/qtversionmanager.h>
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/environment.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/runextensions.h>
|
||||
#include <utils/sleep.h>
|
||||
#include <utils/synchronousprocess.h>
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QSettings>
|
||||
@@ -153,16 +155,13 @@ namespace {
|
||||
if (executable.isEmpty() || shell.isEmpty())
|
||||
return true; // we can't detect, but creator is 32bit so assume 32bit
|
||||
|
||||
QProcess proc;
|
||||
SynchronousProcess proc;
|
||||
proc.setProcessChannelMode(QProcess::MergedChannels);
|
||||
proc.start(executable, QStringList() << shell);
|
||||
if (!proc.waitForFinished(2000)) {
|
||||
proc.kill();
|
||||
proc.setTimeoutS(30);
|
||||
SynchronousProcessResponse response = proc.run(executable, QStringList() << shell);
|
||||
if (response.result != SynchronousProcessResponse::Finished)
|
||||
return true;
|
||||
}
|
||||
if (proc.readAll().contains("x86-64"))
|
||||
return false;
|
||||
return true;
|
||||
return !response.allOutput().contains("x86-64");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@@ -391,17 +390,16 @@ void AndroidConfig::updateAvailableSdkPlatforms() const
|
||||
return;
|
||||
m_availableSdkPlatforms.clear();
|
||||
|
||||
QProcess proc;
|
||||
SynchronousProcess proc;
|
||||
proc.setProcessEnvironment(androidToolEnvironment().toProcessEnvironment());
|
||||
proc.start(androidToolPath().toString(), QStringList() << QLatin1String("list") << QLatin1String("target")); // list avaialbe AVDs
|
||||
if (!proc.waitForFinished(10000)) {
|
||||
proc.terminate();
|
||||
SynchronousProcessResponse response
|
||||
= proc.run(androidToolPath().toString(), QStringList() << QLatin1String("list") << QLatin1String("target")); // list avaialbe AVDs
|
||||
if (response.result == SynchronousProcessResponse::Finished)
|
||||
return;
|
||||
}
|
||||
|
||||
SdkPlatform platform;
|
||||
while (proc.canReadLine()) {
|
||||
const QString line = QString::fromLocal8Bit(proc.readLine().trimmed());
|
||||
foreach (const QString &l, response.allOutput().split('\n')) {
|
||||
const QString line = l.trimmed();
|
||||
if (line.startsWith(QLatin1String("id:")) && line.contains(QLatin1String("android-"))) {
|
||||
int index = line.indexOf(QLatin1String("\"android-"));
|
||||
if (index == -1)
|
||||
@@ -551,17 +549,18 @@ QVector<AndroidDeviceInfo> AndroidConfig::connectedDevices(QString *error) const
|
||||
QVector<AndroidDeviceInfo> AndroidConfig::connectedDevices(const QString &adbToolPath, QString *error)
|
||||
{
|
||||
QVector<AndroidDeviceInfo> devices;
|
||||
QProcess adbProc;
|
||||
adbProc.start(adbToolPath, QStringList() << QLatin1String("devices"));
|
||||
if (!adbProc.waitForFinished(10000)) {
|
||||
adbProc.kill();
|
||||
SynchronousProcess adbProc;
|
||||
adbProc.setTimeoutS(30);
|
||||
SynchronousProcessResponse response
|
||||
= adbProc.run(adbToolPath, QStringList() << QLatin1String("devices"));
|
||||
if (response.result != SynchronousProcessResponse::Finished) {
|
||||
if (error)
|
||||
*error = QApplication::translate("AndroidConfiguration",
|
||||
"Could not run: %1")
|
||||
.arg(adbToolPath + QLatin1String(" devices"));
|
||||
return devices;
|
||||
}
|
||||
QList<QByteArray> adbDevs = adbProc.readAll().trimmed().split('\n');
|
||||
QStringList adbDevs = response.allOutput().split('\n');
|
||||
if (adbDevs.empty())
|
||||
return devices;
|
||||
|
||||
@@ -571,9 +570,9 @@ QVector<AndroidDeviceInfo> AndroidConfig::connectedDevices(const QString &adbToo
|
||||
|
||||
// workaround for '????????????' serial numbers:
|
||||
// can use "adb -d" when only one usb device attached
|
||||
foreach (const QByteArray &device, adbDevs) {
|
||||
const QString serialNo = QString::fromLatin1(device.left(device.indexOf('\t')).trimmed());
|
||||
const QString deviceType = QString::fromLatin1(device.mid(device.indexOf('\t'))).trimmed();
|
||||
foreach (const QString &device, adbDevs) {
|
||||
const QString serialNo = device.left(device.indexOf('\t')).trimmed();
|
||||
const QString deviceType = device.mid(device.indexOf('\t')).trimmed();
|
||||
if (isBootToQt(adbToolPath, serialNo))
|
||||
continue;
|
||||
AndroidDeviceInfo dev;
|
||||
@@ -642,7 +641,7 @@ AndroidConfig::CreateAvdInfo AndroidConfig::createAVDImpl(CreateAvdInfo info, Fi
|
||||
.arg(androidToolPath.toString(), arguments.join(QLatin1Char(' ')));
|
||||
return info;
|
||||
}
|
||||
|
||||
QTC_CHECK(proc.state() == QProcess::Running);
|
||||
proc.write(QByteArray("yes\n")); // yes to "Do you wish to create a custom hardware profile"
|
||||
|
||||
QByteArray question;
|
||||
@@ -664,8 +663,7 @@ AndroidConfig::CreateAvdInfo AndroidConfig::createAVDImpl(CreateAvdInfo info, Fi
|
||||
if (proc.state() != QProcess::Running)
|
||||
break;
|
||||
}
|
||||
|
||||
proc.waitForFinished();
|
||||
QTC_CHECK(proc.state() == QProcess::NotRunning);
|
||||
|
||||
QString errorOutput = QString::fromLocal8Bit(proc.readAllStandardError());
|
||||
// The exit code is always 0, so we need to check stderr
|
||||
@@ -679,16 +677,14 @@ AndroidConfig::CreateAvdInfo AndroidConfig::createAVDImpl(CreateAvdInfo info, Fi
|
||||
|
||||
bool AndroidConfig::removeAVD(const QString &name) const
|
||||
{
|
||||
QProcess proc;
|
||||
SynchronousProcess proc;
|
||||
proc.setTimeoutS(5);
|
||||
proc.setProcessEnvironment(androidToolEnvironment().toProcessEnvironment());
|
||||
proc.start(androidToolPath().toString(),
|
||||
QStringList() << QLatin1String("delete") << QLatin1String("avd")
|
||||
<< QLatin1String("-n") << name);
|
||||
if (!proc.waitForFinished(5000)) {
|
||||
proc.terminate();
|
||||
return false;
|
||||
}
|
||||
return !proc.exitCode();
|
||||
SynchronousProcessResponse response
|
||||
= proc.run(androidToolPath().toString(),
|
||||
QStringList() << QLatin1String("delete") << QLatin1String("avd")
|
||||
<< QLatin1String("-n") << name);
|
||||
return response.result == SynchronousProcessResponse::Finished && response.exitCode == 0;
|
||||
}
|
||||
|
||||
QFuture<QVector<AndroidDeviceInfo>> AndroidConfig::androidVirtualDevicesFuture() const
|
||||
@@ -700,19 +696,20 @@ QFuture<QVector<AndroidDeviceInfo>> AndroidConfig::androidVirtualDevicesFuture()
|
||||
QVector<AndroidDeviceInfo> AndroidConfig::androidVirtualDevices(const QString &androidTool, const Environment &environment)
|
||||
{
|
||||
QVector<AndroidDeviceInfo> devices;
|
||||
QProcess proc;
|
||||
SynchronousProcess proc;
|
||||
proc.setTimeoutS(20);
|
||||
proc.setProcessEnvironment(environment.toProcessEnvironment());
|
||||
proc.start(androidTool,
|
||||
QStringList() << QLatin1String("list") << QLatin1String("avd")); // list available AVDs
|
||||
if (!proc.waitForFinished(20000)) {
|
||||
proc.terminate();
|
||||
SynchronousProcessResponse response
|
||||
= proc.run(androidTool,
|
||||
QStringList() << QLatin1String("list") << QLatin1String("avd")); // list available AVDs
|
||||
if (response.result != SynchronousProcessResponse::Finished)
|
||||
return devices;
|
||||
}
|
||||
QList<QByteArray> avds = proc.readAll().trimmed().split('\n');
|
||||
|
||||
QStringList avds = response.allOutput().split('\n');
|
||||
if (avds.empty())
|
||||
return devices;
|
||||
|
||||
while (avds.first().startsWith("* daemon"))
|
||||
while (avds.first().startsWith(QLatin1String("* daemon")))
|
||||
avds.removeFirst(); // remove the daemon logs
|
||||
avds.removeFirst(); // remove "List of devices attached" header line
|
||||
|
||||
@@ -720,7 +717,7 @@ QVector<AndroidDeviceInfo> AndroidConfig::androidVirtualDevices(const QString &a
|
||||
|
||||
AndroidDeviceInfo dev;
|
||||
for (int i = 0; i < avds.size(); i++) {
|
||||
QString line = QLatin1String(avds.at(i));
|
||||
QString line = avds.at(i);
|
||||
if (!line.contains(QLatin1String("Name:")))
|
||||
continue;
|
||||
|
||||
@@ -732,7 +729,7 @@ QVector<AndroidDeviceInfo> AndroidConfig::androidVirtualDevices(const QString &a
|
||||
dev.cpuAbi.clear();
|
||||
++i;
|
||||
for (; i < avds.size(); ++i) {
|
||||
line = QLatin1String(avds[i]);
|
||||
line = avds.at(i);
|
||||
if (line.contains(QLatin1String("---------")))
|
||||
break;
|
||||
|
||||
@@ -870,13 +867,11 @@ bool AndroidConfig::isBootToQt(const QString &adbToolPath, const QString &device
|
||||
arguments << QLatin1String("shell")
|
||||
<< QLatin1String("ls -l /system/bin/appcontroller || ls -l /usr/bin/appcontroller && echo Boot2Qt");
|
||||
|
||||
QProcess adbProc;
|
||||
adbProc.start(adbToolPath, arguments);
|
||||
if (!adbProc.waitForFinished(10000)) {
|
||||
adbProc.kill();
|
||||
return false;
|
||||
}
|
||||
return adbProc.readAll().contains("Boot2Qt");
|
||||
SynchronousProcess adbProc;
|
||||
adbProc.setTimeoutS(10);
|
||||
SynchronousProcessResponse response = adbProc.run(adbToolPath, arguments);
|
||||
return response.result == SynchronousProcessResponse::Finished
|
||||
&& response.allOutput().contains(QLatin1String("Boot2Qt"));
|
||||
}
|
||||
|
||||
|
||||
@@ -884,17 +879,15 @@ QString AndroidConfig::getDeviceProperty(const QString &adbToolPath, const QStri
|
||||
{
|
||||
// workaround for '????????????' serial numbers
|
||||
QStringList arguments = AndroidDeviceInfo::adbSelector(device);
|
||||
arguments << QLatin1String("shell") << QLatin1String("getprop")
|
||||
<< property;
|
||||
arguments << QLatin1String("shell") << QLatin1String("getprop") << property;
|
||||
|
||||
QProcess adbProc;
|
||||
adbProc.start(adbToolPath, arguments);
|
||||
if (!adbProc.waitForFinished(10000)) {
|
||||
adbProc.kill();
|
||||
SynchronousProcess adbProc;
|
||||
adbProc.setTimeoutS(10);
|
||||
SynchronousProcessResponse response = adbProc.run(adbToolPath, arguments);
|
||||
if (response.result != SynchronousProcessResponse::Finished)
|
||||
return QString();
|
||||
}
|
||||
|
||||
return QString::fromLocal8Bit(adbProc.readAll());
|
||||
return response.allOutput();
|
||||
}
|
||||
|
||||
int AndroidConfig::getSDKVersion(const QString &device) const
|
||||
@@ -988,16 +981,13 @@ bool AndroidConfig::hasFinishedBooting(const QString &device) const
|
||||
arguments << QLatin1String("shell") << QLatin1String("getprop")
|
||||
<< QLatin1String("init.svc.bootanim");
|
||||
|
||||
QProcess adbProc;
|
||||
adbProc.start(adbToolPath().toString(), arguments);
|
||||
if (!adbProc.waitForFinished(10000)) {
|
||||
adbProc.kill();
|
||||
SynchronousProcess adbProc;
|
||||
adbProc.setTimeoutS(10);
|
||||
SynchronousProcessResponse response = adbProc.run(adbToolPath().toString(), arguments);
|
||||
if (response.result != SynchronousProcessResponse::Finished)
|
||||
return false;
|
||||
}
|
||||
QString value = QString::fromLocal8Bit(adbProc.readAll().trimmed());
|
||||
if (value == QLatin1String("stopped"))
|
||||
return true;
|
||||
return false;
|
||||
QString value = response.allOutput().trimmed();
|
||||
return value == QLatin1String("stopped");
|
||||
}
|
||||
|
||||
QStringList AndroidConfig::getAbis(const QString &device) const
|
||||
@@ -1010,15 +1000,14 @@ QStringList AndroidConfig::getAbis(const QString &adbToolPath, const QString &de
|
||||
QStringList result;
|
||||
// First try via ro.product.cpu.abilist
|
||||
QStringList arguments = AndroidDeviceInfo::adbSelector(device);
|
||||
arguments << QLatin1String("shell") << QLatin1String("getprop");
|
||||
arguments << QLatin1String("ro.product.cpu.abilist");
|
||||
QProcess adbProc;
|
||||
adbProc.start(adbToolPath, arguments);
|
||||
if (!adbProc.waitForFinished(10000)) {
|
||||
adbProc.kill();
|
||||
arguments << QLatin1String("shell") << QLatin1String("getprop") << QLatin1String("ro.product.cpu.abilist");
|
||||
SynchronousProcess adbProc;
|
||||
adbProc.setTimeoutS(10);
|
||||
SynchronousProcessResponse response = adbProc.run(adbToolPath, arguments);
|
||||
if (response.result != SynchronousProcessResponse::Finished)
|
||||
return result;
|
||||
}
|
||||
QString output = QString::fromLocal8Bit(adbProc.readAll().trimmed());
|
||||
|
||||
QString output = response.allOutput().trimmed();
|
||||
if (!output.isEmpty()) {
|
||||
QStringList result = output.split(QLatin1Char(','));
|
||||
if (!result.isEmpty())
|
||||
@@ -1034,13 +1023,13 @@ QStringList AndroidConfig::getAbis(const QString &adbToolPath, const QString &de
|
||||
else
|
||||
arguments << QString::fromLatin1("ro.product.cpu.abi%1").arg(i);
|
||||
|
||||
QProcess adbProc;
|
||||
adbProc.start(adbToolPath, arguments);
|
||||
if (!adbProc.waitForFinished(10000)) {
|
||||
adbProc.kill();
|
||||
SynchronousProcess abiProc;
|
||||
abiProc.setTimeoutS(10);
|
||||
SynchronousProcessResponse abiResponse = abiProc.run(adbToolPath, arguments);
|
||||
if (abiResponse.result != SynchronousProcessResponse::Finished)
|
||||
return result;
|
||||
}
|
||||
QString abi = QString::fromLocal8Bit(adbProc.readAll().trimmed());
|
||||
|
||||
QString abi = abiResponse.allOutput().trimmed();
|
||||
if (abi.isEmpty())
|
||||
break;
|
||||
result << abi;
|
||||
@@ -1483,13 +1472,12 @@ void AndroidConfigurations::load()
|
||||
} else if (HostOsInfo::isMacHost()) {
|
||||
QFileInfo javaHomeExec(QLatin1String("/usr/libexec/java_home"));
|
||||
if (javaHomeExec.isExecutable() && !javaHomeExec.isDir()) {
|
||||
QProcess proc;
|
||||
SynchronousProcess proc;
|
||||
proc.setTimeoutS(2);
|
||||
proc.setProcessChannelMode(QProcess::MergedChannels);
|
||||
proc.start(javaHomeExec.absoluteFilePath());
|
||||
if (!proc.waitForFinished(2000)) {
|
||||
proc.kill();
|
||||
} else {
|
||||
const QString &javaHome = QString::fromLocal8Bit(proc.readAll().trimmed());
|
||||
SynchronousProcessResponse response = proc.run(javaHomeExec.absoluteFilePath(), QStringList());
|
||||
if (response.result == SynchronousProcessResponse::Finished) {
|
||||
const QString &javaHome = response.allOutput().trimmed();
|
||||
if (!javaHome.isEmpty() && QFileInfo::exists(javaHome))
|
||||
m_config.setOpenJDKLocation(FileName::fromString(javaHome));
|
||||
}
|
||||
|
||||
@@ -27,8 +27,9 @@
|
||||
#include "androidconfigurations.h"
|
||||
#include "ui_androidcreatekeystorecertificate.h"
|
||||
|
||||
#include <utils/synchronousprocess.h>
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QProcess>
|
||||
#include <QMessageBox>
|
||||
|
||||
using namespace Android::Internal;
|
||||
@@ -162,6 +163,7 @@ void AndroidCreateKeystoreCertificate::on_buttonBox_accepted()
|
||||
if (ui->stateNameLineEdit->text().length())
|
||||
distinguishedNames += QLatin1String(", S=") + ui->stateNameLineEdit->text().replace(QLatin1Char(','), QLatin1String("\\,"));
|
||||
|
||||
const QString command = AndroidConfigurations::currentConfig().keytoolPath().toString();
|
||||
QStringList params;
|
||||
params << QLatin1String("-genkey") << QLatin1String("-keyalg") << QLatin1String("RSA")
|
||||
<< QLatin1String("-keystore") << m_keystoreFilePath.toString()
|
||||
@@ -172,16 +174,13 @@ void AndroidCreateKeystoreCertificate::on_buttonBox_accepted()
|
||||
<< QLatin1String("-keypass") << certificatePassword()
|
||||
<< QLatin1String("-dname") << distinguishedNames;
|
||||
|
||||
QProcess genKeyCertProc;
|
||||
genKeyCertProc.start(AndroidConfigurations::currentConfig().keytoolPath().toString(), params );
|
||||
Utils::SynchronousProcess genKeyCertProc;
|
||||
genKeyCertProc.setTimeoutS(15);
|
||||
Utils::SynchronousProcessResponse response = genKeyCertProc.run(command, params);
|
||||
|
||||
if (!genKeyCertProc.waitForStarted() || !genKeyCertProc.waitForFinished())
|
||||
return;
|
||||
|
||||
if (genKeyCertProc.exitCode()) {
|
||||
QMessageBox::critical(this, tr("Error")
|
||||
, QString::fromLatin1(genKeyCertProc.readAllStandardOutput())
|
||||
+ QString::fromLatin1(genKeyCertProc.readAllStandardError()));
|
||||
if (response.result != Utils::SynchronousProcessResponse::Finished || response.exitCode != 0) {
|
||||
QMessageBox::critical(this, tr("Error"),
|
||||
response.exitMessage(command, 15) + QLatin1Char('\n') + response.allOutput());
|
||||
return;
|
||||
}
|
||||
accept();
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/qtcprocess.h>
|
||||
#include <utils/synchronousprocess.h>
|
||||
|
||||
#include <QInputDialog>
|
||||
#include <QMessageBox>
|
||||
@@ -354,7 +355,10 @@ AndroidDeployQtStep::DeployResult AndroidDeployQtStep::runDeploy(QFutureInterfac
|
||||
.arg(QDir::toNativeSeparators(m_command), args),
|
||||
BuildStep::MessageOutput);
|
||||
|
||||
while (m_process->state() != QProcess::NotRunning && !m_process->waitForFinished(200)) {
|
||||
while (!m_process->waitForFinished(200)) {
|
||||
if (m_process->state() == QProcess::NotRunning)
|
||||
break;
|
||||
|
||||
if (fi.isCanceled()) {
|
||||
m_process->kill();
|
||||
m_process->waitForFinished();
|
||||
@@ -464,25 +468,12 @@ void AndroidDeployQtStep::run(QFutureInterface<bool> &fi)
|
||||
|
||||
void AndroidDeployQtStep::runCommand(const QString &program, const QStringList &arguments)
|
||||
{
|
||||
QProcess buildProc;
|
||||
Utils::SynchronousProcess buildProc;
|
||||
buildProc.setTimeoutS(2 * 60);
|
||||
emit addOutput(tr("Package deploy: Running command \"%1 %2\".").arg(program).arg(arguments.join(QLatin1Char(' '))), BuildStep::MessageOutput);
|
||||
buildProc.start(program, arguments);
|
||||
if (!buildProc.waitForStarted()) {
|
||||
emit addOutput(tr("Packaging error: Could not start command \"%1 %2\". Reason: %3")
|
||||
.arg(program).arg(arguments.join(QLatin1Char(' '))).arg(buildProc.errorString()), BuildStep::ErrorMessageOutput);
|
||||
return;
|
||||
}
|
||||
if (!buildProc.waitForFinished(2 * 60 * 1000)
|
||||
|| buildProc.error() != QProcess::UnknownError
|
||||
|| buildProc.exitCode() != 0) {
|
||||
QString mainMessage = tr("Packaging error: Command \"%1 %2\" failed.")
|
||||
.arg(program).arg(arguments.join(QLatin1Char(' ')));
|
||||
if (buildProc.error() != QProcess::UnknownError)
|
||||
mainMessage += QLatin1Char(' ') + tr("Reason: %1").arg(buildProc.errorString());
|
||||
else
|
||||
mainMessage += tr("Exit code: %1").arg(buildProc.exitCode());
|
||||
emit addOutput(mainMessage, BuildStep::ErrorMessageOutput);
|
||||
}
|
||||
Utils::SynchronousProcessResponse response = buildProc.run(program, arguments);
|
||||
if (response.result != Utils::SynchronousProcessResponse::Finished || response.exitCode != 0)
|
||||
emit addOutput(response.exitMessage(program, 2 * 60), BuildStep::ErrorMessageOutput);
|
||||
}
|
||||
|
||||
AndroidDeviceInfo AndroidDeployQtStep::deviceInfo() const
|
||||
|
||||
@@ -32,9 +32,7 @@
|
||||
#include <projectexplorer/abstractprocessstep.h>
|
||||
#include <qtsupport/baseqtversion.h>
|
||||
|
||||
namespace Utils {
|
||||
class QtcProcess;
|
||||
}
|
||||
namespace Utils { class QtcProcess; }
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QAbstractItemModel;
|
||||
|
||||
@@ -51,6 +51,7 @@
|
||||
#include <qtsupport/qtkitinformation.h>
|
||||
#include <qtsupport/qtsupportconstants.h>
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/synchronousprocess.h>
|
||||
|
||||
#include <QDir>
|
||||
#include <QFileSystemWatcher>
|
||||
@@ -345,13 +346,13 @@ void AndroidManager::installQASIPackage(ProjectExplorer::Target *target, const Q
|
||||
QStringList arguments = AndroidDeviceInfo::adbSelector(deviceSerialNumber);
|
||||
arguments << QLatin1String("install") << QLatin1String("-r ") << packagePath;
|
||||
|
||||
process->connect(process, SIGNAL(finished(int)), process, SLOT(deleteLater()));
|
||||
connect(process, static_cast<void (QProcess::*)(int)>(&QProcess::finished),
|
||||
process, &QObject::deleteLater);
|
||||
const QString adb = AndroidConfigurations::currentConfig().adbToolPath().toString();
|
||||
Core::MessageManager::write(adb + QLatin1Char(' ') + arguments.join(QLatin1Char(' ')));
|
||||
process->start(adb, arguments);
|
||||
if (!process->waitForFinished(500))
|
||||
if (!process->waitForStarted(500) && process->state() != QProcess::Running)
|
||||
delete process;
|
||||
|
||||
}
|
||||
|
||||
bool AndroidManager::checkKeystorePassword(const QString &keystorePath, const QString &keystorePasswd)
|
||||
@@ -364,16 +365,10 @@ bool AndroidManager::checkKeystorePassword(const QString &keystorePath, const QS
|
||||
<< keystorePath
|
||||
<< QLatin1String("--storepass")
|
||||
<< keystorePasswd;
|
||||
QProcess proc;
|
||||
proc.start(AndroidConfigurations::currentConfig().keytoolPath().toString(), arguments);
|
||||
if (!proc.waitForStarted(10000))
|
||||
return false;
|
||||
if (!proc.waitForFinished(10000)) {
|
||||
proc.kill();
|
||||
proc.waitForFinished();
|
||||
return false;
|
||||
}
|
||||
return proc.exitCode() == 0;
|
||||
Utils::SynchronousProcess proc;
|
||||
proc.setTimeoutS(10);
|
||||
Utils::SynchronousProcessResponse response = proc.run(AndroidConfigurations::currentConfig().keytoolPath().toString(), arguments);
|
||||
return (response.result == Utils::SynchronousProcessResponse::Finished && response.exitCode == 0);
|
||||
}
|
||||
|
||||
bool AndroidManager::checkCertificatePassword(const QString &keystorePath, const QString &keystorePasswd, const QString &alias, const QString &certificatePasswd)
|
||||
@@ -393,16 +388,11 @@ bool AndroidManager::checkCertificatePassword(const QString &keystorePath, const
|
||||
else
|
||||
arguments << certificatePasswd;
|
||||
|
||||
QProcess proc;
|
||||
proc.start(AndroidConfigurations::currentConfig().keytoolPath().toString(), arguments);
|
||||
if (!proc.waitForStarted(10000))
|
||||
return false;
|
||||
if (!proc.waitForFinished(10000)) {
|
||||
proc.kill();
|
||||
proc.waitForFinished();
|
||||
return false;
|
||||
}
|
||||
return proc.exitCode() == 0;
|
||||
Utils::SynchronousProcess proc;
|
||||
proc.setTimeoutS(10);
|
||||
Utils::SynchronousProcessResponse response
|
||||
= proc.run(AndroidConfigurations::currentConfig().keytoolPath().toString(), arguments);
|
||||
return response.result == Utils::SynchronousProcessResponse::Finished && response.exitCode == 0;
|
||||
}
|
||||
|
||||
bool AndroidManager::checkForQt51Files(Utils::FileName fileName)
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include <qtsupport/qtkitinformation.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/runextensions.h>
|
||||
#include <utils/synchronousprocess.h>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDir>
|
||||
@@ -169,10 +170,11 @@ AndroidRunner::AndroidRunner(QObject *parent,
|
||||
|
||||
|
||||
// Detect busybox, as we need to pass -w to ps to get wide output.
|
||||
QProcess psProc;
|
||||
psProc.start(m_adb, selector() << _("shell") << _("readlink") << _("$(which ps)"));
|
||||
psProc.waitForFinished();
|
||||
QByteArray which = psProc.readAll();
|
||||
Utils::SynchronousProcess psProc;
|
||||
psProc.setTimeoutS(5);
|
||||
Utils::SynchronousProcessResponse response
|
||||
= psProc.run(m_adb, selector() << _("shell") << _("readlink") << _("$(which ps)"));
|
||||
const QString which = response.allOutput();
|
||||
m_isBusyBox = which.startsWith("busybox");
|
||||
|
||||
m_checkPIDTimer.setInterval(1000);
|
||||
@@ -302,10 +304,8 @@ void AndroidRunner::checkPID()
|
||||
|
||||
void AndroidRunner::forceStop()
|
||||
{
|
||||
QProcess proc;
|
||||
proc.start(m_adb, selector() << _("shell") << _("am") << _("force-stop")
|
||||
<< m_androidRunnable.packageName);
|
||||
proc.waitForFinished();
|
||||
runAdb(selector() << _("shell") << _("am") << _("force-stop") << m_androidRunnable.packageName,
|
||||
nullptr, 30);
|
||||
|
||||
// try killing it via kill -9
|
||||
const QByteArray out = runPs();
|
||||
@@ -334,34 +334,22 @@ void AndroidRunner::asyncStart()
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
forceStop();
|
||||
QString errorMessage;
|
||||
|
||||
if (m_useCppDebugger) {
|
||||
// Remove pong file.
|
||||
QProcess adb;
|
||||
adb.start(m_adb, selector() << _("shell") << _("rm") << m_pongFile);
|
||||
adb.waitForFinished();
|
||||
}
|
||||
if (m_useCppDebugger)
|
||||
runAdb(selector() << _("shell") << _("rm") << m_pongFile); // Remove pong file.
|
||||
|
||||
foreach (const QStringList &entry, m_androidRunnable.beforeStartADBCommands) {
|
||||
QProcess adb;
|
||||
adb.start(m_adb, selector() << entry);
|
||||
adb.waitForFinished();
|
||||
}
|
||||
foreach (const QStringList &entry, m_androidRunnable.beforeStartADBCommands)
|
||||
runAdb(selector() << entry);
|
||||
|
||||
QStringList args = selector();
|
||||
args << _("shell") << _("am") << _("start") << _("-n") << m_androidRunnable.intentName;
|
||||
|
||||
if (m_useCppDebugger) {
|
||||
QProcess adb;
|
||||
adb.start(m_adb, selector() << _("forward")
|
||||
<< QString::fromLatin1("tcp:%1").arg(m_localGdbServerPort.number())
|
||||
<< _("localfilesystem:") + m_gdbserverSocket);
|
||||
if (!adb.waitForStarted()) {
|
||||
emit remoteProcessFinished(tr("Failed to forward C++ debugging ports. Reason: %1.").arg(adb.errorString()));
|
||||
return;
|
||||
}
|
||||
if (!adb.waitForFinished(10000)) {
|
||||
emit remoteProcessFinished(tr("Failed to forward C++ debugging ports."));
|
||||
if (!runAdb(selector() << _("forward")
|
||||
<< QString::fromLatin1("tcp:%1").arg(m_localGdbServerPort.number())
|
||||
<< _("localfilesystem:") + m_gdbserverSocket, &errorMessage)) {
|
||||
emit remoteProcessFinished(tr("Failed to forward C++ debugging ports. Reason: %1.").arg(errorMessage));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -380,15 +368,9 @@ void AndroidRunner::asyncStart()
|
||||
args << _("-e") << _("gdbserver_socket") << m_gdbserverSocket;
|
||||
|
||||
if (m_handShakeMethod == SocketHandShake) {
|
||||
QProcess adb;
|
||||
const QString port = QString::fromLatin1("tcp:%1").arg(socketHandShakePort);
|
||||
adb.start(m_adb, selector() << _("forward") << port << _("localabstract:") + pingPongSocket);
|
||||
if (!adb.waitForStarted()) {
|
||||
emit remoteProcessFinished(tr("Failed to forward ping pong ports. Reason: %1.").arg(adb.errorString()));
|
||||
return;
|
||||
}
|
||||
if (!adb.waitForFinished()) {
|
||||
emit remoteProcessFinished(tr("Failed to forward ping pong ports."));
|
||||
if (!runAdb(selector() << _("forward") << port << _("localabstract:") + pingPongSocket, &errorMessage)) {
|
||||
emit remoteProcessFinished(tr("Failed to forward ping pong ports. Reason: %1.").arg(errorMessage));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -397,14 +379,8 @@ void AndroidRunner::asyncStart()
|
||||
if (m_qmlDebugServices != QmlDebug::NoQmlDebugServices) {
|
||||
// currently forward to same port on device and host
|
||||
const QString port = QString::fromLatin1("tcp:%1").arg(m_qmlPort.number());
|
||||
QProcess adb;
|
||||
adb.start(m_adb, selector() << _("forward") << port << port);
|
||||
if (!adb.waitForStarted()) {
|
||||
emit remoteProcessFinished(tr("Failed to forward QML debugging ports. Reason: %1.").arg(adb.errorString()));
|
||||
return;
|
||||
}
|
||||
if (!adb.waitForFinished()) {
|
||||
emit remoteProcessFinished(tr("Failed to forward QML debugging ports."));
|
||||
if (!runAdb(selector() << _("forward") << port << port, &errorMessage)) {
|
||||
emit remoteProcessFinished(tr("Failed to forward QML debugging ports. Reason: %1.").arg(errorMessage));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -414,15 +390,8 @@ void AndroidRunner::asyncStart()
|
||||
.arg(m_qmlPort.number()).arg(QmlDebug::qmlDebugServices(m_qmlDebugServices));
|
||||
}
|
||||
|
||||
QProcess adb;
|
||||
adb.start(m_adb, args);
|
||||
if (!adb.waitForStarted()) {
|
||||
emit remoteProcessFinished(tr("Failed to start the activity. Reason: %1.").arg(adb.errorString()));
|
||||
return;
|
||||
}
|
||||
if (!adb.waitForFinished(10000)) {
|
||||
adb.terminate();
|
||||
emit remoteProcessFinished(tr("Unable to start \"%1\".").arg(m_androidRunnable.packageName));
|
||||
if (!runAdb(args, &errorMessage)) {
|
||||
emit remoteProcessFinished(tr("Failed to start the activity. Reason: %1.").arg(errorMessage));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -476,9 +445,7 @@ void AndroidRunner::asyncStart()
|
||||
tmp.open();
|
||||
tmp.close();
|
||||
|
||||
QProcess process;
|
||||
process.start(m_adb, selector() << _("pull") << m_pingFile << tmp.fileName());
|
||||
process.waitForFinished();
|
||||
runAdb(selector() << _("pull") << m_pingFile << tmp.fileName());
|
||||
|
||||
QFile res(tmp.fileName());
|
||||
const bool doBreak = res.size();
|
||||
@@ -510,18 +477,28 @@ bool AndroidRunner::adbShellAmNeedsQuotes()
|
||||
// The command will fail with a complaint about the "--dummy"
|
||||
// option on newer SDKs, and with "No intent supplied" on older ones.
|
||||
// In case the test itself fails assume a new SDK.
|
||||
QProcess adb;
|
||||
adb.start(m_adb, selector() << _("shell") << _("am") << _("start")
|
||||
<< _("-e") << _("dummy") <<_("dummy --dummy"));
|
||||
if (!adb.waitForStarted())
|
||||
Utils::SynchronousProcess adb;
|
||||
adb.setTimeoutS(10);
|
||||
Utils::SynchronousProcessResponse response
|
||||
= adb.run(m_adb, selector() << _("shell") << _("am") << _("start")
|
||||
<< _("-e") << _("dummy") <<_("dummy --dummy"));
|
||||
if (response.result == Utils::SynchronousProcessResponse::StartFailed
|
||||
|| response.result != Utils::SynchronousProcessResponse::Finished)
|
||||
return true;
|
||||
|
||||
if (!adb.waitForFinished(10000))
|
||||
return true;
|
||||
const QString output = response.allOutput();
|
||||
return output.contains(QLatin1String("Error: No intent supplied"));
|
||||
}
|
||||
|
||||
QByteArray output = adb.readAllStandardError() + adb.readAllStandardOutput();
|
||||
bool oldSdk = output.contains("Error: No intent supplied");
|
||||
return !oldSdk;
|
||||
bool AndroidRunner::runAdb(const QStringList &args, QString *errorMessage, int timeoutS)
|
||||
{
|
||||
Utils::SynchronousProcess adb;
|
||||
adb.setTimeoutS(timeoutS);
|
||||
Utils::SynchronousProcessResponse response
|
||||
= adb.run(m_adb, args);
|
||||
if (errorMessage)
|
||||
*errorMessage = response.exitMessage(m_adb, timeoutS);
|
||||
return response.result == Utils::SynchronousProcessResponse::Finished;
|
||||
}
|
||||
|
||||
void AndroidRunner::handleRemoteDebuggerRunning()
|
||||
@@ -535,9 +512,7 @@ void AndroidRunner::handleRemoteDebuggerRunning()
|
||||
QTemporaryFile tmp(QDir::tempPath() + _("/pingpong"));
|
||||
tmp.open();
|
||||
|
||||
QProcess process;
|
||||
process.start(m_adb, selector() << _("push") << tmp.fileName() << m_pongFile);
|
||||
process.waitForFinished();
|
||||
runAdb(selector() << _("push") << tmp.fileName() << m_pongFile);
|
||||
}
|
||||
QTC_CHECK(m_processPID != -1);
|
||||
}
|
||||
@@ -558,11 +533,8 @@ void AndroidRunner::stop()
|
||||
m_adbLogcatProcess.waitForFinished();
|
||||
m_psProc.kill();
|
||||
m_psProc.waitForFinished();
|
||||
foreach (const QStringList &entry, m_androidRunnable.afterFinishADBCommands) {
|
||||
QProcess adb;
|
||||
adb.start(m_adb, selector() << entry);
|
||||
adb.waitForFinished();
|
||||
}
|
||||
foreach (const QStringList &entry, m_androidRunnable.afterFinishADBCommands)
|
||||
runAdb(selector() << entry);
|
||||
}
|
||||
|
||||
void AndroidRunner::logcatProcess(const QByteArray &text, QByteArray &buffer, bool onlyError)
|
||||
@@ -622,19 +594,9 @@ void AndroidRunner::logcatReadStandardOutput()
|
||||
|
||||
void AndroidRunner::adbKill(qint64 pid)
|
||||
{
|
||||
{
|
||||
QProcess process;
|
||||
process.start(m_adb, selector() << _("shell")
|
||||
<< _("kill") << QLatin1String("-9") << QString::number(pid));
|
||||
process.waitForFinished();
|
||||
}
|
||||
{
|
||||
QProcess process;
|
||||
process.start(m_adb, selector() << _("shell")
|
||||
<< _("run-as") << m_androidRunnable.packageName
|
||||
<< _("kill") << QLatin1String("-9") << QString::number(pid));
|
||||
process.waitForFinished();
|
||||
}
|
||||
runAdb(selector() << _("shell") << _("kill") << QLatin1String("-9") << QString::number(pid));
|
||||
runAdb(selector() << _("shell") << _("run-as") << m_androidRunnable.packageName
|
||||
<< _("kill") << QLatin1String("-9") << QString::number(pid));
|
||||
}
|
||||
|
||||
QString AndroidRunner::displayName() const
|
||||
|
||||
@@ -90,6 +90,7 @@ private:
|
||||
bool adbShellAmNeedsQuotes();
|
||||
|
||||
private:
|
||||
bool runAdb(const QStringList &args, QString *errorMessage = nullptr, int timeoutS = 10);
|
||||
QProcess m_adbLogcatProcess;
|
||||
QProcess m_psProc;
|
||||
QTimer m_checkPIDTimer;
|
||||
|
||||
Reference in New Issue
Block a user