Bug 1344244 - Part 2: Merge similar code into android.py. r=glandium

This refactoring unifies similar code that has been copy-pasted and
subsequently diverged.

MozReview-Commit-ID: EuVQBR4gsDo

--HG--
extra : rebase_source : bda66ef9001a1cddf75417aaeebd9dcecd05a6b7
This commit is contained in:
Nick Alexander 2017-07-05 14:02:58 -07:00
Родитель 6d62fe4972
Коммит 6dfa75bd3c
5 изменённых файлов: 85 добавлений и 140 удалений

Просмотреть файл

@ -194,6 +194,45 @@ def install_mobile_android_sdk_or_ndk(url, path):
os.chdir(old_path)
def get_paths(os_name):
mozbuild_path = os.environ.get('MOZBUILD_STATE_PATH',
os.path.expanduser(os.path.join('~', '.mozbuild')))
sdk_path = os.environ.get('ANDROID_SDK_HOME',
os.path.join(mozbuild_path, 'android-sdk-{}'.format(os_name)))
ndk_path = os.environ.get('ANDROID_NDK_HOME',
os.path.join(mozbuild_path, 'android-ndk-r11c'))
return (mozbuild_path, sdk_path, ndk_path)
def ensure_android(os_name, artifact_mode):
'''
Ensure the Android SDK (and NDK, if `artifact_mode` is falsy) are
installed. If not, fetch and unpack the SDK and/or NDK from the
given URLs. Ensure the required Android SDK packages are
installed.
`os_name` can be 'linux' or 'macosx'.
'''
# The user may have an external Android SDK (in which case we
# save them a lengthy download), or they may have already
# completed the download. We unpack to
# ~/.mozbuild/{android-sdk-$OS_NAME, android-ndk-r11c}.
mozbuild_path, sdk_path, ndk_path = get_paths(os_name)
ext = 'zip' if os_name == 'macosx' else 'tgz'
sdk_url = 'https://dl.google.com/android/android-sdk_r24.0.1-{}.{}'.format(os_name, ext)
ndk_url = android_ndk_url(os_name)
ensure_android_sdk_and_ndk(path=mozbuild_path,
sdk_path=sdk_path, sdk_url=sdk_url,
ndk_path=ndk_path, ndk_url=ndk_url,
artifact_mode=artifact_mode)
# We expect the |android| tool to be at
# ~/.mozbuild/android-sdk-$OS_NAME/tools/android.
android_tool = os.path.join(sdk_path, 'tools', 'android')
ensure_android_packages(android_tool=android_tool)
def ensure_android_sdk_and_ndk(path, sdk_path, sdk_url, ndk_path, ndk_url, artifact_mode):
'''
Ensure the Android SDK and NDK are found at the given paths. If not, fetch
@ -251,7 +290,8 @@ def ensure_android_packages(android_tool, packages=None):
raise Exception(MISSING_ANDROID_PACKAGES % (', '.join(missing), ', '.join(failing)))
def suggest_mozconfig(sdk_path=None, ndk_path=None, artifact_mode=False):
def suggest_mozconfig(os_name, artifact_mode=False):
_mozbuild_path, sdk_path, ndk_path = get_paths(os_name)
if artifact_mode:
print(MOBILE_ANDROID_ARTIFACT_MODE_MOZCONFIG_TEMPLATE % (sdk_path))
else:
@ -259,9 +299,14 @@ def suggest_mozconfig(sdk_path=None, ndk_path=None, artifact_mode=False):
def android_ndk_url(os_name, ver='r11c'):
# Produce a URL like 'https://dl.google.com/android/repository/android-ndk-r11c-linux-x86_64.zip
# Produce a URL like
# 'https://dl.google.com/android/repository/android-ndk-r11c-linux-x86_64.zip
base_url = 'https://dl.google.com/android/repository/android-ndk'
if os_name == 'macosx':
# |mach bootstrap| uses 'macosx', but Google uses 'darwin'.
os_name = 'darwin'
if sys.maxsize > 2**32:
arch = 'x86_64'
else:

Просмотреть файл

@ -66,10 +66,13 @@ class ArchlinuxBootstrapper(StyloInstall, BaseBootstrapper):
]
MOBILE_ANDROID_COMMON_PACKAGES = [
'zlib', # mobile/android requires system zlib.
'jdk7-openjdk', # It would be nice to handle alternative JDKs. See https://wiki.archlinux.org/index.php/Java.
'wget', # For downloading the Android SDK and NDK.
'multilib/lib32-libstdc++5', # See comment about 32 bit binaries and multilib below.
# It would be nice to handle alternative JDKs. See
# https://wiki.archlinux.org/index.php/Java.
'jdk7-openjdk',
# For downloading the Android SDK and NDK.
'wget',
# See comment about 32 bit binaries and multilib below.
'multilib/lib32-libstdc++5',
'multilib/lib32-ncurses',
'multilib/lib32-readline',
'multilib/lib32-zlib',
@ -100,12 +103,9 @@ class ArchlinuxBootstrapper(StyloInstall, BaseBootstrapper):
self.pacman_install(*self.BROWSER_PACKAGES)
def ensure_mobile_android_packages(self, artifact_mode=False):
import android
# Multi-part process:
# 1. System packages.
# 2. Android SDK. Android NDK only if we are not in artifact mode.
# 3. Android packages.
# 2. Android SDK. Android NDK only if we are not in artifact mode. Android packages.
# 1. This is hard to believe, but the Android SDK binaries are 32-bit
# and that conflicts with 64-bit Arch installations out of the box. The
@ -113,7 +113,7 @@ class ArchlinuxBootstrapper(StyloInstall, BaseBootstrapper):
# requires manual intervention.
try:
self.pacman_install(*self.MOBILE_ANDROID_COMMON_PACKAGES)
except e:
except Exception as e:
print('Failed to install all packages. The Android developer '
'toolchain requires 32 bit binaries be enabled (see '
'https://wiki.archlinux.org/index.php/Android). You may need to '
@ -121,27 +121,13 @@ class ArchlinuxBootstrapper(StyloInstall, BaseBootstrapper):
'at https://wiki.archlinux.org/index.php/Multilib.')
raise e
# 2. The user may have an external Android SDK (in which case we save
# them a lengthy download), or they may have already completed the
# download. We unpack to ~/.mozbuild/{android-sdk-linux, android-ndk-r11c}.
mozbuild_path = os.environ.get('MOZBUILD_STATE_PATH', os.path.expanduser(os.path.join('~', '.mozbuild')))
self.sdk_path = os.environ.get('ANDROID_SDK_HOME', os.path.join(mozbuild_path, 'android-sdk-linux'))
self.ndk_path = os.environ.get('ANDROID_NDK_HOME', os.path.join(mozbuild_path, 'android-ndk-r11c'))
self.sdk_url = 'https://dl.google.com/android/android-sdk_r24.0.1-linux.tgz'
self.ndk_url = android.android_ndk_url('linux')
android.ensure_android_sdk_and_ndk(path=mozbuild_path,
sdk_path=self.sdk_path, sdk_url=self.sdk_url,
ndk_path=self.ndk_path, ndk_url=self.ndk_url,
artifact_mode=artifact_mode)
android_tool = os.path.join(self.sdk_path, 'tools', 'android')
android.ensure_android_packages(android_tool=android_tool)
# 2. Android pieces.
import android
android.ensure_android('linux', artifact_mode=artifact_mode)
def suggest_mobile_android_mozconfig(self, artifact_mode=False):
import android
android.suggest_mozconfig(sdk_path=self.sdk_path,
ndk_path=self.ndk_path,
artifact_mode=artifact_mode)
android.suggest_mozconfig('linux', artifact_mode=artifact_mode)
def suggest_mobile_android_artifact_mode_mozconfig(self):
self.suggest_mobile_android_mozconfig(artifact_mode=True)

Просмотреть файл

@ -2,7 +2,6 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
import os
import platform
from mozboot.base import BaseBootstrapper
@ -109,37 +108,15 @@ class CentOSFedoraBootstrapper(StyloInstall, BaseBootstrapper):
self.run_as_root(['rpm', '-ivh', yasm])
def ensure_mobile_android_packages(self, artifact_mode=False):
import android
# Install Android specific packages.
self.dnf_install(*self.mobile_android_packages)
# Fetch Android SDK and NDK.
mozbuild_path = os.environ.get('MOZBUILD_STATE_PATH', os.path.expanduser(os.path.join('~', '.mozbuild')))
self.sdk_path = os.environ.get('ANDROID_SDK_HOME', os.path.join(mozbuild_path, 'android-sdk-linux'))
self.ndk_path = os.environ.get('ANDROID_NDK_HOME', os.path.join(mozbuild_path, 'android-ndk-r11c'))
self.sdk_url = 'https://dl.google.com/android/android-sdk_r24.0.1-linux.tgz'
self.ndk_url = android.android_ndk_url('linux')
android.ensure_android_sdk_and_ndk(path=mozbuild_path,
sdk_path=self.sdk_path, sdk_url=self.sdk_url,
ndk_path=self.ndk_path, ndk_url=self.ndk_url,
artifact_mode=artifact_mode)
# Most recent version of build-tools appears to be 23.0.1 on Fedora
packages = [p for p in android.ANDROID_PACKAGES if not p.startswith('build-tools')]
packages.append('build-tools-23.0.1')
# 3. We expect the |android| tool to be at
# ~/.mozbuild/android-sdk-linux/tools/android.
android_tool = os.path.join(self.sdk_path, 'tools', 'android')
android.ensure_android_packages(android_tool=android_tool, packages=packages)
import android
android.ensure_android('linux', artifact_mode=artifact_mode)
def suggest_mobile_android_mozconfig(self, artifact_mode=False):
import android
android.suggest_mozconfig(sdk_path=self.sdk_path,
ndk_path=self.ndk_path,
artifact_mode=artifact_mode)
android.suggest_mozconfig('linux', artifact_mode=artifact_mode)
def suggest_mobile_android_artifact_mode_mozconfig(self):
self.suggest_mobile_android_mozconfig(artifact_mode=True)

Просмотреть файл

@ -2,9 +2,6 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import os
import sys
from mozboot.base import BaseBootstrapper
from mozboot.linux_common import StyloInstall
@ -74,12 +71,10 @@ class DebianBootstrapper(StyloInstall, BaseBootstrapper):
# These are common packages for building Firefox for Android
# (mobile/android) for all Debian-derived distros (such as Ubuntu).
MOBILE_ANDROID_COMMON_PACKAGES = [
'zlib1g-dev', # mobile/android requires system zlib.
'default-jdk',
'wget', # For downloading the Android SDK and NDK.
'libncurses5:i386', # See comments about i386 below.
'libstdc++6:i386',
'zlib1g:i386',
]
# Subclasses can add packages to this variable to have them installed.
@ -93,8 +88,8 @@ class DebianBootstrapper(StyloInstall, BaseBootstrapper):
self.packages = self.COMMON_PACKAGES + self.DISTRO_PACKAGES
self.browser_packages = self.BROWSER_COMMON_PACKAGES + self.BROWSER_DISTRO_PACKAGES
self.mobile_android_packages = self.MOBILE_ANDROID_COMMON_PACKAGES + self.MOBILE_ANDROID_DISTRO_PACKAGES
self.mobile_android_packages = self.MOBILE_ANDROID_COMMON_PACKAGES + \
self.MOBILE_ANDROID_DISTRO_PACKAGES
def install_system_packages(self):
self.apt_install(*self.packages)
@ -116,12 +111,9 @@ class DebianBootstrapper(StyloInstall, BaseBootstrapper):
self.apt_install(*self.browser_packages)
def ensure_mobile_android_packages(self, artifact_mode=False):
import android
# Multi-part process:
# 1. System packages.
# 2. Android SDK. Android NDK only if we are not in artifact mode.
# 3. Android packages.
# 2. Android SDK. Android NDK only if we are not in artifact mode. Android packages.
# 1. This is hard to believe, but the Android SDK binaries are 32-bit
# and that conflicts with 64-bit Debian and Ubuntu installations out of
@ -133,30 +125,13 @@ class DebianBootstrapper(StyloInstall, BaseBootstrapper):
self.apt_update()
self.apt_install(*self.mobile_android_packages)
# 2. The user may have an external Android SDK (in which case we save
# them a lengthy download), or they may have already completed the
# download. We unpack to ~/.mozbuild/{android-sdk-linux, android-ndk-r11c}.
mozbuild_path = os.environ.get('MOZBUILD_STATE_PATH', os.path.expanduser(os.path.join('~', '.mozbuild')))
self.sdk_path = os.environ.get('ANDROID_SDK_HOME', os.path.join(mozbuild_path, 'android-sdk-linux'))
self.ndk_path = os.environ.get('ANDROID_NDK_HOME', os.path.join(mozbuild_path, 'android-ndk-r11c'))
self.sdk_url = 'https://dl.google.com/android/android-sdk_r24.0.1-linux.tgz'
self.ndk_url = android.android_ndk_url('linux')
android.ensure_android_sdk_and_ndk(path=mozbuild_path,
sdk_path=self.sdk_path, sdk_url=self.sdk_url,
ndk_path=self.ndk_path, ndk_url=self.ndk_url,
artifact_mode=artifact_mode)
# 3. We expect the |android| tool to at
# ~/.mozbuild/android-sdk-linux/tools/android.
android_tool = os.path.join(self.sdk_path, 'tools', 'android')
android.ensure_android_packages(android_tool=android_tool)
# 2. Android pieces.
import android
android.ensure_android('linux', artifact_mode=artifact_mode)
def suggest_mobile_android_mozconfig(self, artifact_mode=False):
import android
android.suggest_mozconfig(sdk_path=self.sdk_path,
ndk_path=self.ndk_path,
artifact_mode=artifact_mode)
android.suggest_mozconfig('linux', artifact_mode=artifact_mode)
def suggest_mobile_android_artifact_mode_mozconfig(self):
self.suggest_mobile_android_mozconfig(artifact_mode=True)

Просмотреть файл

@ -333,10 +333,7 @@ class OSXBootstrapper(BaseBootstrapper):
def ensure_homebrew_mobile_android_packages(self, artifact_mode=False):
# Multi-part process:
# 1. System packages.
# 2. Android SDK. Android NDK only if we are not in artifact mode.
# 3. Android packages.
import android
# 2. Android SDK. Android NDK only if we are not in artifact mode. Android packages.
# 1. System packages.
packages = [
@ -352,34 +349,17 @@ class OSXBootstrapper(BaseBootstrapper):
if installed:
print(JAVA_LICENSE_NOTICE) # We accepted a license agreement for the user.
# 2. The user may have an external Android SDK (in which case we save
# them a lengthy download), or they may have already completed the
# download. We unpack to ~/.mozbuild/{android-sdk-linux, android-ndk-r11c}.
mozbuild_path = os.environ.get('MOZBUILD_STATE_PATH', os.path.expanduser(os.path.join('~', '.mozbuild')))
self.sdk_path = os.environ.get('ANDROID_SDK_HOME', os.path.join(mozbuild_path, 'android-sdk-macosx'))
self.ndk_path = os.environ.get('ANDROID_NDK_HOME', os.path.join(mozbuild_path, 'android-ndk-r11c'))
self.sdk_url = 'https://dl.google.com/android/android-sdk_r24.0.1-macosx.zip'
is_64bits = sys.maxsize > 2**32
if is_64bits:
self.ndk_url = android.android_ndk_url('darwin')
else:
if not is_64bits:
raise Exception('You need a 64-bit version of Mac OS X to build Firefox for Android.')
android.ensure_android_sdk_and_ndk(path=mozbuild_path,
sdk_path=self.sdk_path, sdk_url=self.sdk_url,
ndk_path=self.ndk_path, ndk_url=self.ndk_url,
artifact_mode=artifact_mode)
# 3. We expect the |android| tool to at
# ~/.mozbuild/android-sdk-macosx/tools/android.
android_tool = os.path.join(self.sdk_path, 'tools', 'android')
android.ensure_android_packages(android_tool=android_tool)
# 2. Android pieces.
import android
android.ensure_android('macosx', artifact_mode=artifact_mode)
def suggest_homebrew_mobile_android_mozconfig(self, artifact_mode=False):
import android
android.suggest_mozconfig(sdk_path=self.sdk_path,
ndk_path=self.ndk_path,
artifact_mode=artifact_mode)
android.suggest_mozconfig('macosx', artifact_mode=artifact_mode)
def _ensure_macports_packages(self, packages):
self.port = self.which('port')
@ -418,10 +398,7 @@ class OSXBootstrapper(BaseBootstrapper):
def ensure_macports_mobile_android_packages(self, artifact_mode=False):
# Multi-part process:
# 1. System packages.
# 2. Android SDK. Android NDK only if we are not in artifact mode.
# 3. Android packages.
import android
# 2. Android SDK. Android NDK only if we are not in artifact mode. Android packages.
# 1. System packages.
packages = [
@ -431,36 +408,21 @@ class OSXBootstrapper(BaseBootstrapper):
# Verify the presence of java and javac.
if not self.which('java') or not self.which('javac'):
raise Exception('You need to have Java version 1.7 or later installed. Please visit http://www.java.com/en/download/mac_download.jsp to get the latest version.')
raise Exception('You need to have Java version 1.7 or later installed. '
'Please visit http://www.java.com/en/download/mac_download.jsp '
'to get the latest version.')
# 2. The user may have an external Android SDK (in which case we save
# them a lengthy download), or they may have already completed the
# download. We unpack to ~/.mozbuild/{android-sdk-linux, android-ndk-r11b}.
mozbuild_path = os.environ.get('MOZBUILD_STATE_PATH', os.path.expanduser(os.path.join('~', '.mozbuild')))
self.sdk_path = os.environ.get('ANDROID_SDK_HOME', os.path.join(mozbuild_path, 'android-sdk-macosx'))
self.ndk_path = os.environ.get('ANDROID_NDK_HOME', os.path.join(mozbuild_path, 'android-ndk-r11b'))
self.sdk_url = 'https://dl.google.com/android/android-sdk_r24.0.1-macosx.zip'
is_64bits = sys.maxsize > 2**32
if is_64bits:
self.ndk_url = android.android_ndk_url('darwin')
else:
if not is_64bits:
raise Exception('You need a 64-bit version of Mac OS X to build Firefox for Android.')
android.ensure_android_sdk_and_ndk(path=mozbuild_path,
sdk_path=self.sdk_path, sdk_url=self.sdk_url,
ndk_path=self.ndk_path, ndk_url=self.ndk_url,
artifact_mode=artifact_mode)
# 3. We expect the |android| tool to at
# ~/.mozbuild/android-sdk-macosx/tools/android.
android_tool = os.path.join(self.sdk_path, 'tools', 'android')
android.ensure_android_packages(android_tool=android_tool)
# 2. Android pieces.
import android
android.ensure_android('macosx', artifact_mode=artifact_mode)
def suggest_macports_mobile_android_mozconfig(self, artifact_mode=False):
import android
android.suggest_mozconfig(sdk_path=self.sdk_path,
ndk_path=self.ndk_path,
artifact_mode=artifact_mode)
android.suggest_mozconfig('macosx', artifact_mode=artifact_mode)
def ensure_package_manager(self):
'''