Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 1 | # Copyright (C) 2014 Google Inc. All rights reserved. |
| 2 | # |
| 3 | # Redistribution and use in source and binary forms, with or without |
| 4 | # modification, are permitted provided that the following conditions are |
| 5 | # met: |
| 6 | # |
| 7 | # * Redistributions of source code must retain the above copyright |
| 8 | # notice, this list of conditions and the following disclaimer. |
| 9 | # * Redistributions in binary form must reproduce the above |
| 10 | # copyright notice, this list of conditions and the following disclaimer |
| 11 | # in the documentation and/or other materials provided with the |
| 12 | # distribution. |
| 13 | # * Neither the name of Google Inc. 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 |
| 18 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 19 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 20 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 21 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 22 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 23 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 24 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 25 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 27 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Yang Guo | 75beda9 | 2019-10-28 08:29:25 +0100 | [diff] [blame] | 28 | """ |
| 29 | DevTools presubmit script |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 30 | |
| 31 | See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
| 32 | for more details about the presubmit API built into gcl. |
| 33 | """ |
| 34 | |
| 35 | import sys |
| 36 | |
Yang Guo | a7845d5 | 2019-10-31 11:30:23 +0100 | [diff] [blame] | 37 | EXCLUSIVE_CHANGE_DIRECTORIES = [ |
| 38 | [ 'third_party', 'v8' ], |
| 39 | [ 'node_modules' ], |
| 40 | [ 'OWNERS' ], |
| 41 | ] |
| 42 | |
Liviu Rau | fd2e321 | 2019-12-18 16:38:20 +0100 | [diff] [blame] | 43 | AUTOROLL_ACCOUNT = "devtools-ci-autoroll-builder@chops-service-accounts.iam.gserviceaccount.com" |
Mathias Bynens | a0a6e29 | 2019-12-17 13:24:08 +0100 | [diff] [blame] | 44 | |
Tim van der Lippe | 4d004ec | 2020-03-03 18:32:01 +0000 | [diff] [blame] | 45 | |
| 46 | def _ExecuteSubProcess(input_api, output_api, script_path, args, results): |
| 47 | process = input_api.subprocess.Popen( |
| 48 | [input_api.python_executable, script_path] + args, stdout=input_api.subprocess.PIPE, stderr=input_api.subprocess.STDOUT) |
| 49 | out, _ = process.communicate() |
| 50 | if process.returncode != 0: |
| 51 | results.append(output_api.PresubmitError(out)) |
| 52 | else: |
| 53 | results.append(output_api.PresubmitNotifyResult(out)) |
| 54 | return results |
| 55 | |
| 56 | |
Yang Guo | a7845d5 | 2019-10-31 11:30:23 +0100 | [diff] [blame] | 57 | def _CheckChangesAreExclusiveToDirectory(input_api, output_api): |
Tim van der Lippe | bc42a63 | 2019-11-28 14:22:55 +0000 | [diff] [blame] | 58 | if input_api.change.DISABLE_THIRD_PARTY_CHECK != None: |
| 59 | return [] |
Brandon Goddard | e702867 | 2020-01-30 09:31:04 -0800 | [diff] [blame] | 60 | results = [output_api.PresubmitNotifyResult('Directory Exclusivity Check:')] |
Yang Guo | a7845d5 | 2019-10-31 11:30:23 +0100 | [diff] [blame] | 61 | def IsParentDir(file, dir): |
| 62 | while file != '': |
| 63 | if file == dir: |
| 64 | return True |
| 65 | file = input_api.os_path.dirname(file) |
Yang Guo | a7845d5 | 2019-10-31 11:30:23 +0100 | [diff] [blame] | 66 | return False |
| 67 | |
| 68 | def FileIsInDir(file, dirs): |
| 69 | for dir in dirs: |
| 70 | if IsParentDir(file, dir): |
| 71 | return True |
| 72 | |
| 73 | affected_files = input_api.LocalPaths() |
Yang Guo | a7845d5 | 2019-10-31 11:30:23 +0100 | [diff] [blame] | 74 | num_affected = len(affected_files) |
| 75 | for dirs in EXCLUSIVE_CHANGE_DIRECTORIES: |
Paul Lewis | 14effba | 2019-12-02 14:56:40 +0000 | [diff] [blame] | 76 | dir_list = ', '.join(dirs) |
Yang Guo | a7845d5 | 2019-10-31 11:30:23 +0100 | [diff] [blame] | 77 | affected_in_dir = filter(lambda f: FileIsInDir(f, dirs), affected_files) |
| 78 | num_in_dir = len(affected_in_dir) |
| 79 | if num_in_dir == 0: |
| 80 | continue |
Tim van der Lippe | ebb94a9 | 2019-11-19 17:07:53 +0000 | [diff] [blame] | 81 | # Addition of new third_party folders must have a new entry in `.gitignore` |
| 82 | if '.gitignore' in affected_files: |
| 83 | num_in_dir = num_in_dir + 1 |
Yang Guo | a7845d5 | 2019-10-31 11:30:23 +0100 | [diff] [blame] | 84 | if num_in_dir < num_affected: |
Brandon Goddard | e702867 | 2020-01-30 09:31:04 -0800 | [diff] [blame] | 85 | results.append(output_api |
Paul Lewis | 14effba | 2019-12-02 14:56:40 +0000 | [diff] [blame] | 86 | .PresubmitError(('CLs that affect files in "%s" should be limited to these files/directories.' % dir_list) + |
Brandon Goddard | e702867 | 2020-01-30 09:31:04 -0800 | [diff] [blame] | 87 | ' You can disable this check by adding DISABLE_THIRD_PARTY_CHECK=<reason> to your commit message')) |
| 88 | break |
| 89 | |
| 90 | return results |
Yang Guo | a7845d5 | 2019-10-31 11:30:23 +0100 | [diff] [blame] | 91 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 92 | |
| 93 | def _CheckBuildGN(input_api, output_api): |
Brandon Goddard | e702867 | 2020-01-30 09:31:04 -0800 | [diff] [blame] | 94 | results = [output_api.PresubmitNotifyResult('Running BUILD.GN check:')] |
Yang Guo | 75beda9 | 2019-10-28 08:29:25 +0100 | [diff] [blame] | 95 | script_path = input_api.os_path.join(input_api.PresubmitLocalPath(), 'scripts', 'check_gn.js') |
Brandon Goddard | e702867 | 2020-01-30 09:31:04 -0800 | [diff] [blame] | 96 | results.extend(_checkWithNodeScript(input_api, output_api, script_path)) |
| 97 | return results |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 98 | |
| 99 | |
Tim van der Lippe | e4bdd74 | 2019-12-17 16:40:16 +0100 | [diff] [blame] | 100 | def _CheckJSON(input_api, output_api): |
Brandon Goddard | e702867 | 2020-01-30 09:31:04 -0800 | [diff] [blame] | 101 | results = [output_api.PresubmitNotifyResult('Running JSON Validator:')] |
Tim van der Lippe | e4bdd74 | 2019-12-17 16:40:16 +0100 | [diff] [blame] | 102 | script_path = input_api.os_path.join(input_api.PresubmitLocalPath(), 'scripts', 'json_validator', 'validate_module_json.js') |
Brandon Goddard | e702867 | 2020-01-30 09:31:04 -0800 | [diff] [blame] | 103 | results.extend(_checkWithNodeScript(input_api, output_api, script_path)) |
| 104 | return results |
Tim van der Lippe | e4bdd74 | 2019-12-17 16:40:16 +0100 | [diff] [blame] | 105 | |
| 106 | |
Brandon Goddard | 53faba1 | 2020-01-24 16:55:04 +0000 | [diff] [blame] | 107 | def _CheckLicenses(input_api, output_api): |
Brandon Goddard | e702867 | 2020-01-30 09:31:04 -0800 | [diff] [blame] | 108 | results = [output_api.PresubmitNotifyResult('Running License Header Check:')] |
Brandon Goddard | 53faba1 | 2020-01-24 16:55:04 +0000 | [diff] [blame] | 109 | script_path = input_api.os_path.join(input_api.PresubmitLocalPath(), 'scripts', 'test', 'run_license_header_check.js') |
Brandon Goddard | e702867 | 2020-01-30 09:31:04 -0800 | [diff] [blame] | 110 | results.extend(_checkWithNodeScript(input_api, output_api, script_path)) |
| 111 | return results |
Brandon Goddard | 53faba1 | 2020-01-24 16:55:04 +0000 | [diff] [blame] | 112 | |
| 113 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 114 | def _CheckFormat(input_api, output_api): |
Brandon Goddard | e702867 | 2020-01-30 09:31:04 -0800 | [diff] [blame] | 115 | results = [output_api.PresubmitNotifyResult('Running Format Checks:')] |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 116 | def popen(args): |
| 117 | return input_api.subprocess.Popen(args=args, stdout=input_api.subprocess.PIPE, stderr=input_api.subprocess.STDOUT) |
| 118 | |
| 119 | affected_files = _getAffectedJSFiles(input_api) |
| 120 | if len(affected_files) == 0: |
Brandon Goddard | e702867 | 2020-01-30 09:31:04 -0800 | [diff] [blame] | 121 | return results |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 122 | original_sys_path = sys.path |
| 123 | try: |
Yang Guo | 75beda9 | 2019-10-28 08:29:25 +0100 | [diff] [blame] | 124 | sys.path = sys.path + [input_api.os_path.join(input_api.PresubmitLocalPath(), 'scripts')] |
Yang Guo | d817698 | 2019-10-04 20:30:35 +0000 | [diff] [blame] | 125 | import devtools_paths |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 126 | finally: |
| 127 | sys.path = original_sys_path |
| 128 | |
| 129 | ignore_files = [] |
| 130 | eslint_ignore_path = input_api.os_path.join(input_api.PresubmitLocalPath(), '.eslintignore') |
| 131 | with open(eslint_ignore_path, 'r') as ignore_manifest: |
| 132 | for line in ignore_manifest: |
Jack Franklin | e245d1a | 2020-02-13 15:25:13 +0000 | [diff] [blame] | 133 | if '*' not in line.strip(): |
| 134 | ignore_files.append(input_api.os_path.normpath(line.strip())) |
Mathias Bynens | 032591d | 2019-10-21 11:51:31 +0200 | [diff] [blame] | 135 | formattable_files = [ |
| 136 | affected_file for affected_file in affected_files if all(ignore_file not in affected_file for ignore_file in ignore_files) |
| 137 | ] |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 138 | if len(formattable_files) == 0: |
Brandon Goddard | e702867 | 2020-01-30 09:31:04 -0800 | [diff] [blame] | 139 | return results |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 140 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 141 | format_args = ['git', 'cl', 'format', '--js'] + formattable_files |
| 142 | format_process = popen(format_args) |
| 143 | format_out, _ = format_process.communicate() |
| 144 | if format_process.returncode != 0: |
Brandon Goddard | e702867 | 2020-01-30 09:31:04 -0800 | [diff] [blame] | 145 | results.append(output_api.PresubmitError(format_out)) |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 146 | |
Brandon Goddard | e702867 | 2020-01-30 09:31:04 -0800 | [diff] [blame] | 147 | return results |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 148 | |
| 149 | |
e52a82bdfb5106bd658c2c5ea465e200 | 594be1e | 2019-10-29 16:02:46 -0700 | [diff] [blame] | 150 | def _CheckDevtoolsLocalization(input_api, output_api, check_all_files=False): # pylint: disable=invalid-name |
Brandon Goddard | e702867 | 2020-01-30 09:31:04 -0800 | [diff] [blame] | 151 | results = [output_api.PresubmitNotifyResult('Running Localization Checks:')] |
Mandy Chen | e997da7 | 2019-08-22 23:50:19 +0000 | [diff] [blame] | 152 | devtools_root = input_api.PresubmitLocalPath() |
vidorteg | 2b675b0 | 2019-11-25 09:51:28 -0800 | [diff] [blame] | 153 | script_path = input_api.os_path.join(devtools_root, 'scripts', 'test', 'run_localization_check.py') |
Paul Lewis | 954a5a9 | 2019-11-20 15:33:49 +0000 | [diff] [blame] | 154 | if check_all_files == True: |
vidorteg | 2b675b0 | 2019-11-25 09:51:28 -0800 | [diff] [blame] | 155 | # Scan all files and fix any errors |
vidorteg | 75c025e | 2019-11-25 09:52:43 -0800 | [diff] [blame] | 156 | args = ['--autofix', '--all'] |
Paul Lewis | 954a5a9 | 2019-11-20 15:33:49 +0000 | [diff] [blame] | 157 | else: |
vidorteg | 2b675b0 | 2019-11-25 09:51:28 -0800 | [diff] [blame] | 158 | devtools_front_end = input_api.os_path.join(devtools_root, 'front_end') |
| 159 | affected_front_end_files = _getAffectedFiles(input_api, [devtools_front_end], ['D'], |
| 160 | ['.js', '.grdp', '.grd', 'module.json']) |
| 161 | |
| 162 | if len(affected_front_end_files) == 0: |
Brandon Goddard | e702867 | 2020-01-30 09:31:04 -0800 | [diff] [blame] | 163 | return results |
Christy Chen | 1ab87e0 | 2020-01-30 16:32:16 -0800 | [diff] [blame] | 164 | |
| 165 | with input_api.CreateTemporaryFile() as file_list: |
| 166 | for affected_file in affected_front_end_files: |
| 167 | file_list.write(affected_file + '\n') |
| 168 | file_list.close() |
| 169 | |
vidorteg | 2b675b0 | 2019-11-25 09:51:28 -0800 | [diff] [blame] | 170 | # Scan only added or modified files with specific extensions. |
Christy Chen | 1ab87e0 | 2020-01-30 16:32:16 -0800 | [diff] [blame] | 171 | args = ['--autofix', '--file-list', file_list.name] |
Tim van der Lippe | 4d004ec | 2020-03-03 18:32:01 +0000 | [diff] [blame] | 172 | |
| 173 | return _ExecuteSubProcess(input_api, output_api, script_path, args, results) |
Mandy Chen | 465b4f7 | 2019-03-21 22:52:54 +0000 | [diff] [blame] | 174 | |
| 175 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 176 | def _CheckDevtoolsStyle(input_api, output_api): |
Brandon Goddard | e702867 | 2020-01-30 09:31:04 -0800 | [diff] [blame] | 177 | results = [output_api.PresubmitNotifyResult('Running Devtools Style Check:')] |
Yang Guo | 75beda9 | 2019-10-28 08:29:25 +0100 | [diff] [blame] | 178 | lint_path = input_api.os_path.join(input_api.PresubmitLocalPath(), 'scripts', 'test', 'run_lint_check.py') |
Tim van der Lippe | 4d004ec | 2020-03-03 18:32:01 +0000 | [diff] [blame] | 179 | |
| 180 | return _ExecuteSubProcess(input_api, output_api, lint_path, [], results) |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 181 | |
| 182 | |
Joel Einbinder | f6f86b6 | 2019-06-10 23:19:12 +0000 | [diff] [blame] | 183 | def _CheckOptimizeSVGHashes(input_api, output_api): |
Brandon Goddard | e702867 | 2020-01-30 09:31:04 -0800 | [diff] [blame] | 184 | results = [output_api.PresubmitNotifyResult('Running SVG Optimization Check:')] |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 185 | if not input_api.platform.startswith('linux'): |
Brandon Goddard | e702867 | 2020-01-30 09:31:04 -0800 | [diff] [blame] | 186 | return results |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 187 | |
| 188 | original_sys_path = sys.path |
| 189 | try: |
| 190 | sys.path = sys.path + [input_api.os_path.join(input_api.PresubmitLocalPath(), 'scripts', 'build')] |
| 191 | import devtools_file_hashes |
| 192 | finally: |
| 193 | sys.path = original_sys_path |
| 194 | |
| 195 | absolute_local_paths = [af.AbsoluteLocalPath() for af in input_api.AffectedFiles(include_deletes=False)] |
Yang Guo | 75beda9 | 2019-10-28 08:29:25 +0100 | [diff] [blame] | 196 | images_src_path = input_api.os_path.join('devtools', 'front_end', 'Images', 'src') |
| 197 | image_source_file_paths = [path for path in absolute_local_paths if images_src_path in path and path.endswith('.svg')] |
| 198 | image_sources_path = input_api.os_path.join(input_api.PresubmitLocalPath(), 'front_end', 'Images', 'src') |
| 199 | hashes_file_name = 'optimize_svg.hashes' |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 200 | hashes_file_path = input_api.os_path.join(image_sources_path, hashes_file_name) |
| 201 | invalid_hash_file_paths = devtools_file_hashes.files_with_invalid_hashes(hashes_file_path, image_source_file_paths) |
| 202 | if len(invalid_hash_file_paths) == 0: |
Brandon Goddard | e702867 | 2020-01-30 09:31:04 -0800 | [diff] [blame] | 203 | return results |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 204 | invalid_hash_file_names = [input_api.os_path.basename(file_path) for file_path in invalid_hash_file_paths] |
Yang Guo | 75beda9 | 2019-10-28 08:29:25 +0100 | [diff] [blame] | 205 | file_paths_str = ', '.join(invalid_hash_file_names) |
| 206 | error_message = 'The following SVG files should be optimized using optimize_svg_images script before uploading: \n - %s' % file_paths_str |
Brandon Goddard | e702867 | 2020-01-30 09:31:04 -0800 | [diff] [blame] | 207 | results.append(output_api.PresubmitError(error_message)) |
| 208 | return results |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 209 | |
| 210 | |
| 211 | def _CheckCSSViolations(input_api, output_api): |
Brandon Goddard | e702867 | 2020-01-30 09:31:04 -0800 | [diff] [blame] | 212 | results = [output_api.PresubmitNotifyResult('Running CSS Violation Check:')] |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 213 | for f in input_api.AffectedFiles(include_deletes=False): |
Yang Guo | 75beda9 | 2019-10-28 08:29:25 +0100 | [diff] [blame] | 214 | if not f.LocalPath().endswith('.css'): |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 215 | continue |
| 216 | for line_number, line in f.ChangedContents(): |
Yang Guo | 75beda9 | 2019-10-28 08:29:25 +0100 | [diff] [blame] | 217 | if '/deep/' in line: |
| 218 | results.append(output_api.PresubmitError(('%s:%d uses /deep/ selector') % (f.LocalPath(), line_number))) |
| 219 | if '::shadow' in line: |
| 220 | results.append(output_api.PresubmitError(('%s:%d uses ::shadow selector') % (f.LocalPath(), line_number))) |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 221 | return results |
| 222 | |
Mathias Bynens | 032591d | 2019-10-21 11:51:31 +0200 | [diff] [blame] | 223 | |
Tim van der Lippe | 4d004ec | 2020-03-03 18:32:01 +0000 | [diff] [blame] | 224 | def _CheckGeneratedFiles(input_api, output_api): |
Tim van der Lippe | b3b9076 | 2020-03-04 15:21:52 +0000 | [diff] [blame^] | 225 | v8_directory_path = input_api.os_path.join(input_api.PresubmitLocalPath(), 'v8') |
| 226 | blink_directory_path = input_api.os_path.join(input_api.PresubmitLocalPath(), 'third_party', 'blink') |
| 227 | protocol_location = input_api.os_path.join(blink_directory_path, 'public', 'devtools_protocol') |
| 228 | scripts_build_path = input_api.os_path.join(input_api.PresubmitLocalPath(), 'scripts', 'build') |
| 229 | |
| 230 | generated_aria_path = input_api.os_path.join(scripts_build_path, 'generate_aria.py') |
| 231 | generated_supported_css_path = input_api.os_path.join(scripts_build_path, 'generate_supported_css.py') |
| 232 | generated_protocol_path = input_api.os_path.join(scripts_build_path, 'code_generator_frontend.py') |
| 233 | concatenate_protocols_path = input_api.os_path.join(input_api.PresubmitLocalPath(), 'third_party', 'inspector_protocol', |
| 234 | 'concatenate_protocols.py') |
| 235 | |
| 236 | affected_files = _getAffectedFiles(input_api, [ |
| 237 | v8_directory_path, |
| 238 | blink_directory_path, |
| 239 | input_api.os_path.join(input_api.PresubmitLocalPath(), 'third_party', 'pyjson5'), |
| 240 | generated_aria_path, |
| 241 | generated_supported_css_path, |
| 242 | concatenate_protocols_path, |
| 243 | generated_protocol_path, |
| 244 | ], [], ['.pdl', '.json5', '.py']) |
| 245 | |
| 246 | if len(affected_files) == 0: |
| 247 | return [] |
| 248 | |
Tim van der Lippe | 4d004ec | 2020-03-03 18:32:01 +0000 | [diff] [blame] | 249 | results = [output_api.PresubmitNotifyResult('Running Generated Files Check:')] |
| 250 | |
Tim van der Lippe | 4d004ec | 2020-03-03 18:32:01 +0000 | [diff] [blame] | 251 | results = _ExecuteSubProcess(input_api, output_api, generated_aria_path, [], results) |
Tim van der Lippe | b3b9076 | 2020-03-04 15:21:52 +0000 | [diff] [blame^] | 252 | results = _ExecuteSubProcess(input_api, output_api, generated_supported_css_path, [], results) |
Tim van der Lippe | 4d004ec | 2020-03-03 18:32:01 +0000 | [diff] [blame] | 253 | |
Tim van der Lippe | b3b9076 | 2020-03-04 15:21:52 +0000 | [diff] [blame^] | 254 | results = _ExecuteSubProcess( |
| 255 | input_api, |
| 256 | output_api, |
| 257 | concatenate_protocols_path, |
| 258 | [ |
| 259 | input_api.os_path.join(protocol_location, 'browser_protocol.pdl'), |
| 260 | input_api.os_path.join(v8_directory_path, 'include', 'js_protocol.pdl'), |
| 261 | # output_file |
| 262 | input_api.os_path.join(protocol_location, 'browser_protocol.json'), |
| 263 | ], |
| 264 | results) |
| 265 | |
| 266 | results = _ExecuteSubProcess(input_api, output_api, generated_protocol_path, [], results) |
Tim van der Lippe | f664763 | 2020-03-04 13:46:31 +0000 | [diff] [blame] | 267 | |
Tim van der Lippe | 4d004ec | 2020-03-03 18:32:01 +0000 | [diff] [blame] | 268 | return results |
| 269 | |
| 270 | |
Tim van der Lippe | 5279f84 | 2020-01-14 16:26:38 +0000 | [diff] [blame] | 271 | def _CheckNoUncheckedFiles(input_api, output_api): |
| 272 | results = [] |
| 273 | process = input_api.subprocess.Popen(['git', 'diff', '--exit-code'], |
| 274 | stdout=input_api.subprocess.PIPE, |
| 275 | stderr=input_api.subprocess.STDOUT) |
| 276 | out, _ = process.communicate() |
| 277 | if process.returncode != 0: |
| 278 | return [output_api.PresubmitError('You have changed files that need to be committed.')] |
| 279 | return [] |
| 280 | |
Tim van der Lippe | 8fdda11 | 2020-01-27 11:27:06 +0000 | [diff] [blame] | 281 | def _CheckForTooLargeFiles(input_api, output_api): |
Christy Chen | 1ab87e0 | 2020-01-30 16:32:16 -0800 | [diff] [blame] | 282 | """Avoid large files, especially binary files, in the repository since |
Tim van der Lippe | 8fdda11 | 2020-01-27 11:27:06 +0000 | [diff] [blame] | 283 | git doesn't scale well for those. They will be in everyone's repo |
| 284 | clones forever, forever making Chromium slower to clone and work |
| 285 | with.""" |
Christy Chen | 1ab87e0 | 2020-01-30 16:32:16 -0800 | [diff] [blame] | 286 | # Uploading files to cloud storage is not trivial so we don't want |
| 287 | # to set the limit too low, but the upper limit for "normal" large |
| 288 | # files seems to be 1-2 MB, with a handful around 5-8 MB, so |
| 289 | # anything over 20 MB is exceptional. |
| 290 | TOO_LARGE_FILE_SIZE_LIMIT = 20 * 1024 * 1024 # 10 MB |
| 291 | too_large_files = [] |
| 292 | for f in input_api.AffectedFiles(): |
| 293 | # Check both added and modified files (but not deleted files). |
| 294 | if f.Action() in ('A', 'M'): |
| 295 | size = input_api.os_path.getsize(f.AbsoluteLocalPath()) |
| 296 | if size > TOO_LARGE_FILE_SIZE_LIMIT: |
| 297 | too_large_files.append("%s: %d bytes" % (f.LocalPath(), size)) |
| 298 | if too_large_files: |
| 299 | message = ( |
| 300 | 'Do not commit large files to git since git scales badly for those.\n' + |
| 301 | 'Instead put the large files in cloud storage and use DEPS to\n' + |
| 302 | 'fetch them.\n' + '\n'.join(too_large_files) |
| 303 | ) |
| 304 | return [output_api.PresubmitError( |
| 305 | 'Too large files found in commit', long_text=message + '\n')] |
| 306 | else: |
| 307 | return [] |
Tim van der Lippe | 8fdda11 | 2020-01-27 11:27:06 +0000 | [diff] [blame] | 308 | |
Tim van der Lippe | 5279f84 | 2020-01-14 16:26:38 +0000 | [diff] [blame] | 309 | |
Yang Guo | 4fd355c | 2019-09-19 10:59:03 +0200 | [diff] [blame] | 310 | def _CommonChecks(input_api, output_api): |
Mathias Bynens | 032591d | 2019-10-21 11:51:31 +0200 | [diff] [blame] | 311 | """Checks common to both upload and commit.""" |
| 312 | results = [] |
Liviu Rau | fd2e321 | 2019-12-18 16:38:20 +0100 | [diff] [blame] | 313 | results.extend(input_api.canned_checks.CheckAuthorizedAuthor(input_api, output_api, |
| 314 | bot_whitelist=[AUTOROLL_ACCOUNT] |
| 315 | )) |
Mathias Bynens | 032591d | 2019-10-21 11:51:31 +0200 | [diff] [blame] | 316 | results.extend(input_api.canned_checks.CheckOwnersFormat(input_api, output_api)) |
| 317 | results.extend(input_api.canned_checks.CheckOwners(input_api, output_api)) |
| 318 | results.extend(input_api.canned_checks.CheckChangeHasNoCrAndHasOnlyOneEol(input_api, output_api)) |
| 319 | results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace(input_api, output_api)) |
| 320 | results.extend(input_api.canned_checks.CheckGenderNeutral(input_api, output_api)) |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 321 | results.extend(_CheckBuildGN(input_api, output_api)) |
Tim van der Lippe | 4d004ec | 2020-03-03 18:32:01 +0000 | [diff] [blame] | 322 | results.extend(_CheckGeneratedFiles(input_api, output_api)) |
Tim van der Lippe | e4bdd74 | 2019-12-17 16:40:16 +0100 | [diff] [blame] | 323 | results.extend(_CheckJSON(input_api, output_api)) |
Brandon Goddard | 53faba1 | 2020-01-24 16:55:04 +0000 | [diff] [blame] | 324 | results.extend(_CheckLicenses(input_api, output_api)) |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 325 | results.extend(_CheckDevtoolsStyle(input_api, output_api)) |
Tim van der Lippe | 5497d48 | 2020-01-14 15:27:30 +0000 | [diff] [blame] | 326 | results.extend(_CheckFormat(input_api, output_api)) |
Joel Einbinder | f6f86b6 | 2019-06-10 23:19:12 +0000 | [diff] [blame] | 327 | results.extend(_CheckOptimizeSVGHashes(input_api, output_api)) |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 328 | results.extend(_CheckCSSViolations(input_api, output_api)) |
Yang Guo | a7845d5 | 2019-10-31 11:30:23 +0100 | [diff] [blame] | 329 | results.extend(_CheckChangesAreExclusiveToDirectory(input_api, output_api)) |
Tim van der Lippe | 5279f84 | 2020-01-14 16:26:38 +0000 | [diff] [blame] | 330 | results.extend(_CheckNoUncheckedFiles(input_api, output_api)) |
Tim van der Lippe | 8fdda11 | 2020-01-27 11:27:06 +0000 | [diff] [blame] | 331 | results.extend(_CheckForTooLargeFiles(input_api, output_api)) |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 332 | return results |
| 333 | |
| 334 | |
Liviu Rau | d614e09 | 2020-01-08 10:56:33 +0100 | [diff] [blame] | 335 | def CheckChangeOnUpload(input_api, output_api): |
| 336 | results = [] |
| 337 | results.extend(_CommonChecks(input_api, output_api)) |
| 338 | results.extend(_CheckDevtoolsLocalization(input_api, output_api)) |
| 339 | return results |
| 340 | |
| 341 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 342 | def CheckChangeOnCommit(input_api, output_api): |
Mandy Chen | f0fbdbe | 2019-08-22 23:58:37 +0000 | [diff] [blame] | 343 | results = [] |
Yang Guo | 4fd355c | 2019-09-19 10:59:03 +0200 | [diff] [blame] | 344 | results.extend(_CommonChecks(input_api, output_api)) |
e52a82bdfb5106bd658c2c5ea465e200 | 594be1e | 2019-10-29 16:02:46 -0700 | [diff] [blame] | 345 | results.extend(_CheckDevtoolsLocalization(input_api, output_api, True)) |
Mathias Bynens | 032591d | 2019-10-21 11:51:31 +0200 | [diff] [blame] | 346 | results.extend(input_api.canned_checks.CheckChangeHasDescription(input_api, output_api)) |
Mandy Chen | f0fbdbe | 2019-08-22 23:58:37 +0000 | [diff] [blame] | 347 | return results |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 348 | |
| 349 | |
Mandy Chen | a6be46a | 2019-07-09 17:06:27 +0000 | [diff] [blame] | 350 | def _getAffectedFiles(input_api, parent_directories, excluded_actions, accepted_endings): # pylint: disable=invalid-name |
Yang Guo | 75beda9 | 2019-10-28 08:29:25 +0100 | [diff] [blame] | 351 | """Return absolute file paths of affected files (not due to an excluded action) |
Mandy Chen | a6be46a | 2019-07-09 17:06:27 +0000 | [diff] [blame] | 352 | under a parent directory with an accepted file ending. |
Yang Guo | 75beda9 | 2019-10-28 08:29:25 +0100 | [diff] [blame] | 353 | """ |
Mandy Chen | a6be46a | 2019-07-09 17:06:27 +0000 | [diff] [blame] | 354 | local_paths = [ |
| 355 | f.AbsoluteLocalPath() for f in input_api.AffectedFiles() if all(f.Action() != action for action in excluded_actions) |
| 356 | ] |
| 357 | affected_files = [ |
| 358 | file_name for file_name in local_paths |
| 359 | if any(parent_directory in file_name for parent_directory in parent_directories) and any( |
| 360 | file_name.endswith(accepted_ending) for accepted_ending in accepted_endings) |
| 361 | ] |
| 362 | return affected_files |
| 363 | |
| 364 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 365 | def _getAffectedFrontEndFiles(input_api): |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 366 | devtools_root = input_api.PresubmitLocalPath() |
Yang Guo | 75beda9 | 2019-10-28 08:29:25 +0100 | [diff] [blame] | 367 | devtools_front_end = input_api.os_path.join(devtools_root, 'front_end') |
| 368 | affected_front_end_files = _getAffectedFiles(input_api, [devtools_front_end], ['D'], ['.js']) |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 369 | return [input_api.os_path.relpath(file_name, devtools_root) for file_name in affected_front_end_files] |
| 370 | |
| 371 | |
| 372 | def _getAffectedJSFiles(input_api): |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 373 | devtools_root = input_api.PresubmitLocalPath() |
Yang Guo | 75beda9 | 2019-10-28 08:29:25 +0100 | [diff] [blame] | 374 | devtools_front_end = input_api.os_path.join(devtools_root, 'front_end') |
| 375 | devtools_scripts = input_api.os_path.join(devtools_root, 'scripts') |
| 376 | affected_js_files = _getAffectedFiles(input_api, [devtools_front_end, devtools_scripts], ['D'], ['.js']) |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 377 | return [input_api.os_path.relpath(file_name, devtools_root) for file_name in affected_js_files] |
| 378 | |
| 379 | |
Lorne Mitchell | c56ff2d | 2019-05-28 23:35:03 +0000 | [diff] [blame] | 380 | def _checkWithNodeScript(input_api, output_api, script_path, script_arguments=None): # pylint: disable=invalid-name |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 381 | original_sys_path = sys.path |
| 382 | try: |
Yang Guo | 75beda9 | 2019-10-28 08:29:25 +0100 | [diff] [blame] | 383 | sys.path = sys.path + [input_api.os_path.join(input_api.PresubmitLocalPath(), 'scripts')] |
Yang Guo | d817698 | 2019-10-04 20:30:35 +0000 | [diff] [blame] | 384 | import devtools_paths |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 385 | finally: |
| 386 | sys.path = original_sys_path |
| 387 | |
Yang Guo | d817698 | 2019-10-04 20:30:35 +0000 | [diff] [blame] | 388 | node_path = devtools_paths.node_path() |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 389 | |
Lorne Mitchell | c56ff2d | 2019-05-28 23:35:03 +0000 | [diff] [blame] | 390 | if script_arguments is None: |
| 391 | script_arguments = [] |
Mandy Chen | 465b4f7 | 2019-03-21 22:52:54 +0000 | [diff] [blame] | 392 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 393 | process = input_api.subprocess.Popen( |
Lorne Mitchell | c56ff2d | 2019-05-28 23:35:03 +0000 | [diff] [blame] | 394 | [node_path, script_path] + script_arguments, stdout=input_api.subprocess.PIPE, stderr=input_api.subprocess.STDOUT) |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 395 | out, _ = process.communicate() |
| 396 | |
| 397 | if process.returncode != 0: |
| 398 | return [output_api.PresubmitError(out)] |
| 399 | return [output_api.PresubmitNotifyResult(out)] |