1 # Copyright 2022 The Dawn & Tint Authors
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are met:
6 # 1. Redistributions of source code must retain the above copyright notice, this
7 # list of conditions and the following disclaimer.
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.
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.
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.
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)",
39 r"(?i)gr[ea]y[-_]?hat",
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$",
71 r"(?i)\bflying\sblind\b",
72 r"(?i)\bblind\seye\b",
83 NONINCLUSIVE_REGEX_LIST = []
84 for reg in NONINCLUSIVE_REGEXES:
85 NONINCLUSIVE_REGEX_LIST.append(re.compile(reg))
90 def _CheckNonInclusiveLanguage(input_api, output_api, source_file_filter=None):
91 """Checks the files for non-inclusive language."""
94 for f in input_api.AffectedFiles(include_deletes=False,
95 file_filter=source_file_filter):
97 for line in f.NewContents():
99 for reg in NONINCLUSIVE_REGEX_LIST:
100 match = reg.search(line)
103 "{} ({}): found non-inclusive language: {}".format(
104 f.LocalPath(), line_num, match.group(0)))
108 output_api.PresubmitPromptWarning("Non-inclusive language found:",
115 def _NonInclusiveFileFilter(file):
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
141 return file.LocalPath().replace('\\', '/') not in filter_list
144 def _CheckNoStaleGen(input_api, output_api):
147 go = input_api.os_path.join(input_api.change.RepositoryRoot(), "tools",
148 "golang", "bin", "go")
149 if input_api.is_windows:
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, )))
160 results.append(output_api.PresubmitPromptWarning('%s' % (e, )))
164 def _DoCommonChecks(input_api, output_api):
167 input_api.canned_checks.CheckForCommitObjects(input_api, output_api))
168 results.extend(_CheckNoStaleGen(input_api, output_api))
170 input_api.canned_checks.CheckChangedLUCIConfigs(input_api, output_api))
172 result_factory = output_api.PresubmitPromptWarning
173 if input_api.is_committing:
174 result_factory = output_api.PresubmitError
177 input_api.canned_checks.CheckPatchFormatted(
181 result_factory=result_factory))
183 input_api.canned_checks.CheckChangeHasDescription(
184 input_api, output_api))
186 input_api.canned_checks.CheckGNFormatted(input_api, output_api))
188 input_api.canned_checks.CheckChangeHasNoCrAndHasOnlyOneEol(
189 input_api, output_api))
191 input_api.canned_checks.CheckChangeHasNoTabs(input_api, output_api))
193 input_api.canned_checks.CheckChangeTodoHasOwner(input_api, output_api))
195 input_api.canned_checks.CheckChangeHasNoStrayWhitespace(
196 input_api, output_api))
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.
202 input_api.canned_checks.CheckChangeLintsClean(
203 input_api, output_api, lint_filters=LINT_FILTERS, verbose_level=1))
205 _CheckNonInclusiveLanguage(input_api, output_api,
206 _NonInclusiveFileFilter))
210 def CheckChangeOnUpload(input_api, output_api):
211 return _DoCommonChecks(input_api, output_api)
214 def CheckChangeOnCommit(input_api, output_api):
215 return _DoCommonChecks(input_api, output_api)