forked from qt-creator/qt-creator
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:
@@ -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,31 +698,18 @@ 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.")
|
||||||
.arg(kit()->displayName()), Task::Error);
|
.arg(kit()->displayName()), Task::Error);
|
||||||
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) {
|
||||||
@@ -751,24 +733,23 @@ void AndroidBuildApkStep::doRun()
|
|||||||
|
|
||||||
if (!from.copyFile(to)) {
|
if (!from.copyFile(to)) {
|
||||||
reportWarningOrError(Tr::tr("Cannot copy the target's lib file %1 to the "
|
reportWarningOrError(Tr::tr("Cannot copy the target's lib file %1 to the "
|
||||||
"Android build folder %2.")
|
"Android build folder %2.")
|
||||||
.arg(fileName, androidLibsDir.toUserOutput()),
|
.arg(fileName, androidLibsDir.toUserOutput()),
|
||||||
Task::Error);
|
Task::Error);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
BuildSystem *bs = buildSystem();
|
BuildSystem *bs = buildSystem();
|
||||||
const FilePaths targets = Utils::transform(
|
const FilePaths targets = Utils::transform(
|
||||||
bs->extraData(buildKey, Android::Constants::AndroidTargets).toStringList(),
|
bs->extraData(buildKey, Android::Constants::AndroidTargets).toStringList(),
|
||||||
&FilePath::fromUserInput);
|
&FilePath::fromUserInput);
|
||||||
if (targets.isEmpty())
|
if (targets.isEmpty())
|
||||||
return inputExists; // qmake does this job for us
|
return inputExists; // qmake does this job for us
|
||||||
|
|
||||||
@@ -781,9 +762,9 @@ void AndroidBuildApkStep::doRun()
|
|||||||
for (const FilePath &target : targets) {
|
for (const FilePath &target : targets) {
|
||||||
if (!copyFileIfNewer(target, androidLibsDir.pathAppended(target.fileName()))) {
|
if (!copyFileIfNewer(target, androidLibsDir.pathAppended(target.fileName()))) {
|
||||||
reportWarningOrError(
|
reportWarningOrError(
|
||||||
Tr::tr("Cannot copy file \"%1\" to Android build libs folder \"%2\".")
|
Tr::tr("Cannot copy file \"%1\" to Android build libs folder \"%2\".")
|
||||||
.arg(target.toUserOutput()).arg(androidLibsDir.toUserOutput()),
|
.arg(target.toUserOutput()).arg(androidLibsDir.toUserOutput()),
|
||||||
Task::Error);
|
Task::Error);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -819,41 +800,61 @@ 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;
|
||||||
|
|
||||||
QString qmlRootPath = bs->extraData(buildKey, "QML_ROOT_PATH").toString();
|
QString qmlRootPath = bs->extraData(buildKey, "QML_ROOT_PATH").toString();
|
||||||
if (qmlRootPath.isEmpty())
|
if (qmlRootPath.isEmpty())
|
||||||
qmlRootPath = target()->project()->rootProjectDirectory().toString();
|
qmlRootPath = target()->project()->rootProjectDirectory().toString();
|
||||||
deploySettings["qml-root-path"] = qmlRootPath;
|
deploySettings["qml-root-path"] = qmlRootPath;
|
||||||
|
|
||||||
QFile f{m_inputFile.toString()};
|
QFile f{m_inputFile.toString()};
|
||||||
if (!f.open(QIODevice::WriteOnly)) {
|
if (!f.open(QIODevice::WriteOnly)) {
|
||||||
reportWarningOrError(Tr::tr("Cannot open androiddeployqt input file \"%1\" for writing.")
|
reportWarningOrError(Tr::tr("Cannot open androiddeployqt input file \"%1\" for writing.")
|
||||||
.arg(m_inputFile.toUserOutput()), Task::Error);
|
.arg(m_inputFile.toUserOutput()), Task::Error);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
f.write(QJsonDocument{deploySettings}.toJson());
|
f.write(QJsonDocument{deploySettings}.toJson());
|
||||||
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)
|
||||||
|
Reference in New Issue
Block a user