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 100755 |
index 0000000000000000000000000000000000000000..c8b383004fc0c574d7583c0ba48b543de53e4c92 |
--- /dev/null |
+++ b/build/android/install-emulator-deps.py |
@@ -0,0 +1,179 @@ |
+#!/usr/bin/env python |
+# Copyright (c) 2012 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 subprocess |
+import shutil |
pasko-google - do not use
2013/03/21 12:08:37
import order needs tiny treatment
navabi
2013/03/26 21:27:30
Done.
|
+import sys |
+ |
+ |
+# From the Android Developer's website. |
+SDK_BASE_URL = 'http://dl.google.com/android/adt' |
+SDK_ZIP = 'adt-bundle-linux-x86_64-20130219.zip' |
+ |
+# 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-17' |
+ |
+ |
+def RunCommand(args): |
+ """Execute a command and return stdout and stderr. |
+ |
+ Args: |
+ args: list of the command and the args to the command. |
+ |
+ Returns: |
+ (output, stderr, rc): stdout and stderr and return code |
+ """ |
+ logging.info('Running command: %s' % args) |
+ proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
+ output, stderr = proc.communicate() |
+ rc = proc.returncode |
+ return (str(output).strip(), stderr, rc) |
+ |
+ |
+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')) |
+ |
+ |
+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) = 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 |
+ """ |
+ logging.info('Download Android SDK.') |
+ sdk_url = '%s/%s' % (SDK_BASE_URL, SDK_ZIP) |
+ try: |
+ # RunCommand(['curl', '-o', '/tmp/sdk.zip', sdk_url]) |
pasko-google - do not use
2013/03/21 12:08:37
please don't forget to uncomment before committing
navabi
2013/03/26 21:27:30
Done.
|
+ (_, stderr, rc) = RunCommand(['unzip', '-o', '/tmp/sdk.zip', '-d', '/tmp/']) |
pasko-google - do not use
2013/03/21 12:08:37
/tmp/sdk.zip is never removed, should probably do
navabi
2013/03/26 21:27:30
Done.
|
+ if rc: |
+ print stderr |
+ 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 |
+ return True |
+ |
+ |
+def InstallKVM(): |
+ """Installs KVM packages.""" |
+ (output, stderr, rc) = RunCommand(['sudo', 'apt-get', 'install', 'kvm']) |
+ if rc: |
+ logging.critical('ERROR: Did not install KVM. Make sure Intel KVM is \ |
pasko-google - do not use
2013/03/21 12:08:37
This is not necessarily Intel, there is analogous
digit1
2013/03/21 12:48:53
This, also the BIOS will have no mention of KVM, w
navabi
2013/03/26 21:27:30
Done.
|
+enabled in BIOS.') |
+ print '%s\n%s' % output, stderr |
+ (output, stderr, rc) = RunCommand(['sudo', 'modprobe', 'kvm-intel']) |
pasko-google - do not use
2013/03/21 12:08:37
please put a TODO(navabi): Use modprobe kvm-amd on
navabi
2013/03/26 21:27:30
Done.
|
+ if rc: |
+ logging.critical('ERROR: Did not add KVM module to Linux Kernal. Make sure \ |
+Intel KVM is enabled in BIOS.') |
pasko-google - do not use
2013/03/21 12:08:37
please no carriage return escaping here and below,
navabi
2013/03/26 21:27:30
Done.
|
+ print '%s\n%s' % output, stderr |
+ # Now check to ensure KVM acceleration can be used. |
+ (output, stderr, rc) = RunCommand(['kvm-ok']) |
+ if rc: |
+ logging.critical('ERROR: Can not use KVM acceleration. Make sure Intel KVM \ |
+is enabled in BIOS.') |
pasko-google - do not use
2013/03/21 12:08:37
same thing about replacing 'Intel KVM' with 'hardw
navabi
2013/03/26 21:27:30
Done.
|
+ print '%s\n%s' % output, stderr |
+ |
+ |
+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: |
+ RunCommand(['curl', '-o', '/tmp/x86_img.zip', X86_IMG_URL]) |
pasko-google - do not use
2013/03/21 12:08:37
please also remove /tmp/x86_img.zip:
finally:
os
navabi
2013/03/26 21:27:30
Done.
|
+ (_, stderr, rc) = RunCommand(['unzip', '-o', '/tmp/x86_img.zip', '-d', |
+ '/tmp/']) |
+ if rc: |
+ print stderr |
+ 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 |
+ 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') |
+ logging.root.setLevel(logging.INFO) |
+ |
+ # 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(): |
pasko-google - do not use
2013/03/21 12:08:37
I would like to move it to the first part of work
navabi
2013/03/26 21:27:30
Since the script currently only support Intel virt
|
+ logging.info('KVM already installed and enabled.') |
+ else: |
+ InstallKVM() |
+ |
+ |
+if __name__ == '__main__': |
+ sys.exit(main(sys.argv)) |