Chromium Code Reviews| Index: build/android/install_emulator_deps.py |
| diff --git a/build/android/install_emulator_deps.py b/build/android/install_emulator_deps.py |
| index 08f0f368a4087fc63d3cec9e60a2aba7fe160356..30c76a103ed89f249cd945fbdecaecb7208046c1 100755 |
| --- a/build/android/install_emulator_deps.py |
| +++ b/build/android/install_emulator_deps.py |
| @@ -11,25 +11,34 @@ install and enable KVM, if virtualization has been enabled in the BIOS. |
| import logging |
| +import optparse |
| import os |
| +import re |
| import shutil |
| import sys |
| from pylib import cmd_helper |
| from pylib import constants |
| +from pylib import pexpect |
| from pylib.utils import run_tests_helper |
| +# Android API level |
| +DEFAULT_ANDROID_API_LEVEL = constants.ANDROID_SDK_VERSION |
| + |
| # From the Android Developer's website. |
| +# Keep this up to date; the user can install older API levels as necessary. |
| SDK_BASE_URL = 'http://dl.google.com/android/adt' |
| -SDK_ZIP = 'adt-bundle-linux-x86_64-20130729.zip' |
| +SDK_ZIP = 'adt-bundle-linux-x86_64-20131030.zip' |
| # Android x86 system image from the Intel website: |
| # http://software.intel.com/en-us/articles/intel-eula-x86-android-4-2-jelly-bean-bin |
| -X86_IMG_URL = 'http://download-software.intel.com/sites/landingpage/android/sysimg_x86-18_r01.zip' |
| - |
| -# Android API level |
| -API_TARGET = 'android-%s' % constants.ANDROID_SDK_VERSION |
| - |
| +# These don't exist prior to Android-15. |
| +# As of 08 Nov 2013, Android-19 is not yet available either. |
| +X86_IMG_URLS = { |
| + 15: 'http://download-software.intel.com/sites/landingpage/android/sysimg_x86-15_r01.zip', |
| + 16: 'http://download-software.intel.com/sites/landingpage/android/sysimg_x86-16_r01.zip', |
| + 17: 'http://download-software.intel.com/sites/landingpage/android/sysimg_x86-17_r01.zip', |
| + 18: 'http://download-software.intel.com/sites/landingpage/android/sysimg_x86-18_r01.zip'} |
| def CheckSDK(): |
| """Check if SDK is already installed. |
| @@ -40,15 +49,43 @@ def CheckSDK(): |
| return os.path.exists(constants.EMULATOR_SDK_ROOT) |
| -def CheckX86Image(): |
| +def CheckSDKPlatform(api_level=DEFAULT_ANDROID_API_LEVEL): |
| + """Check if the "SDK Platform" for the specified API level is installed. |
| + This is necessary in order for the emulator to run when the target |
| + is specified. |
| + |
| + Args: |
| + api_level: the Android API level to check; defaults to the latest API. |
| + |
| + Returns: |
| + True if the platform is already installed. |
| + """ |
| + android_binary = os.path.join(constants.EMULATOR_SDK_ROOT, 'sdk', 'tools', 'android') |
| + pattern = re.compile('id: [0-9]+ or "android-%d"' % api_level) |
| + try: |
| + exit_code, stdout = cmd_helper.GetCmdStatusAndOutput([android_binary, 'list']) |
|
Maria
2013/11/10 21:05:17
check for successful exit code?
Andrew Hayden (chromium.org)
2013/11/11 16:59:27
Done.
|
| + for line in stdout.split('\n'): |
| + if pattern.match(line): |
| + return True |
| + return False |
|
Maria
2013/11/10 21:05:17
I am worried that "android list" command output fo
Andrew Hayden (chromium.org)
2013/11/11 16:59:27
Done.
|
| + except OSError: |
| + logging.info('broken sdk') |
|
Maria
2013/11/10 21:05:17
I think this needs a better error message
Andrew Hayden (chromium.org)
2013/11/11 16:59:27
Done.
|
| + return False |
| + |
| + |
| +def CheckX86Image(api_level=DEFAULT_ANDROID_API_LEVEL): |
| """Check if Android system images have been installed. |
| + Args: |
| + api_level: the Android API level to check for; defaults to the latest API. |
| + |
| Returns: |
| - True if sdk/system-images/<API TARGET>/x86 exists inside EMULATOR_SDK_ROOT. |
| + True if sdk/system-images/android-<api_level>/x86 exists inside EMULATOR_SDK_ROOT. |
| """ |
| + api_target = 'android-%d' % api_level |
| return os.path.exists(os.path.join(constants.EMULATOR_SDK_ROOT, |
| 'sdk', 'system-images', |
| - API_TARGET, 'x86')) |
| + api_target, 'x86')) |
| def CheckKVM(): |
| @@ -103,22 +140,71 @@ def InstallKVM(): |
| 'AMD SVM).') |
| -def GetX86Image(): |
| - """Download x86 system image from Intel's website.""" |
| +def GetX86Image(api_level=DEFAULT_ANDROID_API_LEVEL): |
| + """Download x86 system image from Intel's website. |
| + |
| + Args: |
| + api_level: the Android API level to download for; defaults to the latest API. |
| + """ |
| logging.info('Download x86 system image directory into sdk directory.') |
| + # TODO(andrewhayden) Use python tempfile lib instead |
|
Maria
2013/11/10 21:05:17
: after TODO()
Andrew Hayden (chromium.org)
2013/11/11 16:59:27
Done.
|
| + temp_file = '/tmp/x86_img_android-%d.zip' % api_level |
| + if api_level not in X86_IMG_URLS: |
| + raise Exception('ERROR: no URL known to download x86 system image for api level %s' % api_level) |
| try: |
| - cmd_helper.RunCmd(['curl', '-o', '/tmp/x86_img.zip', X86_IMG_URL]) |
| - rc = cmd_helper.RunCmd(['unzip', '-o', '/tmp/x86_img.zip', '-d', '/tmp/']) |
| + cmd_helper.RunCmd(['curl', '-o', temp_file, X86_IMG_URLS[api_level]]) |
| + rc = cmd_helper.RunCmd(['unzip', '-o', temp_file, '-d', '/tmp/']) |
| if rc: |
| raise Exception('ERROR: Could not download/unzip image zip.') |
| + api_target = 'android-%d' % api_level |
| sys_imgs = os.path.join(constants.EMULATOR_SDK_ROOT, 'sdk', |
| - 'system-images', API_TARGET, 'x86') |
| + 'system-images', api_target, 'x86') |
| + logging.info('Deploying system image to %s' % sys_imgs) |
| shutil.move('/tmp/x86', sys_imgs) |
| finally: |
| - os.unlink('/tmp/x86_img.zip') |
| + os.unlink(temp_file) |
| + |
| + |
| +def GetSDKPlatform(api_level=DEFAULT_ANDROID_API_LEVEL): |
| + """Update the SDK to include the platform specified. |
| + |
| + Args: |
| + api_level: the Android API level to download; defaults to the latest API. |
| + """ |
| + android_binary = os.path.join(constants.EMULATOR_SDK_ROOT, 'sdk', 'tools', 'android') |
| + pattern = re.compile('\s*([0-9]+)- SDK Platform Android [\.,0-9]+, API %d.*' % api_level) |
| + # Example: |
| + # 2- SDK Platform Android 4.3, API 18, revision 2 |
| + exit_code, stdout = cmd_helper.GetCmdStatusAndOutput([android_binary, 'list', 'sdk']) |
| + for line in stdout.split('\n'): |
| + match = pattern.match(line) |
| + if match: |
| + index=match.group(1) |
|
Maria
2013/11/10 21:05:17
space around =
Andrew Hayden (chromium.org)
2013/11/11 16:59:27
Done.
|
| + print('package %s corresponds to platform level %d, initiating update' % (index, api_level)) |
| + # update sdk --no-ui --filter $INDEX |
| + update_command = [android_binary, 'update', 'sdk', '--no-ui', '--filter', index] |
| + update_command_str = ' '.join(update_command) |
| + logging.info('running update command: %s' % update_command_str) |
| + update_process = pexpect.spawn(update_command_str) |
| + # TODO(andrewhayden): Do we need to bug the user about this? |
| + if update_process.expect('Do you accept the license') != 0: |
| + raise Exception('License agreement check failed') |
| + update_process.sendline('y') |
| + if update_process.expect('Done. 1 package installed.') == 0: |
| + print('Successfully installed platform for API level %d' % api_level) |
| + return |
| + else: |
| + raise Exception('Failed to install platform update') |
| + raise Exception('Could not find API level %d in the list of available updates for the SDK!' % api_level) |
|
Maria
2013/11/10 21:05:17
long line
|
| def main(argv): |
| + opt_parser = optparse.OptionParser(description='AVD script.') |
|
Maria
2013/11/10 21:05:17
I think you need to update description here
Andrew Hayden (chromium.org)
2013/11/11 16:59:27
Done.
|
| + opt_parser.add_option('--api-level', dest='api_level', |
| + help='API level to ensure installed', |
| + type='int', default=DEFAULT_ANDROID_API_LEVEL) |
| + options, _ = opt_parser.parse_args(argv[1:]) |
| + |
| logging.basicConfig(level=logging.INFO, |
| format='# %(asctime)-15s: %(message)s') |
| run_tests_helper.SetLogLevel(verbose_count=1) |
| @@ -129,11 +215,18 @@ def main(argv): |
| else: |
| GetSDK() |
| + # Check target. The target has to be installed in order for the emulator to start. |
| + if CheckSDKPlatform(options.api_level): |
| + logging.info('The SDK platform for api %d is already present, skipping download.' % options.api_level) |
|
Maria
2013/11/10 21:05:17
Long line
|
| + else: |
| + logging.info('The SDK platform for api %d is not present. Installing.' % options.api_level) |
| + GetSDKPlatform(options.api_level) |
| + |
| # Download the x86 system image only if needed. |
| - if CheckX86Image(): |
| - logging.info('The x86 image is already present, skipping download.') |
| + if CheckX86Image(options.api_level): |
| + logging.info('The x86 image for api %d is already present, skipping download.' % options.api_level) |
| else: |
| - GetX86Image() |
| + GetX86Image(options.api_level) |
| # Make sure KVM packages are installed and enabled. |
| if CheckKVM(): |