buildbot_run.py 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. #!/usr/bin/env python
  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.
  5. """Argument-less script to select what to run on the buildbots."""
  6. import filecmp
  7. import os
  8. import shutil
  9. import subprocess
  10. import sys
  11. if sys.platform in ['win32', 'cygwin']:
  12. EXE_SUFFIX = '.exe'
  13. else:
  14. EXE_SUFFIX = ''
  15. BUILDBOT_DIR = os.path.dirname(os.path.abspath(__file__))
  16. TRUNK_DIR = os.path.dirname(BUILDBOT_DIR)
  17. ROOT_DIR = os.path.dirname(TRUNK_DIR)
  18. ANDROID_DIR = os.path.join(ROOT_DIR, 'android')
  19. CMAKE_DIR = os.path.join(ROOT_DIR, 'cmake')
  20. CMAKE_BIN_DIR = os.path.join(CMAKE_DIR, 'bin')
  21. OUT_DIR = os.path.join(TRUNK_DIR, 'out')
  22. def CallSubProcess(*args, **kwargs):
  23. """Wrapper around subprocess.call which treats errors as build exceptions."""
  24. with open(os.devnull) as devnull_fd:
  25. retcode = subprocess.call(stdin=devnull_fd, *args, **kwargs)
  26. if retcode != 0:
  27. print '@@@STEP_EXCEPTION@@@'
  28. sys.exit(1)
  29. def PrepareCmake():
  30. """Build CMake 2.8.8 since the version in Precise is 2.8.7."""
  31. if os.environ['BUILDBOT_CLOBBER'] == '1':
  32. print '@@@BUILD_STEP Clobber CMake checkout@@@'
  33. shutil.rmtree(CMAKE_DIR)
  34. # We always build CMake 2.8.8, so no need to do anything
  35. # if the directory already exists.
  36. if os.path.isdir(CMAKE_DIR):
  37. return
  38. print '@@@BUILD_STEP Initialize CMake checkout@@@'
  39. os.mkdir(CMAKE_DIR)
  40. print '@@@BUILD_STEP Sync CMake@@@'
  41. CallSubProcess(
  42. ['git', 'clone',
  43. '--depth', '1',
  44. '--single-branch',
  45. '--branch', 'v2.8.8',
  46. '--',
  47. 'git://cmake.org/cmake.git',
  48. CMAKE_DIR],
  49. cwd=CMAKE_DIR)
  50. print '@@@BUILD_STEP Build CMake@@@'
  51. CallSubProcess(
  52. ['/bin/bash', 'bootstrap', '--prefix=%s' % CMAKE_DIR],
  53. cwd=CMAKE_DIR)
  54. CallSubProcess( ['make', 'cmake'], cwd=CMAKE_DIR)
  55. _ANDROID_SETUP = 'source build/envsetup.sh && lunch full-eng'
  56. def PrepareAndroidTree():
  57. """Prepare an Android tree to run 'android' format tests."""
  58. if os.environ['BUILDBOT_CLOBBER'] == '1':
  59. print '@@@BUILD_STEP Clobber Android checkout@@@'
  60. shutil.rmtree(ANDROID_DIR)
  61. # (Re)create the directory so that the following steps will succeed.
  62. if not os.path.isdir(ANDROID_DIR):
  63. os.mkdir(ANDROID_DIR)
  64. # We use a manifest from the gyp project listing pinned revisions of AOSP to
  65. # use, to ensure that we test against a stable target. This needs to be
  66. # updated to pick up new build system changes sometimes, so we must test if
  67. # it has changed.
  68. manifest_filename = 'aosp_manifest.xml'
  69. gyp_manifest = os.path.join(BUILDBOT_DIR, manifest_filename)
  70. android_manifest = os.path.join(ANDROID_DIR, '.repo', 'manifests',
  71. manifest_filename)
  72. manifest_is_current = (os.path.isfile(android_manifest) and
  73. filecmp.cmp(gyp_manifest, android_manifest))
  74. if not manifest_is_current:
  75. # It's safe to repeat these steps, so just do them again to make sure we are
  76. # in a good state.
  77. print '@@@BUILD_STEP Initialize Android checkout@@@'
  78. CallSubProcess(
  79. ['repo', 'init',
  80. '-u', 'https://android.googlesource.com/platform/manifest',
  81. '-b', 'master',
  82. '-g', 'all,-notdefault,-device,-darwin,-mips,-x86'],
  83. cwd=ANDROID_DIR)
  84. shutil.copy(gyp_manifest, android_manifest)
  85. print '@@@BUILD_STEP Sync Android@@@'
  86. CallSubProcess(['repo', 'sync', '-j4', '-m', manifest_filename],
  87. cwd=ANDROID_DIR)
  88. # If we already built the system image successfully and didn't sync to a new
  89. # version of the source, skip running the build again as it's expensive even
  90. # when there's nothing to do.
  91. system_img = os.path.join(ANDROID_DIR, 'out', 'target', 'product', 'generic',
  92. 'system.img')
  93. if manifest_is_current and os.path.isfile(system_img):
  94. return
  95. print '@@@BUILD_STEP Build Android@@@'
  96. CallSubProcess(
  97. ['/bin/bash',
  98. '-c', '%s && make -j4' % _ANDROID_SETUP],
  99. cwd=ANDROID_DIR)
  100. def StartAndroidEmulator():
  101. """Start an android emulator from the built android tree."""
  102. print '@@@BUILD_STEP Start Android emulator@@@'
  103. CallSubProcess(['/bin/bash', '-c',
  104. '%s && adb kill-server ' % _ANDROID_SETUP],
  105. cwd=ANDROID_DIR)
  106. # If taskset is available, use it to force adbd to run only on one core, as,
  107. # sadly, it improves its reliability (see crbug.com/268450).
  108. adbd_wrapper = ''
  109. with open(os.devnull, 'w') as devnull_fd:
  110. if subprocess.call(['which', 'taskset'], stdout=devnull_fd) == 0:
  111. adbd_wrapper = 'taskset -c 0'
  112. CallSubProcess(['/bin/bash', '-c',
  113. '%s && %s adb start-server ' % (_ANDROID_SETUP, adbd_wrapper)],
  114. cwd=ANDROID_DIR)
  115. subprocess.Popen(
  116. ['/bin/bash', '-c',
  117. '%s && emulator -no-window' % _ANDROID_SETUP],
  118. cwd=ANDROID_DIR)
  119. CallSubProcess(
  120. ['/bin/bash', '-c',
  121. '%s && adb wait-for-device' % _ANDROID_SETUP],
  122. cwd=ANDROID_DIR)
  123. def StopAndroidEmulator():
  124. """Stop all android emulators."""
  125. print '@@@BUILD_STEP Stop Android emulator@@@'
  126. # If this fails, it's because there is no emulator running.
  127. subprocess.call(['pkill', 'emulator.*'])
  128. def GypTestFormat(title, format=None, msvs_version=None, tests=[]):
  129. """Run the gyp tests for a given format, emitting annotator tags.
  130. See annotator docs at:
  131. https://sites.google.com/a/chromium.org/dev/developers/testing/chromium-build-infrastructure/buildbot-annotations
  132. Args:
  133. format: gyp format to test.
  134. Returns:
  135. 0 for sucesss, 1 for failure.
  136. """
  137. if not format:
  138. format = title
  139. print '@@@BUILD_STEP ' + title + '@@@'
  140. sys.stdout.flush()
  141. env = os.environ.copy()
  142. if msvs_version:
  143. env['GYP_MSVS_VERSION'] = msvs_version
  144. command = ' '.join(
  145. [sys.executable, 'gyp/gyptest.py',
  146. '--all',
  147. '--passed',
  148. '--format', format,
  149. '--path', CMAKE_BIN_DIR,
  150. '--chdir', 'gyp'] + tests)
  151. if format == 'android':
  152. # gyptest needs the environment setup from envsetup/lunch in order to build
  153. # using the 'android' backend, so this is done in a single shell.
  154. retcode = subprocess.call(
  155. ['/bin/bash',
  156. '-c', '%s && cd %s && %s' % (_ANDROID_SETUP, ROOT_DIR, command)],
  157. cwd=ANDROID_DIR, env=env)
  158. else:
  159. retcode = subprocess.call(command, cwd=ROOT_DIR, env=env, shell=True)
  160. if retcode:
  161. # Emit failure tag, and keep going.
  162. print '@@@STEP_FAILURE@@@'
  163. return 1
  164. return 0
  165. def GypBuild():
  166. # Dump out/ directory.
  167. print '@@@BUILD_STEP cleanup@@@'
  168. print 'Removing %s...' % OUT_DIR
  169. shutil.rmtree(OUT_DIR, ignore_errors=True)
  170. print 'Done.'
  171. retcode = 0
  172. # The Android gyp bot runs on linux so this must be tested first.
  173. if os.environ['BUILDBOT_BUILDERNAME'] == 'gyp-android':
  174. PrepareAndroidTree()
  175. StartAndroidEmulator()
  176. try:
  177. retcode += GypTestFormat('android')
  178. finally:
  179. StopAndroidEmulator()
  180. elif sys.platform.startswith('linux'):
  181. retcode += GypTestFormat('ninja')
  182. retcode += GypTestFormat('make')
  183. PrepareCmake()
  184. retcode += GypTestFormat('cmake')
  185. elif sys.platform == 'darwin':
  186. retcode += GypTestFormat('ninja')
  187. retcode += GypTestFormat('xcode')
  188. retcode += GypTestFormat('make')
  189. elif sys.platform == 'win32':
  190. retcode += GypTestFormat('ninja')
  191. if os.environ['BUILDBOT_BUILDERNAME'] == 'gyp-win64':
  192. retcode += GypTestFormat('msvs-ninja-2013', format='msvs-ninja',
  193. msvs_version='2013',
  194. tests=[
  195. r'test\generator-output\gyptest-actions.py',
  196. r'test\generator-output\gyptest-relocate.py',
  197. r'test\generator-output\gyptest-rules.py'])
  198. retcode += GypTestFormat('msvs-2013', format='msvs', msvs_version='2013')
  199. else:
  200. raise Exception('Unknown platform')
  201. if retcode:
  202. # TODO(bradnelson): once the annotator supports a postscript (section for
  203. # after the build proper that could be used for cumulative failures),
  204. # use that instead of this. This isolates the final return value so
  205. # that it isn't misattributed to the last stage.
  206. print '@@@BUILD_STEP failures@@@'
  207. sys.exit(retcode)
  208. if __name__ == '__main__':
  209. GypBuild()