Avi Drissman | 047c7dc | 2022-09-27 23:23:14 | [diff] [blame] | 1 | # Copyright 2013 The Chromium Authors |
Kent Tamura | c3e4431 | 2018-04-07 16:30:24 | [diff] [blame] | 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
Kent Tamura | c3e4431 | 2018-04-07 16:30:24 | [diff] [blame] | 4 | """Top-level presubmit script for Blink. |
| 5 | |
Daniel McArdle | f883817 | 2019-12-06 21:36:48 | [diff] [blame] | 6 | See https://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
Kent Tamura | c3e4431 | 2018-04-07 16:30:24 | [diff] [blame] | 7 | for more details about the presubmit API built into gcl. |
| 8 | """ |
| 9 | |
Ho Cheung | c07ebfa | 2023-10-27 02:59:57 | [diff] [blame] | 10 | import importlib |
Kent Tamura | c3e4431 | 2018-04-07 16:30:24 | [diff] [blame] | 11 | import inspect |
| 12 | import os |
Daniel McArdle | f883817 | 2019-12-06 21:36:48 | [diff] [blame] | 13 | import re |
Kent Tamura | c3e4431 | 2018-04-07 16:30:24 | [diff] [blame] | 14 | |
| 15 | try: |
| 16 | # pylint: disable=C0103 |
Ho Cheung | c07ebfa | 2023-10-27 02:59:57 | [diff] [blame] | 17 | module_name = 'audit_non_blink_usage' |
| 18 | module_path = os.path.join( |
| 19 | os.path.dirname(inspect.stack()[0][1]), |
| 20 | 'tools/blinkpy/presubmit/audit_non_blink_usage.py') |
| 21 | audit_non_blink_usage = importlib.machinery.SourceFileLoader( |
| 22 | module_name, module_path).load_module() |
Kent Tamura | c3e4431 | 2018-04-07 16:30:24 | [diff] [blame] | 23 | except IOError: |
Kent Tamura | c9bbe0a | 2020-12-22 14:39:56 | [diff] [blame] | 24 | # One of the presubmit upload tests tries to exec this script, which |
| 25 | # doesn't interact so well with the import hack... just ignore the |
| 26 | # exception here and hope for the best. |
Kent Tamura | c3e4431 | 2018-04-07 16:30:24 | [diff] [blame] | 27 | pass |
| 28 | |
Kent Tamura | c3e4431 | 2018-04-07 16:30:24 | [diff] [blame] | 29 | _EXCLUDED_PATHS = ( |
Robert Ma | ad740d9 | 2019-06-03 13:18:12 | [diff] [blame] | 30 | # These are third-party dependencies that we don't directly control. |
| 31 | r'^third_party[\\/]blink[\\/]tools[\\/]blinkpy[\\/]third_party[\\/]wpt[\\/]wpt[\\/].*', |
Robert Ma | ad740d9 | 2019-06-03 13:18:12 | [diff] [blame] | 32 | r'^third_party[\\/]blink[\\/]web_tests[\\/]external[\\/]wpt[\\/]resources[\\/]webidl2[\\/].*', |
Kent Tamura | c3e4431 | 2018-04-07 16:30:24 | [diff] [blame] | 33 | ) |
| 34 | |
| 35 | |
| 36 | def _CheckForWrongMojomIncludes(input_api, output_api): |
| 37 | # In blink the code should either use -blink.h or -shared.h mojom |
| 38 | # headers, except in public where only -shared.h headers should be |
| 39 | # used to avoid exporting Blink types outside Blink. |
| 40 | def source_file_filter(path): |
Kent Tamura | c9bbe0a | 2020-12-22 14:39:56 | [diff] [blame] | 41 | return input_api.FilterSourceFile( |
| 42 | path, |
| 43 | files_to_skip=[ |
Dave Tapuska | cf95aaa | 2022-07-20 17:00:54 | [diff] [blame] | 44 | r'.*_test.*\.(cc|h)$', |
Yao Xiao | 7503daff | 2024-10-16 17:14:42 | [diff] [blame] | 45 | r'.*_unittest.*\.(cc|h)$', |
Matt Menke | 132d70e | 2021-06-29 01:19:28 | [diff] [blame] | 46 | r'third_party[\\/]blink[\\/]common[\\/]', |
| 47 | r'third_party[\\/]blink[\\/]public[\\/]common[\\/]', |
| 48 | r'third_party[\\/]blink[\\/]renderer[\\/]platform[\\/]loader[\\/]fetch[\\/]url_loader[\\/]', |
Yuzu Saijo | e12e7ae | 2022-08-22 05:56:55 | [diff] [blame] | 49 | r'third_party[\\/]blink[\\/]renderer[\\/]core[\\/]frame[\\/]web_view_impl.*\.(cc|h)$', |
Dave Tapuska | cf95aaa | 2022-07-20 17:00:54 | [diff] [blame] | 50 | r'third_party[\\/]blink[\\/]renderer[\\/]core[\\/]frame[\\/]web.*frame.*\.(cc|h)$', |
Kent Tamura | c9bbe0a | 2020-12-22 14:39:56 | [diff] [blame] | 51 | ]) |
Kent Tamura | c3e4431 | 2018-04-07 16:30:24 | [diff] [blame] | 52 | |
Dave Tapuska | 8cc2539 | 2020-01-22 18:36:48 | [diff] [blame] | 53 | pattern = input_api.re.compile(r'#include\s+[<"](.+)\.mojom(.*)\.h[>"]') |
Kent Tamura | c3e4431 | 2018-04-07 16:30:24 | [diff] [blame] | 54 | public_folder = input_api.os_path.normpath('third_party/blink/public/') |
| 55 | non_blink_mojom_errors = [] |
| 56 | public_blink_mojom_errors = [] |
Dave Tapuska | 8cc2539 | 2020-01-22 18:36:48 | [diff] [blame] | 57 | |
Kent Tamura | c9bbe0a | 2020-12-22 14:39:56 | [diff] [blame] | 58 | # Allow including specific non-blink interfaces that are used in the |
| 59 | # public C++ API. Adding to these allowed interfaces should meet the |
| 60 | # following conditions: |
| 61 | # - Its pros/cons is discussed and have consensus on |
Erik Chen | 0fbe13a | 2023-10-02 22:51:52 | [diff] [blame] | 62 | # platform-architecture-dev@ or |
Kent Tamura | c9bbe0a | 2020-12-22 14:39:56 | [diff] [blame] | 63 | # - It uses POD types that will not import STL (or base string) types into |
| 64 | # blink (such as no strings or vectors). |
Makoto Shimazu | 9e4b946a | 2020-03-09 05:19:17 | [diff] [blame] | 65 | # |
Kent Tamura | c9bbe0a | 2020-12-22 14:39:56 | [diff] [blame] | 66 | # So far, non-blink interfaces are allowed only for loading / loader and |
| 67 | # media interfaces so that we don't need type conversions to get through |
| 68 | # the boundary between Blink and non-Blink. |
| 69 | allowed_interfaces = ( |
| 70 | 'services/network/public/mojom/cross_origin_embedder_policy', |
Camille Lamy | f29b0e2 | 2025-01-23 11:48:54 | [diff] [blame] | 71 | 'services/network/public/mojom/document_isolation_policy', |
Hans Wennborg | a61b304 | 2021-06-15 12:06:31 | [diff] [blame] | 72 | 'services/network/public/mojom/early_hints', |
Kent Tamura | c9bbe0a | 2020-12-22 14:39:56 | [diff] [blame] | 73 | 'services/network/public/mojom/fetch_api', |
| 74 | 'services/network/public/mojom/load_timing_info', |
| 75 | 'services/network/public/mojom/url_loader', |
| 76 | 'services/network/public/mojom/url_loader_factory', |
| 77 | 'services/network/public/mojom/url_response_head', |
Marijn Kruisselbrink | aae1e88 | 2022-09-23 22:54:17 | [diff] [blame] | 78 | 'third_party/blink/public/mojom/blob/blob', |
Kent Tamura | c9bbe0a | 2020-12-22 14:39:56 | [diff] [blame] | 79 | 'third_party/blink/public/mojom/blob/serialized_blob', |
Yao Xiao | 94203f5 | 2024-09-13 17:35:57 | [diff] [blame] | 80 | 'third_party/blink/public/mojom/browser_interface_broker', |
Kent Tamura | c9bbe0a | 2020-12-22 14:39:56 | [diff] [blame] | 81 | 'third_party/blink/public/mojom/fetch/fetch_api_request', |
Erik Chen | 5fe571f | 2023-10-11 23:01:15 | [diff] [blame] | 82 | 'third_party/blink/public/mojom/loader/code_cache', |
Ming-Ying Chung | 2715fbbe | 2023-10-18 04:13:19 | [diff] [blame] | 83 | 'third_party/blink/public/mojom/loader/fetch_later', |
Alex Yang | cc8ef63 | 2024-10-08 20:13:37 | [diff] [blame] | 84 | 'third_party/blink/public/mojom/loader/local_resource_loader_config', |
Kent Tamura | c9bbe0a | 2020-12-22 14:39:56 | [diff] [blame] | 85 | 'third_party/blink/public/mojom/loader/resource_load_info', |
| 86 | 'third_party/blink/public/mojom/loader/resource_load_info_notifier', |
Erik Chen | 5fe571f | 2023-10-11 23:01:15 | [diff] [blame] | 87 | 'third_party/blink/public/mojom/loader/transferrable_url_loader', |
| 88 | 'third_party/blink/public/mojom/navigation/renderer_content_settings', |
Lingqi Chi | 2a7b3c4 | 2024-05-31 03:50:06 | [diff] [blame] | 89 | 'third_party/blink/public/mojom/page/prerender_page_param', |
Ari Chivukula | cc91f922 | 2024-08-21 14:44:51 | [diff] [blame] | 90 | 'third_party/blink/public/mojom/partitioned_popins/partitioned_popin_params', |
Kent Tamura | c9bbe0a | 2020-12-22 14:39:56 | [diff] [blame] | 91 | 'third_party/blink/public/mojom/worker/subresource_loader_updater', |
Yao Xiao | c20779e | 2023-08-25 16:27:30 | [diff] [blame] | 92 | 'third_party/blink/public/mojom/worker/worklet_global_scope_creation_params', |
Yao Xiao | c20779e | 2023-08-25 16:27:30 | [diff] [blame] | 93 | 'media/mojo/mojom/interface_factory', 'media/mojo/mojom/audio_decoder', |
| 94 | 'media/mojo/mojom/audio_encoder', 'media/mojo/mojom/video_decoder', |
Guido Urdaneta | a5c57ea | 2021-03-02 10:53:57 | [diff] [blame] | 95 | 'media/mojo/mojom/media_metrics_provider') |
Dave Tapuska | 8cc2539 | 2020-01-22 18:36:48 | [diff] [blame] | 96 | |
Kent Tamura | c3e4431 | 2018-04-07 16:30:24 | [diff] [blame] | 97 | for f in input_api.AffectedFiles(file_filter=source_file_filter): |
| 98 | for line_num, line in f.ChangedContents(): |
| 99 | error_list = None |
Kent Tamura | c3e4431 | 2018-04-07 16:30:24 | [diff] [blame] | 100 | match = pattern.match(line) |
Dave Tapuska | 8cc2539 | 2020-01-22 18:36:48 | [diff] [blame] | 101 | if (match and match.group(1) not in allowed_interfaces): |
Eriko Kurimoto | 61f1281 | 2020-01-31 08:06:50 | [diff] [blame] | 102 | if match.group(2) not in ('-shared', '-forward'): |
Leon Han | b6bd8e6 | 2019-05-29 03:18:20 | [diff] [blame] | 103 | if f.LocalPath().startswith(public_folder): |
Kent Tamura | c3e4431 | 2018-04-07 16:30:24 | [diff] [blame] | 104 | error_list = public_blink_mojom_errors |
Kent Tamura | c9bbe0a | 2020-12-22 14:39:56 | [diff] [blame] | 105 | elif match.group(2) not in ('-blink', '-blink-forward', |
| 106 | '-blink-test-utils'): |
| 107 | # Neither -shared.h, -blink.h, -blink-forward.h nor |
| 108 | # -blink-test-utils.h. |
Kent Tamura | c3e4431 | 2018-04-07 16:30:24 | [diff] [blame] | 109 | error_list = non_blink_mojom_errors |
| 110 | |
| 111 | if error_list is not None: |
Kent Tamura | c9bbe0a | 2020-12-22 14:39:56 | [diff] [blame] | 112 | error_list.append(' %s:%d %s' % |
| 113 | (f.LocalPath(), line_num, line)) |
Kent Tamura | c3e4431 | 2018-04-07 16:30:24 | [diff] [blame] | 114 | |
| 115 | results = [] |
| 116 | if non_blink_mojom_errors: |
Kent Tamura | c9bbe0a | 2020-12-22 14:39:56 | [diff] [blame] | 117 | results.append( |
| 118 | output_api.PresubmitError( |
| 119 | 'Files that include non-Blink variant mojoms found. ' |
| 120 | 'You must include .mojom-blink.h, .mojom-forward.h or ' |
| 121 | '.mojom-shared.h instead:', non_blink_mojom_errors)) |
Kent Tamura | c3e4431 | 2018-04-07 16:30:24 | [diff] [blame] | 122 | |
| 123 | if public_blink_mojom_errors: |
Kent Tamura | c9bbe0a | 2020-12-22 14:39:56 | [diff] [blame] | 124 | results.append( |
| 125 | output_api.PresubmitError( |
| 126 | 'Public blink headers using Blink variant mojoms found. ' |
| 127 | 'You must include .mojom-forward.h or .mojom-shared.h ' |
| 128 | 'instead:', public_blink_mojom_errors)) |
Kent Tamura | c3e4431 | 2018-04-07 16:30:24 | [diff] [blame] | 129 | |
| 130 | return results |
| 131 | |
| 132 | |
| 133 | def _CommonChecks(input_api, output_api): |
| 134 | """Checks common to both upload and commit.""" |
| 135 | # We should figure out what license checks we actually want to use. |
| 136 | license_header = r'.*' |
| 137 | |
| 138 | results = [] |
Kent Tamura | c9bbe0a | 2020-12-22 14:39:56 | [diff] [blame] | 139 | results.extend( |
| 140 | input_api.canned_checks.PanProjectChecks( |
| 141 | input_api, |
| 142 | output_api, |
| 143 | excluded_paths=_EXCLUDED_PATHS, |
Bruce Dawson | ae257be | 2022-07-22 15:48:26 | [diff] [blame] | 144 | owners_check=False, |
Kent Tamura | c9bbe0a | 2020-12-22 14:39:56 | [diff] [blame] | 145 | maxlen=800, |
Bruce Dawson | e7f7956e | 2022-05-03 16:42:17 | [diff] [blame] | 146 | license_header=license_header, |
| 147 | global_checks=False)) |
Kent Tamura | c3e4431 | 2018-04-07 16:30:24 | [diff] [blame] | 148 | results.extend(_CheckForWrongMojomIncludes(input_api, output_api)) |
| 149 | return results |
| 150 | |
| 151 | |
Andrew Grieve | 713b89b | 2024-10-15 20:20:08 | [diff] [blame] | 152 | def FilterPaths(input_api): |
Fergal Daly | 4fc8a21 | 2018-10-01 08:43:26 | [diff] [blame] | 153 | """Returns input files with certain paths removed.""" |
Kent Tamura | c3e4431 | 2018-04-07 16:30:24 | [diff] [blame] | 154 | files = [] |
| 155 | for f in input_api.AffectedFiles(): |
Jonathan Lee | 4c5f1f5 | 2022-09-26 20:43:04 | [diff] [blame] | 156 | file_path = f.AbsoluteLocalPath() |
| 157 | # Filter out changes in web_tests/ so they are not linted. Some files |
| 158 | # are intentionally malformed for testing. Also, external WPTs may have |
| 159 | # non-Chromium authors. |
Kent Tamura | d910234 | 2022-06-15 19:47:35 | [diff] [blame] | 160 | if 'web_tests' + input_api.os_path.sep in file_path: |
Kent Tamura | c3e4431 | 2018-04-07 16:30:24 | [diff] [blame] | 161 | continue |
Andrew Grieve | 713b89b | 2024-10-15 20:20:08 | [diff] [blame] | 162 | if input_api.os_path.sep + 'PRESUBMIT' in file_path: |
Kent Tamura | c3e4431 | 2018-04-07 16:30:24 | [diff] [blame] | 163 | continue |
Daniel McArdle | f883817 | 2019-12-06 21:36:48 | [diff] [blame] | 164 | # Skip files that were generated by bison. |
Kent Tamura | c9bbe0a | 2020-12-22 14:39:56 | [diff] [blame] | 165 | if re.search( |
Andrew Grieve | 713b89b | 2024-10-15 20:20:08 | [diff] [blame] | 166 | 'third_party.blink.renderer.' |
| 167 | 'core.xml.xpath_grammar_generated\.(cc|h)$', file_path): |
Dave Tapuska | 8cc2539 | 2020-01-22 18:36:48 | [diff] [blame] | 168 | continue |
Jonathan Lee | 4c5f1f5 | 2022-09-26 20:43:04 | [diff] [blame] | 169 | files.append(file_path) |
Fergal Daly | 4fc8a21 | 2018-10-01 08:43:26 | [diff] [blame] | 170 | return files |
| 171 | |
| 172 | |
| 173 | def _CheckStyle(input_api, output_api): |
Andrew Grieve | 713b89b | 2024-10-15 20:20:08 | [diff] [blame] | 174 | files = FilterPaths(input_api) |
Kent Tamura | f76ea8f | 2018-04-17 04:45:07 | [diff] [blame] | 175 | # Do not call check_blink_style.py with empty affected file list if all |
Kent Tamura | c3e4431 | 2018-04-07 16:30:24 | [diff] [blame] | 176 | # input_api.AffectedFiles got filtered. |
| 177 | if not files: |
| 178 | return [] |
Kent Tamura | c3e4431 | 2018-04-07 16:30:24 | [diff] [blame] | 179 | |
Fergal Daly | 4fc8a21 | 2018-10-01 08:43:26 | [diff] [blame] | 180 | style_checker_path = input_api.os_path.join(input_api.PresubmitLocalPath(), |
Kent Tamura | c9bbe0a | 2020-12-22 14:39:56 | [diff] [blame] | 181 | 'tools', |
| 182 | 'check_blink_style.py') |
Bruce Dawson | 5f7cbff | 2022-05-25 17:36:44 | [diff] [blame] | 183 | # When running git cl presubmit --all this presubmit may be asked to check |
| 184 | # ~260 files, leading to a command line that is about 17,000 characters. |
| 185 | # This goes past the Windows 8191 character cmd.exe limit and causes cryptic |
| 186 | # failures. To avoid these we break the command up into smaller pieces. |
| 187 | # Depending on how long the command is on Windows the error may be: |
| 188 | # The command line is too long. |
| 189 | # Or it may be: |
| 190 | # OSError: Execution failed with error: [WinError 206] The filename or |
| 191 | # extension is too long. |
| 192 | # The latter error comes from CreateProcess hitting its 32768 character |
| 193 | # limit. |
Bruce Dawson | 5130baf | 2022-06-23 22:25:12 | [diff] [blame] | 194 | files_per_command = 40 if input_api.is_windows else 1000 |
Fergal Daly | 4fc8a21 | 2018-10-01 08:43:26 | [diff] [blame] | 195 | results = [] |
Bruce Dawson | 5f7cbff | 2022-05-25 17:36:44 | [diff] [blame] | 196 | for i in range(0, len(files), files_per_command): |
| 197 | args = [ |
Bruce Dawson | 5130baf | 2022-06-23 22:25:12 | [diff] [blame] | 198 | input_api.python3_executable, style_checker_path, '--diff-files' |
Bruce Dawson | 5f7cbff | 2022-05-25 17:36:44 | [diff] [blame] | 199 | ] |
| 200 | args += files[i:i + files_per_command] |
| 201 | |
| 202 | try: |
| 203 | child = input_api.subprocess.Popen( |
| 204 | args, stderr=input_api.subprocess.PIPE) |
| 205 | _, stderrdata = child.communicate() |
| 206 | if child.returncode != 0: |
| 207 | results.append( |
| 208 | output_api.PresubmitError('check_blink_style.py failed', |
Kent Tamura | 2b1330c | 2022-08-29 05:20:07 | [diff] [blame] | 209 | [stderrdata.decode('utf-8')])) |
Bruce Dawson | 5f7cbff | 2022-05-25 17:36:44 | [diff] [blame] | 210 | except Exception as e: |
Kent Tamura | c9bbe0a | 2020-12-22 14:39:56 | [diff] [blame] | 211 | results.append( |
Bruce Dawson | 5f7cbff | 2022-05-25 17:36:44 | [diff] [blame] | 212 | output_api.PresubmitNotifyResult( |
| 213 | 'Could not run check_blink_style.py', [str(e)])) |
Kent Tamura | c3e4431 | 2018-04-07 16:30:24 | [diff] [blame] | 214 | |
Jonathan Lee | 4c5f1f5 | 2022-09-26 20:43:04 | [diff] [blame] | 215 | # By default, the pylint canned check lints all Python files together to |
| 216 | # check for potential problems between dependencies. This is slow to run |
| 217 | # across all of Blink (>2 min), so only lint affected files. |
| 218 | affected_python_files = [ |
| 219 | input_api.os_path.relpath(file_path, input_api.PresubmitLocalPath()) |
| 220 | for file_path in files if input_api.fnmatch.fnmatch(file_path, '*.py') |
| 221 | ] |
Jonathan Lee | 6da63fc | 2023-08-15 04:23:07 | [diff] [blame] | 222 | if affected_python_files: |
| 223 | pylintrc = input_api.os_path.join('tools', 'blinkpy', 'pylintrc') |
| 224 | results.extend( |
| 225 | input_api.RunTests( |
| 226 | input_api.canned_checks.GetPylint( |
| 227 | input_api, |
| 228 | output_api, |
| 229 | files_to_check=[ |
| 230 | re.escape(path) for path in affected_python_files |
| 231 | ], |
| 232 | pylintrc=pylintrc))) |
Kent Tamura | c3e4431 | 2018-04-07 16:30:24 | [diff] [blame] | 233 | return results |
| 234 | |
| 235 | |
| 236 | def _CheckForPrintfDebugging(input_api, output_api): |
| 237 | """Generally speaking, we'd prefer not to land patches that printf |
| 238 | debug output. |
| 239 | """ |
| 240 | printf_re = input_api.re.compile(r'^\s*(printf\(|fprintf\(stderr,)') |
| 241 | errors = input_api.canned_checks._FindNewViolationsOfRule( |
Kent Tamura | c9bbe0a | 2020-12-22 14:39:56 | [diff] [blame] | 242 | lambda _, x: not printf_re.search(x), input_api, None) |
Kent Tamura | c3e4431 | 2018-04-07 16:30:24 | [diff] [blame] | 243 | errors = [' * %s' % violation for violation in errors] |
| 244 | if errors: |
Kent Tamura | c9bbe0a | 2020-12-22 14:39:56 | [diff] [blame] | 245 | return [ |
| 246 | output_api.PresubmitPromptOrNotify( |
| 247 | 'printf debugging is best debugging! That said, it might ' |
| 248 | 'be a good idea to drop the following occurences from ' |
| 249 | 'your patch before uploading:\n%s' % '\n'.join(errors)) |
| 250 | ] |
Kent Tamura | c3e4431 | 2018-04-07 16:30:24 | [diff] [blame] | 251 | return [] |
| 252 | |
| 253 | |
| 254 | def _CheckForForbiddenChromiumCode(input_api, output_api): |
Kent Tamura | c9bbe0a | 2020-12-22 14:39:56 | [diff] [blame] | 255 | """Checks that Blink uses Chromium classes and namespaces only in |
| 256 | permitted code. |
| 257 | """ |
| 258 | # TODO(dcheng): This is pretty similar to _FindNewViolationsOfRule. |
| 259 | # Unfortunately, that can't be used directly because it doesn't give the |
| 260 | # callable enough information (namely the path to the file), so we |
| 261 | # duplicate the logic here... |
Kent Tamura | c3e4431 | 2018-04-07 16:30:24 | [diff] [blame] | 262 | results = [] |
| 263 | for f in input_api.AffectedFiles(): |
| 264 | path = f.LocalPath() |
Kent Tamura | c9bbe0a | 2020-12-22 14:39:56 | [diff] [blame] | 265 | errors = audit_non_blink_usage.check( |
| 266 | path, [(i + 1, l) for i, l in enumerate(f.NewContents())]) |
Kent Tamura | c3e4431 | 2018-04-07 16:30:24 | [diff] [blame] | 267 | if errors: |
| 268 | errors = audit_non_blink_usage.check(path, f.ChangedContents()) |
| 269 | if errors: |
Fergal Daly | 5f9d296 | 2018-10-05 08:46:07 | [diff] [blame] | 270 | for error in errors: |
Daniel Cheng | a09856d | 2025-05-29 01:04:45 | [diff] [blame] | 271 | if not results: |
| 272 | results.append( |
| 273 | output_api.PresubmitNotifyResult( |
| 274 | 'Non-Blink usage violations detected. Please ' |
| 275 | 'check if there are usable Blink equivalents; ' |
| 276 | 'if none exist, please allowlist the new uses ' |
| 277 | 'in third_party/blink/tools/blinkpy/presubmit/' |
| 278 | 'audit_non_blink_usage.py')) |
Fergal Daly | 5f9d296 | 2018-10-05 08:46:07 | [diff] [blame] | 279 | msg = '%s:%d uses disallowed identifier %s' % ( |
| 280 | path, error.line, error.identifier) |
| 281 | if error.advice: |
| 282 | msg += ". Advice: %s" % "\n".join(error.advice) |
Miyoung Shin | ba0f172b | 2020-01-23 09:10:41 | [diff] [blame] | 283 | if error.warning: |
| 284 | results.append(output_api.PresubmitPromptWarning(msg)) |
| 285 | else: |
| 286 | results.append(output_api.PresubmitError(msg)) |
Kent Tamura | c3e4431 | 2018-04-07 16:30:24 | [diff] [blame] | 287 | return results |
| 288 | |
| 289 | |
| 290 | def CheckChangeOnUpload(input_api, output_api): |
| 291 | results = [] |
| 292 | results.extend(_CommonChecks(input_api, output_api)) |
| 293 | results.extend(_CheckStyle(input_api, output_api)) |
| 294 | results.extend(_CheckForPrintfDebugging(input_api, output_api)) |
| 295 | results.extend(_CheckForForbiddenChromiumCode(input_api, output_api)) |
| 296 | return results |
| 297 | |
| 298 | |
| 299 | def CheckChangeOnCommit(input_api, output_api): |
| 300 | results = [] |
| 301 | results.extend(_CommonChecks(input_api, output_api)) |
Kent Tamura | c3e4431 | 2018-04-07 16:30:24 | [diff] [blame] | 302 | return results |