Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(427)

Side by Side Diff: annotated_steps.py

Issue 1135343004: Give the possibility of placing a custom annotated_steps in tools inside the package. (Closed) Base URL: https://github.com/dart-lang/package-bots.git@master
Patch Set: Small cleanups Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | config_parser.py » ('j') | config_parser.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 2
3 # Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 3 # Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
4 # for details. All rights reserved. Use of this source code is governed by a 4 # for details. All rights reserved. Use of this source code is governed by a
5 # BSD-style license that can be found in the LICENSE file. 5 # BSD-style license that can be found in the LICENSE file.
6 6
7 import imp 7 import imp
8 import os 8 import os
9 import re 9 import re
10 import shutil 10 import shutil
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 builder_pattern.group(4), 74 builder_pattern.group(4),
75 is_repo, 75 is_repo,
76 is_sample) 76 is_sample)
77 77
78 class BuildStep(object): 78 class BuildStep(object):
79 """ 79 """
80 A context manager for handling build steps. 80 A context manager for handling build steps.
81 81
82 When the context manager is entered, it prints the "@@@BUILD_STEP __@@@" 82 When the context manager is entered, it prints the "@@@BUILD_STEP __@@@"
83 message. If it exits from an error being raised it displays the 83 message. If it exits from an error being raised it displays the
84 "@@@STEP_FAILURE@@@" message. 84 "@@@STEP_FAILURE __@@@" message.
85 85
86 If swallow_error is True, then this will catch and discard any OSError that 86 If swallow_error is True, then this will catch and discard any OSError that
87 is thrown. This lets you run later BuildSteps if the current one fails. 87 is thrown. This lets you run later BuildSteps if the current one fails.
88 """ 88 """
89 def __init__(self, name, swallow_error=False): 89 def __init__(self, name, swallow_error=False):
90 self.name = name 90 self.name = name
91 self.swallow_error = swallow_error 91 self.swallow_error = swallow_error
92 92
93 def __enter__(self): 93 def __enter__(self):
94 print '@@@BUILD_STEP %s@@@' % self.name 94 print '@@@BUILD_STEP %s@@@' % self.name
95 sys.stdout.flush() 95 sys.stdout.flush()
96 96
97 def __exit__(self, type, value, traceback): 97 def __exit__(self, type, value, traceback):
98 if value: 98 if value:
99 print '@@@STEP_FAILURE@@@' 99 print '@@@STEP_FAILURE %s@@@' % self.name
100 sys.stdout.flush() 100 sys.stdout.flush()
101 if self.swallow_error and isinstance(value, OSError): 101 if self.swallow_error and isinstance(value, OSError):
102 return True 102 return True
103 103
104 class TempDir(object): 104 class TempDir(object):
105 def __init__(self, prefix=''): 105 def __init__(self, prefix=''):
106 self._temp_dir = None 106 self._temp_dir = None
107 self._prefix = prefix 107 self._prefix = prefix
108 108
109 def __enter__(self): 109 def __enter__(self):
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 args = [sys.executable, 'tools/build.py', 151 args = [sys.executable, 'tools/build.py',
152 '-mrelease,debug', '--arch=ia32', 152 '-mrelease,debug', '--arch=ia32',
153 'create_sdk'] 153 'create_sdk']
154 RunProcess(args) 154 RunProcess(args)
155 155
156 def GetSDK(bot_info): 156 def GetSDK(bot_info):
157 with BuildStep('Get sdk'): 157 with BuildStep('Get sdk'):
158 namer = bot_utils.GCSNamer(channel=bot_utils.Channel.DEV) 158 namer = bot_utils.GCSNamer(channel=bot_utils.Channel.DEV)
159 # TODO(ricow): Be smarter here, only download if new. 159 # TODO(ricow): Be smarter here, only download if new.
160 build_root = GetBuildRoot(bot_info) 160 build_root = GetBuildRoot(bot_info)
161 SafeDelete(os.path.join(build_root, 'dart-sdk')) 161 SafeDelete(os.path.join(build_root, 'dart-sdk'), bot_info)
162 if not os.path.exists(build_root): 162 if not os.path.exists(build_root):
163 os.makedirs(build_root) 163 os.makedirs(build_root)
164 local_zip = os.path.join(build_root, 'sdk.zip') 164 local_zip = os.path.join(build_root, 'sdk.zip')
165 gsutils = bot_utils.GSUtil() 165 gsutils = bot_utils.GSUtil()
166 gsutils.execute(['cp', 166 gsutils.execute(['cp',
167 namer.sdk_zipfilepath('latest', bot_info.system, 167 namer.sdk_zipfilepath('latest', bot_info.system,
168 'ia32', 'release'), 168 'ia32', 'release'),
169 local_zip]) 169 local_zip])
170 if bot_info.system == 'windows': 170 if bot_info.system == 'windows':
171 with zipfile.ZipFile(local_zip, 'r') as zip_file: 171 with zipfile.ZipFile(local_zip, 'r') as zip_file:
172 zip_file.extractall(path=build_root) 172 zip_file.extractall(path=build_root)
173 else: 173 else:
174 # We don't keep the execution bit if we use python's zipfile on possix. 174 # We don't keep the execution bit if we use python's zipfile on possix.
175 RunProcess(['unzip', local_zip, '-d', build_root]) 175 RunProcess(['unzip', local_zip, '-d', build_root])
176 176
177 def GetPackagePath(bot_info): 177 def GetPackagePath(bot_info):
178 if bot_info.is_repo: 178 if bot_info.is_repo:
179 return os.path.join('pkg', bot_info.package_name) 179 return os.path.join('pkg', bot_info.package_name)
180 return os.path.join('third_party', 'pkg', bot_info.package_name) 180 return os.path.join('third_party', 'pkg', bot_info.package_name)
181 181
182 def GetBuildRoot(bot_info): 182 def GetBuildRoot(bot_info):
183 system = bot_info.system 183 system = bot_info.system
184 if system == 'windows': 184 if system == 'windows':
185 system = 'win32' 185 system = 'win32'
186 if system == 'mac': 186 if system == 'mac':
187 system = 'macos' 187 system = 'macos'
188 return utils.GetBuildRoot(system, mode='release', arch='ia32', 188 return utils.GetBuildRoot(system, mode='release', arch='ia32',
189 target_os=system) 189 target_os=system)
190 190
191 def SafeDelete(path): 191 def SafeDelete(path, bot_info):
192 if bot_info.system == 'windows': 192 if bot_info.system == 'windows':
193 if os.path.exists(path): 193 if os.path.exists(path):
194 args = ['cmd.exe', '/c', 'rmdir', '/q', '/s', path] 194 args = ['cmd.exe', '/c', 'rmdir', '/q', '/s', path]
195 RunProcess(args) 195 RunProcess(args)
196 else: 196 else:
197 shutil.rmtree(path, ignore_errors=True) 197 shutil.rmtree(path, ignore_errors=True)
198 198
199 199
200 def GetPackageCopy(bot_info): 200 def GetPackageCopy(bot_info):
201 build_root = GetBuildRoot(bot_info) 201 build_root = GetBuildRoot(bot_info)
202 package_copy = os.path.join(build_root, 'package_copy') 202 package_copy = os.path.join(build_root, 'package_copy')
203 package_path = GetPackagePath(bot_info) 203 package_path = GetPackagePath(bot_info)
204 copy_path = os.path.join(package_copy, bot_info.package_name) 204 copy_path = os.path.join(package_copy, bot_info.package_name)
205 SafeDelete(package_copy) 205 SafeDelete(package_copy, bot_info)
206 no_git = shutil.ignore_patterns('.git') 206 no_git = shutil.ignore_patterns('.git')
207 shutil.copytree(package_path, copy_path, symlinks=False, ignore=no_git) 207 shutil.copytree(package_path, copy_path, symlinks=False, ignore=no_git)
208 return copy_path 208 return copy_path
209 209
210 def GetSdkBin(): 210 def GetSdkBin(bot_info):
211 return os.path.join(os.getcwd(), GetBuildRoot(bot_info), 211 return os.path.join(os.getcwd(), GetBuildRoot(bot_info),
212 'dart-sdk', 'bin') 212 'dart-sdk', 'bin')
213 213
214 def GetVM(): 214 def GetVM(bot_info):
215 executable = 'dart.exe' if bot_info.system == 'windows' else 'dart' 215 executable = 'dart.exe' if bot_info.system == 'windows' else 'dart'
216 return os.path.join(GetSdkBin(), executable) 216 return os.path.join(GetSdkBin(bot_info), executable)
217 217
218 def GetPub(bot_info): 218 def GetPub(bot_info):
219 executable = 'pub.bat' if bot_info.system == 'windows' else 'pub' 219 executable = 'pub.bat' if bot_info.system == 'windows' else 'pub'
220 return os.path.join(GetSdkBin(), executable) 220 return os.path.join(GetSdkBin(bot_info), executable)
221 221
222 def GetPubEnv(bot_info): 222 def GetPubEnv(bot_info):
223 return {'PUB_CACHE' : os.path.join(os.getcwd(), 223 return {'PUB_CACHE' : os.path.join(os.getcwd(),
224 GetBuildRoot(bot_info), 'pub_cache') } 224 GetBuildRoot(bot_info), 'pub_cache') }
225 225
226 # _RunPubCacheRepair and _CheckPubCacheCorruption are not used right now, but we 226 # _RunPubCacheRepair and _CheckPubCacheCorruption are not used right now, but we
227 # keep them around because they provide an easy way to diagnose and fix issues 227 # keep them around because they provide an easy way to diagnose and fix issues
228 # in the bots. 228 # in the bots.
229 def _RunPubCacheRepair(bot_info, path): 229 def _RunPubCacheRepair(bot_info, path):
230 pub = GetPub(bot_info) 230 pub = GetPub(bot_info)
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 system = bot_info.system 333 system = bot_info.system
334 xvfb_command = ['xvfb-run', '-a', '--server-args=-screen 0 1024x768x24'] 334 xvfb_command = ['xvfb-run', '-a', '--server-args=-screen 0 1024x768x24']
335 xvfb_args = xvfb_command if system == 'linux' else [] 335 xvfb_args = xvfb_command if system == 'linux' else []
336 suffix = ' under build' if folder == 'build/test' else '' 336 suffix = ' under build' if folder == 'build/test' else ''
337 with BuildStep('Test vm release mode%s' % suffix, swallow_error=True): 337 with BuildStep('Test vm release mode%s' % suffix, swallow_error=True):
338 args = [sys.executable, 'tools/test.py', 338 args = [sys.executable, 'tools/test.py',
339 '-mrelease', '-rvm', '-cnone'] + standard_args 339 '-mrelease', '-rvm', '-cnone'] + standard_args
340 args.extend(LogsArgument()) 340 args.extend(LogsArgument())
341 # For easy integration testing we give access to the sdk bin directory. 341 # For easy integration testing we give access to the sdk bin directory.
342 # This only makes sense on vm testing. 342 # This only makes sense on vm testing.
343 extra_env = { 'DART_SDK_BIN' : GetSdkBin() } 343 extra_env = { 'DART_SDK_BIN' : GetSdkBin(bot_info) }
344 RunProcess(args, extra_env=extra_env) 344 RunProcess(args, extra_env=extra_env)
345 with BuildStep('Test analyzer%s' % suffix, swallow_error=True): 345 with BuildStep('Test analyzer%s' % suffix, swallow_error=True):
346 args = [sys.executable, 'tools/test.py', 346 args = [sys.executable, 'tools/test.py',
347 '-mrelease', '-rnone', '-cdart2analyzer'] + standard_args 347 '-mrelease', '-rnone', '-cdart2analyzer'] + standard_args
348 args.extend(LogsArgument()) 348 args.extend(LogsArgument())
349 RunProcess(args) 349 RunProcess(args)
350 if bot_info.system != 'windows': 350 if bot_info.system != 'windows':
351 with BuildStep('Test dartium%s' % suffix, swallow_error=True): 351 with BuildStep('Test dartium%s' % suffix, swallow_error=True):
352 test_args = [sys.executable, 'tools/test.py', 352 test_args = [sys.executable, 'tools/test.py',
353 '-mrelease', '-rdartium', '-cnone', '-j4'] 353 '-mrelease', '-rdartium', '-cnone', '-j4']
354 args = xvfb_args + test_args + standard_args 354 args = xvfb_args + test_args + standard_args
355 args.extend(LogsArgument()) 355 args.extend(LogsArgument())
356 RunProcess(args) 356 RunProcess(args)
357 357
358 for runtime in JS_RUNTIMES[system]: 358 for runtime in JS_RUNTIMES[system]:
359 with BuildStep('dart2js-%s%s' % (runtime, suffix), swallow_error=True): 359 with BuildStep('dart2js-%s%s' % (runtime, suffix), swallow_error=True):
360 test_args = [sys.executable, 'tools/test.py', 360 test_args = [sys.executable, 'tools/test.py',
361 '-mrelease', '-r%s' % runtime, '-cdart2js', '-j4', 361 '-mrelease', '-r%s' % runtime, '-cdart2js', '-j4',
362 '--dart2js-batch'] 362 '--dart2js-batch']
363 args = xvfb_args + test_args + standard_args 363 args = xvfb_args + test_args + standard_args
364 args.extend(LogsArgument()) 364 args.extend(LogsArgument())
365 RunProcess(args) 365 RunProcess(args)
366 366
367 def FillMagicMarkers(v, replacements):
368 def replace(match):
369 word = match.group(1)
370 if not word in replacements:
371 raise Exception("Unknown magic marker %s. Known mappings are: %s" %
372 (word, replacements))
373 return replacements[word]
374 return re.sub(r"\$(\w+)", replace, v)
367 375
368 def RunHooks(hooks, section_name): 376 # Runs the script given by test_config.get_config if it exists, does nothing
377 # otherwise.
378 # Returns `True` if the script was run.
379 def RunCustomScript(test_config):
380 custom_script = test_config.get_custom_script()
381 if custom_script:
382 with BuildStep('Running custom script %s' % custom_script, swallow_error=Tru e):
ricow1 2015/05/19 09:58:05 long line
sigurdm 2015/05/19 13:32:16 Done.
383 exit_code = subprocess.call(
384 FillMagicMarkers(custom_script, test_config.replacements))
385 if exit_code != 0:
386 print "Custom script failed"
387 return True
388 else:
389 return False
390
391
392 def RunHooks(hooks, section_name, replacements):
369 for name, command in hooks.iteritems(): 393 for name, command in hooks.iteritems():
394 command = FillMagicMarkers(command, replacements)
370 with BuildStep('%s: %s' % (section_name, name), swallow_error=True): 395 with BuildStep('%s: %s' % (section_name, name), swallow_error=True):
371 RunProcess(command, shell=True) 396 RunProcess(command, shell=True)
372 397
373 def RunPrePubUpgradeHooks(test_config): 398 def RunPrePubUpgradeHooks(test_config):
374 RunHooks(test_config.get_pre_pub_upgrade_hooks(), "Pre pub upgrade hooks") 399 RunHooks(test_config.get_pre_pub_upgrade_hooks(), "Pre pub upgrade hooks",
400 test_config.replacements)
375 401
376 def RunPrePubBuildHooks(test_config): 402 def RunPrePubBuildHooks(test_config):
377 RunHooks(test_config.get_pre_pub_build_hooks(), "Pre pub build hooks") 403 RunHooks(test_config.get_pre_pub_build_hooks(), "Pre pub build hooks",
404 test_config.replacements)
378 405
379 def RunPostPubBuildHooks(test_config): 406 def RunPostPubBuildHooks(test_config):
380 RunHooks(test_config.get_post_pub_build_hooks(), "Pre pub build hooks") 407 RunHooks(test_config.get_post_pub_build_hooks(), "Pre pub build hooks",
408 test_config.replacements)
381 409
382 def RunPreTestHooks(test_config): 410 def RunPreTestHooks(test_config):
383 RunHooks(test_config.get_pre_test_hooks(), "Pre test hooks") 411 RunHooks(test_config.get_pre_test_hooks(), "Pre test hooks",
412 test_config.replacements)
384 413
385 def RunPostTestHooks(test_config): 414 def RunPostTestHooks(test_config):
386 RunHooks(test_config.get_post_test_hooks(), "Post test hooks") 415 RunHooks(test_config.get_post_test_hooks(), "Post test hooks")
387 416
388 if __name__ == '__main__': 417 def main():
389 bot_info = GetBotInfo() 418 bot_info = GetBotInfo()
419
390 print 'Bot info: %s' % bot_info 420 print 'Bot info: %s' % bot_info
391 copy_path = GetPackageCopy(bot_info) 421 copy_path = GetPackageCopy(bot_info)
392 config_file = os.path.join(copy_path, '.test_config') 422 config_file = os.path.join(copy_path, '.test_config')
393 test_config = config_parser.ConfigParser(config_file, 423 test_config = config_parser.ConfigParser(config_file)
394 GetVM(), 424 test_config.replacements = {
395 copy_path) 425 'dart': GetVM(bot_info),
396 GetSDK(bot_info) 426 'project_root': copy_path
397 print 'Running testing in copy of package in %s' % copy_path 427 }
398 RunPrePubUpgradeHooks(test_config)
399 RunPubUpgrade(bot_info, copy_path)
400 428
401 RunPrePubBuildHooks(test_config) 429 if not RunCustomScript(test_config):
402 RunPubBuild(bot_info, copy_path, 'web') 430 print "No custom script found, running default steps."
403 RunPubBuild(bot_info, copy_path, 'test', 'debug')
404 RunPostPubBuildHooks(test_config)
405 FixupTestControllerJS(copy_path)
406 431
407 RunPreTestHooks(test_config) 432 GetSDK(bot_info)
408 RunPackageTesting(bot_info, copy_path, 'test') 433 print 'Running testing in copy of package in %s' % copy_path
409 RunPackageTesting(bot_info, copy_path, 'build/test') 434 RunPrePubUpgradeHooks(test_config)
410 RunPostTestHooks(test_config) 435 RunPubUpgrade(bot_info, copy_path)
436
437 RunPrePubBuildHooks(test_config)
438 RunPubBuild(bot_info, copy_path, 'web')
439 RunPubBuild(bot_info, copy_path, 'test', 'debug')
440 RunPostPubBuildHooks(test_config)
441 FixupTestControllerJS(copy_path)
442
443 RunPreTestHooks(test_config)
444 RunPackageTesting(bot_info, copy_path, 'test')
445 RunPackageTesting(bot_info, copy_path, 'build/test')
446 RunPostTestHooks(test_config)
447
448 if __name__ == '__main__':
449 main()
OLDNEW
« no previous file with comments | « no previous file | config_parser.py » ('j') | config_parser.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698