Android: Use Util::FilePath for working directory in deploy step

Change-Id: I37e716f267cbcc39bc0bddc8b37e84613e048721
Reviewed-by: Vikas Pachdha <vikas.pachdha@qt.io>
This commit is contained in:
hjk
2019-06-05 10:47:30 +02:00
parent 0439eea6bc
commit 8e7138f06a
2 changed files with 20 additions and 20 deletions

View File

@@ -237,7 +237,7 @@ bool AndroidDeployQtStep::init()
m_apkPath = Utils::FilePath::fromString(node->data(Constants::AndroidApk).toString()); m_apkPath = Utils::FilePath::fromString(node->data(Constants::AndroidApk).toString());
if (!m_apkPath.isEmpty()) { if (!m_apkPath.isEmpty()) {
m_manifestName = Utils::FilePath::fromString(node->data(Constants::AndroidManifest).toString()); m_manifestName = Utils::FilePath::fromString(node->data(Constants::AndroidManifest).toString());
m_command = AndroidConfigurations::currentConfig().adbToolPath().toString(); m_command = AndroidConfigurations::currentConfig().adbToolPath();
AndroidManager::setManifestPath(target(), m_manifestName); AndroidManager::setManifestPath(target(), m_manifestName);
} else { } else {
QString jsonFile; QString jsonFile;
@@ -246,20 +246,19 @@ bool AndroidDeployQtStep::init()
if (jsonFile.isEmpty()) { if (jsonFile.isEmpty()) {
emit addOutput(tr("Cannot find the androiddeploy Json file."), OutputFormat::Stderr); emit addOutput(tr("Cannot find the androiddeploy Json file."), OutputFormat::Stderr);
return false; return false;
} m_command = version->qmakeProperty("QT_HOST_BINS"); }
m_command = FilePath::fromString(version->qmakeProperty("QT_HOST_BINS"));
if (m_command.isEmpty()) { if (m_command.isEmpty()) {
emit addOutput(tr("Cannot find the androiddeployqt tool."), OutputFormat::Stderr); emit addOutput(tr("Cannot find the androiddeployqt tool."), OutputFormat::Stderr);
return false; return false;
} }
qCDebug(deployStepLog) << "Using androiddeployqt"; qCDebug(deployStepLog) << "Using androiddeployqt";
if (!m_command.endsWith(QLatin1Char('/'))) m_command = m_command.pathAppended(HostOsInfo::withExecutableSuffix("androiddeployqt"));
m_command += QLatin1Char('/');
m_command += Utils::HostOsInfo::withExecutableSuffix(QLatin1String("androiddeployqt"));
m_workingDirectory = bc->buildDirectory().pathAppended(Constants::ANDROID_BUILDDIRECTORY).toString(); m_workingDirectory = bc->buildDirectory().pathAppended(Constants::ANDROID_BUILDDIRECTORY);
m_androiddeployqtArgs.addArgs({"--verbose", m_androiddeployqtArgs.addArgs({"--verbose",
"--output", m_workingDirectory, "--output", m_workingDirectory.toString(),
"--no-build", "--no-build",
"--input", jsonFile}); "--input", jsonFile});
@@ -280,14 +279,14 @@ bool AndroidDeployQtStep::init()
} }
} else { } else {
m_uninstallPreviousPackageRun = true; m_uninstallPreviousPackageRun = true;
m_command = AndroidConfigurations::currentConfig().adbToolPath().toString(); m_command = AndroidConfigurations::currentConfig().adbToolPath();
const AndroidConfig &config = AndroidConfigurations::currentConfig(); const AndroidConfig &config = AndroidConfigurations::currentConfig();
m_apkPath = deployQtLive ? config.qtLiveApkPath() : AndroidManager::apkPath(target()); m_apkPath = deployQtLive ? config.qtLiveApkPath() : AndroidManager::apkPath(target());
m_workingDirectory = bc ? bc->buildDirectory().toString() : QString(); m_workingDirectory = bc ? bc->buildDirectory() : FilePath();
} }
m_environment = bc ? bc->environment() : Utils::Environment(); m_environment = bc ? bc->environment() : Utils::Environment();
m_adbPath = AndroidConfigurations::currentConfig().adbToolPath().toString(); m_adbPath = AndroidConfigurations::currentConfig().adbToolPath();
AndroidAvdManager avdManager; AndroidAvdManager avdManager;
// Start the AVD if not running. // Start the AVD if not running.
@@ -298,7 +297,7 @@ bool AndroidDeployQtStep::init()
AndroidDeployQtStep::DeployErrorCode AndroidDeployQtStep::runDeploy() AndroidDeployQtStep::DeployErrorCode AndroidDeployQtStep::runDeploy()
{ {
CommandLine cmd(Utils::FilePath::fromString(m_command), {}); CommandLine cmd(m_command, {});
if (m_useAndroiddeployqt && m_apkPath.isEmpty()) { if (m_useAndroiddeployqt && m_apkPath.isEmpty()) {
cmd.addArgs(m_androiddeployqtArgs.arguments()); cmd.addArgs(m_androiddeployqtArgs.arguments());
if (m_uninstallPreviousPackageRun) if (m_uninstallPreviousPackageRun)
@@ -346,7 +345,7 @@ AndroidDeployQtStep::DeployErrorCode AndroidDeployQtStep::runDeploy()
} }
qCDebug(deployStepLog) << "Uninstalling previous package"; qCDebug(deployStepLog) << "Uninstalling previous package";
emit addOutput(tr("Uninstall previous package %1.").arg(packageName), OutputFormat::NormalMessage); emit addOutput(tr("Uninstall previous package %1.").arg(packageName), OutputFormat::NormalMessage);
runCommand(m_adbPath, runCommand(m_adbPath.toString(),
AndroidDeviceInfo::adbSelector(m_serialNumber) AndroidDeviceInfo::adbSelector(m_serialNumber)
<< QLatin1String("uninstall") << packageName); << QLatin1String("uninstall") << packageName);
} }
@@ -357,7 +356,7 @@ AndroidDeployQtStep::DeployErrorCode AndroidDeployQtStep::runDeploy()
m_process = new Utils::QtcProcess; m_process = new Utils::QtcProcess;
m_process->setCommand(cmd); m_process->setCommand(cmd);
m_process->setWorkingDirectory(m_workingDirectory); m_process->setWorkingDirectory(m_workingDirectory.toString());
m_process->setEnvironment(m_environment); m_process->setEnvironment(m_environment);
if (Utils::HostOsInfo::isWindowsHost()) if (Utils::HostOsInfo::isWindowsHost())
@@ -402,14 +401,15 @@ AndroidDeployQtStep::DeployErrorCode AndroidDeployQtStep::runDeploy()
m_process = nullptr; m_process = nullptr;
if (exitStatus == QProcess::NormalExit && exitCode == 0) { if (exitStatus == QProcess::NormalExit && exitCode == 0) {
emit addOutput(tr("The process \"%1\" exited normally.").arg(m_command), emit addOutput(tr("The process \"%1\" exited normally.").arg(m_command.toUserOutput()),
BuildStep::OutputFormat::NormalMessage); BuildStep::OutputFormat::NormalMessage);
} else if (exitStatus == QProcess::NormalExit) { } else if (exitStatus == QProcess::NormalExit) {
emit addOutput(tr("The process \"%1\" exited with code %2.") emit addOutput(tr("The process \"%1\" exited with code %2.")
.arg(m_command, QString::number(exitCode)), .arg(m_command.toUserOutput(), QString::number(exitCode)),
BuildStep::OutputFormat::ErrorMessage); BuildStep::OutputFormat::ErrorMessage);
} else { } else {
emit addOutput(tr("The process \"%1\" crashed.").arg(m_command), BuildStep::OutputFormat::ErrorMessage); emit addOutput(tr("The process \"%1\" crashed.").arg(m_command.toUserOutput()),
BuildStep::OutputFormat::ErrorMessage);
} }
if (deployError != NoError) { if (deployError != NoError) {
@@ -489,7 +489,7 @@ bool AndroidDeployQtStep::runImpl()
for (auto itr = m_filesToPull.constBegin(); itr != m_filesToPull.constEnd(); ++itr) { for (auto itr = m_filesToPull.constBegin(); itr != m_filesToPull.constEnd(); ++itr) {
QFile::remove(itr.value()); QFile::remove(itr.value());
runCommand(m_adbPath, runCommand(m_adbPath.toString(),
AndroidDeviceInfo::adbSelector(m_serialNumber) AndroidDeviceInfo::adbSelector(m_serialNumber)
<< "pull" << itr.key() << itr.value()); << "pull" << itr.key() << itr.value());
if (!QFileInfo::exists(itr.value())) { if (!QFileInfo::exists(itr.value())) {

View File

@@ -118,9 +118,9 @@ private:
bool m_askForUninstall = false; bool m_askForUninstall = false;
static const Core::Id Id; static const Core::Id Id;
Utils::CommandLine m_androiddeployqtArgs; Utils::CommandLine m_androiddeployqtArgs;
QString m_adbPath; Utils::FilePath m_adbPath;
QString m_command; Utils::FilePath m_command;
QString m_workingDirectory; Utils::FilePath m_workingDirectory;
Utils::Environment m_environment; Utils::Environment m_environment;
Utils::QtcProcess *m_process = nullptr; Utils::QtcProcess *m_process = nullptr;
AndroidDeviceInfo m_deviceInfo; AndroidDeviceInfo m_deviceInfo;