1# Copyright (C) 2009 Google Inc. All rights reserved. 2# 3# Redistribution and use in source and binary forms, with or without 4# modification, are permitted provided that the following conditions are 5# met: 6# 7# * Redistributions of source code must retain the above copyright 8# notice, this list of conditions and the following disclaimer. 9# * Redistributions in binary form must reproduce the above 10# copyright notice, this list of conditions and the following disclaimer 11# in the documentation and/or other materials provided with the 12# distribution. 13# * Neither the name of Google Inc. nor the names of its 14# contributors may be used to endorse or promote products derived from 15# this software without specific prior written permission. 16# 17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 29import webkitpy.steps as steps 30 31from webkitpy.executive import ScriptError 32from webkitpy.webkit_logging import log 33from webkitpy.scm import CheckoutNeedsUpdate 34from webkitpy.queueengine import QueueEngine 35 36 37class StepSequenceErrorHandler(): 38 @classmethod 39 def handle_script_error(cls, tool, patch, script_error): 40 raise NotImplementedError, "subclasses must implement" 41 42 43class StepSequence(object): 44 def __init__(self, steps): 45 self._steps = steps or [] 46 47 def options(self): 48 collected_options = [ 49 steps.Options.parent_command, 50 steps.Options.quiet, 51 ] 52 for step in self._steps: 53 collected_options = collected_options + step.options() 54 # Remove duplicates. 55 collected_options = sorted(set(collected_options)) 56 return collected_options 57 58 def _run(self, tool, options, state): 59 for step in self._steps: 60 step(tool, options).run(state) 61 62 def run_and_handle_errors(self, tool, options, state=None): 63 if not state: 64 state = {} 65 try: 66 self._run(tool, options, state) 67 except CheckoutNeedsUpdate, e: 68 log("Commit failed because the checkout is out of date. Please update and try again.") 69 log("You can pass --no-build to skip building/testing after update if you believe the new commits did not affect the results.") 70 QueueEngine.exit_after_handled_error(e) 71 except ScriptError, e: 72 if not options.quiet: 73 log(e.message_with_output()) 74 if options.parent_command: 75 command = tool.command_by_name(options.parent_command) 76 command.handle_script_error(tool, state, e) 77 QueueEngine.exit_after_handled_error(e) 78