Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 1 | # Copyright 2022 The Dawn & Tint Authors |
Corentin Wallez | 4c35101 | 2018-08-27 10:10:28 +0200 | [diff] [blame] | 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
dan sinclair | d9496f3 | 2020-11-16 15:01:27 +0000 | [diff] [blame] | 15 | import re |
Corentin Wallez | 4c35101 | 2018-08-27 10:10:28 +0200 | [diff] [blame] | 16 | |
Ryan Harrison | 45aed4b | 2021-07-20 17:57:20 +0000 | [diff] [blame] | 17 | USE_PYTHON3 = True |
| 18 | |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 19 | NONINCLUSIVE_REGEXES = [ |
dan sinclair | d9496f3 | 2020-11-16 15:01:27 +0000 | [diff] [blame] | 20 | r"(?i)black[-_]?list", |
| 21 | r"(?i)white[-_]?list", |
| 22 | r"(?i)gr[ea]y[-_]?list", |
| 23 | r"(?i)(first class citizen)", |
| 24 | r"(?i)black[-_]?hat", |
| 25 | r"(?i)white[-_]?hat", |
| 26 | r"(?i)gr[ea]y[-_]?hat", |
| 27 | r"(?i)master", |
| 28 | r"(?i)slave", |
| 29 | r"(?i)\bhim\b", |
| 30 | r"(?i)\bhis\b", |
| 31 | r"(?i)\bshe\b", |
| 32 | r"(?i)\bher\b", |
| 33 | r"(?i)\bguys\b", |
| 34 | r"(?i)\bhers\b", |
| 35 | r"(?i)\bman\b", |
| 36 | r"(?i)\bwoman\b", |
| 37 | r"(?i)\she\s", |
| 38 | r"(?i)\she$", |
| 39 | r"(?i)^he\s", |
| 40 | r"(?i)^he$", |
| 41 | r"(?i)\she['|\u2019]d\s", |
| 42 | r"(?i)\she['|\u2019]d$", |
| 43 | r"(?i)^he['|\u2019]d\s", |
| 44 | r"(?i)^he['|\u2019]d$", |
| 45 | r"(?i)\she['|\u2019]s\s", |
| 46 | r"(?i)\she['|\u2019]s$", |
| 47 | r"(?i)^he['|\u2019]s\s", |
| 48 | r"(?i)^he['|\u2019]s$", |
| 49 | r"(?i)\she['|\u2019]ll\s", |
| 50 | r"(?i)\she['|\u2019]ll$", |
| 51 | r"(?i)^he['|\u2019]ll\s", |
| 52 | r"(?i)^he['|\u2019]ll$", |
| 53 | r"(?i)grandfather", |
| 54 | r"(?i)\bmitm\b", |
| 55 | r"(?i)\bcrazy\b", |
| 56 | r"(?i)\binsane\b", |
| 57 | r"(?i)\bblind\sto\b", |
| 58 | r"(?i)\bflying\sblind\b", |
| 59 | r"(?i)\bblind\seye\b", |
| 60 | r"(?i)\bcripple\b", |
| 61 | r"(?i)\bcrippled\b", |
| 62 | r"(?i)\bdumb\b", |
| 63 | r"(?i)\bdummy\b", |
| 64 | r"(?i)\bparanoid\b", |
| 65 | r"(?i)\bsane\b", |
| 66 | r"(?i)\bsanity\b", |
| 67 | r"(?i)red[-_]?line", |
| 68 | ] |
| 69 | |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 70 | NONINCLUSIVE_REGEX_LIST = [] |
| 71 | for reg in NONINCLUSIVE_REGEXES: |
| 72 | NONINCLUSIVE_REGEX_LIST.append(re.compile(reg)) |
dan sinclair | d9496f3 | 2020-11-16 15:01:27 +0000 | [diff] [blame] | 73 | |
dan sinclair | fcf5679 | 2022-04-11 13:05:40 +0000 | [diff] [blame] | 74 | LINT_FILTERS = [] |
dan sinclair | c4502a0 | 2022-04-08 12:08:56 +0000 | [diff] [blame] | 75 | |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 76 | |
| 77 | def _CheckNonInclusiveLanguage(input_api, output_api, source_file_filter=None): |
Ryan Harrison | 6d27f23 | 2021-07-20 17:16:31 +0000 | [diff] [blame] | 78 | """Checks the files for non-inclusive language.""" |
dan sinclair | d9496f3 | 2020-11-16 15:01:27 +0000 | [diff] [blame] | 79 | |
Ryan Harrison | 6d27f23 | 2021-07-20 17:16:31 +0000 | [diff] [blame] | 80 | matches = [] |
| 81 | for f in input_api.AffectedFiles(include_deletes=False, |
| 82 | file_filter=source_file_filter): |
dan sinclair | fb5a492 | 2022-04-19 22:25:45 +0000 | [diff] [blame] | 83 | line_num = 0 |
| 84 | for line in f.NewContents(): |
| 85 | line_num += 1 |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 86 | for reg in NONINCLUSIVE_REGEX_LIST: |
Ryan Harrison | 6d27f23 | 2021-07-20 17:16:31 +0000 | [diff] [blame] | 87 | match = reg.search(line) |
| 88 | if match: |
| 89 | matches.append( |
| 90 | "{} ({}): found non-inclusive language: {}".format( |
| 91 | f.LocalPath(), line_num, match.group(0))) |
dan sinclair | d9496f3 | 2020-11-16 15:01:27 +0000 | [diff] [blame] | 92 | |
Ryan Harrison | 6d27f23 | 2021-07-20 17:16:31 +0000 | [diff] [blame] | 93 | if len(matches): |
| 94 | return [ |
dan sinclair | fcf5679 | 2022-04-11 13:05:40 +0000 | [diff] [blame] | 95 | output_api.PresubmitPromptWarning("Non-inclusive language found:", |
Ryan Harrison | 6d27f23 | 2021-07-20 17:16:31 +0000 | [diff] [blame] | 96 | items=matches) |
| 97 | ] |
dan sinclair | d9496f3 | 2020-11-16 15:01:27 +0000 | [diff] [blame] | 98 | |
Ryan Harrison | 6d27f23 | 2021-07-20 17:16:31 +0000 | [diff] [blame] | 99 | return [] |
dan sinclair | d9496f3 | 2020-11-16 15:01:27 +0000 | [diff] [blame] | 100 | |
| 101 | |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 102 | def _NonInclusiveFileFilter(file): |
| 103 | filter_list = [ |
dan sinclair | fb5a492 | 2022-04-19 22:25:45 +0000 | [diff] [blame] | 104 | "Doxyfile", # References to main pages |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 105 | "PRESUBMIT.py", # Non-inclusive language check data |
dan sinclair | fb5a492 | 2022-04-19 22:25:45 +0000 | [diff] [blame] | 106 | "PRESUBMIT.py.tint", # Non-inclusive language check data |
| 107 | "docs/dawn/debug_markers.md", # External URL |
| 108 | "docs/dawn/infra.md", # Infra settings |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 109 | "docs/tint/spirv-input-output-variables.md", # External URL |
dan sinclair | fb5a492 | 2022-04-19 22:25:45 +0000 | [diff] [blame] | 110 | "infra/config/global/generated/cr-buildbucket.cfg", # Infra settings |
| 111 | "infra/config/global/main.star", # Infra settings |
| 112 | "infra/kokoro/windows/build.bat", # External URL |
| 113 | "src/dawn/common/GPUInfo.cpp", # External URL |
| 114 | "src/dawn/native/metal/BackendMTL.mm", # OSX Constant |
| 115 | "src/dawn/native/vulkan/SamplerVk.cpp", # External URL |
| 116 | "src/dawn/native/vulkan/TextureVk.cpp", # External URL |
Ben Clayton | 61b5aac | 2022-12-12 23:06:43 +0000 | [diff] [blame] | 117 | "src/tools/src/cmd/run-cts/main.go", # Terminal type name |
dan sinclair | fb5a492 | 2022-04-19 22:25:45 +0000 | [diff] [blame] | 118 | "src/dawn/samples/ComputeBoids.cpp", # External URL |
| 119 | "src/dawn/tests/end2end/DepthBiasTests.cpp", # External URL |
dan sinclair | 46c32d8 | 2022-07-20 15:53:14 +0000 | [diff] [blame] | 120 | "src/tint/transform/canonicalize_entry_point_io.cc", # External URL |
dan sinclair | fb5a492 | 2022-04-19 22:25:45 +0000 | [diff] [blame] | 121 | "test/tint/samples/compute_boids.wgsl", # External URL |
| 122 | "third_party/khronos/KHR/khrplatform.h", # Third party file |
| 123 | "tools/roll-all", # Branch name |
| 124 | "tools/src/container/key.go", # External URL |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 125 | "go.sum", # External URL |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 126 | ] |
dan sinclair | fb5a492 | 2022-04-19 22:25:45 +0000 | [diff] [blame] | 127 | return file.LocalPath() not in filter_list |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 128 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 129 | |
Ben Clayton | bca96d9 | 2022-11-16 21:34:14 +0000 | [diff] [blame] | 130 | def _CheckNoStaleGen(input_api, output_api): |
| 131 | results = [] |
| 132 | try: |
| 133 | go = input_api.os_path.join(input_api.change.RepositoryRoot(), "tools", |
| 134 | "golang", "bin", "go") |
| 135 | if input_api.is_windows: |
| 136 | go += '.exe' |
| 137 | input_api.subprocess.check_call_out( |
| 138 | [go, "run", "tools/src/cmd/gen/main.go", "--check-stale"], |
| 139 | stdout=input_api.subprocess.PIPE, |
| 140 | stderr=input_api.subprocess.PIPE, |
| 141 | cwd=input_api.change.RepositoryRoot()) |
| 142 | except input_api.subprocess.CalledProcessError as e: |
| 143 | if input_api.is_committing: |
| 144 | results.append(output_api.PresubmitError('%s' % (e, ))) |
| 145 | else: |
| 146 | results.append(output_api.PresubmitPromptWarning('%s' % (e, ))) |
| 147 | return results |
| 148 | |
| 149 | |
Corentin Wallez | 4c35101 | 2018-08-27 10:10:28 +0200 | [diff] [blame] | 150 | def _DoCommonChecks(input_api, output_api): |
| 151 | results = [] |
Ben Clayton | bca96d9 | 2022-11-16 21:34:14 +0000 | [diff] [blame] | 152 | results.extend(_CheckNoStaleGen(input_api, output_api)) |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 153 | results.extend( |
| 154 | input_api.canned_checks.CheckChangedLUCIConfigs(input_api, output_api)) |
dan sinclair | 17f2047 | 2022-11-10 18:23:41 +0000 | [diff] [blame] | 155 | |
| 156 | result_factory = output_api.PresubmitPromptWarning |
| 157 | if input_api.is_committing: |
| 158 | result_factory = output_api.PresubmitError |
| 159 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 160 | results.extend( |
dan sinclair | 17f2047 | 2022-11-10 18:23:41 +0000 | [diff] [blame] | 161 | input_api.canned_checks.CheckPatchFormatted( |
| 162 | input_api, |
| 163 | output_api, |
| 164 | check_python=True, |
| 165 | result_factory=result_factory)) |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 166 | results.extend( |
| 167 | input_api.canned_checks.CheckChangeHasDescription( |
| 168 | input_api, output_api)) |
| 169 | results.extend( |
| 170 | input_api.canned_checks.CheckGNFormatted(input_api, output_api)) |
| 171 | results.extend( |
| 172 | input_api.canned_checks.CheckChangeHasNoCrAndHasOnlyOneEol( |
| 173 | input_api, output_api)) |
| 174 | results.extend( |
| 175 | input_api.canned_checks.CheckChangeHasNoTabs(input_api, output_api)) |
| 176 | results.extend( |
| 177 | input_api.canned_checks.CheckChangeTodoHasOwner(input_api, output_api)) |
| 178 | results.extend( |
| 179 | input_api.canned_checks.CheckChangeHasNoStrayWhitespace( |
| 180 | input_api, output_api)) |
| 181 | results.extend( |
| 182 | input_api.canned_checks.CheckDoNotSubmit(input_api, output_api)) |
dan sinclair | 2a3d994 | 2022-04-13 16:14:26 +0000 | [diff] [blame] | 183 | # Note, the verbose_level here should match what is set in tools/lint so |
| 184 | # the same set of lint errors are reported on the CQ and Kokoro bots. |
dan sinclair | c4502a0 | 2022-04-08 12:08:56 +0000 | [diff] [blame] | 185 | results.extend( |
| 186 | input_api.canned_checks.CheckChangeLintsClean( |
dan sinclair | 2a3d994 | 2022-04-13 16:14:26 +0000 | [diff] [blame] | 187 | input_api, output_api, lint_filters=LINT_FILTERS, verbose_level=1)) |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 188 | results.extend( |
| 189 | _CheckNonInclusiveLanguage(input_api, output_api, |
| 190 | _NonInclusiveFileFilter)) |
Corentin Wallez | 4c35101 | 2018-08-27 10:10:28 +0200 | [diff] [blame] | 191 | return results |
Corentin Wallez | 99612ae | 2018-08-20 14:54:15 +0200 | [diff] [blame] | 192 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 193 | |
Corentin Wallez | 99612ae | 2018-08-20 14:54:15 +0200 | [diff] [blame] | 194 | def CheckChangeOnUpload(input_api, output_api): |
Corentin Wallez | 4c35101 | 2018-08-27 10:10:28 +0200 | [diff] [blame] | 195 | return _DoCommonChecks(input_api, output_api) |
Corentin Wallez | 99612ae | 2018-08-20 14:54:15 +0200 | [diff] [blame] | 196 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 197 | |
Corentin Wallez | 99612ae | 2018-08-20 14:54:15 +0200 | [diff] [blame] | 198 | def CheckChangeOnCommit(input_api, output_api): |
Corentin Wallez | 4c35101 | 2018-08-27 10:10:28 +0200 | [diff] [blame] | 199 | return _DoCommonChecks(input_api, output_api) |