2 # Copyright (c) 2012 Google Inc. 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.
7 """Argument-less script to select what to run on the buildbots."""
17 if sys.platform in ['win32', 'cygwin']:
23 BUILDBOT_DIR = os.path.dirname(os.path.abspath(__file__))
24 TRUNK_DIR = os.path.dirname(BUILDBOT_DIR)
25 ROOT_DIR = os.path.dirname(TRUNK_DIR)
26 ANDROID_DIR = os.path.join(ROOT_DIR, 'android')
27 CMAKE_DIR = os.path.join(ROOT_DIR, 'cmake')
28 CMAKE_BIN_DIR = os.path.join(CMAKE_DIR, 'bin')
29 OUT_DIR = os.path.join(TRUNK_DIR, 'out')
32 def CallSubProcess(*args, **kwargs):
33 """Wrapper around subprocess.call which treats errors as build exceptions."""
34 with open(os.devnull) as devnull_fd:
35 retcode = subprocess.call(stdin=devnull_fd, *args, **kwargs)
37 print '@@@STEP_EXCEPTION@@@'
42 """Build CMake 2.8.8 since the version in Precise is 2.8.7."""
43 if os.environ['BUILDBOT_CLOBBER'] == '1':
44 print '@@@BUILD_STEP Clobber CMake checkout@@@'
45 shutil.rmtree(CMAKE_DIR)
47 # We always build CMake 2.8.8, so no need to do anything
48 # if the directory already exists.
49 if os.path.isdir(CMAKE_DIR):
52 print '@@@BUILD_STEP Initialize CMake checkout@@@'
55 print '@@@BUILD_STEP Sync CMake@@@'
62 'git://cmake.org/cmake.git',
66 print '@@@BUILD_STEP Build CMake@@@'
68 ['/bin/bash', 'bootstrap', '--prefix=%s' % CMAKE_DIR],
71 CallSubProcess( ['make', 'cmake'], cwd=CMAKE_DIR)
74 _ANDROID_SETUP = 'source build/envsetup.sh && lunch full-eng'
77 def PrepareAndroidTree():
78 """Prepare an Android tree to run 'android' format tests."""
79 if os.environ['BUILDBOT_CLOBBER'] == '1':
80 print '@@@BUILD_STEP Clobber Android checkout@@@'
81 shutil.rmtree(ANDROID_DIR)
83 # (Re)create the directory so that the following steps will succeed.
84 if not os.path.isdir(ANDROID_DIR):
87 # We use a manifest from the gyp project listing pinned revisions of AOSP to
88 # use, to ensure that we test against a stable target. This needs to be
89 # updated to pick up new build system changes sometimes, so we must test if
91 manifest_filename = 'aosp_manifest.xml'
92 gyp_manifest = os.path.join(BUILDBOT_DIR, manifest_filename)
93 android_manifest = os.path.join(ANDROID_DIR, '.repo', 'manifests',
95 manifest_is_current = (os.path.isfile(android_manifest) and
96 filecmp.cmp(gyp_manifest, android_manifest))
97 if not manifest_is_current:
98 # It's safe to repeat these steps, so just do them again to make sure we are
100 print '@@@BUILD_STEP Initialize Android checkout@@@'
103 '-u', 'https://android.googlesource.com/platform/manifest',
105 '-g', 'all,-notdefault,-device,-darwin,-mips,-x86'],
107 shutil.copy(gyp_manifest, android_manifest)
109 print '@@@BUILD_STEP Sync Android@@@'
110 CallSubProcess(['repo', 'sync', '-j4', '-m', manifest_filename],
113 # If we already built the system image successfully and didn't sync to a new
114 # version of the source, skip running the build again as it's expensive even
115 # when there's nothing to do.
116 system_img = os.path.join(ANDROID_DIR, 'out', 'target', 'product', 'generic',
118 if manifest_is_current and os.path.isfile(system_img):
121 print '@@@BUILD_STEP Build Android@@@'
124 '-c', '%s && make -j4' % _ANDROID_SETUP],
128 def StartAndroidEmulator():
129 """Start an android emulator from the built android tree."""
130 print '@@@BUILD_STEP Start Android emulator@@@'
132 CallSubProcess(['/bin/bash', '-c',
133 '%s && adb kill-server ' % _ANDROID_SETUP],
136 # If taskset is available, use it to force adbd to run only on one core, as,
137 # sadly, it improves its reliability (see crbug.com/268450).
139 with open(os.devnull, 'w') as devnull_fd:
140 if subprocess.call(['which', 'taskset'], stdout=devnull_fd) == 0:
141 adbd_wrapper = 'taskset -c 0'
142 CallSubProcess(['/bin/bash', '-c',
143 '%s && %s adb start-server ' % (_ANDROID_SETUP, adbd_wrapper)],
148 '%s && emulator -no-window' % _ANDROID_SETUP],
152 '%s && adb wait-for-device' % _ANDROID_SETUP],
156 def StopAndroidEmulator():
157 """Stop all android emulators."""
158 print '@@@BUILD_STEP Stop Android emulator@@@'
159 # If this fails, it's because there is no emulator running.
160 subprocess.call(['pkill', 'emulator.*'])
163 def GypTestFormat(title, format=None, msvs_version=None, tests=[]):
164 """Run the gyp tests for a given format, emitting annotator tags.
166 See annotator docs at:
167 https://sites.google.com/a/chromium.org/dev/developers/testing/chromium-build-infrastructure/buildbot-annotations
169 format: gyp format to test.
171 0 for sucesss, 1 for failure.
176 print '@@@BUILD_STEP ' + title + '@@@'
178 env = os.environ.copy()
180 env['GYP_MSVS_VERSION'] = msvs_version
182 [sys.executable, 'trunk/gyptest.py',
186 '--path', CMAKE_BIN_DIR,
187 '--chdir', 'trunk'] + tests)
188 if format == 'android':
189 # gyptest needs the environment setup from envsetup/lunch in order to build
190 # using the 'android' backend, so this is done in a single shell.
191 retcode = subprocess.call(
193 '-c', '%s && cd %s && %s' % (_ANDROID_SETUP, ROOT_DIR, command)],
194 cwd=ANDROID_DIR, env=env)
196 retcode = subprocess.call(command, cwd=ROOT_DIR, env=env, shell=True)
198 # Emit failure tag, and keep going.
199 print '@@@STEP_FAILURE@@@'
205 # Dump out/ directory.
206 print '@@@BUILD_STEP cleanup@@@'
207 print 'Removing %s...' % OUT_DIR
208 shutil.rmtree(OUT_DIR, ignore_errors=True)
212 # The Android gyp bot runs on linux so this must be tested first.
213 if os.environ['BUILDBOT_BUILDERNAME'] == 'gyp-android':
215 StartAndroidEmulator()
217 retcode += GypTestFormat('android')
219 StopAndroidEmulator()
220 elif sys.platform.startswith('linux'):
221 retcode += GypTestFormat('ninja')
222 retcode += GypTestFormat('make')
224 retcode += GypTestFormat('cmake')
225 elif sys.platform == 'darwin':
226 retcode += GypTestFormat('ninja')
227 retcode += GypTestFormat('xcode')
228 retcode += GypTestFormat('make')
229 elif sys.platform == 'win32':
230 retcode += GypTestFormat('ninja')
231 if os.environ['BUILDBOT_BUILDERNAME'] == 'gyp-win64':
232 retcode += GypTestFormat('msvs-ninja-2013', format='msvs-ninja',
235 'test\generator-output\gyptest-actions.py',
236 'test\generator-output\gyptest-relocate.py',
237 'test\generator-output\gyptest-rules.py'])
238 retcode += GypTestFormat('msvs-2013', format='msvs', msvs_version='2013')
240 raise Exception('Unknown platform')
242 # TODO(bradnelson): once the annotator supports a postscript (section for
243 # after the build proper that could be used for cumulative failures),
244 # use that instead of this. This isolates the final return value so
245 # that it isn't misattributed to the last stage.
246 print '@@@BUILD_STEP failures@@@'
250 if __name__ == '__main__':