AndroidBuildApkStep: Employ task tree for running

Task-number: QTCREATORBUG-29168
Change-Id: I40fb62ae33e436ba79cad852bf4661f72fb45bda
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
Jarek Kobus
2023-07-12 11:08:51 +02:00
parent ecd524f12b
commit f507eec207

View File

@@ -484,11 +484,6 @@ AndroidBuildApkStep::AndroidBuildApkStep(BuildStepList *parent, Utils::Id id)
if (format == OutputFormat::Stderr) if (format == OutputFormat::Stderr)
stdError(string); stdError(string);
}); });
setDoneHook([this](bool success) {
if (m_openPackageLocationForRun && success)
QTimer::singleShot(0, this, &AndroidBuildApkStep::showInGraphicalShell);
});
} }
bool AndroidBuildApkStep::init() bool AndroidBuildApkStep::init()
@@ -703,24 +698,9 @@ static bool copyFileIfNewer(const FilePath &sourceFilePath,
void AndroidBuildApkStep::doRun() void AndroidBuildApkStep::doRun()
{ {
if (m_skipBuilding) { using namespace Tasking;
reportWarningOrError(Tr::tr("Android deploy settings file not found, not building an APK."),
Task::Error);
emit finished(true);
return;
}
if (AndroidManager::skipInstallationAndPackageSteps(target())) {
reportWarningOrError(Tr::tr("Product type is not an application, not building an APK."),
Task::Warning);
emit finished(true);
return;
}
auto setup = [this] {
const auto androidAbis = AndroidManager::applicationAbis(target());
const QString buildKey = target()->activeBuildKey();
const auto setupHelper = [this] {
QtSupport::QtVersion *version = QtSupport::QtKitAspect::qtVersion(kit()); QtSupport::QtVersion *version = QtSupport::QtKitAspect::qtVersion(kit());
if (!version) { if (!version) {
reportWarningOrError(Tr::tr("The Qt version for kit %1 is invalid.") reportWarningOrError(Tr::tr("The Qt version for kit %1 is invalid.")
@@ -728,6 +708,8 @@ void AndroidBuildApkStep::doRun()
return false; return false;
} }
const auto androidAbis = AndroidManager::applicationAbis(target());
const QString buildKey = target()->activeBuildKey();
const FilePath buildDir = buildDirectory(); const FilePath buildDir = buildDirectory();
const FilePath androidBuildDir = AndroidManager::androidBuildDirectory(target()); const FilePath androidBuildDir = AndroidManager::androidBuildDirectory(target());
for (const auto &abi : androidAbis) { for (const auto &abi : androidAbis) {
@@ -758,10 +740,9 @@ void AndroidBuildApkStep::doRun()
} }
} }
} }
} }
bool inputExists = m_inputFile.exists(); const bool inputExists = m_inputFile.exists();
if (inputExists && !AndroidManager::isQtCreatorGenerated(m_inputFile)) if (inputExists && !AndroidManager::isQtCreatorGenerated(m_inputFile))
return true; // use the generated file if it was not generated by qtcreator return true; // use the generated file if it was not generated by qtcreator
@@ -819,15 +800,15 @@ void AndroidBuildApkStep::doRun()
} }
deploySettings["application-binary"] = applicationBinary; deploySettings["application-binary"] = applicationBinary;
QString extraLibs = bs->extraData(buildKey, Android::Constants::AndroidExtraLibs).toString(); const QString extraLibs = bs->extraData(buildKey, Android::Constants::AndroidExtraLibs).toString();
if (!extraLibs.isEmpty()) if (!extraLibs.isEmpty())
deploySettings["android-extra-libs"] = extraLibs; deploySettings["android-extra-libs"] = extraLibs;
QString androidSrcs = bs->extraData(buildKey, Android::Constants::AndroidPackageSourceDir).toString(); const QString androidSrcs = bs->extraData(buildKey, Android::Constants::AndroidPackageSourceDir).toString();
if (!androidSrcs.isEmpty()) if (!androidSrcs.isEmpty())
deploySettings["android-package-source-directory"] = androidSrcs; deploySettings["android-package-source-directory"] = androidSrcs;
QString qmlImportPath = bs->extraData(buildKey, "QML_IMPORT_PATH").toString(); const QString qmlImportPath = bs->extraData(buildKey, "QML_IMPORT_PATH").toString();
if (!qmlImportPath.isEmpty()) if (!qmlImportPath.isEmpty())
deploySettings["qml-import-paths"] = qmlImportPath; deploySettings["qml-import-paths"] = qmlImportPath;
@@ -846,14 +827,34 @@ void AndroidBuildApkStep::doRun()
return true; return true;
}; };
if (!setup()) { const auto onSetup = [this, setupHelper] {
reportWarningOrError(Tr::tr("Cannot set up \"%1\", not building an APK.").arg(displayName()), if (m_skipBuilding) {
Task::Error); reportWarningOrError(Tr::tr("Android deploy settings file not found, "
emit finished(false); "not building an APK."), Task::Error);
return; return SetupResult::StopWithDone;
} }
if (AndroidManager::skipInstallationAndPackageSteps(target())) {
reportWarningOrError(Tr::tr("Product type is not an application, not building an APK."),
Task::Warning);
return SetupResult::StopWithDone;
}
if (setupHelper())
return SetupResult::Continue;
reportWarningOrError(Tr::tr("Cannot set up \"%1\", not building an APK.")
.arg(displayName()), Task::Error);
return SetupResult::StopWithError;
};
const auto onDone = [this] {
if (m_openPackageLocationForRun)
QTimer::singleShot(0, this, &AndroidBuildApkStep::showInGraphicalShell);
};
AbstractProcessStep::doRun(); const Group root {
onGroupSetup(onSetup),
onGroupDone(onDone),
defaultProcessTask()
};
runTaskTree(root);
} }
void AndroidBuildApkStep::reportWarningOrError(const QString &message, Task::TaskType type) void AndroidBuildApkStep::reportWarningOrError(const QString &message, Task::TaskType type)