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 | # |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 3 | # Redistribution and use in source and binary forms, with or without |
| 4 | # modification, are permitted provided that the following conditions are met: |
Corentin Wallez | 4c35101 | 2018-08-27 10:10:28 +0200 | [diff] [blame] | 5 | # |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 6 | # 1. Redistributions of source code must retain the above copyright notice, this |
| 7 | # list of conditions and the following disclaimer. |
Corentin Wallez | 4c35101 | 2018-08-27 10:10:28 +0200 | [diff] [blame] | 8 | # |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 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. |
Corentin Wallez | 4c35101 | 2018-08-27 10:10:28 +0200 | [diff] [blame] | 27 | |
dan sinclair | d9496f3 | 2020-11-16 15:01:27 +0000 | [diff] [blame] | 28 | import re |
Corentin Wallez | 4c35101 | 2018-08-27 10:10:28 +0200 | [diff] [blame] | 29 | |
Ryan Harrison | 45aed4b | 2021-07-20 17:57:20 +0000 | [diff] [blame] | 30 | USE_PYTHON3 = True |
| 31 | |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 32 | NONINCLUSIVE_REGEXES = [ |
dan sinclair | d9496f3 | 2020-11-16 15:01:27 +0000 | [diff] [blame] | 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 | |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 83 | NONINCLUSIVE_REGEX_LIST = [] |
| 84 | for reg in NONINCLUSIVE_REGEXES: |
| 85 | NONINCLUSIVE_REGEX_LIST.append(re.compile(reg)) |
dan sinclair | d9496f3 | 2020-11-16 15:01:27 +0000 | [diff] [blame] | 86 | |
dan sinclair | fcf5679 | 2022-04-11 13:05:40 +0000 | [diff] [blame] | 87 | LINT_FILTERS = [] |
dan sinclair | c4502a0 | 2022-04-08 12:08:56 +0000 | [diff] [blame] | 88 | |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 89 | |
| 90 | def _CheckNonInclusiveLanguage(input_api, output_api, source_file_filter=None): |
Ryan Harrison | 6d27f23 | 2021-07-20 17:16:31 +0000 | [diff] [blame] | 91 | """Checks the files for non-inclusive language.""" |
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 | matches = [] |
| 94 | for f in input_api.AffectedFiles(include_deletes=False, |
| 95 | file_filter=source_file_filter): |
dan sinclair | fb5a492 | 2022-04-19 22:25:45 +0000 | [diff] [blame] | 96 | line_num = 0 |
| 97 | for line in f.NewContents(): |
| 98 | line_num += 1 |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 99 | for reg in NONINCLUSIVE_REGEX_LIST: |
Ryan Harrison | 6d27f23 | 2021-07-20 17:16:31 +0000 | [diff] [blame] | 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))) |
dan sinclair | d9496f3 | 2020-11-16 15:01:27 +0000 | [diff] [blame] | 105 | |
Ryan Harrison | 6d27f23 | 2021-07-20 17:16:31 +0000 | [diff] [blame] | 106 | if len(matches): |
| 107 | return [ |
dan sinclair | fcf5679 | 2022-04-11 13:05:40 +0000 | [diff] [blame] | 108 | output_api.PresubmitPromptWarning("Non-inclusive language found:", |
Ryan Harrison | 6d27f23 | 2021-07-20 17:16:31 +0000 | [diff] [blame] | 109 | items=matches) |
| 110 | ] |
dan sinclair | d9496f3 | 2020-11-16 15:01:27 +0000 | [diff] [blame] | 111 | |
Ryan Harrison | 6d27f23 | 2021-07-20 17:16:31 +0000 | [diff] [blame] | 112 | return [] |
dan sinclair | d9496f3 | 2020-11-16 15:01:27 +0000 | [diff] [blame] | 113 | |
| 114 | |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 115 | def _NonInclusiveFileFilter(file): |
| 116 | filter_list = [ |
dan sinclair | fb5a492 | 2022-04-19 22:25:45 +0000 | [diff] [blame] | 117 | "Doxyfile", # References to main pages |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 118 | "PRESUBMIT.py", # Non-inclusive language check data |
dan sinclair | fb5a492 | 2022-04-19 22:25:45 +0000 | [diff] [blame] | 119 | "PRESUBMIT.py.tint", # Non-inclusive language check data |
| 120 | "docs/dawn/debug_markers.md", # External URL |
| 121 | "docs/dawn/infra.md", # Infra settings |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 122 | "docs/tint/spirv-input-output-variables.md", # External URL |
dan sinclair | fb5a492 | 2022-04-19 22:25:45 +0000 | [diff] [blame] | 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 |
Ben Clayton | 61b5aac | 2022-12-12 23:06:43 +0000 | [diff] [blame] | 130 | "src/tools/src/cmd/run-cts/main.go", # Terminal type name |
dan sinclair | fb5a492 | 2022-04-19 22:25:45 +0000 | [diff] [blame] | 131 | "src/dawn/samples/ComputeBoids.cpp", # External URL |
| 132 | "src/dawn/tests/end2end/DepthBiasTests.cpp", # External URL |
dan sinclair | 46c32d8 | 2022-07-20 15:53:14 +0000 | [diff] [blame] | 133 | "src/tint/transform/canonicalize_entry_point_io.cc", # External URL |
dan sinclair | fb5a492 | 2022-04-19 22:25:45 +0000 | [diff] [blame] | 134 | "test/tint/samples/compute_boids.wgsl", # External URL |
Antonio Maiorano | b94856d | 2023-06-22 21:30:50 +0000 | [diff] [blame] | 135 | "third_party/gn/dxc/BUILD.gn", # Third party file |
Antonio Maiorano | 83bdc7f | 2023-08-21 15:29:35 +0000 | [diff] [blame] | 136 | "third_party/khronos/EGL-Registry/api/KHR/khrplatform.h", # Third party file |
dan sinclair | fb5a492 | 2022-04-19 22:25:45 +0000 | [diff] [blame] | 137 | "tools/roll-all", # Branch name |
| 138 | "tools/src/container/key.go", # External URL |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 139 | "go.sum", # External URL |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 140 | ] |
Antonio Maiorano | 5e16416 | 2023-06-20 17:12:37 +0000 | [diff] [blame] | 141 | return file.LocalPath().replace('\\', '/') not in filter_list |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 142 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 143 | |
Ben Clayton | bca96d9 | 2022-11-16 21:34:14 +0000 | [diff] [blame] | 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 | |
Corentin Wallez | 4c35101 | 2018-08-27 10:10:28 +0200 | [diff] [blame] | 164 | def _DoCommonChecks(input_api, output_api): |
| 165 | results = [] |
Joanna Wang | 77ce559 | 2023-08-04 22:26:55 +0000 | [diff] [blame] | 166 | results.extend( |
| 167 | input_api.canned_checks.CheckForCommitObjects(input_api, output_api)) |
Ben Clayton | bca96d9 | 2022-11-16 21:34:14 +0000 | [diff] [blame] | 168 | results.extend(_CheckNoStaleGen(input_api, output_api)) |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 169 | results.extend( |
| 170 | input_api.canned_checks.CheckChangedLUCIConfigs(input_api, output_api)) |
dan sinclair | 17f2047 | 2022-11-10 18:23:41 +0000 | [diff] [blame] | 171 | |
| 172 | result_factory = output_api.PresubmitPromptWarning |
| 173 | if input_api.is_committing: |
| 174 | result_factory = output_api.PresubmitError |
| 175 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 176 | results.extend( |
dan sinclair | 17f2047 | 2022-11-10 18:23:41 +0000 | [diff] [blame] | 177 | input_api.canned_checks.CheckPatchFormatted( |
| 178 | input_api, |
| 179 | output_api, |
| 180 | check_python=True, |
| 181 | result_factory=result_factory)) |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 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)) |
dan sinclair | 2a3d994 | 2022-04-13 16:14:26 +0000 | [diff] [blame] | 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. |
dan sinclair | c4502a0 | 2022-04-08 12:08:56 +0000 | [diff] [blame] | 201 | results.extend( |
| 202 | input_api.canned_checks.CheckChangeLintsClean( |
dan sinclair | 2a3d994 | 2022-04-13 16:14:26 +0000 | [diff] [blame] | 203 | input_api, output_api, lint_filters=LINT_FILTERS, verbose_level=1)) |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 204 | results.extend( |
| 205 | _CheckNonInclusiveLanguage(input_api, output_api, |
| 206 | _NonInclusiveFileFilter)) |
Corentin Wallez | 4c35101 | 2018-08-27 10:10:28 +0200 | [diff] [blame] | 207 | return results |
Corentin Wallez | 99612ae | 2018-08-20 14:54:15 +0200 | [diff] [blame] | 208 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 209 | |
Corentin Wallez | 99612ae | 2018-08-20 14:54:15 +0200 | [diff] [blame] | 210 | def CheckChangeOnUpload(input_api, output_api): |
Corentin Wallez | 4c35101 | 2018-08-27 10:10:28 +0200 | [diff] [blame] | 211 | return _DoCommonChecks(input_api, output_api) |
Corentin Wallez | 99612ae | 2018-08-20 14:54:15 +0200 | [diff] [blame] | 212 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 213 | |
Corentin Wallez | 99612ae | 2018-08-20 14:54:15 +0200 | [diff] [blame] | 214 | def CheckChangeOnCommit(input_api, output_api): |
Corentin Wallez | 4c35101 | 2018-08-27 10:10:28 +0200 | [diff] [blame] | 215 | return _DoCommonChecks(input_api, output_api) |