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 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 """ |
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. | 22 # From the Android Developer's website. |
23 ARMV7_IMG_URL = 'https://dl-ssl.google.com/android/repository/sysimg_armv7a-18_r 01.zip' | 23 SDK_BASE_URL = 'http://dl.google.com/android/adt' |
24 SDK_ZIP = 'adt-bundle-linux-x86_64-20130729.zip' | |
24 | 25 |
25 # Android x86 system image from the Intel website: | 26 # Android x86 system image from the Intel website: |
26 # http://software.intel.com/en-us/articles/intel-eula-x86-android-4-2-jelly-bean -bin | 27 # http://software.intel.com/en-us/articles/intel-eula-x86-android-4-2-jelly-bean -bin |
27 X86_IMG_URL = 'http://download-software.intel.com/sites/landingpage/android/sysi mg_x86-18_r01.zip' | 28 X86_IMG_URL = 'http://download-software.intel.com/sites/landingpage/android/sysi mg_x86-18_r01.zip' |
28 | 29 |
29 # Android API level | 30 # Android API level |
30 API_TARGET = 'android-%s' % constants.ANDROID_SDK_VERSION | 31 API_TARGET = 'android-%s' % constants.ANDROID_SDK_VERSION |
31 | 32 |
32 | 33 |
33 def CheckSDK(): | 34 def CheckSDK(): |
34 """Check if SDK is already installed. | 35 """Check if SDK is already installed. |
35 | 36 |
36 Returns: | 37 Returns: |
37 True if android_tools directory exists in current directory. | 38 True if the emulator SDK directory (src/android_emulator_sdk/) exists. |
38 """ | 39 """ |
39 return os.path.exists(os.path.join(constants.EMULATOR_SDK_ROOT, | 40 return os.path.exists(constants.EMULATOR_SDK_ROOT) |
40 'android_tools')) | |
41 | |
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 | 41 |
54 | 42 |
55 def CheckX86Image(): | 43 def CheckX86Image(): |
56 """Check if Android system images have been installed. | 44 """Check if Android system images have been installed. |
57 | 45 |
58 Returns: | 46 Returns: |
59 True if android_tools/sdk/system-images directory exists. | 47 True if sdk/system-images/<API TARGET>/x86 exists inside EMULATOR_SDK_ROOT. |
60 """ | 48 """ |
61 return os.path.exists(os.path.join(constants.EMULATOR_SDK_ROOT, | 49 return os.path.exists(os.path.join(constants.EMULATOR_SDK_ROOT, |
62 'android_tools', 'sdk', 'system-images', | 50 'sdk', 'system-images', |
63 API_TARGET, 'x86')) | 51 API_TARGET, 'x86')) |
64 | 52 |
65 | 53 |
66 def CheckKVM(): | 54 def CheckKVM(): |
67 """Check if KVM is enabled. | 55 """Check if KVM is enabled. |
68 | 56 |
69 Returns: | 57 Returns: |
70 True if kvm-ok returns 0 (already enabled) | 58 True if kvm-ok returns 0 (already enabled) |
71 """ | 59 """ |
72 try: | 60 try: |
73 return not cmd_helper.RunCmd(['kvm-ok']) | 61 return not cmd_helper.RunCmd(['kvm-ok']) |
74 except OSError: | 62 except OSError: |
75 logging.info('kvm-ok not installed') | 63 logging.info('kvm-ok not installed') |
76 return False | 64 return False |
77 | 65 |
78 | 66 |
67 def GetSDK(): | |
68 """Download the SDK and unzip it into EMULATOR_SDK_ROOT.""" | |
69 logging.info('Download Android SDK.') | |
70 sdk_url = '%s/%s' % (SDK_BASE_URL, SDK_ZIP) | |
71 try: | |
72 cmd_helper.RunCmd(['curl', '-o', '/tmp/sdk.zip', sdk_url]) | |
73 print 'curled unzipping...' | |
74 rc = cmd_helper.RunCmd(['unzip', '-o', '/tmp/sdk.zip', '-d', '/tmp/']) | |
75 if rc: | |
76 raise Exception('ERROR: could not download/unzip Android SDK.') | |
77 # Get the name of the sub-directory that everything will be extracted to. | |
78 dirname, _ = os.path.splitext(SDK_ZIP) | |
79 zip_dir = '/tmp/%s' % dirname | |
80 # Move the extracted directory to EMULATOR_SDK_ROOT | |
81 shutil.move(zip_dir, constants.EMULATOR_SDK_ROOT) | |
navabi1
2013/10/04 18:41:48
Won't this move the unzipped directory adt-bundle-
Raphael Kubo da Costa (rakuco)
2013/10/04 19:04:19
This function is only called if src/android_emulat
navabi
2013/10/04 19:11:58
Ah! Right. That looks good.
| |
82 finally: | |
83 os.unlink('/tmp/sdk.zip') | |
84 | |
85 | |
79 def InstallKVM(): | 86 def InstallKVM(): |
80 """Installs KVM packages.""" | 87 """Installs KVM packages.""" |
81 rc = cmd_helper.RunCmd(['sudo', 'apt-get', 'install', 'kvm']) | 88 rc = cmd_helper.RunCmd(['sudo', 'apt-get', 'install', 'kvm']) |
82 if rc: | 89 if rc: |
83 logging.critical('ERROR: Did not install KVM. Make sure hardware ' | 90 logging.critical('ERROR: Did not install KVM. Make sure hardware ' |
84 'virtualization is enabled in BIOS (i.e. Intel VT-x or ' | 91 'virtualization is enabled in BIOS (i.e. Intel VT-x or ' |
85 'AMD SVM).') | 92 'AMD SVM).') |
86 # TODO(navabi): Use modprobe kvm-amd on AMD processors. | 93 # TODO(navabi): Use modprobe kvm-amd on AMD processors. |
87 rc = cmd_helper.RunCmd(['sudo', 'modprobe', 'kvm-intel']) | 94 rc = cmd_helper.RunCmd(['sudo', 'modprobe', 'kvm-intel']) |
88 if rc: | 95 if rc: |
89 logging.critical('ERROR: Did not add KVM module to Linux Kernal. Make sure ' | 96 logging.critical('ERROR: Did not add KVM module to Linux Kernal. Make sure ' |
90 'hardware virtualization is enabled in BIOS.') | 97 'hardware virtualization is enabled in BIOS.') |
91 # Now check to ensure KVM acceleration can be used. | 98 # Now check to ensure KVM acceleration can be used. |
92 rc = cmd_helper.RunCmd(['kvm-ok']) | 99 rc = cmd_helper.RunCmd(['kvm-ok']) |
93 if rc: | 100 if rc: |
94 logging.critical('ERROR: Can not use KVM acceleration. Make sure hardware ' | 101 logging.critical('ERROR: Can not use KVM acceleration. Make sure hardware ' |
95 'virtualization is enabled in BIOS (i.e. Intel VT-x or ' | 102 'virtualization is enabled in BIOS (i.e. Intel VT-x or ' |
96 'AMD SVM).') | 103 'AMD SVM).') |
97 | 104 |
98 | 105 |
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 | |
114 def GetX86Image(): | 106 def GetX86Image(): |
115 """Download x86 system image from Intel's website.""" | 107 """Download x86 system image from Intel's website.""" |
116 logging.info('Download x86 system image directory into sdk directory.') | 108 logging.info('Download x86 system image directory into sdk directory.') |
117 try: | 109 try: |
118 cmd_helper.RunCmd(['curl', '-o', '/tmp/x86_img.zip', X86_IMG_URL]) | 110 cmd_helper.RunCmd(['curl', '-o', '/tmp/x86_img.zip', X86_IMG_URL]) |
119 rc = cmd_helper.RunCmd(['unzip', '-o', '/tmp/x86_img.zip', '-d', '/tmp/']) | 111 rc = cmd_helper.RunCmd(['unzip', '-o', '/tmp/x86_img.zip', '-d', '/tmp/']) |
120 if rc: | 112 if rc: |
121 raise Exception('ERROR: Could not download/unzip image zip.') | 113 raise Exception('ERROR: Could not download/unzip image zip.') |
122 sys_imgs = os.path.join(constants.EMULATOR_SDK_ROOT, 'android_tools', 'sdk', | 114 sys_imgs = os.path.join(constants.EMULATOR_SDK_ROOT, 'sdk', |
123 'system-images', API_TARGET, 'x86') | 115 'system-images', API_TARGET, 'x86') |
124 shutil.move('/tmp/x86', sys_imgs) | 116 shutil.move('/tmp/x86', sys_imgs) |
125 finally: | 117 finally: |
126 os.unlink('/tmp/x86_img.zip') | 118 os.unlink('/tmp/x86_img.zip') |
127 | 119 |
128 | 120 |
129 def main(argv): | 121 def main(argv): |
130 logging.basicConfig(level=logging.INFO, | 122 logging.basicConfig(level=logging.INFO, |
131 format='# %(asctime)-15s: %(message)s') | 123 format='# %(asctime)-15s: %(message)s') |
132 run_tests_helper.SetLogLevel(verbose_count=1) | 124 run_tests_helper.SetLogLevel(verbose_count=1) |
133 | 125 |
134 if not CheckSDK(): | 126 # Calls below will download emulator SDK and/or system images only if needed. |
135 logging.critical( | 127 if CheckSDK(): |
136 'ERROR: android_tools does not exist. Make sure your .gclient file ' | 128 logging.info('android_emulator_sdk/ already exists, skipping download.') |
137 'contains the right \'target_os\' entry. See ' | 129 else: |
138 'https://code.google.com/p/chromium/wiki/AndroidBuildInstructions for ' | 130 GetSDK() |
139 'more information.') | |
140 return 1 | |
141 | 131 |
142 # Download system images only if needed. | 132 # Download the x86 system image only if needed. |
143 if CheckARMv7Image(): | |
144 logging.info('The ARMv7 image is already present.') | |
145 else: | |
146 GetARMv7Image() | |
147 | |
148 if CheckX86Image(): | 133 if CheckX86Image(): |
149 logging.info('The x86 image is already present.') | 134 logging.info('The x86 image is already present, skipping download.') |
150 else: | 135 else: |
151 GetX86Image() | 136 GetX86Image() |
152 | 137 |
153 # Make sure KVM packages are installed and enabled. | 138 # Make sure KVM packages are installed and enabled. |
154 if CheckKVM(): | 139 if CheckKVM(): |
155 logging.info('KVM already installed and enabled.') | 140 logging.info('KVM already installed and enabled.') |
156 else: | 141 else: |
157 InstallKVM() | 142 InstallKVM() |
158 | 143 |
159 | 144 |
160 if __name__ == '__main__': | 145 if __name__ == '__main__': |
161 sys.exit(main(sys.argv)) | 146 sys.exit(main(sys.argv)) |
OLD | NEW |