"""Argument-less script to select what to run on the buildbots."""
+import filecmp
import os
import shutil
import subprocess
def CallSubProcess(*args, **kwargs):
"""Wrapper around subprocess.call which treats errors as build exceptions."""
- retcode = subprocess.call(*args, **kwargs)
+ with open(os.devnull) as devnull_fd:
+ retcode = subprocess.call(stdin=devnull_fd, *args, **kwargs)
if retcode != 0:
print '@@@STEP_EXCEPTION@@@'
sys.exit(1)
print '@@@BUILD_STEP Initialize CMake checkout@@@'
os.mkdir(CMAKE_DIR)
- CallSubProcess(['git', 'config', '--global', 'user.name', 'trybot'])
- CallSubProcess(['git', 'config', '--global',
- 'user.email', 'chrome-bot@google.com'])
- CallSubProcess(['git', 'config', '--global', 'color.ui', 'false'])
print '@@@BUILD_STEP Sync CMake@@@'
CallSubProcess(
print '@@@BUILD_STEP Clobber Android checkout@@@'
shutil.rmtree(ANDROID_DIR)
- # The release of Android we use is static, so there's no need to do anything
- # if the directory already exists.
- if os.path.isdir(ANDROID_DIR):
+ # (Re)create the directory so that the following steps will succeed.
+ if not os.path.isdir(ANDROID_DIR):
+ os.mkdir(ANDROID_DIR)
+
+ # We use a manifest from the gyp project listing pinned revisions of AOSP to
+ # use, to ensure that we test against a stable target. This needs to be
+ # updated to pick up new build system changes sometimes, so we must test if
+ # it has changed.
+ manifest_filename = 'aosp_manifest.xml'
+ gyp_manifest = os.path.join(BUILDBOT_DIR, manifest_filename)
+ android_manifest = os.path.join(ANDROID_DIR, '.repo', 'manifests',
+ manifest_filename)
+ manifest_is_current = (os.path.isfile(android_manifest) and
+ filecmp.cmp(gyp_manifest, android_manifest))
+ if not manifest_is_current:
+ # It's safe to repeat these steps, so just do them again to make sure we are
+ # in a good state.
+ print '@@@BUILD_STEP Initialize Android checkout@@@'
+ CallSubProcess(
+ ['repo', 'init',
+ '-u', 'https://android.googlesource.com/platform/manifest',
+ '-b', 'master',
+ '-g', 'all,-notdefault,-device,-darwin,-mips,-x86'],
+ cwd=ANDROID_DIR)
+ shutil.copy(gyp_manifest, android_manifest)
+
+ print '@@@BUILD_STEP Sync Android@@@'
+ CallSubProcess(['repo', 'sync', '-j4', '-m', manifest_filename],
+ cwd=ANDROID_DIR)
+
+ # If we already built the system image successfully and didn't sync to a new
+ # version of the source, skip running the build again as it's expensive even
+ # when there's nothing to do.
+ system_img = os.path.join(ANDROID_DIR, 'out', 'target', 'product', 'generic',
+ 'system.img')
+ if manifest_is_current and os.path.isfile(system_img):
return
- print '@@@BUILD_STEP Initialize Android checkout@@@'
- os.mkdir(ANDROID_DIR)
- CallSubProcess(['git', 'config', '--global', 'user.name', 'trybot'])
- CallSubProcess(['git', 'config', '--global',
- 'user.email', 'chrome-bot@google.com'])
- CallSubProcess(['git', 'config', '--global', 'color.ui', 'false'])
- CallSubProcess(
- ['repo', 'init',
- '-u', 'https://android.googlesource.com/platform/manifest',
- '-b', 'android-4.2.1_r1',
- '-g', 'all,-notdefault,-device,-darwin,-mips,-x86'],
- cwd=ANDROID_DIR)
-
- print '@@@BUILD_STEP Sync Android@@@'
- CallSubProcess(['repo', 'sync', '-j4'], cwd=ANDROID_DIR)
-
print '@@@BUILD_STEP Build Android@@@'
CallSubProcess(
['/bin/bash',
def StartAndroidEmulator():
"""Start an android emulator from the built android tree."""
print '@@@BUILD_STEP Start Android emulator@@@'
- android_host_bin = '$ANDROID_HOST_OUT/bin'
+
+ CallSubProcess(['/bin/bash', '-c',
+ '%s && adb kill-server ' % _ANDROID_SETUP],
+ cwd=ANDROID_DIR)
+
+ # If taskset is available, use it to force adbd to run only on one core, as,
+ # sadly, it improves its reliability (see crbug.com/268450).
+ adbd_wrapper = ''
+ with open(os.devnull, 'w') as devnull_fd:
+ if subprocess.call(['which', 'taskset'], stdout=devnull_fd) == 0:
+ adbd_wrapper = 'taskset -c 0'
+ CallSubProcess(['/bin/bash', '-c',
+ '%s && %s adb start-server ' % (_ANDROID_SETUP, adbd_wrapper)],
+ cwd=ANDROID_DIR)
+
subprocess.Popen(
['/bin/bash', '-c',
- '%s && %s/emulator -no-window' % (_ANDROID_SETUP, android_host_bin)],
+ '%s && emulator -no-window' % _ANDROID_SETUP],
cwd=ANDROID_DIR)
CallSubProcess(
['/bin/bash', '-c',
- '%s && %s/adb wait-for-device' % (_ANDROID_SETUP, android_host_bin)],
+ '%s && adb wait-for-device' % _ANDROID_SETUP],
cwd=ANDROID_DIR)