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 logging.critical('ERROR: Could not download/unzip image zip.') | |
107 raise | |
Paweł Hajdan Jr.
2013/09/12 17:44:43
This is suspect. You're not catching any exception
| |
108 sys_imgs = os.path.join(constants.EMULATOR_SDK_ROOT, 'android_tools', 'sdk', | |
109 'system-images', API_TARGET, 'armeabi-v7a') | |
110 shutil.move('/tmp/armeabi-v7a', sys_imgs) | |
111 finally: | |
112 os.unlink('/tmp/armv7_img.zip') | |
113 | |
114 | |
84 def GetX86Image(): | 115 def GetX86Image(): |
85 """Download x86 system image from Intel's website.""" | 116 """Download x86 system image from Intel's website.""" |
86 logging.info('Download x86 system image directory into sdk directory.') | 117 logging.info('Download x86 system image directory into sdk directory.') |
87 try: | 118 try: |
88 cmd_helper.RunCmd(['curl', '-o', '/tmp/x86_img.zip', X86_IMG_URL]) | 119 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/']) | 120 rc = cmd_helper.RunCmd(['unzip', '-o', '/tmp/x86_img.zip', '-d', '/tmp/']) |
90 if rc: | 121 if rc: |
91 logging.critical('ERROR: Could not download/unzip image zip.') | 122 logging.critical('ERROR: Could not download/unzip image zip.') |
92 raise | 123 raise |
93 sys_imgs = os.path.join(constants.EMULATOR_SDK_ROOT, 'android_tools', 'sdk', | 124 sys_imgs = os.path.join(constants.EMULATOR_SDK_ROOT, 'android_tools', 'sdk', |
94 'system-images', API_TARGET, 'x86') | 125 'system-images', API_TARGET, 'x86') |
95 shutil.move('/tmp/x86', sys_imgs) | 126 shutil.move('/tmp/x86', sys_imgs) |
96 finally: | 127 finally: |
97 os.unlink('/tmp/x86_img.zip') | 128 os.unlink('/tmp/x86_img.zip') |
98 | 129 |
99 | 130 |
100 def main(argv): | 131 def main(argv): |
101 logging.basicConfig(level=logging.INFO, | 132 logging.basicConfig(level=logging.INFO, |
102 format='# %(asctime)-15s: %(message)s') | 133 format='# %(asctime)-15s: %(message)s') |
103 run_tests_helper.SetLogLevel(verbose_count=1) | 134 run_tests_helper.SetLogLevel(verbose_count=1) |
104 | 135 |
105 if not CheckSDK(): | 136 if not CheckSDK(): |
106 logging.critical( | 137 logging.critical( |
107 'ERROR: android_tools does not exist. Make sure your .gclient file ' | 138 'ERROR: android_tools does not exist. Make sure your .gclient file ' |
108 'contains the right \'target_os\' entry. See ' | 139 'contains the right \'target_os\' entry. See ' |
109 'https://code.google.com/p/chromium/wiki/AndroidBuildInstructions for ' | 140 'https://code.google.com/p/chromium/wiki/AndroidBuildInstructions for ' |
110 'more information.') | 141 'more information.') |
111 return 1 | 142 return 1 |
112 | 143 |
113 logging.info('Emulator deps for ARM emulator complete.') | 144 # Download system images only if needed. |
145 if CheckARMv7Image(): | |
146 logging.info('The ARMv7 image is already present.') | |
147 else: | |
148 GetARMv7Image() | |
114 | 149 |
115 # Download system images only if needed. | |
116 if CheckX86Image(): | 150 if CheckX86Image(): |
117 logging.info('system-images directory already exists.') | 151 logging.info('The x86 image is already present.') |
118 else: | 152 else: |
119 GetX86Image() | 153 GetX86Image() |
120 | 154 |
121 # Make sure KVM packages are installed and enabled. | 155 # Make sure KVM packages are installed and enabled. |
122 if CheckKVM(): | 156 if CheckKVM(): |
123 logging.info('KVM already installed and enabled.') | 157 logging.info('KVM already installed and enabled.') |
124 else: | 158 else: |
125 InstallKVM() | 159 InstallKVM() |
126 | 160 |
127 | 161 |
128 if __name__ == '__main__': | 162 if __name__ == '__main__': |
129 sys.exit(main(sys.argv)) | 163 sys.exit(main(sys.argv)) |
OLD | NEW |