Fix for Geolocation webTCT failures
[platform/framework/web/chromium-efl.git] / third_party / dawn / PRESUBMIT.py
1 # Copyright 2022 The Dawn & Tint Authors
2 #
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are met:
5 #
6 # 1. Redistributions of source code must retain the above copyright notice, this
7 #    list of conditions and the following disclaimer.
8 #
9 # 2. Redistributions in binary form must reproduce the above copyright notice,
10 #    this list of conditions and the following disclaimer in the documentation
11 #    and/or other materials provided with the distribution.
12 #
13 # 3. Neither the name of the copyright holder 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 "AS IS"
18 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 import re
29
30 USE_PYTHON3 = True
31
32 NONINCLUSIVE_REGEXES = [
33     r"(?i)black[-_]?list",
34     r"(?i)white[-_]?list",
35     r"(?i)gr[ea]y[-_]?list",
36     r"(?i)(first class citizen)",
37     r"(?i)black[-_]?hat",
38     r"(?i)white[-_]?hat",
39     r"(?i)gr[ea]y[-_]?hat",
40     r"(?i)master",
41     r"(?i)slave",
42     r"(?i)\bhim\b",
43     r"(?i)\bhis\b",
44     r"(?i)\bshe\b",
45     r"(?i)\bher\b",
46     r"(?i)\bguys\b",
47     r"(?i)\bhers\b",
48     r"(?i)\bman\b",
49     r"(?i)\bwoman\b",
50     r"(?i)\she\s",
51     r"(?i)\she$",
52     r"(?i)^he\s",
53     r"(?i)^he$",
54     r"(?i)\she['|\u2019]d\s",
55     r"(?i)\she['|\u2019]d$",
56     r"(?i)^he['|\u2019]d\s",
57     r"(?i)^he['|\u2019]d$",
58     r"(?i)\she['|\u2019]s\s",
59     r"(?i)\she['|\u2019]s$",
60     r"(?i)^he['|\u2019]s\s",
61     r"(?i)^he['|\u2019]s$",
62     r"(?i)\she['|\u2019]ll\s",
63     r"(?i)\she['|\u2019]ll$",
64     r"(?i)^he['|\u2019]ll\s",
65     r"(?i)^he['|\u2019]ll$",
66     r"(?i)grandfather",
67     r"(?i)\bmitm\b",
68     r"(?i)\bcrazy\b",
69     r"(?i)\binsane\b",
70     r"(?i)\bblind\sto\b",
71     r"(?i)\bflying\sblind\b",
72     r"(?i)\bblind\seye\b",
73     r"(?i)\bcripple\b",
74     r"(?i)\bcrippled\b",
75     r"(?i)\bdumb\b",
76     r"(?i)\bdummy\b",
77     r"(?i)\bparanoid\b",
78     r"(?i)\bsane\b",
79     r"(?i)\bsanity\b",
80     r"(?i)red[-_]?line",
81 ]
82
83 NONINCLUSIVE_REGEX_LIST = []
84 for reg in NONINCLUSIVE_REGEXES:
85     NONINCLUSIVE_REGEX_LIST.append(re.compile(reg))
86
87 LINT_FILTERS = []
88
89
90 def _CheckNonInclusiveLanguage(input_api, output_api, source_file_filter=None):
91     """Checks the files for non-inclusive language."""
92
93     matches = []
94     for f in input_api.AffectedFiles(include_deletes=False,
95                                      file_filter=source_file_filter):
96         line_num = 0
97         for line in f.NewContents():
98             line_num += 1
99             for reg in NONINCLUSIVE_REGEX_LIST:
100                 match = reg.search(line)
101                 if match:
102                     matches.append(
103                         "{} ({}): found non-inclusive language: {}".format(
104                             f.LocalPath(), line_num, match.group(0)))
105
106     if len(matches):
107         return [
108             output_api.PresubmitPromptWarning("Non-inclusive language found:",
109                                               items=matches)
110         ]
111
112     return []
113
114
115 def _NonInclusiveFileFilter(file):
116     filter_list = [
117         "Doxyfile",  # References to main pages
118         "PRESUBMIT.py",  # Non-inclusive language check data
119         "PRESUBMIT.py.tint",  # Non-inclusive language check data
120         "docs/dawn/debug_markers.md",  # External URL
121         "docs/dawn/infra.md",  # Infra settings
122         "docs/tint/spirv-input-output-variables.md",  # External URL
123         "infra/config/global/generated/cr-buildbucket.cfg",  # Infra settings
124         "infra/config/global/main.star",  # Infra settings
125         "infra/kokoro/windows/build.bat",  # External URL
126         "src/dawn/common/GPUInfo.cpp",  # External URL
127         "src/dawn/native/metal/BackendMTL.mm",  # OSX Constant
128         "src/dawn/native/vulkan/SamplerVk.cpp",  # External URL
129         "src/dawn/native/vulkan/TextureVk.cpp",  # External URL
130         "src/tools/src/cmd/run-cts/main.go",  # Terminal type name
131         "src/dawn/samples/ComputeBoids.cpp",  # External URL
132         "src/dawn/tests/end2end/DepthBiasTests.cpp",  # External URL
133         "src/tint/transform/canonicalize_entry_point_io.cc",  # External URL
134         "test/tint/samples/compute_boids.wgsl",  # External URL
135         "third_party/gn/dxc/BUILD.gn",  # Third party file
136         "third_party/khronos/EGL-Registry/api/KHR/khrplatform.h",  # Third party file
137         "tools/roll-all",  # Branch name
138         "tools/src/container/key.go",  # External URL
139         "go.sum",  # External URL
140     ]
141     return file.LocalPath().replace('\\', '/') not in filter_list
142
143
144 def _CheckNoStaleGen(input_api, output_api):
145     results = []
146     try:
147         go = input_api.os_path.join(input_api.change.RepositoryRoot(), "tools",
148                                     "golang", "bin", "go")
149         if input_api.is_windows:
150             go += '.exe'
151         input_api.subprocess.check_call_out(
152             [go, "run", "tools/src/cmd/gen/main.go", "--check-stale"],
153             stdout=input_api.subprocess.PIPE,
154             stderr=input_api.subprocess.PIPE,
155             cwd=input_api.change.RepositoryRoot())
156     except input_api.subprocess.CalledProcessError as e:
157         if input_api.is_committing:
158             results.append(output_api.PresubmitError('%s' % (e, )))
159         else:
160             results.append(output_api.PresubmitPromptWarning('%s' % (e, )))
161     return results
162
163
164 def _DoCommonChecks(input_api, output_api):
165     results = []
166     results.extend(
167         input_api.canned_checks.CheckForCommitObjects(input_api, output_api))
168     results.extend(_CheckNoStaleGen(input_api, output_api))
169     results.extend(
170         input_api.canned_checks.CheckChangedLUCIConfigs(input_api, output_api))
171
172     result_factory = output_api.PresubmitPromptWarning
173     if input_api.is_committing:
174         result_factory = output_api.PresubmitError
175
176     results.extend(
177         input_api.canned_checks.CheckPatchFormatted(
178             input_api,
179             output_api,
180             check_python=True,
181             result_factory=result_factory))
182     results.extend(
183         input_api.canned_checks.CheckChangeHasDescription(
184             input_api, output_api))
185     results.extend(
186         input_api.canned_checks.CheckGNFormatted(input_api, output_api))
187     results.extend(
188         input_api.canned_checks.CheckChangeHasNoCrAndHasOnlyOneEol(
189             input_api, output_api))
190     results.extend(
191         input_api.canned_checks.CheckChangeHasNoTabs(input_api, output_api))
192     results.extend(
193         input_api.canned_checks.CheckChangeTodoHasOwner(input_api, output_api))
194     results.extend(
195         input_api.canned_checks.CheckChangeHasNoStrayWhitespace(
196             input_api, output_api))
197     results.extend(
198         input_api.canned_checks.CheckDoNotSubmit(input_api, output_api))
199     # Note, the verbose_level here should match what is set in tools/lint so
200     # the same set of lint errors are reported on the CQ and Kokoro bots.
201     results.extend(
202         input_api.canned_checks.CheckChangeLintsClean(
203             input_api, output_api, lint_filters=LINT_FILTERS, verbose_level=1))
204     results.extend(
205         _CheckNonInclusiveLanguage(input_api, output_api,
206                                    _NonInclusiveFileFilter))
207     return results
208
209
210 def CheckChangeOnUpload(input_api, output_api):
211     return _DoCommonChecks(input_api, output_api)
212
213
214 def CheckChangeOnCommit(input_api, output_api):
215     return _DoCommonChecks(input_api, output_api)