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 31fcbf0becf5bea536f17f5681af47430142f2b2..cbc88ea5d56bb17db3a476f04263f132038278ba 100755 |
| --- a/build/android/install_emulator_deps.py |
| +++ b/build/android/install_emulator_deps.py |
| @@ -14,7 +14,6 @@ import logging |
| import optparse |
| import os |
| import re |
| -import shutil |
| import sys |
| from devil.utils import cmd_helper |
| @@ -49,7 +48,7 @@ def CheckSDK(): |
| Returns: |
| True if the emulator SDK directory (src/android_emulator_sdk/) exists. |
| """ |
| - return os.path.exists(constants.EMULATOR_SDK_ROOT) |
| + return os.path.exists(constants.ANDROID_SDK_ROOT) |
| def CheckSDKPlatform(api_level=DEFAULT_ANDROID_API_LEVEL): |
| @@ -63,8 +62,7 @@ def CheckSDKPlatform(api_level=DEFAULT_ANDROID_API_LEVEL): |
| Returns: |
| True if the platform is already installed. |
| """ |
| - android_binary = os.path.join(constants.EMULATOR_SDK_ROOT, |
| - 'sdk', 'tools', 'android') |
| + android_binary = os.path.join(constants.ANDROID_SDK_ROOT, 'tools', 'android') |
| pattern = re.compile('id: [0-9]+ or "android-%d"' % api_level) |
| try: |
| exit_code, stdout = cmd_helper.GetCmdStatusAndOutput( |
| @@ -87,13 +85,13 @@ def CheckX86Image(api_level=DEFAULT_ANDROID_API_LEVEL): |
| api_level: the Android API level to check for; defaults to the latest API. |
| Returns: |
| - True if sdk/system-images/android-<api_level>/x86 exists inside |
| - EMULATOR_SDK_ROOT. |
| + True if sdk/system-images/android-<api_level>/default/x86 exists inside |
| + ANDROID_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')) |
| + return os.path.exists(os.path.join(constants.ANDROID_SDK_ROOT, |
| + 'system-images', api_target, 'default', |
| + 'x86')) |
| def CheckKVM(): |
| @@ -122,25 +120,6 @@ def RunKvmOk(): |
| return False |
| -def GetSDK(): |
| - """Download the SDK and unzip it into EMULATOR_SDK_ROOT.""" |
| - logging.info('Download Android SDK.') |
| - sdk_url = '%s/%s' % (SDK_BASE_URL, SDK_ZIP) |
| - try: |
| - cmd_helper.RunCmd(['curl', '-o', '/tmp/sdk.zip', sdk_url]) |
| - print 'curled unzipping...' |
| - rc = cmd_helper.RunCmd(['unzip', '-o', '/tmp/sdk.zip', '-d', '/tmp/']) |
| - if rc: |
| - raise Exception('ERROR: could not download/unzip Android SDK.') |
| - # Get the name of the sub-directory that everything will be extracted to. |
| - dirname, _ = os.path.splitext(SDK_ZIP) |
| - zip_dir = '/tmp/%s' % dirname |
| - # Move the extracted directory to EMULATOR_SDK_ROOT |
| - shutil.move(zip_dir, constants.EMULATOR_SDK_ROOT) |
| - finally: |
| - os.unlink('/tmp/sdk.zip') |
| - |
| - |
| def InstallKVM(): |
| """Installs KVM packages.""" |
| rc = cmd_helper.RunCmd(['sudo', 'apt-get', 'install', 'kvm']) |
| @@ -160,70 +139,73 @@ def InstallKVM(): |
| 'AMD SVM).') |
| -def GetX86Image(api_level=DEFAULT_ANDROID_API_LEVEL): |
| - """Download x86 system image from Intel's website. |
| +def UpdateSDK(api_level, package_name, package_pattern, timeout=30): |
|
mikecase (-- gone --)
2015/09/15 22:26:55
I would factor out this 30 to the top of the modul
Yoland Yan(Google)
2015/09/20 21:57:37
Done
|
| + '''This function update SDK with a filter index. |
| Args: |
| api_level: the Android API level to download for. |
| - """ |
| - logging.info('Download x86 system image directory into sdk directory.') |
| - # TODO(andrewhayden): Use python tempfile lib instead |
| - temp_file = '/tmp/x86_img_android-%d.zip' % api_level |
| - if api_level not in X86_IMG_URLS: |
| - raise Exception('ERROR: no URL known for x86 image for android-%s' % |
| - api_level) |
| - try: |
| - 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') |
| - logging.info('Deploying system image to %s', sys_imgs) |
| - shutil.move('/tmp/x86', sys_imgs) |
| - finally: |
| - os.unlink(temp_file) |
| + package_pattern: the mattern to match the filter index from |
|
mikecase (-- gone --)
2015/09/15 22:26:55
missing description of "package_name" parameter
Yoland Yan(Google)
2015/09/20 21:57:37
Done
|
| + timeout: the amount of time wait for update command |
| + ''' |
| + android_binary = os.path.join(constants.ANDROID_SDK_ROOT, 'tools', 'android') |
| + list_sdk_repo_command = [android_binary, 'list', 'sdk', '--all'] |
| -def GetSDKPlatform(api_level=DEFAULT_ANDROID_API_LEVEL): |
| - """Update the SDK to include the platform specified. |
| + exit_code, stdout = cmd_helper.GetCmdStatusAndOutput(list_sdk_repo_command) |
| - Args: |
| - api_level: the Android API level to download |
| - """ |
| - android_binary = os.path.join(constants.EMULATOR_SDK_ROOT, |
| - 'sdk', 'tools', 'android') |
| - pattern = re.compile( |
| - r'\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']) |
| if exit_code != 0: |
| - raise Exception('\'android list sdk\' command return %d' % exit_code) |
| + raise Exception('\'android list sdk --all\' command return %d' % exit_code) |
| + |
| for line in stdout.split('\n'): |
| - match = pattern.match(line) |
| + match = package_pattern.match(line) |
| if match: |
| index = match.group(1) |
| - print 'package %s corresponds to platform level %d' % (index, api_level) |
| - # update sdk --no-ui --filter $INDEX |
| - update_command = [android_binary, |
| - 'update', 'sdk', '--no-ui', '--filter', index] |
| + logging.info('package %s corresponds to %s with api level %d' |
| + % (index, package_name, api_level)) |
| + update_command = [android_binary, 'update', 'sdk', '--no-ui', '--all', |
| + '--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 |
| + if update_process.expect( |
| + 'Done. 1 package installed.', timeout=timeout) == 0: |
| + logging.info('Successfully installed %s for API level %d' |
| + % (package_name, api_level)) |
|
mikecase (-- gone --)
2015/09/15 22:26:55
nit: single extra space before the %
Yoland Yan(Google)
2015/09/20 21:57:36
Done
|
| return |
| else: |
| raise Exception('Failed to install platform update') |
| raise Exception('Could not find android-%d update for the SDK!' % api_level) |
| +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. |
| + """ |
| + logging.info('Download x86 system image directory into sdk directory.') |
| + |
| + x86_package_pattern = re.compile( |
| + r'\s*([0-9]+)- Intel x86 Atom System Image, Android API %d.*' % api_level) |
| + |
| + UpdateSDK(api_level, 'x86 system image', x86_package_pattern, 60) |
|
mikecase (-- gone --)
2015/09/15 22:26:55
I would factor out this 60 to the top of the modul
Yoland Yan(Google)
2015/09/20 21:57:37
Done
|
| + |
| +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 |
| + """ |
| + logging.info('Download SDK Platform directory into sdk directory.') |
| + |
| + platform_package_pattern = re.compile( |
| + r'\s*([0-9]+)- SDK Platform Android [\.,0-9]+, API %d.*' % api_level) |
| + |
| + UpdateSDK(api_level, 'SDK Platform', platform_package_pattern) |
| + |
| def main(argv): |
| opt_parser = optparse.OptionParser( |
| @@ -248,7 +230,9 @@ def main(argv): |
| if CheckSDK(): |
| logging.info('android_emulator_sdk/ already exists, skipping download.') |
| else: |
| - GetSDK() |
| + logging.critical('ERROR: Emulator SDK not installed in %s' |
| + % constants.ANDROID_SDK_ROOT) |
| + return 1 |
| # Check target. The target has to be installed in order to run the emulator. |
| if CheckSDKPlatform(options.api_level): |