WebKitTools/Scripts/webkitpy/tool/commands/earlywarningsystem.py
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     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 
       
    29 from webkitpy.tool.commands.queues import AbstractReviewQueue
       
    30 from webkitpy.common.config.committers import CommitterList
       
    31 from webkitpy.common.config.ports import WebKitPort
       
    32 from webkitpy.common.system.executive import ScriptError
       
    33 from webkitpy.tool.bot.queueengine import QueueEngine
       
    34 
       
    35 
       
    36 class AbstractEarlyWarningSystem(AbstractReviewQueue):
       
    37     _build_style = "release"
       
    38 
       
    39     def __init__(self):
       
    40         AbstractReviewQueue.__init__(self)
       
    41         self.port = WebKitPort.port(self.port_name)
       
    42 
       
    43     def should_proceed_with_work_item(self, patch):
       
    44         return True
       
    45 
       
    46     def _can_build(self):
       
    47         try:
       
    48             self.run_webkit_patch([
       
    49                 "build",
       
    50                 self.port.flag(),
       
    51                 "--build",
       
    52                 "--build-style=%s" % self._build_style,
       
    53                 "--force-clean",
       
    54                 "--no-update",
       
    55                 "--quiet"])
       
    56             return True
       
    57         except ScriptError, e:
       
    58             self._update_status("Unable to perform a build")
       
    59             return False
       
    60 
       
    61     def _build(self, patch, first_run=False):
       
    62         try:
       
    63             args = [
       
    64                 "build-attachment",
       
    65                 self.port.flag(),
       
    66                 "--build",
       
    67                 "--build-style=%s" % self._build_style,
       
    68                 "--force-clean",
       
    69                 "--quiet",
       
    70                 "--non-interactive",
       
    71                 patch.id()]
       
    72             if not first_run:
       
    73                 # See commit-queue for an explanation of what we're doing here.
       
    74                 args.append("--no-update")
       
    75                 args.append("--parent-command=%s" % self.name)
       
    76             self.run_webkit_patch(args)
       
    77             return True
       
    78         except ScriptError, e:
       
    79             if first_run:
       
    80                 return False
       
    81             raise
       
    82 
       
    83     def review_patch(self, patch):
       
    84         if not self._build(patch, first_run=True):
       
    85             if not self._can_build():
       
    86                 return False
       
    87             self._build(patch)
       
    88         return True
       
    89 
       
    90     @classmethod
       
    91     def handle_script_error(cls, tool, state, script_error):
       
    92         is_svn_apply = script_error.command_name() == "svn-apply"
       
    93         status_id = cls._update_status_for_script_error(tool, state, script_error, is_error=is_svn_apply)
       
    94         if is_svn_apply:
       
    95             QueueEngine.exit_after_handled_error(script_error)
       
    96         results_link = tool.status_server.results_url_for_status(status_id)
       
    97         message = "Attachment %s did not build on %s:\nBuild output: %s" % (state["patch"].id(), cls.port_name, results_link)
       
    98         tool.bugs.post_comment_to_bug(state["patch"].bug_id(), message, cc=cls.watchers)
       
    99         exit(1)
       
   100 
       
   101 
       
   102 class GtkEWS(AbstractEarlyWarningSystem):
       
   103     name = "gtk-ews"
       
   104     port_name = "gtk"
       
   105     watchers = AbstractEarlyWarningSystem.watchers + [
       
   106         "gns@gnome.org",
       
   107         "xan.lopez@gmail.com",
       
   108     ]
       
   109 
       
   110 
       
   111 class QtEWS(AbstractEarlyWarningSystem):
       
   112     name = "qt-ews"
       
   113     port_name = "qt"
       
   114 
       
   115 
       
   116 class WinEWS(AbstractEarlyWarningSystem):
       
   117     name = "win-ews"
       
   118     port_name = "win"
       
   119     # Use debug, the Apple Win port fails to link Release on 32-bit Windows.
       
   120     # https://bugs.webkit.org/show_bug.cgi?id=39197
       
   121     _build_style = "debug"
       
   122 
       
   123 
       
   124 class AbstractChromiumEWS(AbstractEarlyWarningSystem):
       
   125     port_name = "chromium"
       
   126     watchers = AbstractEarlyWarningSystem.watchers + [
       
   127         "dglazkov@chromium.org",
       
   128     ]
       
   129 
       
   130 
       
   131 class ChromiumLinuxEWS(AbstractChromiumEWS):
       
   132     # FIXME: We should rename this command to cr-linux-ews, but that requires
       
   133     #        a database migration. :(
       
   134     name = "chromium-ews"
       
   135 
       
   136 
       
   137 class ChromiumWindowsEWS(AbstractChromiumEWS):
       
   138     name = "cr-win-ews"
       
   139 
       
   140 
       
   141 class ChromiumMacEWS(AbstractChromiumEWS):
       
   142     name = "cr-mac-ews"
       
   143 
       
   144 
       
   145 # For platforms that we can't run inside a VM (like Mac OS X), we require
       
   146 # patches to be uploaded by committers, who are generally trustworthy folk. :)
       
   147 class AbstractCommitterOnlyEWS(AbstractEarlyWarningSystem):
       
   148     def __init__(self, committers=CommitterList()):
       
   149         AbstractEarlyWarningSystem.__init__(self)
       
   150         self._committers = committers
       
   151 
       
   152     def process_work_item(self, patch):
       
   153         if not self._committers.committer_by_email(patch.attacher_email()):
       
   154             self._did_error(patch, "%s cannot process patches from non-committers :(" % self.name)
       
   155             return
       
   156         AbstractEarlyWarningSystem.process_work_item(self, patch)
       
   157 
       
   158 
       
   159 class MacEWS(AbstractCommitterOnlyEWS):
       
   160     name = "mac-ews"
       
   161     port_name = "mac"