Bug 1384202 - Add --no-interactive bootstrap support for Android SDK and NDK. r=rillian

Hacky, but it works -- until Google updates its license hashes.  This
looks ahead to using |mach bootstrap| to build docker images.

MozReview-Commit-ID: DF23v8tr8SW

--HG--
extra : rebase_source : 5a80bdd5ddfb551b374464f42c3783fef5a71fc3
This commit is contained in:
Nick Alexander 2017-07-19 15:29:11 -07:00
Родитель 23992bf0ff
Коммит c519abed2e
6 изменённых файлов: 43 добавлений и 9 удалений

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

@ -141,7 +141,17 @@ def get_paths(os_name):
return (mozbuild_path, sdk_path, ndk_path) return (mozbuild_path, sdk_path, ndk_path)
def ensure_android(os_name, artifact_mode): def ensure_dir(dir):
'''Ensures the given directory exists'''
if dir and not os.path.exists(dir):
try:
os.makedirs(dir)
except OSError as error:
if error.errno != errno.EEXIST:
raise
def ensure_android(os_name, artifact_mode=False, no_interactive=False):
''' '''
Ensure the Android SDK (and NDK, if `artifact_mode` is falsy) are 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 installed. If not, fetch and unpack the SDK and/or NDK from the
@ -164,6 +174,21 @@ def ensure_android(os_name, artifact_mode):
ndk_path=ndk_path, ndk_url=ndk_url, ndk_path=ndk_path, ndk_url=ndk_url,
artifact_mode=artifact_mode) artifact_mode=artifact_mode)
if no_interactive:
# Cribbed from observation and https://stackoverflow.com/a/38381577.
path = os.path.join(mozbuild_path, 'android-sdk-{}'.format(os_name), 'licenses')
ensure_dir(path)
licenses = {
'android-sdk-license': '8933bad161af4178b1185d1a37fbf41ea5269c55',
'android-sdk-preview-license': '84831b9409646a918e30573bab4c9c91346d8abd',
}
for license, tag in licenses.items():
lname = os.path.join(path, license)
if not os.path.isfile(lname):
open(lname, 'w').write('\n{}\n'.format(tag))
# We expect the |sdkmanager| tool to be at # We expect the |sdkmanager| tool to be at
# ~/.mozbuild/android-sdk-$OS_NAME/tools/bin/sdkmanager. # ~/.mozbuild/android-sdk-$OS_NAME/tools/bin/sdkmanager.
sdkmanager_tool = os.path.join(sdk_path, 'tools', 'bin', 'sdkmanager') sdkmanager_tool = os.path.join(sdk_path, 'tools', 'bin', 'sdkmanager')
@ -249,6 +274,8 @@ def main(argv):
parser = optparse.OptionParser() parser = optparse.OptionParser()
parser.add_option('-a', '--artifact-mode', dest='artifact_mode', action='store_true', parser.add_option('-a', '--artifact-mode', dest='artifact_mode', action='store_true',
help='If true, install only the Android SDK (and not the Android NDK).') help='If true, install only the Android SDK (and not the Android NDK).')
parser.add_option('--no-interactive', dest='no_interactive', action='store_true',
help='Accept the Android SDK licenses without user interaction.')
options, _ = parser.parse_args(argv) options, _ = parser.parse_args(argv)
@ -263,7 +290,7 @@ def main(argv):
raise NotImplementedError("We don't support bootstrapping the Android SDK (or Android NDK) " raise NotImplementedError("We don't support bootstrapping the Android SDK (or Android NDK) "
"on {} yet!".format(platform.system())) "on {} yet!".format(platform.system()))
ensure_android(os_name, options.artifact_mode) ensure_android(os_name, artifact_mode=options.artifact_mode, no_interactive=options.no_interactive)
suggest_mozconfig(os_name, options.artifact_mode) suggest_mozconfig(os_name, options.artifact_mode)
return 0 return 0

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

@ -123,7 +123,8 @@ class ArchlinuxBootstrapper(StyloInstall, BaseBootstrapper):
# 2. Android pieces. # 2. Android pieces.
import android import android
android.ensure_android('linux', artifact_mode=artifact_mode) android.ensure_android('linux', artifact_mode=artifact_mode,
no_interactive=self.no_interactive)
def suggest_mobile_android_mozconfig(self, artifact_mode=False): def suggest_mobile_android_mozconfig(self, artifact_mode=False):
import android import android

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

@ -112,7 +112,8 @@ class CentOSFedoraBootstrapper(StyloInstall, BaseBootstrapper):
self.dnf_install(*self.mobile_android_packages) self.dnf_install(*self.mobile_android_packages)
import android import android
android.ensure_android('linux', artifact_mode=artifact_mode) android.ensure_android('linux', artifact_mode=artifact_mode,
no_interactive=self.no_interactive)
def suggest_mobile_android_mozconfig(self, artifact_mode=False): def suggest_mobile_android_mozconfig(self, artifact_mode=False):
import android import android

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

@ -127,7 +127,8 @@ class DebianBootstrapper(StyloInstall, BaseBootstrapper):
# 2. Android pieces. # 2. Android pieces.
import android import android
android.ensure_android('linux', artifact_mode=artifact_mode) android.ensure_android('linux', artifact_mode=artifact_mode,
no_interactive=self.no_interactive)
def suggest_mobile_android_mozconfig(self, artifact_mode=False): def suggest_mobile_android_mozconfig(self, artifact_mode=False):
import android import android

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

@ -23,10 +23,12 @@ class Bootstrap(object):
default=None, default=None,
help='Pass in an application choice (see mozboot.bootstrap.APPLICATIONS) ' help='Pass in an application choice (see mozboot.bootstrap.APPLICATIONS) '
'instead of using the default interactive prompt.') 'instead of using the default interactive prompt.')
def bootstrap(self, application_choice=None): @CommandArgument('--no-interactive', dest='no_interactive', action='store_true',
help='Answer yes to any (Y/n) interactive prompts.')
def bootstrap(self, application_choice=None, no_interactive=False):
from mozboot.bootstrap import Bootstrapper from mozboot.bootstrap import Bootstrapper
bootstrapper = Bootstrapper(choice=application_choice) bootstrapper = Bootstrapper(choice=application_choice, no_interactive=no_interactive)
bootstrapper.bootstrap() bootstrapper.bootstrap()

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

@ -354,7 +354,8 @@ class OSXBootstrapper(BaseBootstrapper):
# 2. Android pieces. # 2. Android pieces.
import android import android
android.ensure_android('macosx', artifact_mode=artifact_mode) android.ensure_android('macosx', artifact_mode=artifact_mode,
no_interactive=self.no_interactive)
def suggest_homebrew_mobile_android_mozconfig(self, artifact_mode=False): def suggest_homebrew_mobile_android_mozconfig(self, artifact_mode=False):
import android import android
@ -417,7 +418,8 @@ class OSXBootstrapper(BaseBootstrapper):
# 2. Android pieces. # 2. Android pieces.
import android import android
android.ensure_android('macosx', artifact_mode=artifact_mode) android.ensure_android('macosx', artifact_mode=artifact_mode,
no_interactive=self.no_interactive)
def suggest_macports_mobile_android_mozconfig(self, artifact_mode=False): def suggest_macports_mobile_android_mozconfig(self, artifact_mode=False):
import android import android