Home | History | Annotate | Download | only in steps
      1 # Copyright (C) 2010 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.common.system.executive import ScriptError
     30 from webkitpy.common.config.ports import WebKitPort
     31 from webkitpy.tool.steps.options import Options
     32 
     33 
     34 class AbstractStep(object):
     35     def __init__(self, tool, options):
     36         self._tool = tool
     37         self._options = options
     38 
     39     def _changed_files(self, state):
     40         return self.cached_lookup(state, "changed_files")
     41 
     42     _well_known_keys = {
     43         "bug_title": lambda self, state: self._tool.bugs.fetch_bug(state["bug_id"]).title(),
     44         "changed_files": lambda self, state: self._tool.scm().changed_files(self._options.git_commit),
     45         "diff": lambda self, state: self._tool.scm().create_patch(self._options.git_commit, changed_files=self._changed_files(state)),
     46         # Absolute path to ChangeLog files.
     47         "changelogs": lambda self, state: self._tool.checkout().modified_changelogs(self._options.git_commit, changed_files=self._changed_files(state)),
     48     }
     49 
     50     def cached_lookup(self, state, key, promise=None):
     51         if state.get(key):
     52             return state[key]
     53         if not promise:
     54             promise = self._well_known_keys.get(key)
     55         state[key] = promise(self, state)
     56         return state[key]
     57 
     58     def did_modify_checkout(self, state):
     59         state["diff"] = None
     60         state["changelogs"] = None
     61         state["changed_files"] = None
     62 
     63     @classmethod
     64     def options(cls):
     65         return [
     66             # We need this option here because cached_lookup uses it.  :(
     67             Options.git_commit,
     68         ]
     69 
     70     def run(self, state):
     71         raise NotImplementedError, "subclasses must implement"
     72