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)
 | 
			
		||||
            stdError(string);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    setDoneHook([this](bool success) {
 | 
			
		||||
        if (m_openPackageLocationForRun && success)
 | 
			
		||||
            QTimer::singleShot(0, this, &AndroidBuildApkStep::showInGraphicalShell);
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool AndroidBuildApkStep::init()
 | 
			
		||||
@@ -703,31 +698,18 @@ static bool copyFileIfNewer(const FilePath &sourceFilePath,
 | 
			
		||||
 | 
			
		||||
void AndroidBuildApkStep::doRun()
 | 
			
		||||
{
 | 
			
		||||
    if (m_skipBuilding) {
 | 
			
		||||
        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();
 | 
			
		||||
    using namespace Tasking;
 | 
			
		||||
 | 
			
		||||
    const auto setupHelper = [this] {
 | 
			
		||||
        QtSupport::QtVersion *version = QtSupport::QtKitAspect::qtVersion(kit());
 | 
			
		||||
        if (!version) {
 | 
			
		||||
            reportWarningOrError(Tr::tr("The Qt version for kit %1 is invalid.")
 | 
			
		||||
                                 .arg(kit()->displayName()), Task::Error);
 | 
			
		||||
                                     .arg(kit()->displayName()), Task::Error);
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        const auto androidAbis = AndroidManager::applicationAbis(target());
 | 
			
		||||
        const QString buildKey = target()->activeBuildKey();
 | 
			
		||||
        const FilePath buildDir = buildDirectory();
 | 
			
		||||
        const FilePath androidBuildDir = AndroidManager::androidBuildDirectory(target());
 | 
			
		||||
        for (const auto &abi : androidAbis) {
 | 
			
		||||
@@ -751,24 +733,23 @@ void AndroidBuildApkStep::doRun()
 | 
			
		||||
 | 
			
		||||
                    if (!from.copyFile(to)) {
 | 
			
		||||
                        reportWarningOrError(Tr::tr("Cannot copy the target's lib file %1 to the "
 | 
			
		||||
                                                "Android build folder %2.")
 | 
			
		||||
                                             .arg(fileName, androidLibsDir.toUserOutput()),
 | 
			
		||||
                                                    "Android build folder %2.")
 | 
			
		||||
                                                 .arg(fileName, androidLibsDir.toUserOutput()),
 | 
			
		||||
                                             Task::Error);
 | 
			
		||||
                        return false;
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        bool inputExists = m_inputFile.exists();
 | 
			
		||||
        const bool inputExists = m_inputFile.exists();
 | 
			
		||||
        if (inputExists && !AndroidManager::isQtCreatorGenerated(m_inputFile))
 | 
			
		||||
            return true; // use the generated file if it was not generated by qtcreator
 | 
			
		||||
 | 
			
		||||
        BuildSystem *bs = buildSystem();
 | 
			
		||||
        const FilePaths targets = Utils::transform(
 | 
			
		||||
                    bs->extraData(buildKey, Android::Constants::AndroidTargets).toStringList(),
 | 
			
		||||
                    &FilePath::fromUserInput);
 | 
			
		||||
            bs->extraData(buildKey, Android::Constants::AndroidTargets).toStringList(),
 | 
			
		||||
            &FilePath::fromUserInput);
 | 
			
		||||
        if (targets.isEmpty())
 | 
			
		||||
            return inputExists; // qmake does this job for us
 | 
			
		||||
 | 
			
		||||
@@ -781,9 +762,9 @@ void AndroidBuildApkStep::doRun()
 | 
			
		||||
            for (const FilePath &target : targets) {
 | 
			
		||||
                if (!copyFileIfNewer(target, androidLibsDir.pathAppended(target.fileName()))) {
 | 
			
		||||
                    reportWarningOrError(
 | 
			
		||||
                                Tr::tr("Cannot copy file \"%1\" to Android build libs folder \"%2\".")
 | 
			
		||||
                                .arg(target.toUserOutput()).arg(androidLibsDir.toUserOutput()),
 | 
			
		||||
                                Task::Error);
 | 
			
		||||
                        Tr::tr("Cannot copy file \"%1\" to Android build libs folder \"%2\".")
 | 
			
		||||
                            .arg(target.toUserOutput()).arg(androidLibsDir.toUserOutput()),
 | 
			
		||||
                        Task::Error);
 | 
			
		||||
                    return false;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
@@ -819,41 +800,61 @@ void AndroidBuildApkStep::doRun()
 | 
			
		||||
        }
 | 
			
		||||
        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())
 | 
			
		||||
            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())
 | 
			
		||||
            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())
 | 
			
		||||
            deploySettings["qml-import-paths"] = qmlImportPath;
 | 
			
		||||
 | 
			
		||||
        QString qmlRootPath = bs->extraData(buildKey, "QML_ROOT_PATH").toString();
 | 
			
		||||
        if (qmlRootPath.isEmpty())
 | 
			
		||||
            qmlRootPath = target()->project()->rootProjectDirectory().toString();
 | 
			
		||||
         deploySettings["qml-root-path"] = qmlRootPath;
 | 
			
		||||
        deploySettings["qml-root-path"] = qmlRootPath;
 | 
			
		||||
 | 
			
		||||
        QFile f{m_inputFile.toString()};
 | 
			
		||||
        if (!f.open(QIODevice::WriteOnly)) {
 | 
			
		||||
            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;
 | 
			
		||||
        }
 | 
			
		||||
        f.write(QJsonDocument{deploySettings}.toJson());
 | 
			
		||||
        return true;
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    if (!setup()) {
 | 
			
		||||
        reportWarningOrError(Tr::tr("Cannot set up \"%1\", not building an APK.").arg(displayName()),
 | 
			
		||||
                             Task::Error);
 | 
			
		||||
        emit finished(false);
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
    const auto onSetup = [this, setupHelper] {
 | 
			
		||||
        if (m_skipBuilding) {
 | 
			
		||||
            reportWarningOrError(Tr::tr("Android deploy settings file not found, "
 | 
			
		||||
                                        "not building an APK."), Task::Error);
 | 
			
		||||
            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)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user