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
4 # found in the LICENSE file.
6 """Installs deps for using SDK emulator for testing.
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.
18 from pylib
import cmd_helper
19 from pylib
import constants
20 from pylib
.utils
import run_tests_helper
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'
26 # 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
28 X86_IMG_URL
= 'http://download-software.intel.com/sites/landingpage/android/sysimg_x86-17_r01.zip'
31 API_TARGET
= 'android-%s' % constants
.ANDROID_SDK_VERSION
35 """Check if SDK is already installed.
38 True if android_tools directory exists in current directory.
40 return os
.path
.exists(os
.path
.join(constants
.EMULATOR_SDK_ROOT
,
45 """Check if Android system images have been installed.
48 True if android_tools/sdk/system-images directory exists.
50 return os
.path
.exists(os
.path
.join(constants
.EMULATOR_SDK_ROOT
,
51 'android_tools', 'sdk', 'system-images',
56 """Check if KVM is enabled.
59 True if kvm-ok returns 0 (already enabled)
62 return not cmd_helper
.RunCmd(['kvm-ok'])
64 logging
.info('kvm-ok not installed')
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
)
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/'])
77 logging
.critical('ERROR: could not download/unzip Android SDK.')
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
)
86 os
.unlink('/tmp/sdk.zip')
90 """Installs KVM packages."""
91 rc
= cmd_helper
.RunCmd(['sudo', 'apt-get', 'install', 'kvm'])
93 logging
.critical('ERROR: Did not install KVM. Make sure hardware '
94 'virtualization is enabled in BIOS (i.e. Intel VT-x or '
96 # TODO(navabi): Use modprobe kvm-amd on AMD processors.
97 rc
= cmd_helper
.RunCmd(['sudo', 'modprobe', 'kvm-intel'])
99 logging
.critical('ERROR: Did not add KVM module to Linux Kernal. Make sure '
100 'hardware virtualization is enabled in BIOS.')
101 # Now check to ensure KVM acceleration can be used.
102 rc
= cmd_helper
.RunCmd(['kvm-ok'])
104 logging
.critical('ERROR: Can not use KVM acceleration. Make sure hardware '
105 'virtualization is enabled in BIOS (i.e. Intel VT-x or '
110 """Download x86 system image from Intel's website."""
111 logging
.info('Download x86 system image directory into sdk directory.')
113 cmd_helper
.RunCmd(['curl', '-o', '/tmp/x86_img.zip', X86_IMG_URL
])
114 rc
= cmd_helper
.RunCmd(['unzip', '-o', '/tmp/x86_img.zip', '-d', '/tmp/'])
116 logging
.critical('ERROR: Could not download/unzip image zip.')
118 sys_imgs
= os
.path
.join(constants
.EMULATOR_SDK_ROOT
, 'android_tools', 'sdk',
119 'system-images', API_TARGET
, 'x86')
120 shutil
.move('/tmp/x86', sys_imgs
)
122 os
.unlink('/tmp/x86_img.zip')
126 logging
.basicConfig(level
=logging
.INFO
,
127 format
='# %(asctime)-15s: %(message)s')
128 run_tests_helper
.SetLogLevel(verbose_count
=1)
130 # Calls below will download emulator SDK and/or system images only if needed.
132 logging
.info('android_tools directory already exists (not downloading).')
136 logging
.info('Emulator deps for ARM emulator complete.')
139 logging
.info('system-images directory already exists.')
143 # Make sure KVM packages are installed and enabled.
145 logging
.info('KVM already installed and enabled.')
150 if __name__
== '__main__':
151 sys
.exit(main(sys
.argv
))