OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Installs deps for using SDK emulator for testing. | 6 """Installs deps for using SDK emulator for testing. |
7 | 7 |
8 The script will download the SDK and system images, if they are not present, and | 8 The script will download the SDK and system images, if they are not present, and |
9 install and enable KVM, if virtualization has been enabled in the BIOS. | 9 install and enable KVM, if virtualization has been enabled in the BIOS. |
10 """ | 10 """ |
(...skipping 12 matching lines...) Expand all Loading... |
23 from pylib.utils import run_tests_helper | 23 from pylib.utils import run_tests_helper |
24 | 24 |
25 # Android API level | 25 # Android API level |
26 DEFAULT_ANDROID_API_LEVEL = constants.ANDROID_SDK_VERSION | 26 DEFAULT_ANDROID_API_LEVEL = constants.ANDROID_SDK_VERSION |
27 | 27 |
28 # From the Android Developer's website. | 28 # From the Android Developer's website. |
29 # Keep this up to date; the user can install older API levels as necessary. | 29 # Keep this up to date; the user can install older API levels as necessary. |
30 SDK_BASE_URL = 'http://dl.google.com/android/adt' | 30 SDK_BASE_URL = 'http://dl.google.com/android/adt' |
31 SDK_ZIP = 'adt-bundle-linux-x86_64-20131030.zip' | 31 SDK_ZIP = 'adt-bundle-linux-x86_64-20131030.zip' |
32 | 32 |
33 # pylint: disable=C0301 | 33 # pylint: disable=line-too-long |
34 # Android x86 system image from the Intel website: | 34 # Android x86 system image from the Intel website: |
35 # http://software.intel.com/en-us/articles/intel-eula-x86-android-4-2-jelly-bean
-bin | 35 # http://software.intel.com/en-us/articles/intel-eula-x86-android-4-2-jelly-bean
-bin |
36 # These don't exist prior to Android-15. | 36 # These don't exist prior to Android-15. |
37 # As of 08 Nov 2013, Android-19 is not yet available either. | 37 # As of 08 Nov 2013, Android-19 is not yet available either. |
38 X86_IMG_URLS = { | 38 X86_IMG_URLS = { |
39 15: 'https://software.intel.com/sites/landingpage/android/sysimg_x86-15_r01.zi
p', | 39 15: 'https://software.intel.com/sites/landingpage/android/sysimg_x86-15_r01.zi
p', |
40 16: 'https://software.intel.com/sites/landingpage/android/sysimg_x86-16_r01.zi
p', | 40 16: 'https://software.intel.com/sites/landingpage/android/sysimg_x86-16_r01.zi
p', |
41 17: 'https://software.intel.com/sites/landingpage/android/sysimg_x86-17_r01.zi
p', | 41 17: 'https://software.intel.com/sites/landingpage/android/sysimg_x86-17_r01.zi
p', |
42 18: 'https://software.intel.com/sites/landingpage/android/sysimg_x86-18_r01.zi
p', | 42 18: 'https://software.intel.com/sites/landingpage/android/sysimg_x86-18_r01.zi
p', |
43 19: 'https://software.intel.com/sites/landingpage/android/sysimg_x86-19_r01.zi
p'} | 43 19: 'https://software.intel.com/sites/landingpage/android/sysimg_x86-19_r01.zi
p'} |
44 #pylint: enable=C0301 | 44 #pylint: enable=line-too-long |
45 | 45 |
46 def CheckSDK(): | 46 def CheckSDK(): |
47 """Check if SDK is already installed. | 47 """Check if SDK is already installed. |
48 | 48 |
49 Returns: | 49 Returns: |
50 True if the emulator SDK directory (src/android_emulator_sdk/) exists. | 50 True if the emulator SDK directory (src/android_emulator_sdk/) exists. |
51 """ | 51 """ |
52 return os.path.exists(constants.EMULATOR_SDK_ROOT) | 52 return os.path.exists(constants.EMULATOR_SDK_ROOT) |
53 | 53 |
54 | 54 |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 | 187 |
188 | 188 |
189 def GetSDKPlatform(api_level=DEFAULT_ANDROID_API_LEVEL): | 189 def GetSDKPlatform(api_level=DEFAULT_ANDROID_API_LEVEL): |
190 """Update the SDK to include the platform specified. | 190 """Update the SDK to include the platform specified. |
191 | 191 |
192 Args: | 192 Args: |
193 api_level: the Android API level to download | 193 api_level: the Android API level to download |
194 """ | 194 """ |
195 android_binary = os.path.join(constants.EMULATOR_SDK_ROOT, | 195 android_binary = os.path.join(constants.EMULATOR_SDK_ROOT, |
196 'sdk', 'tools', 'android') | 196 'sdk', 'tools', 'android') |
197 pattern = re.compile('\s*([0-9]+)- SDK Platform Android [\.,0-9]+, API %d.*' % | 197 pattern = re.compile( |
198 api_level) | 198 r'\s*([0-9]+)- SDK Platform Android [\.,0-9]+, API %d.*' % api_level) |
199 # Example: | 199 # Example: |
200 # 2- SDK Platform Android 4.3, API 18, revision 2 | 200 # 2- SDK Platform Android 4.3, API 18, revision 2 |
201 exit_code, stdout = cmd_helper.GetCmdStatusAndOutput( | 201 exit_code, stdout = cmd_helper.GetCmdStatusAndOutput( |
202 [android_binary, 'list', 'sdk']) | 202 [android_binary, 'list', 'sdk']) |
203 if exit_code != 0: | 203 if exit_code != 0: |
204 raise Exception('\'android list sdk\' command return %d' % exit_code) | 204 raise Exception('\'android list sdk\' command return %d' % exit_code) |
205 for line in stdout.split('\n'): | 205 for line in stdout.split('\n'): |
206 match = pattern.match(line) | 206 match = pattern.match(line) |
207 if match: | 207 if match: |
208 index = match.group(1) | 208 index = match.group(1) |
209 print('package %s corresponds to platform level %d' % (index, api_level)) | 209 print 'package %s corresponds to platform level %d' % (index, api_level) |
210 # update sdk --no-ui --filter $INDEX | 210 # update sdk --no-ui --filter $INDEX |
211 update_command = [android_binary, | 211 update_command = [android_binary, |
212 'update', 'sdk', '--no-ui', '--filter', index] | 212 'update', 'sdk', '--no-ui', '--filter', index] |
213 update_command_str = ' '.join(update_command) | 213 update_command_str = ' '.join(update_command) |
214 logging.info('running update command: %s' % update_command_str) | 214 logging.info('running update command: %s' % update_command_str) |
215 update_process = pexpect.spawn(update_command_str) | 215 update_process = pexpect.spawn(update_command_str) |
216 # TODO(andrewhayden): Do we need to bug the user about this? | 216 # TODO(andrewhayden): Do we need to bug the user about this? |
217 if update_process.expect('Do you accept the license') != 0: | 217 if update_process.expect('Do you accept the license') != 0: |
218 raise Exception('License agreement check failed') | 218 raise Exception('License agreement check failed') |
219 update_process.sendline('y') | 219 update_process.sendline('y') |
220 if update_process.expect('Done. 1 package installed.') == 0: | 220 if update_process.expect('Done. 1 package installed.') == 0: |
221 print('Successfully installed platform for API level %d' % api_level) | 221 print 'Successfully installed platform for API level %d' % api_level |
222 return | 222 return |
223 else: | 223 else: |
224 raise Exception('Failed to install platform update') | 224 raise Exception('Failed to install platform update') |
225 raise Exception('Could not find android-%d update for the SDK!' % api_level) | 225 raise Exception('Could not find android-%d update for the SDK!' % api_level) |
226 | 226 |
227 | 227 |
228 def main(argv): | 228 def main(argv): |
229 opt_parser = optparse.OptionParser( | 229 opt_parser = optparse.OptionParser( |
230 description='Install dependencies for running the Android emulator') | 230 description='Install dependencies for running the Android emulator') |
231 opt_parser.add_option('--api-level', dest='api_level', | 231 opt_parser.add_option('--api-level', dest='api_level', |
232 help='The API level (e.g., 19 for Android 4.4) to ensure is available', | 232 help='The API level (e.g., 19 for Android 4.4) to ensure is available', |
233 type='int', default=DEFAULT_ANDROID_API_LEVEL) | 233 type='int', default=DEFAULT_ANDROID_API_LEVEL) |
234 opt_parser.add_option('-v', dest='verbose', action='store_true', | 234 opt_parser.add_option('-v', dest='verbose', action='store_true', |
235 help='enable verbose logging') | 235 help='enable verbose logging') |
236 options, _ = opt_parser.parse_args(argv[1:]) | 236 options, _ = opt_parser.parse_args(argv[1:]) |
237 | 237 |
238 # run_tests_helper will set logging to INFO or DEBUG | 238 # run_tests_helper will set logging to INFO or DEBUG |
239 # We achieve verbose output by configuring it with 2 (==DEBUG) | 239 # We achieve verbose output by configuring it with 2 (==DEBUG) |
240 verbosity = 1 | 240 verbosity = 1 |
241 if (options.verbose): | 241 if options.verbose: |
242 verbosity = 2 | 242 verbosity = 2 |
243 logging.basicConfig(level=logging.INFO, | 243 logging.basicConfig(level=logging.INFO, |
244 format='# %(asctime)-15s: %(message)s') | 244 format='# %(asctime)-15s: %(message)s') |
245 run_tests_helper.SetLogLevel(verbose_count=verbosity) | 245 run_tests_helper.SetLogLevel(verbose_count=verbosity) |
246 | 246 |
247 # Calls below will download emulator SDK and/or system images only if needed. | 247 # Calls below will download emulator SDK and/or system images only if needed. |
248 if CheckSDK(): | 248 if CheckSDK(): |
249 logging.info('android_emulator_sdk/ already exists, skipping download.') | 249 logging.info('android_emulator_sdk/ already exists, skipping download.') |
250 else: | 250 else: |
251 GetSDK() | 251 GetSDK() |
(...skipping 16 matching lines...) Expand all Loading... |
268 | 268 |
269 # Make sure KVM packages are installed and enabled. | 269 # Make sure KVM packages are installed and enabled. |
270 if CheckKVM(): | 270 if CheckKVM(): |
271 logging.info('KVM already installed and enabled.') | 271 logging.info('KVM already installed and enabled.') |
272 else: | 272 else: |
273 InstallKVM() | 273 InstallKVM() |
274 | 274 |
275 | 275 |
276 if __name__ == '__main__': | 276 if __name__ == '__main__': |
277 sys.exit(main(sys.argv)) | 277 sys.exit(main(sys.argv)) |
OLD | NEW |