Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(702)

Unified Diff: build/android/install-emulator-deps.py

Issue 12407004: Add script to download SDK, system images and create and start AVDs for testing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed frankf's comments. Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: build/android/install-emulator-deps.py
diff --git a/build/android/install-emulator-deps.py b/build/android/install-emulator-deps.py
new file mode 100644
index 0000000000000000000000000000000000000000..e0f2bfce3eb6d52a48e7b19cddf5caaa9db84e37
--- /dev/null
+++ b/build/android/install-emulator-deps.py
@@ -0,0 +1,170 @@
+#!/usr/bin/env python
+# Copyright (c) 2013 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Installs deps for using SDK emulator for testing.
+
+The script will download the SDK and system images, if they are not present, and
+install and enable KVM, if virtualization has been enabled in the BIOS.
+"""
+
+
+import logging
+import os
+import shutil
+import subprocess
+import sys
+
+from pylib import cmd_helper
+from pylib import constants
+from pylib.utils import run_tests_helper
+
+# From the Android Developer's website.
+SDK_BASE_URL = 'http://dl.google.com/android/adt'
+SDK_ZIP = 'adt-bundle-linux-x86_64-20130219.zip'
+
+# Android x86 system image from the Intel website:
+# http://software.intel.com/en-us/articles/intel-eula-x86-android-4-2-jelly-bean-bin
+X86_IMG_URL = 'http://download-software.intel.com/sites/landingpage/android/sysimg_x86-17_r01.zip'
+
+# Android API level
+API_TARGET = 'android-%s' % constants.ANDROID_SDK_VERSION
+
+
+def CheckSDK():
+ """Check if SDK is already installed.
+
+ Returns:
+ true if android_tools directory exists in current directory.
+ """
+ return os.path.exists(os.path.join(os.getcwd(), 'android_tools'))
frankf 2013/03/27 05:16:08 can this be relative to __FILE__ instead of getcwd
navabi 2013/03/27 17:13:36 Done.
+
+
+def CheckX86Image():
+ """Check if Android system images have been installed.
+
+ Returns:
+ true if android_tools/sdk/system-images directory exists.
+ """
+ return os.path.exists(os.path.join(os.getcwd(), 'android_tools', 'sdk',
+ 'system-images', API_TARGET, 'x86'))
+
+
+def CheckKVM():
+ """Check if KVM is enabled.
+
+ Returns:
+ true if kvm-ok returns 0 (already enabled)
+ """
+ rc = cmd_helper.RunCommand(['kvm-ok'])
+ return not rc
+
+
+def GetSDK():
+ """Download the SDK and unzip in android_tools directory.
+
+ Returns:
+ true if SDK successfully downloaded, false otherwise
frankf 2013/03/27 05:16:08 nit: True
navabi 2013/03/27 17:13:36 Done.
+ """
+ logging.info('Download Android SDK.')
+ sdk_url = '%s/%s' % (SDK_BASE_URL, SDK_ZIP)
+ try:
+ cmd_helper.RunCommand(['curl', '-o', '/tmp/sdk.zip', sdk_url])
+ rc = cmd_helper.RunCommand(['unzip', '-o', '/tmp/sdk.zip', '-d', '/tmp/'])
+ if rc:
+ logging.critical('ERROR: could not download/unzip Android SDK.')
+ raise
+ # Get the name of the sub-directory that everything will be extracted to.
+ dirname, _ = os.path.splitext(SDK_ZIP)
+ zip_dir = '/tmp/%s' % dirname
+ # Move the extracted directory to the current working directory.
+ shutil.move(zip_dir, 'android_tools')
+ except:
+ logging.critical('ERROR: Could not download Android SDK.')
+ return False
frankf 2013/03/27 05:16:08 It's pythonic to raise exceptions instead of retur
navabi 2013/03/27 17:13:36 Done.
+ finally:
+ os.unlink('/tmp/sdk.zip')
+ return True
+
+
+def InstallKVM():
+ """Installs KVM packages."""
+ rc = cmd_helper.RunCommand(['sudo', 'apt-get', 'install', 'kvm'])
+ if rc:
+ logging.critical('ERROR: Did not install KVM. Make sure hardware '
+ 'virtualization is enabled in BIOS (i.e. Intel VT-x or '
+ 'AMD SVM).')
+ # TODO(navabi): Use modprobe kvm-amd on AMD processors.
+ rc = cmd_helper.RunCommand(['sudo', 'modprobe', 'kvm-intel'])
+ if rc:
+ logging.critical('ERROR: Did not add KVM module to Linux Kernal. Make sure '
+ 'hardware virtualization is enabled in BIOS.')
+ # Now check to ensure KVM acceleration can be used.
+ rc = cmd_helper.RunCommand(['kvm-ok'])
+ if rc:
+ logging.critical('ERROR: Can not use KVM acceleration. Make sure hardware '
+ 'virtualization is enabled in BIOS (i.e. Intel VT-x or '
+ 'AMD SVM).')
+
+
+def GetX86Image():
+ """Download x86 system image from Intel's website.
+
+ Returns:
+ true if x86 system image successfully downloaded, false otherwise
+ """
+ logging.info('Download x86 system image directory into sdk directory.')
+ try:
+ cmd_helper.RunCommand(['curl', '-o', '/tmp/x86_img.zip', X86_IMG_URL])
+ rc = cmd_helper.RunCommand(['unzip', '-o', '/tmp/x86_img.zip', '-d',
+ '/tmp/'])
+ if rc:
+ logging.critical('ERROR: Could not download/unzip image zip.')
+ raise
+ sys_imgs = os.path.join(os.getcwd(), 'android_tools', 'sdk',
+ 'system-images', API_TARGET, 'x86')
+ shutil.move('/tmp/x86', sys_imgs)
+ except:
+ logging.critical('ERROR: Could not download x86 image.')
+ return False
+ finally:
+ os.unlink('/tmp/x86_img.zip')
+ return True
+
+
+def main(argv):
+ # Run script from parent directory of chrome checkout, because we do not want
+ # to put SDK and system images into chrome checkout.
+ new_cwd = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..',
+ '..', '..')
+ os.chdir(new_cwd)
+
+ # The location of the SDK used to launch the emulator
+ emulator_sdk = os.path.join(new_cwd, 'android_tools', 'sdk')
+ os.environ['ANDROID_SDK_ROOT'] = emulator_sdk
+
+ logging.basicConfig(level=logging.INFO,
+ format='# %(asctime)-15s: %(message)s')
+ run_tests_helper.SetLogLevel(verbose_count=1)
+
+ # Calls below will download emulator SDK and/or system images only if needed.
+ if CheckSDK():
+ logging.info('android_tools directory already exists (not downloading).')
+ elif not GetSDK():
+ # Can not continue without downloading SDK.
+ return 1
+ if CheckX86Image():
+ logging.info('system-images directory already exists.')
+ else:
+ GetX86Image()
+
+ # Make sure KVM packages are installed and enabled.
+ if CheckKVM():
+ logging.info('KVM already installed and enabled.')
+ else:
+ InstallKVM()
+
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv))

Powered by Google App Engine
This is Rietveld 408576698