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