buildbot_run.py 4.1 KB

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