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..0cb81472e1d16500dd38445b7ba2f568bb1a3df8 100755 |
--- a/build/android/install_emulator_deps.py |
+++ b/build/android/install_emulator_deps.py |
@@ -49,7 +49,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) |
mikecase (-- gone --)
2015/09/12 00:10:16
Same comment as before.
You will have to rebase t
Yoland Yan(Google)
2015/09/12 01:42:38
Done
|
def CheckSDKPlatform(api_level=DEFAULT_ANDROID_API_LEVEL): |
@@ -63,8 +63,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 +86,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(): |
@@ -167,23 +166,39 @@ def GetX86Image(api_level=DEFAULT_ANDROID_API_LEVEL): |
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) |
+ |
+ android_binary = os.path.join(constants.ANDROID_SDK_ROOT, 'tools', 'android') |
+ |
+ pattern = re.compile( |
mikecase (-- gone --)
2015/09/12 00:10:16
I would change the name from "pattern" to somethin
Yoland Yan(Google)
2015/09/12 01:42:38
Done
|
+ r'\s*([0-9]+)- Intel x86 Atom System Image, Android API %d.*' % api_level) |
+ tmp_cmd = [android_binary, 'list', 'sdk', '--all'] |
mikecase (-- gone --)
2015/09/12 00:10:16
I would change the name to something more specific
Yoland Yan(Google)
2015/09/12 01:42:38
Done
|
+ |
+ exit_code, stdout = cmd_helper.GetCmdStatusAndOutput(tmp_cmd) |
+ |
+ if exit_code != 0: |
+ raise Exception('\'android list sdk --all\' command return %d' % exit_code) |
+ for line in stdout.split('\n'): |
+ match = pattern.match(line) |
+ if match: |
+ index = match.group(1) |
+ print 'package %s corresponds to x86 system image with api level %d' |
mikecase (-- gone --)
2015/09/12 00:10:16
use python logging module
Yoland Yan(Google)
2015/09/12 01:42:38
Done
|
+ % (index, 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) |
+ |
+ 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.', timeout=60) == 0: |
+ print 'Successfully installed x86 system image for API level %d' |
mikecase (-- gone --)
2015/09/12 00:10:16
I would use the python logging module instead of p
Yoland Yan(Google)
2015/09/12 01:42:38
Done
|
+ % api_level |
+ return |
+ else: |
+ raise Exception('Failed to install platform update') |
+ raise Exception('Could not find android-%d update for the SDK!' % api_level) |
mikecase (-- gone --)
2015/09/12 00:10:16
This code you added is extremely similar to the be
Yoland Yan(Google)
2015/09/12 01:42:38
Done
|
def GetSDKPlatform(api_level=DEFAULT_ANDROID_API_LEVEL): |
@@ -192,14 +207,13 @@ def GetSDKPlatform(api_level=DEFAULT_ANDROID_API_LEVEL): |
Args: |
api_level: the Android API level to download |
""" |
- 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( |
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']) |
+ [android_binary, 'list', 'sdk', '--all']) |
if exit_code != 0: |
raise Exception('\'android list sdk\' command return %d' % exit_code) |
for line in stdout.split('\n'): |
@@ -207,9 +221,8 @@ def GetSDKPlatform(api_level=DEFAULT_ANDROID_API_LEVEL): |
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] |
+ '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) |
@@ -217,7 +230,7 @@ def GetSDKPlatform(api_level=DEFAULT_ANDROID_API_LEVEL): |
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: |
+ if update_process.expect('Done. 1 package installed.', timeout=60) == 0: |
Yoland Yan(Google)
2015/09/11 19:17:22
It takes a long time to download SDK Platform
|
print 'Successfully installed platform for API level %d' % api_level |
return |
else: |