| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 2 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 3 # for details. All rights reserved. Use of this source code is governed by a | 3 # for details. All rights reserved. Use of this source code is governed by a |
| 4 # BSD-style license that can be found in the LICENSE file. | 4 # BSD-style license that can be found in the LICENSE file. |
| 5 | 5 |
| 6 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 6 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 7 # Use of this source code is governed by a BSD-style license that can be | 7 # Use of this source code is governed by a BSD-style license that can be |
| 8 # found in the LICENSE file. | 8 # found in the LICENSE file. |
| 9 | 9 |
| 10 """Dart client buildbot steps | 10 """Dart client buildbot steps |
| 11 | 11 |
| 12 Compiles dart client apps with dartc, and run the client tests both in headless | 12 Calls a script in tools/bots whose name is based on the name of the bot. |
| 13 chromium and headless dartium. | 13 |
| 14 """ | 14 """ |
| 15 | 15 |
| 16 import imp | 16 import imp |
| 17 import os | 17 import os |
| 18 import re | 18 import re |
| 19 import socket | 19 import socket |
| 20 import subprocess | 20 import subprocess |
| 21 import sys | 21 import sys |
| 22 | 22 |
| 23 BUILDER_NAME = 'BUILDBOT_BUILDERNAME' | 23 BUILDER_NAME = 'BUILDBOT_BUILDERNAME' |
| 24 BUILDER_CLOBBER = 'BUILDBOT_CLOBBER' | 24 BUILDER_CLOBBER = 'BUILDBOT_CLOBBER' |
| 25 REVISION = 'BUILDBOT_REVISION' | |
| 26 | 25 |
| 27 # latest dartium location | 26 def GetName(): |
| 28 DARTIUM_VERSION_FILE = 'client/tests/drt/LAST_VERSION' | 27 """Returns the name of the bot. |
| 29 DARTIUM_V_MATCHER = ( | |
| 30 'gs://dartium-archive/[^/]*/dartium-\w*-inc-([0-9]*).([0-9]*).zip') | |
| 31 | |
| 32 def GetUtils(): | |
| 33 '''Dynamically load the tools/utils.py python module.''' | |
| 34 dart_dir = os.path.abspath(os.path.join(__file__, '..', '..', '..')) | |
| 35 return imp.load_source('utils', os.path.join(dart_dir, 'tools', 'utils.py')) | |
| 36 | |
| 37 utils = GetUtils() | |
| 38 | |
| 39 def GetBuildInfo(): | |
| 40 """Returns a tuple (name, version, mode) where: | |
| 41 - name: A name for the build - the buildbot host if a buildbot. | |
| 42 - version: A version string corresponding to this build. | |
| 43 """ | 28 """ |
| 44 name = None | 29 name = None |
| 45 version = None | |
| 46 | |
| 47 # Populate via builder environment variables. | 30 # Populate via builder environment variables. |
| 48 name = os.environ.get(BUILDER_NAME) | 31 name = os.environ.get(BUILDER_NAME) |
| 49 version = os.environ.get(REVISION) | |
| 50 | 32 |
| 51 # Fall back if not on builder. | 33 # Fall back if not on builder. |
| 52 if not name: | 34 if not name: |
| 53 name = socket.gethostname().split('.')[0] | 35 name = socket.gethostname().split('.')[0] |
| 54 if not version: | 36 return name |
| 55 # In Windows we need to run in the shell, so that we have all the | |
| 56 # environment variables available. | |
| 57 pipe = subprocess.Popen( | |
| 58 ['svnversion', '-n'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, | |
| 59 shell=True) | |
| 60 output = pipe.communicate() | |
| 61 if pipe.returncode == 0: | |
| 62 version = output[0] | |
| 63 else: | |
| 64 version = 'unknown' | |
| 65 return (name, version) | |
| 66 | |
| 67 def GetOutDir(mode): | |
| 68 ''' | |
| 69 get the location to place the output | |
| 70 | |
| 71 args: | |
| 72 utils - the tools/utils.py module | |
| 73 mode - the mode release or debug | |
| 74 ''' | |
| 75 return utils.GetBuildRoot(utils.GuessOS(), mode, utils.ARCH_GUESS) | |
| 76 | |
| 77 def ProcessTools(mode, name, version): | |
| 78 ''' | |
| 79 build and test the tools | |
| 80 | |
| 81 args: | |
| 82 srcpath - the location of the source code to build | |
| 83 mode - the mode release or debug | |
| 84 version - the svn version of the currently checked out code | |
| 85 ''' | |
| 86 print 'ProcessTools' | |
| 87 | |
| 88 toolsBuildScript = os.path.join('.', 'editor', 'build', 'build.py') | |
| 89 | |
| 90 build_installer = name.startswith('dart-editor-installer') | |
| 91 | |
| 92 # TODO(devoncarew): should we move this into GetBuildInfo()? | |
| 93 # get the latest changed revision from the current repository sub-tree | |
| 94 version = GetLatestChangedRevision() | |
| 95 | |
| 96 outdir = GetOutDir(mode) | |
| 97 cmds = [sys.executable, toolsBuildScript, | |
| 98 '--mode=' + mode, '--revision=' + version, | |
| 99 '--name=' + name, '--out=' + outdir] | |
| 100 if build_installer: | |
| 101 cmds.append('--build-installer') | |
| 102 local_env = EnvironmentWithoutBotoConfig() | |
| 103 #if 'linux' in name: | |
| 104 # javahome = os.path.join(os.path.expanduser('~'), 'jdk1.6.0_25') | |
| 105 # local_env['JAVA_HOME'] = javahome | |
| 106 # local_env['PATH'] = (os.path.join(javahome, 'bin') + | |
| 107 # os.pathsep + local_env['PATH']) | |
| 108 | |
| 109 return subprocess.call(cmds, env=local_env) | |
| 110 | |
| 111 def EnvironmentWithoutBotoConfig(environment=None): | |
| 112 # The buildbot sets AWS_CREDENTIAL_FILE/BOTO_CONFIG to the chromium specific | |
| 113 # file, we use the one in home. | |
| 114 custom_env = dict(environment or os.environ) | |
| 115 if 'BOTO_CONFIG' in custom_env: | |
| 116 del custom_env['BOTO_CONFIG'] | |
| 117 if 'AWS_CREDENTIAL_FILE' in custom_env: | |
| 118 del custom_env['AWS_CREDENTIAL_FILE'] | |
| 119 return custom_env | |
| 120 | 37 |
| 121 def ProcessBot(name, target, custom_env=None): | 38 def ProcessBot(name, target, custom_env=None): |
| 122 ''' | 39 ''' |
| 123 Build and test the named bot target (compiler, android, pub). We look for | 40 Build and test the named bot target (compiler, android, pub). We look for |
| 124 the supporting script in tools/bots/ to run the tests and build. | 41 the supporting script in tools/bots/ to run the tests and build. |
| 125 ''' | 42 ''' |
| 126 print 'Process%s' % target.capitalize() | 43 print 'Process%s' % target.capitalize() |
| 127 has_shell = False | 44 has_shell = False |
| 128 environment = custom_env or os.environ | 45 environment = custom_env or os.environ |
| 129 if '-win' in name: | 46 if '-win' in name: |
| 130 # In Windows we need to run in the shell, so that we have all the | 47 # In Windows we need to run in the shell, so that we have all the |
| 131 # environment variables available. | 48 # environment variables available. |
| 132 has_shell = True | 49 has_shell = True |
| 133 return subprocess.call([sys.executable, | 50 return subprocess.call([sys.executable, |
| 134 os.path.join('tools', 'bots', target + '.py')], | 51 os.path.join('tools', 'bots', target + '.py')], |
| 135 env=environment, shell=has_shell) | 52 env=environment, shell=has_shell) |
| 136 | 53 |
| 137 def FixJavaHome(): | |
| 138 buildbot_javahome = os.getenv('BUILDBOT_JAVA_HOME') | |
| 139 if buildbot_javahome: | |
| 140 current_pwd = os.getenv('PWD') | |
| 141 java_home = os.path.join(current_pwd, buildbot_javahome) | |
| 142 java_bin = os.path.join(java_home, 'bin') | |
| 143 os.environ['JAVA_HOME'] = java_home | |
| 144 os.environ['PATH'] = '%s;%s' % (java_bin, os.environ['PATH']) | |
| 145 | |
| 146 print 'Setting java home to ', java_home | |
| 147 sys.stdout.flush() | |
| 148 | |
| 149 def ClobberBuilder(): | 54 def ClobberBuilder(): |
| 150 """ Clobber the builder before we do the build. | 55 """ Clobber the builder before we do the build. |
| 151 """ | 56 """ |
| 152 cmd = [sys.executable, | 57 cmd = [sys.executable, |
| 153 './tools/clean_output_directory.py'] | 58 './tools/clean_output_directory.py'] |
| 154 print 'Clobbering %s' % (' '.join(cmd)) | 59 print 'Clobbering %s' % (' '.join(cmd)) |
| 155 return subprocess.call(cmd) | 60 return subprocess.call(cmd) |
| 156 | 61 |
| 157 def GetShouldClobber(): | 62 def GetShouldClobber(): |
| 158 return os.environ.get(BUILDER_CLOBBER) == "1" | 63 return os.environ.get(BUILDER_CLOBBER) == "1" |
| 159 | 64 |
| 160 def GetLatestChangedRevision(): | |
| 161 revision = utils.GetSVNRevision() | |
| 162 if not revision: | |
| 163 raise Exception("Couldn't determine last changed revision.") | |
| 164 return revision | |
| 165 | |
| 166 def main(): | 65 def main(): |
| 167 if len(sys.argv) == 0: | 66 if len(sys.argv) == 0: |
| 168 print 'Script pathname not known, giving up.' | 67 print 'Script pathname not known, giving up.' |
| 169 return 1 | 68 return 1 |
| 170 | 69 |
| 171 scriptdir = os.path.dirname(sys.argv[0]) | 70 scriptdir = os.path.dirname(sys.argv[0]) |
| 172 # Get at the top-level directory. This script is in client/tools | 71 # Get at the top-level directory. This script is in client/tools |
| 173 os.chdir(os.path.abspath(os.path.join(scriptdir, os.pardir, os.pardir))) | 72 os.chdir(os.path.abspath(os.path.join(scriptdir, os.pardir, os.pardir))) |
| 174 | 73 |
| 175 if GetShouldClobber(): | 74 if GetShouldClobber(): |
| 176 print '@@@BUILD_STEP Clobber@@@' | 75 print '@@@BUILD_STEP Clobber@@@' |
| 177 status = ClobberBuilder() | 76 status = ClobberBuilder() |
| 178 if status != 0: | 77 if status != 0: |
| 179 print '@@@STEP_FAILURE@@@' | 78 print '@@@STEP_FAILURE@@@' |
| 180 return status | 79 return status |
| 181 | 80 |
| 182 | 81 name = GetName() |
| 183 #TODO(sigmund): remove this indirection once we update our bots | |
| 184 (name, version) = GetBuildInfo() | |
| 185 # The buildbot will set a BUILDBOT_JAVA_HOME relative to the dart | |
| 186 # root directory, set JAVA_HOME based on that. | |
| 187 FixJavaHome() | |
| 188 if name.startswith('pub-'): | 82 if name.startswith('pub-'): |
| 189 status = ProcessBot(name, 'pub') | 83 status = ProcessBot(name, 'pub') |
| 190 elif name.startswith('vm-android'): | 84 elif name.startswith('vm-android'): |
| 191 status = ProcessBot(name, 'android') | 85 status = ProcessBot(name, 'android') |
| 192 elif name.startswith('dart-sdk'): | 86 elif name.startswith('dart-sdk'): |
| 193 status = ProcessBot(name, 'dart_sdk') | 87 status = ProcessBot(name, 'dart_sdk') |
| 194 elif name.startswith('cross') or name.startswith('target'): | 88 elif name.startswith('cross') or name.startswith('target'): |
| 195 status = ProcessBot(name, 'cross-vm', | 89 status = ProcessBot(name, 'cross-vm') |
| 196 custom_env=EnvironmentWithoutBotoConfig()) | |
| 197 elif name.startswith('linux-distribution-support'): | 90 elif name.startswith('linux-distribution-support'): |
| 198 status = ProcessBot(name, 'linux_distribution_support') | 91 status = ProcessBot(name, 'linux_distribution_support') |
| 199 elif name.startswith('version-checker'): | 92 elif name.startswith('version-checker'): |
| 200 status = ProcessBot(name, 'version_checker') | 93 status = ProcessBot(name, 'version_checker') |
| 201 elif name.startswith('dart2js-dump-info'): | 94 elif name.startswith('dart2js-dump-info'): |
| 202 status = ProcessBot(name, 'dart2js_dump_info') | 95 status = ProcessBot(name, 'dart2js_dump_info') |
| 203 else: | 96 else: |
| 204 status = ProcessBot(name, 'compiler') | 97 status = ProcessBot(name, 'compiler') |
| 205 | 98 |
| 206 if status: | 99 if status: |
| 207 print '@@@STEP_FAILURE@@@' | 100 print '@@@STEP_FAILURE@@@' |
| 208 | 101 |
| 209 return status | 102 return status |
| 210 | 103 |
| 211 | 104 |
| 212 if __name__ == '__main__': | 105 if __name__ == '__main__': |
| 213 sys.exit(main()) | 106 sys.exit(main()) |
| OLD | NEW |