Add support for webkitpy tests EWS
[WebKit-https.git] / Tools / Scripts / webkitpy / tool / steps / checkpatchrelevance.py
1 # Copyright (C) 2017 Apple 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
5 # are met:
6 # 1.  Redistributions of source code must retain the above copyright
7 #     notice, this list of conditions and the following disclaimer.
8 # 2.  Redistributions in binary form must reproduce the above copyright
9 #     notice, this list of conditions and the following disclaimer in the
10 #     documentation and/or other materials provided with the distribution.
11 #
12 # THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
13 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15 # DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
16 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
18 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
19 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
20 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
21 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
23 import logging
24 import re
25
26 from webkitpy.common.system.executive import ScriptError
27 from webkitpy.tool.steps.abstractstep import AbstractStep
28 from webkitpy.tool.steps.options import Options
29
30 _log = logging.getLogger(__name__)
31
32
33 class CheckPatchRelevance(AbstractStep):
34     @classmethod
35     def options(cls):
36         return AbstractStep.options() + [
37             Options.group,
38             Options.quiet,
39         ]
40
41     bindings_paths = [
42         "Source/WebCore",
43         "Tools",
44     ]
45
46     jsc_paths = [
47         "JSTests/",
48         "Source/JavaScriptCore/",
49         "Source/WTF/",
50         "Source/bmalloc/",
51         "Makefile",
52         "Makefile.shared",
53         "Source/Makefile",
54         "Source/Makefile.shared",
55         "Tools/Scripts/build-webkit",
56         "Tools/Scripts/build-jsc",
57         "Tools/Scripts/jsc-stress-test-helpers/",
58         "Tools/Scripts/run-jsc",
59         "Tools/Scripts/run-jsc-benchmarks",
60         "Tools/Scripts/run-jsc-stress-tests",
61         "Tools/Scripts/run-javascriptcore-tests",
62         "Tools/Scripts/run-layout-jsc",
63         "Tools/Scripts/update-javascriptcore-test-results",
64         "Tools/Scripts/webkitdirs.pm",
65     ]
66
67     webkitpy_paths = [
68         "Tools/Scripts/webkitpy/",
69         "Tools/QueueStatusServer/",
70     ]
71
72     group_to_paths_mapping = {
73         'bindings': bindings_paths,
74         'jsc': jsc_paths,
75         'webkitpy': webkitpy_paths,
76     }
77
78     def _changes_are_relevant(self, changed_files):
79         # In the default case, all patches are relevant
80         if self._options.group not in self.group_to_paths_mapping:
81             return True
82
83         patterns = self.group_to_paths_mapping[self._options.group]
84
85         for changed_file in changed_files:
86             for pattern in patterns:
87                 if re.search(pattern, changed_file, re.IGNORECASE):
88                     return True
89
90         return False
91
92     def run(self, state):
93         _log.info("Checking relevance of patch")
94
95         change_list = self._tool.scm().changed_files()
96
97         if self._changes_are_relevant(change_list):
98             return True
99
100         _log.debug("This patch does not have relevant changes.")
101         raise ScriptError(message="This patch does not have relevant changes.")