Commit 4e37f1cd authored by Daniel Teske's avatar Daniel Teske

Android: Speed up project opening by caching the sdk version

The slowness is due to AndroidToolChain::addToEnvironment() being called
a lot on project opening. Thus we need to avoid any file opening or
process on loading.

This patch does 2 things:
a) It removes the call to sdkTargets() which is unneeded. That actually
checks which avds are available.

b) It caches the target sdk inside a named target setting. That means,
we assume that the file does not change behind our backs.

Task-number: QTCREATORBUG-9164

Change-Id: I9287934a0624db0b3e8318b8cf76e605418850c2
Reviewed-by: default avatarAurindam Jana <aurindam.jana@digia.com>
Reviewed-by: default avatarEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
Reviewed-by: default avatarEike Ziller <eike.ziller@digia.com>
parent 1bdf7225
...@@ -236,6 +236,10 @@ bool AndroidManager::ensureIconAttribute(ProjectExplorer::Target *target) ...@@ -236,6 +236,10 @@ bool AndroidManager::ensureIconAttribute(ProjectExplorer::Target *target)
QString AndroidManager::targetSDK(ProjectExplorer::Target *target) QString AndroidManager::targetSDK(ProjectExplorer::Target *target)
{ {
QVariant v = target->namedSettings(QLatin1String("AndroidManager.TargetSdk"));
if (v.isValid())
return v.toString();
QString fallback = QLatin1String("android-8"); QString fallback = QLatin1String("android-8");
if (QtSupport::BaseQtVersion *qt = QtSupport::QtKitInformation::qtVersion(target->kit())) if (QtSupport::BaseQtVersion *qt = QtSupport::QtKitInformation::qtVersion(target->kit()))
if (qt->qtVersion() >= QtSupport::QtVersionNumber(5, 0, 0)) if (qt->qtVersion() >= QtSupport::QtVersionNumber(5, 0, 0))
...@@ -243,6 +247,7 @@ QString AndroidManager::targetSDK(ProjectExplorer::Target *target) ...@@ -243,6 +247,7 @@ QString AndroidManager::targetSDK(ProjectExplorer::Target *target)
if (!createAndroidTemplatesIfNecessary(target)) if (!createAndroidTemplatesIfNecessary(target))
return AndroidConfigurations::instance().bestMatch(fallback); return AndroidConfigurations::instance().bestMatch(fallback);
QFile file(defaultPropertiesPath(target).toString()); QFile file(defaultPropertiesPath(target).toString());
if (!file.open(QIODevice::ReadOnly)) if (!file.open(QIODevice::ReadOnly))
return AndroidConfigurations::instance().bestMatch(fallback); return AndroidConfigurations::instance().bestMatch(fallback);
...@@ -257,6 +262,7 @@ QString AndroidManager::targetSDK(ProjectExplorer::Target *target) ...@@ -257,6 +262,7 @@ QString AndroidManager::targetSDK(ProjectExplorer::Target *target)
bool AndroidManager::setTargetSDK(ProjectExplorer::Target *target, const QString &sdk) bool AndroidManager::setTargetSDK(ProjectExplorer::Target *target, const QString &sdk)
{ {
updateTarget(target, sdk, applicationName(target)); updateTarget(target, sdk, applicationName(target));
target->setNamedSettings(QLatin1String("AndroidManager.TargetSdk"), sdk);
return true; return true;
} }
......
...@@ -118,8 +118,6 @@ void AndroidQtVersion::addToEnvironment(const ProjectExplorer::Kit *k, Utils::En ...@@ -118,8 +118,6 @@ void AndroidQtVersion::addToEnvironment(const ProjectExplorer::Kit *k, Utils::En
if (AndroidConfigurations::instance().config().ndkLocation.isEmpty() if (AndroidConfigurations::instance().config().ndkLocation.isEmpty()
|| AndroidConfigurations::instance().config().sdkLocation.isEmpty()) || AndroidConfigurations::instance().config().sdkLocation.isEmpty())
return; return;
if (AndroidConfigurations::instance().sdkTargets().isEmpty())
return;
env.set(QLatin1String("ANDROID_NDK_PLATFORM"), env.set(QLatin1String("ANDROID_NDK_PLATFORM"),
AndroidConfigurations::instance().bestMatch(AndroidManager::targetSDK(target))); AndroidConfigurations::instance().bestMatch(AndroidManager::targetSDK(target)));
......
...@@ -64,6 +64,7 @@ const char DC_COUNT_KEY[] = "ProjectExplorer.Target.DeployConfigurationCount"; ...@@ -64,6 +64,7 @@ const char DC_COUNT_KEY[] = "ProjectExplorer.Target.DeployConfigurationCount";
const char ACTIVE_RC_KEY[] = "ProjectExplorer.Target.ActiveRunConfiguration"; const char ACTIVE_RC_KEY[] = "ProjectExplorer.Target.ActiveRunConfiguration";
const char RC_KEY_PREFIX[] = "ProjectExplorer.Target.RunConfiguration."; const char RC_KEY_PREFIX[] = "ProjectExplorer.Target.RunConfiguration.";
const char RC_COUNT_KEY[] = "ProjectExplorer.Target.RunConfigurationCount"; const char RC_COUNT_KEY[] = "ProjectExplorer.Target.RunConfigurationCount";
const char PLUGIN_SETTINGS_KEY[] = "ProjectExplorer.Target.PluginSettings";
} // namespace } // namespace
...@@ -93,6 +94,7 @@ public: ...@@ -93,6 +94,7 @@ public:
RunConfiguration* m_activeRunConfiguration; RunConfiguration* m_activeRunConfiguration;
DeploymentData m_deploymentData; DeploymentData m_deploymentData;
BuildTargetInfoList m_appTargets; BuildTargetInfoList m_appTargets;
QVariantMap m_pluginSettings;
QPixmap m_connectedPixmap; QPixmap m_connectedPixmap;
QPixmap m_readyToUsePixmap; QPixmap m_readyToUsePixmap;
...@@ -517,6 +519,8 @@ QVariantMap Target::toMap() const ...@@ -517,6 +519,8 @@ QVariantMap Target::toMap() const
for (int i = 0; i < rcs.size(); ++i) for (int i = 0; i < rcs.size(); ++i)
map.insert(QString::fromLatin1(RC_KEY_PREFIX) + QString::number(i), rcs.at(i)->toMap()); map.insert(QString::fromLatin1(RC_KEY_PREFIX) + QString::number(i), rcs.at(i)->toMap());
map.insert(QLatin1String(PLUGIN_SETTINGS_KEY), d->m_pluginSettings);
return map; return map;
} }
...@@ -663,6 +667,19 @@ void Target::updateDefaultRunConfigurations() ...@@ -663,6 +667,19 @@ void Target::updateDefaultRunConfigurations()
addRunConfiguration(rc); addRunConfiguration(rc);
} }
QVariant Target::namedSettings(const QString &name) const
{
return d->m_pluginSettings.value(name);
}
void Target::setNamedSettings(const QString &name, const QVariant &value)
{
if (value.isNull())
d->m_pluginSettings.remove(name);
else
d->m_pluginSettings.insert(name, value);
}
static QString formatToolTip(const IDevice::DeviceInfo &input) static QString formatToolTip(const IDevice::DeviceInfo &input)
{ {
QStringList lines; QStringList lines;
...@@ -824,6 +841,9 @@ bool Target::fromMap(const QVariantMap &map) ...@@ -824,6 +841,9 @@ bool Target::fromMap(const QVariantMap &map)
setActiveRunConfiguration(rc); setActiveRunConfiguration(rc);
} }
if (map.contains(QLatin1String(PLUGIN_SETTINGS_KEY)))
d->m_pluginSettings = map.value(QLatin1String(PLUGIN_SETTINGS_KEY)).toMap();
return true; return true;
} }
......
...@@ -116,6 +116,8 @@ public: ...@@ -116,6 +116,8 @@ public:
void updateDefaultDeployConfigurations(); void updateDefaultDeployConfigurations();
void updateDefaultRunConfigurations(); void updateDefaultRunConfigurations();
QVariant namedSettings(const QString &name) const;
void setNamedSettings(const QString &name, const QVariant &value);
signals: signals:
void targetEnabled(bool); void targetEnabled(bool);
void iconChanged(); void iconChanged();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment