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 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 # Android ARMv7 system image for the SDK. |
| 23 ARMV7_IMG_URL = 'https://dl-ssl.google.com/android/repository/sysimg_armv7a-18_r
01.zip' |
| 24 |
22 # Android x86 system image from the Intel website: | 25 # Android x86 system image from the Intel website: |
23 # http://software.intel.com/en-us/articles/intel-eula-x86-android-4-2-jelly-bean
-bin | 26 # http://software.intel.com/en-us/articles/intel-eula-x86-android-4-2-jelly-bean
-bin |
24 X86_IMG_URL = 'http://download-software.intel.com/sites/landingpage/android/sysi
mg_x86-18_r01.zip' | 27 X86_IMG_URL = 'http://download-software.intel.com/sites/landingpage/android/sysi
mg_x86-18_r01.zip' |
25 | 28 |
26 # Android API level | 29 # Android API level |
27 API_TARGET = 'android-%s' % constants.ANDROID_SDK_VERSION | 30 API_TARGET = 'android-%s' % constants.ANDROID_SDK_VERSION |
28 | 31 |
29 | 32 |
30 def CheckSDK(): | 33 def CheckSDK(): |
31 """Check if SDK is already installed. | 34 """Check if SDK is already installed. |
32 | 35 |
33 Returns: | 36 Returns: |
34 True if android_tools directory exists in current directory. | 37 True if android_tools directory exists in current directory. |
35 """ | 38 """ |
36 return os.path.exists(os.path.join(constants.EMULATOR_SDK_ROOT, | 39 return os.path.exists(os.path.join(constants.EMULATOR_SDK_ROOT, |
37 'android_tools')) | 40 'android_tools')) |
38 | 41 |
39 | 42 |
| 43 def CheckARMv7Image(): |
| 44 """Check if the ARMv7 system images have been installed. |
| 45 |
| 46 Returns: |
| 47 True if the armeabi-v7a directory is present inside the Android SDK |
| 48 checkout directory. |
| 49 """ |
| 50 return os.path.exists(os.path.join(constants.EMULATOR_SDK_ROOT, |
| 51 'android_tools', 'sdk', 'system-images', |
| 52 API_TARGET, 'armeabi-v7a')) |
| 53 |
| 54 |
40 def CheckX86Image(): | 55 def CheckX86Image(): |
41 """Check if Android system images have been installed. | 56 """Check if Android system images have been installed. |
42 | 57 |
43 Returns: | 58 Returns: |
44 True if android_tools/sdk/system-images directory exists. | 59 True if android_tools/sdk/system-images directory exists. |
45 """ | 60 """ |
46 return os.path.exists(os.path.join(constants.EMULATOR_SDK_ROOT, | 61 return os.path.exists(os.path.join(constants.EMULATOR_SDK_ROOT, |
47 'android_tools', 'sdk', 'system-images', | 62 'android_tools', 'sdk', 'system-images', |
48 API_TARGET, 'x86')) | 63 API_TARGET, 'x86')) |
49 | 64 |
(...skipping 24 matching lines...) Expand all Loading... |
74 logging.critical('ERROR: Did not add KVM module to Linux Kernal. Make sure ' | 89 logging.critical('ERROR: Did not add KVM module to Linux Kernal. Make sure ' |
75 'hardware virtualization is enabled in BIOS.') | 90 'hardware virtualization is enabled in BIOS.') |
76 # Now check to ensure KVM acceleration can be used. | 91 # Now check to ensure KVM acceleration can be used. |
77 rc = cmd_helper.RunCmd(['kvm-ok']) | 92 rc = cmd_helper.RunCmd(['kvm-ok']) |
78 if rc: | 93 if rc: |
79 logging.critical('ERROR: Can not use KVM acceleration. Make sure hardware ' | 94 logging.critical('ERROR: Can not use KVM acceleration. Make sure hardware ' |
80 'virtualization is enabled in BIOS (i.e. Intel VT-x or ' | 95 'virtualization is enabled in BIOS (i.e. Intel VT-x or ' |
81 'AMD SVM).') | 96 'AMD SVM).') |
82 | 97 |
83 | 98 |
| 99 def GetARMv7Image(): |
| 100 """Download and install the ARMv7 system image.""" |
| 101 logging.info('Download ARMv7 system image directory into sdk directory.') |
| 102 try: |
| 103 cmd_helper.RunCmd(['curl', '-o', '/tmp/armv7_img.zip', ARMV7_IMG_URL]) |
| 104 rc = cmd_helper.RunCmd(['unzip', '-o', '/tmp/armv7_img.zip', '-d', '/tmp/']) |
| 105 if rc: |
| 106 raise Exception('ERROR: Could not download/unzip image zip.') |
| 107 sys_imgs = os.path.join(constants.EMULATOR_SDK_ROOT, 'android_tools', 'sdk', |
| 108 'system-images', API_TARGET, 'armeabi-v7a') |
| 109 shutil.move('/tmp/armeabi-v7a', sys_imgs) |
| 110 finally: |
| 111 os.unlink('/tmp/armv7_img.zip') |
| 112 |
| 113 |
84 def GetX86Image(): | 114 def GetX86Image(): |
85 """Download x86 system image from Intel's website.""" | 115 """Download x86 system image from Intel's website.""" |
86 logging.info('Download x86 system image directory into sdk directory.') | 116 logging.info('Download x86 system image directory into sdk directory.') |
87 try: | 117 try: |
88 cmd_helper.RunCmd(['curl', '-o', '/tmp/x86_img.zip', X86_IMG_URL]) | 118 cmd_helper.RunCmd(['curl', '-o', '/tmp/x86_img.zip', X86_IMG_URL]) |
89 rc = cmd_helper.RunCmd(['unzip', '-o', '/tmp/x86_img.zip', '-d', '/tmp/']) | 119 rc = cmd_helper.RunCmd(['unzip', '-o', '/tmp/x86_img.zip', '-d', '/tmp/']) |
90 if rc: | 120 if rc: |
91 logging.critical('ERROR: Could not download/unzip image zip.') | 121 raise Exception('ERROR: Could not download/unzip image zip.') |
92 raise | |
93 sys_imgs = os.path.join(constants.EMULATOR_SDK_ROOT, 'android_tools', 'sdk', | 122 sys_imgs = os.path.join(constants.EMULATOR_SDK_ROOT, 'android_tools', 'sdk', |
94 'system-images', API_TARGET, 'x86') | 123 'system-images', API_TARGET, 'x86') |
95 shutil.move('/tmp/x86', sys_imgs) | 124 shutil.move('/tmp/x86', sys_imgs) |
96 finally: | 125 finally: |
97 os.unlink('/tmp/x86_img.zip') | 126 os.unlink('/tmp/x86_img.zip') |
98 | 127 |
99 | 128 |
100 def main(argv): | 129 def main(argv): |
101 logging.basicConfig(level=logging.INFO, | 130 logging.basicConfig(level=logging.INFO, |
102 format='# %(asctime)-15s: %(message)s') | 131 format='# %(asctime)-15s: %(message)s') |
103 run_tests_helper.SetLogLevel(verbose_count=1) | 132 run_tests_helper.SetLogLevel(verbose_count=1) |
104 | 133 |
105 if not CheckSDK(): | 134 if not CheckSDK(): |
106 logging.critical( | 135 logging.critical( |
107 'ERROR: android_tools does not exist. Make sure your .gclient file ' | 136 'ERROR: android_tools does not exist. Make sure your .gclient file ' |
108 'contains the right \'target_os\' entry. See ' | 137 'contains the right \'target_os\' entry. See ' |
109 'https://code.google.com/p/chromium/wiki/AndroidBuildInstructions for ' | 138 'https://code.google.com/p/chromium/wiki/AndroidBuildInstructions for ' |
110 'more information.') | 139 'more information.') |
111 return 1 | 140 return 1 |
112 | 141 |
113 logging.info('Emulator deps for ARM emulator complete.') | 142 # Download system images only if needed. |
| 143 if CheckARMv7Image(): |
| 144 logging.info('The ARMv7 image is already present.') |
| 145 else: |
| 146 GetARMv7Image() |
114 | 147 |
115 # Download system images only if needed. | |
116 if CheckX86Image(): | 148 if CheckX86Image(): |
117 logging.info('system-images directory already exists.') | 149 logging.info('The x86 image is already present.') |
118 else: | 150 else: |
119 GetX86Image() | 151 GetX86Image() |
120 | 152 |
121 # Make sure KVM packages are installed and enabled. | 153 # Make sure KVM packages are installed and enabled. |
122 if CheckKVM(): | 154 if CheckKVM(): |
123 logging.info('KVM already installed and enabled.') | 155 logging.info('KVM already installed and enabled.') |
124 else: | 156 else: |
125 InstallKVM() | 157 InstallKVM() |
126 | 158 |
127 | 159 |
128 if __name__ == '__main__': | 160 if __name__ == '__main__': |
129 sys.exit(main(sys.argv)) | 161 sys.exit(main(sys.argv)) |
OLD | NEW |