buildbot_run.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. from __future__ import print_function
  7. import os
  8. import shutil
  9. import subprocess
  10. import sys
  11. BUILDBOT_DIR = os.path.dirname(os.path.abspath(__file__))
  12. TRUNK_DIR = os.path.dirname(BUILDBOT_DIR)
  13. ROOT_DIR = os.path.dirname(TRUNK_DIR)
  14. CMAKE_DIR = os.path.join(ROOT_DIR, 'cmake')
  15. CMAKE_BIN_DIR = os.path.join(CMAKE_DIR, 'bin')
  16. OUT_DIR = os.path.join(TRUNK_DIR, 'out')
  17. def CallSubProcess(*args, **kwargs):
  18. """Wrapper around subprocess.call which treats errors as build exceptions."""
  19. with open(os.devnull) as devnull_fd:
  20. retcode = subprocess.call(stdin=devnull_fd, *args, **kwargs)
  21. if retcode != 0:
  22. print('@@@STEP_EXCEPTION@@@')
  23. sys.exit(1)
  24. def PrepareCmake():
  25. """Build CMake 2.8.8 since the version in Precise is 2.8.7."""
  26. if os.environ['BUILDBOT_CLOBBER'] == '1':
  27. print('@@@BUILD_STEP Clobber CMake checkout@@@')
  28. shutil.rmtree(CMAKE_DIR)
  29. # We always build CMake 2.8.8, so no need to do anything
  30. # if the directory already exists.
  31. if os.path.isdir(CMAKE_DIR):
  32. return
  33. print('@@@BUILD_STEP Initialize CMake checkout@@@')
  34. os.mkdir(CMAKE_DIR)
  35. print('@@@BUILD_STEP Sync CMake@@@')
  36. CallSubProcess(
  37. ['git', 'clone',
  38. '--depth', '1',
  39. '--single-branch',
  40. '--branch', 'v2.8.8',
  41. '--',
  42. 'git://cmake.org/cmake.git',
  43. CMAKE_DIR],
  44. cwd=CMAKE_DIR)
  45. print('@@@BUILD_STEP Build CMake@@@')
  46. CallSubProcess(
  47. ['/bin/bash', 'bootstrap', '--prefix=%s' % CMAKE_DIR],
  48. cwd=CMAKE_DIR)
  49. CallSubProcess( ['make', 'cmake'], cwd=CMAKE_DIR)
  50. def GypTestFormat(title, format=None, msvs_version=None, tests=[]):
  51. """Run the gyp tests for a given format, emitting annotator tags.
  52. See annotator docs at:
  53. https://sites.google.com/a/chromium.org/dev/developers/testing/chromium-build-infrastructure/buildbot-annotations
  54. Args:
  55. format: gyp format to test.
  56. Returns:
  57. 0 for sucesss, 1 for failure.
  58. """
  59. if not format:
  60. format = title
  61. print('@@@BUILD_STEP ' + title + '@@@')
  62. sys.stdout.flush()
  63. env = os.environ.copy()
  64. if msvs_version:
  65. env['GYP_MSVS_VERSION'] = msvs_version
  66. command = ' '.join(
  67. [sys.executable, 'gyp/gyptest.py',
  68. '--all',
  69. '--passed',
  70. '--format', format,
  71. '--path', CMAKE_BIN_DIR,
  72. '--chdir', 'gyp'] + tests)
  73. retcode = subprocess.call(command, cwd=ROOT_DIR, env=env, shell=True)
  74. if retcode:
  75. # Emit failure tag, and keep going.
  76. print('@@@STEP_FAILURE@@@')
  77. return 1
  78. return 0
  79. def GypBuild():
  80. # Dump out/ directory.
  81. print('@@@BUILD_STEP cleanup@@@')
  82. print('Removing %s...' % OUT_DIR)
  83. shutil.rmtree(OUT_DIR, ignore_errors=True)
  84. print('Done.')
  85. retcode = 0
  86. if sys.platform.startswith('linux'):
  87. retcode += GypTestFormat('ninja')
  88. retcode += GypTestFormat('make')
  89. PrepareCmake()
  90. retcode += GypTestFormat('cmake')
  91. elif sys.platform == 'darwin':
  92. retcode += GypTestFormat('ninja')
  93. retcode += GypTestFormat('xcode')
  94. retcode += GypTestFormat('make')
  95. elif sys.platform == 'win32':
  96. retcode += GypTestFormat('ninja')
  97. if os.environ['BUILDBOT_BUILDERNAME'] == 'gyp-win64':
  98. retcode += GypTestFormat('msvs-ninja-2013', format='msvs-ninja',
  99. msvs_version='2013',
  100. tests=[
  101. r'test\generator-output\gyptest-actions.py',
  102. r'test\generator-output\gyptest-relocate.py',
  103. r'test\generator-output\gyptest-rules.py'])
  104. retcode += GypTestFormat('msvs-2013', format='msvs', msvs_version='2013')
  105. else:
  106. raise Exception('Unknown platform')
  107. if retcode:
  108. # TODO(bradnelson): once the annotator supports a postscript (section for
  109. # after the build proper that could be used for cumulative failures),
  110. # use that instead of this. This isolates the final return value so
  111. # that it isn't misattributed to the last stage.
  112. print('@@@BUILD_STEP failures@@@')
  113. sys.exit(retcode)
  114. if __name__ == '__main__':
  115. GypBuild()