androidqmakebuildconfigurationfactory.cpp 5.63 KB
Newer Older
1
/****************************************************************************
2
**
Eike Ziller's avatar
Eike Ziller committed
3 4
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
5 6 7 8 9 10 11
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
Eike Ziller's avatar
Eike Ziller committed
12 13
** a written agreement between you and The Qt Company.  For licensing terms and
** conditions see http://www.qt.io/terms-conditions.  For further information
Eike Ziller's avatar
Eike Ziller committed
14
** use the contact form at http://www.qt.io/contact-us.
15 16 17
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
Eike Ziller's avatar
Eike Ziller committed
18 19 20 21 22 23
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file.  Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24
**
Eike Ziller's avatar
Eike Ziller committed
25 26
** In addition, as a special exception, The Qt Company gives you certain additional
** rights.  These rights are described in The Qt Company LGPL Exception
27 28 29 30
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/

31 32
#include "androidqmakebuildconfigurationfactory.h"
#include "qmakeandroidbuildapkstep.h"
33 34
#include "androidpackageinstallationstep.h"

35
#include <android/androidmanager.h>
36
#include <android/androidconfigurations.h>
37 38

#include <projectexplorer/buildmanager.h>
39
#include <projectexplorer/buildsteplist.h>
40
#include <projectexplorer/projectexplorer.h>
41 42
#include <projectexplorer/projectexplorerconstants.h>

43 44
#include <qmakeprojectmanager/qmakebuildinfo.h>

45
using namespace QmakeAndroidSupport::Internal;
46

47
int AndroidQmakeBuildConfigurationFactory::priority(const ProjectExplorer::Kit *k, const QString &projectPath) const
48
{
49 50 51 52
    if (QmakeBuildConfigurationFactory::priority(k, projectPath) >= 0
            && Android::AndroidManager::supportsAndroid(k))
        return 1;
    return -1;
53 54
}

55
int AndroidQmakeBuildConfigurationFactory::priority(const ProjectExplorer::Target *parent) const
56
{
57 58 59 60 61
    if (QmakeBuildConfigurationFactory::priority(parent) >= 0
            && Android::AndroidManager::supportsAndroid(parent))
        return 1;
    return -1;
}
62

63 64
ProjectExplorer::BuildConfiguration *AndroidQmakeBuildConfigurationFactory::create(ProjectExplorer::Target *parent,
                                                                                   const ProjectExplorer::BuildInfo *info) const
65
{
66 67 68 69
    auto qmakeInfo = static_cast<const QmakeProjectManager::QmakeBuildInfo *>(info);
    AndroidQmakeBuildConfiguration *bc = new AndroidQmakeBuildConfiguration(parent);
    configureBuildConfiguration(parent, bc, qmakeInfo);

70 71 72 73
    ProjectExplorer::BuildStepList *buildSteps = bc->stepList(Core::Id(ProjectExplorer::Constants::BUILDSTEPS_BUILD));
    buildSteps->insertStep(2, new AndroidPackageInstallationStep(buildSteps));
    buildSteps->insertStep(3, new QmakeAndroidBuildApkStep(buildSteps));
    return bc;
74 75
}

76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
ProjectExplorer::BuildConfiguration *AndroidQmakeBuildConfigurationFactory::clone(ProjectExplorer::Target *parent, ProjectExplorer::BuildConfiguration *source)
{
    if (!canClone(parent, source))
        return 0;
    AndroidQmakeBuildConfiguration *oldbc(static_cast<AndroidQmakeBuildConfiguration *>(source));
    return new AndroidQmakeBuildConfiguration(parent, oldbc);
}

ProjectExplorer::BuildConfiguration *AndroidQmakeBuildConfigurationFactory::restore(ProjectExplorer::Target *parent, const QVariantMap &map)
{
    if (!canRestore(parent, map))
        return 0;
    AndroidQmakeBuildConfiguration *bc = new AndroidQmakeBuildConfiguration(parent);
    if (bc->fromMap(map))
        return bc;
    delete bc;
    return 0;
}


AndroidQmakeBuildConfiguration::AndroidQmakeBuildConfiguration(ProjectExplorer::Target *target)
    : QmakeProjectManager::QmakeBuildConfiguration(target)
{

}

AndroidQmakeBuildConfiguration::AndroidQmakeBuildConfiguration(ProjectExplorer::Target *target, AndroidQmakeBuildConfiguration *source)
    : QmakeProjectManager::QmakeBuildConfiguration(target, source)
{
105

106
}
107

108 109 110 111 112 113 114 115
AndroidQmakeBuildConfiguration::AndroidQmakeBuildConfiguration(ProjectExplorer::Target *target, Core::Id id)
    : QmakeProjectManager::QmakeBuildConfiguration(target, id)
{

}

void AndroidQmakeBuildConfiguration::addToEnvironment(Utils::Environment &env) const
{
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
    m_androidNdkPlatform = Android::AndroidConfigurations::currentConfig().bestNdkPlatformMatch(Android::AndroidManager::minimumSDK(target()));
    env.set(QLatin1String("ANDROID_NDK_PLATFORM"), m_androidNdkPlatform);
}

void AndroidQmakeBuildConfiguration::manifestSaved()
{
    using QmakeProjectManager::QMakeStep;
    QString androidNdkPlatform = Android::AndroidConfigurations::currentConfig().bestNdkPlatformMatch(Android::AndroidManager::minimumSDK(target()));
    if (m_androidNdkPlatform == androidNdkPlatform)
        return;

    emitEnvironmentChanged();

    QMakeStep *qs = qmakeStep();
    if (!qs)
        return;

    qs->setForced(true);

    ProjectExplorer::BuildManager::buildList(stepList(ProjectExplorer::Constants::BUILDSTEPS_CLEAN),
                  ProjectExplorer::ProjectExplorerPlugin::displayNameForStepId(ProjectExplorer::Constants::BUILDSTEPS_CLEAN));
    ProjectExplorer::BuildManager::appendStep(qs, ProjectExplorer::ProjectExplorerPlugin::displayNameForStepId(ProjectExplorer::Constants::BUILDSTEPS_CLEAN));
    setSubNodeBuild(0);
139
}