| 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 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 """ |
| 11 | 11 |
| 12 | 12 |
| 13 import logging | 13 import logging |
| 14 import os | 14 import os |
| 15 import shutil | 15 import shutil |
| 16 import sys | 16 import sys |
| 17 | 17 |
| 18 from pylib import cmd_helper | 18 from pylib import cmd_helper |
| 19 from pylib import constants | 19 from pylib import constants |
| 20 from pylib.utils import run_tests_helper | 20 from pylib.utils import run_tests_helper |
| 21 | 21 |
| 22 # From the Android Developer's website. | |
| 23 SDK_BASE_URL = 'http://dl.google.com/android/adt' | |
| 24 SDK_ZIP = 'adt-bundle-linux-x86_64-20130522.zip' | |
| 25 | |
| 26 # Android x86 system image from the Intel website: | 22 # Android x86 system image from the Intel website: |
| 27 # http://software.intel.com/en-us/articles/intel-eula-x86-android-4-2-jelly-bean
-bin | 23 # http://software.intel.com/en-us/articles/intel-eula-x86-android-4-2-jelly-bean
-bin |
| 28 X86_IMG_URL = 'http://download-software.intel.com/sites/landingpage/android/sysi
mg_x86-17_r01.zip' | 24 X86_IMG_URL = 'http://download-software.intel.com/sites/landingpage/android/sysi
mg_x86-17_r01.zip' |
| 29 | 25 |
| 30 # Android API level | 26 # Android API level |
| 31 API_TARGET = 'android-%s' % constants.ANDROID_SDK_VERSION | 27 API_TARGET = 'android-%s' % constants.ANDROID_SDK_VERSION |
| 32 | 28 |
| 33 | 29 |
| 34 def CheckSDK(): | 30 def CheckSDK(): |
| 35 """Check if SDK is already installed. | 31 """Check if SDK is already installed. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 58 Returns: | 54 Returns: |
| 59 True if kvm-ok returns 0 (already enabled) | 55 True if kvm-ok returns 0 (already enabled) |
| 60 """ | 56 """ |
| 61 try: | 57 try: |
| 62 return not cmd_helper.RunCmd(['kvm-ok']) | 58 return not cmd_helper.RunCmd(['kvm-ok']) |
| 63 except OSError: | 59 except OSError: |
| 64 logging.info('kvm-ok not installed') | 60 logging.info('kvm-ok not installed') |
| 65 return False | 61 return False |
| 66 | 62 |
| 67 | 63 |
| 68 def GetSDK(): | |
| 69 """Download the SDK and unzip in android_tools directory.""" | |
| 70 logging.info('Download Android SDK.') | |
| 71 sdk_url = '%s/%s' % (SDK_BASE_URL, SDK_ZIP) | |
| 72 try: | |
| 73 cmd_helper.RunCmd(['curl', '-o', '/tmp/sdk.zip', sdk_url]) | |
| 74 print 'curled unzipping...' | |
| 75 rc = cmd_helper.RunCmd(['unzip', '-o', '/tmp/sdk.zip', '-d', '/tmp/']) | |
| 76 if rc: | |
| 77 logging.critical('ERROR: could not download/unzip Android SDK.') | |
| 78 raise | |
| 79 # Get the name of the sub-directory that everything will be extracted to. | |
| 80 dirname, _ = os.path.splitext(SDK_ZIP) | |
| 81 zip_dir = '/tmp/%s' % dirname | |
| 82 # Move the extracted directory to EMULATOR_SDK_ROOT | |
| 83 dst = os.path.join(constants.EMULATOR_SDK_ROOT, 'android_tools') | |
| 84 shutil.move(zip_dir, dst) | |
| 85 finally: | |
| 86 os.unlink('/tmp/sdk.zip') | |
| 87 | |
| 88 | |
| 89 def InstallKVM(): | 64 def InstallKVM(): |
| 90 """Installs KVM packages.""" | 65 """Installs KVM packages.""" |
| 91 rc = cmd_helper.RunCmd(['sudo', 'apt-get', 'install', 'kvm']) | 66 rc = cmd_helper.RunCmd(['sudo', 'apt-get', 'install', 'kvm']) |
| 92 if rc: | 67 if rc: |
| 93 logging.critical('ERROR: Did not install KVM. Make sure hardware ' | 68 logging.critical('ERROR: Did not install KVM. Make sure hardware ' |
| 94 'virtualization is enabled in BIOS (i.e. Intel VT-x or ' | 69 'virtualization is enabled in BIOS (i.e. Intel VT-x or ' |
| 95 'AMD SVM).') | 70 'AMD SVM).') |
| 96 # TODO(navabi): Use modprobe kvm-amd on AMD processors. | 71 # TODO(navabi): Use modprobe kvm-amd on AMD processors. |
| 97 rc = cmd_helper.RunCmd(['sudo', 'modprobe', 'kvm-intel']) | 72 rc = cmd_helper.RunCmd(['sudo', 'modprobe', 'kvm-intel']) |
| 98 if rc: | 73 if rc: |
| (...skipping 21 matching lines...) Expand all Loading... |
| 120 shutil.move('/tmp/x86', sys_imgs) | 95 shutil.move('/tmp/x86', sys_imgs) |
| 121 finally: | 96 finally: |
| 122 os.unlink('/tmp/x86_img.zip') | 97 os.unlink('/tmp/x86_img.zip') |
| 123 | 98 |
| 124 | 99 |
| 125 def main(argv): | 100 def main(argv): |
| 126 logging.basicConfig(level=logging.INFO, | 101 logging.basicConfig(level=logging.INFO, |
| 127 format='# %(asctime)-15s: %(message)s') | 102 format='# %(asctime)-15s: %(message)s') |
| 128 run_tests_helper.SetLogLevel(verbose_count=1) | 103 run_tests_helper.SetLogLevel(verbose_count=1) |
| 129 | 104 |
| 130 # Calls below will download emulator SDK and/or system images only if needed. | 105 if not CheckSDK(): |
| 131 if CheckSDK(): | 106 logging.critical( |
| 132 logging.info('android_tools directory already exists (not downloading).') | 107 'ERROR: android_tools does not exist. Make sure your .gclient file ' |
| 133 else: | 108 'contains the right \'target_os\' entry. See ' |
| 134 GetSDK() | 109 'https://code.google.com/p/chromium/wiki/AndroidBuildInstructions for ' |
| 110 'more information.') |
| 111 return 1 |
| 135 | 112 |
| 136 logging.info('Emulator deps for ARM emulator complete.') | 113 logging.info('Emulator deps for ARM emulator complete.') |
| 137 | 114 |
| 115 # Download system images only if needed. |
| 138 if CheckX86Image(): | 116 if CheckX86Image(): |
| 139 logging.info('system-images directory already exists.') | 117 logging.info('system-images directory already exists.') |
| 140 else: | 118 else: |
| 141 GetX86Image() | 119 GetX86Image() |
| 142 | 120 |
| 143 # Make sure KVM packages are installed and enabled. | 121 # Make sure KVM packages are installed and enabled. |
| 144 if CheckKVM(): | 122 if CheckKVM(): |
| 145 logging.info('KVM already installed and enabled.') | 123 logging.info('KVM already installed and enabled.') |
| 146 else: | 124 else: |
| 147 InstallKVM() | 125 InstallKVM() |
| 148 | 126 |
| 149 | 127 |
| 150 if __name__ == '__main__': | 128 if __name__ == '__main__': |
| 151 sys.exit(main(sys.argv)) | 129 sys.exit(main(sys.argv)) |
| OLD | NEW |