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 |
Tim van der Lippe | f515fdc | 2020-03-06 16:18:25 +0000 | [diff] [blame] | 36 | import six |
Tim van der Lippe | fb02346 | 2020-08-21 14:10:06 +0100 | [diff] [blame] | 37 | import time |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 38 | |
Yang Guo | a7845d5 | 2019-10-31 11:30:23 +0100 | [diff] [blame] | 39 | EXCLUSIVE_CHANGE_DIRECTORIES = [ |
| 40 | [ 'third_party', 'v8' ], |
| 41 | [ 'node_modules' ], |
| 42 | [ 'OWNERS' ], |
| 43 | ] |
| 44 | |
Liviu Rau | fd2e321 | 2019-12-18 16:38:20 +0100 | [diff] [blame] | 45 | AUTOROLL_ACCOUNT = "devtools-ci-autoroll-builder@chops-service-accounts.iam.gserviceaccount.com" |
Mathias Bynens | a0a6e29 | 2019-12-17 13:24:08 +0100 | [diff] [blame] | 46 | |
Tim van der Lippe | 4d004ec | 2020-03-03 18:32:01 +0000 | [diff] [blame] | 47 | |
| 48 | def _ExecuteSubProcess(input_api, output_api, script_path, args, results): |
Tim van der Lippe | f515fdc | 2020-03-06 16:18:25 +0000 | [diff] [blame] | 49 | if isinstance(script_path, six.string_types): |
| 50 | script_path = [input_api.python_executable, script_path] |
| 51 | |
Tim van der Lippe | fb02346 | 2020-08-21 14:10:06 +0100 | [diff] [blame] | 52 | start_time = time.time() |
Tim van der Lippe | f515fdc | 2020-03-06 16:18:25 +0000 | [diff] [blame] | 53 | process = input_api.subprocess.Popen(script_path + args, stdout=input_api.subprocess.PIPE, stderr=input_api.subprocess.STDOUT) |
Tim van der Lippe | 4d004ec | 2020-03-03 18:32:01 +0000 | [diff] [blame] | 54 | out, _ = process.communicate() |
Tim van der Lippe | fb02346 | 2020-08-21 14:10:06 +0100 | [diff] [blame] | 55 | end_time = time.time() |
| 56 | |
| 57 | time_difference = end_time - start_time |
| 58 | time_info = "Script execution time was %.1fs seconds\n" % (time_difference) |
Tim van der Lippe | 4d004ec | 2020-03-03 18:32:01 +0000 | [diff] [blame] | 59 | if process.returncode != 0: |
Tim van der Lippe | fb02346 | 2020-08-21 14:10:06 +0100 | [diff] [blame] | 60 | results.append(output_api.PresubmitError(time_info + out)) |
Tim van der Lippe | 4d004ec | 2020-03-03 18:32:01 +0000 | [diff] [blame] | 61 | else: |
Tim van der Lippe | fb02346 | 2020-08-21 14:10:06 +0100 | [diff] [blame] | 62 | results.append(output_api.PresubmitNotifyResult(time_info + out)) |
Tim van der Lippe | 4d004ec | 2020-03-03 18:32:01 +0000 | [diff] [blame] | 63 | return results |
| 64 | |
| 65 | |
Yang Guo | a7845d5 | 2019-10-31 11:30:23 +0100 | [diff] [blame] | 66 | def _CheckChangesAreExclusiveToDirectory(input_api, output_api): |
Tim van der Lippe | bc42a63 | 2019-11-28 14:22:55 +0000 | [diff] [blame] | 67 | if input_api.change.DISABLE_THIRD_PARTY_CHECK != None: |
| 68 | return [] |
Brandon Goddard | e702867 | 2020-01-30 09:31:04 -0800 | [diff] [blame] | 69 | results = [output_api.PresubmitNotifyResult('Directory Exclusivity Check:')] |
Yang Guo | a7845d5 | 2019-10-31 11:30:23 +0100 | [diff] [blame] | 70 | def IsParentDir(file, dir): |
| 71 | while file != '': |
| 72 | if file == dir: |
| 73 | return True |
| 74 | file = input_api.os_path.dirname(file) |
Yang Guo | a7845d5 | 2019-10-31 11:30:23 +0100 | [diff] [blame] | 75 | return False |
| 76 | |
| 77 | def FileIsInDir(file, dirs): |
| 78 | for dir in dirs: |
| 79 | if IsParentDir(file, dir): |
| 80 | return True |
| 81 | |
| 82 | affected_files = input_api.LocalPaths() |
Yang Guo | a7845d5 | 2019-10-31 11:30:23 +0100 | [diff] [blame] | 83 | num_affected = len(affected_files) |
| 84 | for dirs in EXCLUSIVE_CHANGE_DIRECTORIES: |
Paul Lewis | 14effba | 2019-12-02 14:56:40 +0000 | [diff] [blame] | 85 | dir_list = ', '.join(dirs) |
Yang Guo | a7845d5 | 2019-10-31 11:30:23 +0100 | [diff] [blame] | 86 | affected_in_dir = filter(lambda f: FileIsInDir(f, dirs), affected_files) |
| 87 | num_in_dir = len(affected_in_dir) |
| 88 | if num_in_dir == 0: |
| 89 | continue |
Tim van der Lippe | ebb94a9 | 2019-11-19 17:07:53 +0000 | [diff] [blame] | 90 | # Addition of new third_party folders must have a new entry in `.gitignore` |
| 91 | if '.gitignore' in affected_files: |
| 92 | num_in_dir = num_in_dir + 1 |
Yang Guo | a7845d5 | 2019-10-31 11:30:23 +0100 | [diff] [blame] | 93 | if num_in_dir < num_affected: |
Brandon Goddard | e702867 | 2020-01-30 09:31:04 -0800 | [diff] [blame] | 94 | results.append(output_api |
Paul Lewis | 14effba | 2019-12-02 14:56:40 +0000 | [diff] [blame] | 95 | .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] | 96 | ' You can disable this check by adding DISABLE_THIRD_PARTY_CHECK=<reason> to your commit message')) |
| 97 | break |
| 98 | |
| 99 | return results |
Yang Guo | a7845d5 | 2019-10-31 11:30:23 +0100 | [diff] [blame] | 100 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 101 | |
| 102 | def _CheckBuildGN(input_api, output_api): |
Brandon Goddard | e702867 | 2020-01-30 09:31:04 -0800 | [diff] [blame] | 103 | results = [output_api.PresubmitNotifyResult('Running BUILD.GN check:')] |
Yang Guo | 75beda9 | 2019-10-28 08:29:25 +0100 | [diff] [blame] | 104 | 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] | 105 | results.extend(_checkWithNodeScript(input_api, output_api, script_path)) |
| 106 | return results |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 107 | |
| 108 | |
Brandon Goddard | 3310437 | 2020-08-13 08:49:23 -0700 | [diff] [blame] | 109 | def _CheckExperimentTelemetry(input_api, output_api): |
Brandon Goddard | 3310437 | 2020-08-13 08:49:23 -0700 | [diff] [blame] | 110 | experiment_telemetry_files = [ |
| 111 | input_api.os_path.join(input_api.PresubmitLocalPath(), 'front_end', |
| 112 | 'main', 'MainImpl.js'), |
| 113 | input_api.os_path.join(input_api.PresubmitLocalPath(), 'front_end', |
| 114 | 'host', 'UserMetrics.js') |
| 115 | ] |
| 116 | affected_main_files = _getAffectedFiles(input_api, |
| 117 | experiment_telemetry_files, [], |
| 118 | ['.js']) |
| 119 | if len(affected_main_files) == 0: |
Tim van der Lippe | fb02346 | 2020-08-21 14:10:06 +0100 | [diff] [blame] | 120 | return [ |
| 121 | output_api.PresubmitNotifyResult( |
| 122 | 'No affected files for telemetry check') |
| 123 | ] |
Brandon Goddard | 3310437 | 2020-08-13 08:49:23 -0700 | [diff] [blame] | 124 | |
Tim van der Lippe | fb02346 | 2020-08-21 14:10:06 +0100 | [diff] [blame] | 125 | results = [ |
| 126 | output_api.PresubmitNotifyResult('Running Experiment Telemetry check:') |
| 127 | ] |
Brandon Goddard | 3310437 | 2020-08-13 08:49:23 -0700 | [diff] [blame] | 128 | script_path = input_api.os_path.join(input_api.PresubmitLocalPath(), |
| 129 | 'scripts', 'check_experiments.js') |
| 130 | results.extend(_checkWithNodeScript(input_api, output_api, script_path)) |
| 131 | return results |
| 132 | |
| 133 | |
Tim van der Lippe | e4bdd74 | 2019-12-17 16:40:16 +0100 | [diff] [blame] | 134 | def _CheckJSON(input_api, output_api): |
Brandon Goddard | e702867 | 2020-01-30 09:31:04 -0800 | [diff] [blame] | 135 | results = [output_api.PresubmitNotifyResult('Running JSON Validator:')] |
Tim van der Lippe | e4bdd74 | 2019-12-17 16:40:16 +0100 | [diff] [blame] | 136 | 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] | 137 | results.extend(_checkWithNodeScript(input_api, output_api, script_path)) |
| 138 | return results |
Tim van der Lippe | e4bdd74 | 2019-12-17 16:40:16 +0100 | [diff] [blame] | 139 | |
| 140 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 141 | def _CheckFormat(input_api, output_api): |
Tim van der Lippe | fdbd42e | 2020-04-07 15:14:36 +0100 | [diff] [blame] | 142 | node_modules_affected_files = _getAffectedFiles(input_api, [input_api.os_path.join(input_api.PresubmitLocalPath(), 'node_modules')], [], []) |
| 143 | |
| 144 | # TODO(crbug.com/1068198): Remove once `git cl format --js` can handle large CLs. |
| 145 | if (len(node_modules_affected_files) > 0): |
| 146 | return [output_api.PresubmitNotifyResult('Skipping Format Checks because `node_modules` files are affected.')] |
| 147 | |
Brandon Goddard | e702867 | 2020-01-30 09:31:04 -0800 | [diff] [blame] | 148 | results = [output_api.PresubmitNotifyResult('Running Format Checks:')] |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 149 | |
Tim van der Lippe | f515fdc | 2020-03-06 16:18:25 +0000 | [diff] [blame] | 150 | return _ExecuteSubProcess(input_api, output_api, ['git', 'cl', 'format', '--js'], [], results) |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 151 | |
| 152 | |
e52a82bdfb5106bd658c2c5ea465e200 | 594be1e | 2019-10-29 16:02:46 -0700 | [diff] [blame] | 153 | def _CheckDevtoolsLocalization(input_api, output_api, check_all_files=False): # pylint: disable=invalid-name |
Mandy Chen | e997da7 | 2019-08-22 23:50:19 +0000 | [diff] [blame] | 154 | devtools_root = input_api.PresubmitLocalPath() |
vidorteg | 2b675b0 | 2019-11-25 09:51:28 -0800 | [diff] [blame] | 155 | 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] | 156 | if check_all_files == True: |
vidorteg | 2b675b0 | 2019-11-25 09:51:28 -0800 | [diff] [blame] | 157 | # Scan all files and fix any errors |
vidorteg | 75c025e | 2019-11-25 09:52:43 -0800 | [diff] [blame] | 158 | args = ['--autofix', '--all'] |
Paul Lewis | 954a5a9 | 2019-11-20 15:33:49 +0000 | [diff] [blame] | 159 | else: |
vidorteg | 2b675b0 | 2019-11-25 09:51:28 -0800 | [diff] [blame] | 160 | devtools_front_end = input_api.os_path.join(devtools_root, 'front_end') |
| 161 | affected_front_end_files = _getAffectedFiles(input_api, [devtools_front_end], ['D'], |
| 162 | ['.js', '.grdp', '.grd', 'module.json']) |
| 163 | |
| 164 | if len(affected_front_end_files) == 0: |
Tim van der Lippe | fb02346 | 2020-08-21 14:10:06 +0100 | [diff] [blame] | 165 | return [ |
| 166 | output_api.PresubmitNotifyResult( |
| 167 | 'No affected files for localization check') |
| 168 | ] |
Christy Chen | 1ab87e0 | 2020-01-30 16:32:16 -0800 | [diff] [blame] | 169 | |
| 170 | with input_api.CreateTemporaryFile() as file_list: |
| 171 | for affected_file in affected_front_end_files: |
| 172 | file_list.write(affected_file + '\n') |
| 173 | file_list.close() |
| 174 | |
vidorteg | 2b675b0 | 2019-11-25 09:51:28 -0800 | [diff] [blame] | 175 | # Scan only added or modified files with specific extensions. |
Christy Chen | 1ab87e0 | 2020-01-30 16:32:16 -0800 | [diff] [blame] | 176 | args = ['--autofix', '--file-list', file_list.name] |
Tim van der Lippe | 4d004ec | 2020-03-03 18:32:01 +0000 | [diff] [blame] | 177 | |
Tim van der Lippe | fb02346 | 2020-08-21 14:10:06 +0100 | [diff] [blame] | 178 | results = [ |
| 179 | output_api.PresubmitNotifyResult('Running Localization Checks:') |
| 180 | ] |
Tim van der Lippe | 4d004ec | 2020-03-03 18:32:01 +0000 | [diff] [blame] | 181 | return _ExecuteSubProcess(input_api, output_api, script_path, args, results) |
Mandy Chen | 465b4f7 | 2019-03-21 22:52:54 +0000 | [diff] [blame] | 182 | |
| 183 | |
Mathias Bynens | 1b2c5e4 | 2020-06-18 08:29:21 +0200 | [diff] [blame] | 184 | def _CheckDevToolsStyleJS(input_api, output_api): |
Tim van der Lippe | fb02346 | 2020-08-21 14:10:06 +0100 | [diff] [blame] | 185 | results = [output_api.PresubmitNotifyResult('JS style check:')] |
Mathias Bynens | 1b2c5e4 | 2020-06-18 08:29:21 +0200 | [diff] [blame] | 186 | lint_path = input_api.os_path.join(input_api.PresubmitLocalPath(), |
| 187 | 'scripts', 'test', |
| 188 | 'run_lint_check_js.js') |
Tim van der Lippe | 4d004ec | 2020-03-03 18:32:01 +0000 | [diff] [blame] | 189 | |
Mathias Bynens | 1b2c5e4 | 2020-06-18 08:29:21 +0200 | [diff] [blame] | 190 | front_end_directory = input_api.os_path.join( |
| 191 | input_api.PresubmitLocalPath(), 'front_end') |
Alex Rudenko | 5556a90 | 2020-09-29 09:37:23 +0000 | [diff] [blame] | 192 | inspector_overlay_directory = input_api.os_path.join( |
| 193 | input_api.PresubmitLocalPath(), 'inspector_overlay') |
Mathias Bynens | 1b2c5e4 | 2020-06-18 08:29:21 +0200 | [diff] [blame] | 194 | test_directory = input_api.os_path.join(input_api.PresubmitLocalPath(), |
| 195 | 'test') |
| 196 | scripts_directory = input_api.os_path.join(input_api.PresubmitLocalPath(), |
| 197 | 'scripts') |
Tim van der Lippe | 2a4ae2b | 2020-03-11 17:28:06 +0000 | [diff] [blame] | 198 | |
Mathias Bynens | 1b2c5e4 | 2020-06-18 08:29:21 +0200 | [diff] [blame] | 199 | default_linted_directories = [ |
Alex Rudenko | 5556a90 | 2020-09-29 09:37:23 +0000 | [diff] [blame] | 200 | front_end_directory, test_directory, scripts_directory, |
| 201 | inspector_overlay_directory |
Mathias Bynens | 1b2c5e4 | 2020-06-18 08:29:21 +0200 | [diff] [blame] | 202 | ] |
Tim van der Lippe | 2a4ae2b | 2020-03-11 17:28:06 +0000 | [diff] [blame] | 203 | |
| 204 | eslint_related_files = [ |
Mathias Bynens | 1b2c5e4 | 2020-06-18 08:29:21 +0200 | [diff] [blame] | 205 | input_api.os_path.join(input_api.PresubmitLocalPath(), 'node_modules', |
| 206 | 'eslint'), |
Tim van der Lippe | 2a4ae2b | 2020-03-11 17:28:06 +0000 | [diff] [blame] | 207 | input_api.os_path.join(input_api.PresubmitLocalPath(), '.eslintrc.js'), |
Mathias Bynens | 1b2c5e4 | 2020-06-18 08:29:21 +0200 | [diff] [blame] | 208 | input_api.os_path.join(input_api.PresubmitLocalPath(), |
| 209 | '.eslintignore'), |
| 210 | input_api.os_path.join(scripts_directory, 'test', |
| 211 | 'run_lint_check_js.py'), |
| 212 | input_api.os_path.join(scripts_directory, 'test', |
| 213 | 'run_lint_check_js.js'), |
Tim van der Lippe | 2a4ae2b | 2020-03-11 17:28:06 +0000 | [diff] [blame] | 214 | input_api.os_path.join(scripts_directory, '.eslintrc.js'), |
| 215 | input_api.os_path.join(scripts_directory, 'eslint_rules'), |
| 216 | ] |
| 217 | |
Mathias Bynens | 1b2c5e4 | 2020-06-18 08:29:21 +0200 | [diff] [blame] | 218 | lint_config_files = _getAffectedFiles(input_api, eslint_related_files, [], |
| 219 | ['.js', '.py', '.eslintignore']) |
Tim van der Lippe | 2a4ae2b | 2020-03-11 17:28:06 +0000 | [diff] [blame] | 220 | |
Mathias Bynens | 0ec5661 | 2020-06-19 09:14:03 +0200 | [diff] [blame] | 221 | should_bail_out, files_to_lint = _getFilesToLint( |
| 222 | input_api, output_api, lint_config_files, default_linted_directories, |
| 223 | ['.js', '.ts'], results) |
| 224 | if should_bail_out: |
Mathias Bynens | 1b2c5e4 | 2020-06-18 08:29:21 +0200 | [diff] [blame] | 225 | return results |
Tim van der Lippe | 2a4ae2b | 2020-03-11 17:28:06 +0000 | [diff] [blame] | 226 | |
Mathias Bynens | 1b2c5e4 | 2020-06-18 08:29:21 +0200 | [diff] [blame] | 227 | results.extend( |
| 228 | _checkWithNodeScript(input_api, output_api, lint_path, files_to_lint)) |
Tim van der Lippe | 9813224 | 2020-04-14 17:16:54 +0100 | [diff] [blame] | 229 | return results |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 230 | |
| 231 | |
Mathias Bynens | 1b2c5e4 | 2020-06-18 08:29:21 +0200 | [diff] [blame] | 232 | def _CheckDevToolsStyleCSS(input_api, output_api): |
Tim van der Lippe | fb02346 | 2020-08-21 14:10:06 +0100 | [diff] [blame] | 233 | results = [output_api.PresubmitNotifyResult('CSS style check:')] |
Mathias Bynens | 1b2c5e4 | 2020-06-18 08:29:21 +0200 | [diff] [blame] | 234 | lint_path = input_api.os_path.join(input_api.PresubmitLocalPath(), |
| 235 | 'scripts', 'test', |
| 236 | 'run_lint_check_css.py') |
| 237 | |
| 238 | front_end_directory = input_api.os_path.join( |
| 239 | input_api.PresubmitLocalPath(), 'front_end') |
Alex Rudenko | 5556a90 | 2020-09-29 09:37:23 +0000 | [diff] [blame] | 240 | inspector_overlay_directory = input_api.os_path.join( |
| 241 | input_api.PresubmitLocalPath(), 'inspector_overlay') |
| 242 | default_linted_directories = [ |
| 243 | front_end_directory, inspector_overlay_directory |
| 244 | ] |
Mathias Bynens | 1b2c5e4 | 2020-06-18 08:29:21 +0200 | [diff] [blame] | 245 | |
| 246 | scripts_directory = input_api.os_path.join(input_api.PresubmitLocalPath(), |
| 247 | 'scripts') |
| 248 | |
| 249 | stylelint_related_files = [ |
| 250 | input_api.os_path.join(input_api.PresubmitLocalPath(), 'node_modules', |
| 251 | 'stylelint'), |
| 252 | input_api.os_path.join(input_api.PresubmitLocalPath(), |
| 253 | '.stylelintrc.json'), |
| 254 | input_api.os_path.join(input_api.PresubmitLocalPath(), |
| 255 | '.stylelintignore'), |
| 256 | input_api.os_path.join(scripts_directory, 'test', |
| 257 | 'run_lint_check_css.py'), |
| 258 | ] |
| 259 | |
| 260 | lint_config_files = _getAffectedFiles(input_api, stylelint_related_files, |
| 261 | [], |
| 262 | ['.json', '.py', '.stylelintignore']) |
| 263 | |
Mathias Bynens | 0ec5661 | 2020-06-19 09:14:03 +0200 | [diff] [blame] | 264 | should_bail_out, files_to_lint = _getFilesToLint( |
| 265 | input_api, output_api, lint_config_files, default_linted_directories, |
| 266 | ['.css'], results) |
| 267 | if should_bail_out: |
Mathias Bynens | 1b2c5e4 | 2020-06-18 08:29:21 +0200 | [diff] [blame] | 268 | return results |
| 269 | |
| 270 | return _ExecuteSubProcess(input_api, output_api, lint_path, files_to_lint, |
| 271 | results) |
| 272 | |
| 273 | |
Joel Einbinder | f6f86b6 | 2019-06-10 23:19:12 +0000 | [diff] [blame] | 274 | def _CheckOptimizeSVGHashes(input_api, output_api): |
Tim van der Lippe | fb02346 | 2020-08-21 14:10:06 +0100 | [diff] [blame] | 275 | if not input_api.platform.startswith('linux'): |
| 276 | return [output_api.PresubmitNotifyResult('Skipping SVG hash check')] |
| 277 | |
Mathias Bynens | 1b2c5e4 | 2020-06-18 08:29:21 +0200 | [diff] [blame] | 278 | results = [ |
| 279 | output_api.PresubmitNotifyResult('Running SVG optimization check:') |
| 280 | ] |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 281 | |
| 282 | original_sys_path = sys.path |
| 283 | try: |
| 284 | sys.path = sys.path + [input_api.os_path.join(input_api.PresubmitLocalPath(), 'scripts', 'build')] |
| 285 | import devtools_file_hashes |
| 286 | finally: |
| 287 | sys.path = original_sys_path |
| 288 | |
| 289 | 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] | 290 | images_src_path = input_api.os_path.join('devtools', 'front_end', 'Images', 'src') |
| 291 | image_source_file_paths = [path for path in absolute_local_paths if images_src_path in path and path.endswith('.svg')] |
| 292 | image_sources_path = input_api.os_path.join(input_api.PresubmitLocalPath(), 'front_end', 'Images', 'src') |
| 293 | hashes_file_name = 'optimize_svg.hashes' |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 294 | hashes_file_path = input_api.os_path.join(image_sources_path, hashes_file_name) |
| 295 | invalid_hash_file_paths = devtools_file_hashes.files_with_invalid_hashes(hashes_file_path, image_source_file_paths) |
| 296 | if len(invalid_hash_file_paths) == 0: |
Brandon Goddard | e702867 | 2020-01-30 09:31:04 -0800 | [diff] [blame] | 297 | return results |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 298 | 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] | 299 | file_paths_str = ', '.join(invalid_hash_file_names) |
| 300 | 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] | 301 | results.append(output_api.PresubmitError(error_message)) |
| 302 | return results |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 303 | |
| 304 | |
Mathias Bynens | 032591d | 2019-10-21 11:51:31 +0200 | [diff] [blame] | 305 | |
Tim van der Lippe | 4d004ec | 2020-03-03 18:32:01 +0000 | [diff] [blame] | 306 | def _CheckGeneratedFiles(input_api, output_api): |
Tim van der Lippe | b3b9076 | 2020-03-04 15:21:52 +0000 | [diff] [blame] | 307 | v8_directory_path = input_api.os_path.join(input_api.PresubmitLocalPath(), 'v8') |
| 308 | blink_directory_path = input_api.os_path.join(input_api.PresubmitLocalPath(), 'third_party', 'blink') |
| 309 | protocol_location = input_api.os_path.join(blink_directory_path, 'public', 'devtools_protocol') |
| 310 | scripts_build_path = input_api.os_path.join(input_api.PresubmitLocalPath(), 'scripts', 'build') |
Tim van der Lippe | 5d2d79b | 2020-03-23 11:45:04 +0000 | [diff] [blame] | 311 | scripts_generated_output_path = input_api.os_path.join(input_api.PresubmitLocalPath(), 'front_end', 'generated') |
Tim van der Lippe | b3b9076 | 2020-03-04 15:21:52 +0000 | [diff] [blame] | 312 | |
| 313 | generated_aria_path = input_api.os_path.join(scripts_build_path, 'generate_aria.py') |
| 314 | generated_supported_css_path = input_api.os_path.join(scripts_build_path, 'generate_supported_css.py') |
| 315 | generated_protocol_path = input_api.os_path.join(scripts_build_path, 'code_generator_frontend.py') |
| 316 | concatenate_protocols_path = input_api.os_path.join(input_api.PresubmitLocalPath(), 'third_party', 'inspector_protocol', |
| 317 | 'concatenate_protocols.py') |
| 318 | |
| 319 | affected_files = _getAffectedFiles(input_api, [ |
| 320 | v8_directory_path, |
| 321 | blink_directory_path, |
| 322 | input_api.os_path.join(input_api.PresubmitLocalPath(), 'third_party', 'pyjson5'), |
| 323 | generated_aria_path, |
| 324 | generated_supported_css_path, |
| 325 | concatenate_protocols_path, |
| 326 | generated_protocol_path, |
Tim van der Lippe | 5d2d79b | 2020-03-23 11:45:04 +0000 | [diff] [blame] | 327 | scripts_generated_output_path, |
| 328 | ], [], ['.pdl', '.json5', '.py', '.js']) |
Tim van der Lippe | b3b9076 | 2020-03-04 15:21:52 +0000 | [diff] [blame] | 329 | |
| 330 | if len(affected_files) == 0: |
Tim van der Lippe | fb02346 | 2020-08-21 14:10:06 +0100 | [diff] [blame] | 331 | return [ |
| 332 | output_api.PresubmitNotifyResult( |
| 333 | 'No affected files for generated files check') |
| 334 | ] |
Tim van der Lippe | b3b9076 | 2020-03-04 15:21:52 +0000 | [diff] [blame] | 335 | |
Tim van der Lippe | 4d004ec | 2020-03-03 18:32:01 +0000 | [diff] [blame] | 336 | results = [output_api.PresubmitNotifyResult('Running Generated Files Check:')] |
Tim van der Lippe | b0d65f1 | 2020-03-05 12:15:24 +0000 | [diff] [blame] | 337 | generate_protocol_resources_path = input_api.os_path.join(input_api.PresubmitLocalPath(), 'scripts', 'deps', |
| 338 | 'generate_protocol_resources.py') |
Tim van der Lippe | 4d004ec | 2020-03-03 18:32:01 +0000 | [diff] [blame] | 339 | |
Tim van der Lippe | b0d65f1 | 2020-03-05 12:15:24 +0000 | [diff] [blame] | 340 | return _ExecuteSubProcess(input_api, output_api, generate_protocol_resources_path, [], results) |
Tim van der Lippe | 4d004ec | 2020-03-03 18:32:01 +0000 | [diff] [blame] | 341 | |
| 342 | |
Christy Chen | 2d6d9a6 | 2020-09-22 09:04:09 -0700 | [diff] [blame] | 343 | def _CollectStrings(input_api, output_api): |
| 344 | devtools_root = input_api.PresubmitLocalPath() |
| 345 | devtools_front_end = input_api.os_path.join(devtools_root, 'front_end') |
| 346 | affected_front_end_files = _getAffectedFiles(input_api, |
| 347 | [devtools_front_end], ['D'], |
| 348 | ['.js']) |
| 349 | if len(affected_front_end_files) == 0: |
| 350 | return [ |
| 351 | output_api.PresubmitNotifyResult( |
| 352 | 'No affected files to run collect-strings') |
| 353 | ] |
| 354 | |
| 355 | results = [ |
| 356 | output_api.PresubmitNotifyResult('Collecting strings from front_end:') |
| 357 | ] |
| 358 | script_path = input_api.os_path.join(devtools_root, 'third_party', 'i18n', |
| 359 | 'collect-strings.js') |
| 360 | results.extend(_checkWithNodeScript(input_api, output_api, script_path)) |
| 361 | results.append( |
| 362 | output_api.PresubmitNotifyResult( |
| 363 | 'Please commit en-US.json if changes are generated.')) |
| 364 | return results |
| 365 | |
| 366 | |
Tim van der Lippe | 5279f84 | 2020-01-14 16:26:38 +0000 | [diff] [blame] | 367 | def _CheckNoUncheckedFiles(input_api, output_api): |
| 368 | results = [] |
| 369 | process = input_api.subprocess.Popen(['git', 'diff', '--exit-code'], |
| 370 | stdout=input_api.subprocess.PIPE, |
| 371 | stderr=input_api.subprocess.STDOUT) |
| 372 | out, _ = process.communicate() |
| 373 | if process.returncode != 0: |
Jack Franklin | 324f304 | 2020-09-03 11:28:29 +0100 | [diff] [blame] | 374 | files_changed_process = input_api.subprocess.Popen( |
| 375 | ['git', 'diff', '--name-only'], |
| 376 | stdout=input_api.subprocess.PIPE, |
| 377 | stderr=input_api.subprocess.STDOUT) |
Tim van der Lippe | 9bb1cf6 | 2020-03-06 16:17:02 +0000 | [diff] [blame] | 378 | files_changed, _ = files_changed_process.communicate() |
| 379 | |
| 380 | return [ |
| 381 | output_api.PresubmitError('You have changed files that need to be committed:'), |
| 382 | output_api.PresubmitError(files_changed) |
| 383 | ] |
Tim van der Lippe | 5279f84 | 2020-01-14 16:26:38 +0000 | [diff] [blame] | 384 | return [] |
| 385 | |
Tim van der Lippe | 8fdda11 | 2020-01-27 11:27:06 +0000 | [diff] [blame] | 386 | def _CheckForTooLargeFiles(input_api, output_api): |
Christy Chen | 1ab87e0 | 2020-01-30 16:32:16 -0800 | [diff] [blame] | 387 | """Avoid large files, especially binary files, in the repository since |
Tim van der Lippe | 8fdda11 | 2020-01-27 11:27:06 +0000 | [diff] [blame] | 388 | git doesn't scale well for those. They will be in everyone's repo |
| 389 | clones forever, forever making Chromium slower to clone and work |
| 390 | with.""" |
Christy Chen | 1ab87e0 | 2020-01-30 16:32:16 -0800 | [diff] [blame] | 391 | # Uploading files to cloud storage is not trivial so we don't want |
| 392 | # to set the limit too low, but the upper limit for "normal" large |
| 393 | # files seems to be 1-2 MB, with a handful around 5-8 MB, so |
| 394 | # anything over 20 MB is exceptional. |
| 395 | TOO_LARGE_FILE_SIZE_LIMIT = 20 * 1024 * 1024 # 10 MB |
| 396 | too_large_files = [] |
| 397 | for f in input_api.AffectedFiles(): |
| 398 | # Check both added and modified files (but not deleted files). |
| 399 | if f.Action() in ('A', 'M'): |
| 400 | size = input_api.os_path.getsize(f.AbsoluteLocalPath()) |
| 401 | if size > TOO_LARGE_FILE_SIZE_LIMIT: |
| 402 | too_large_files.append("%s: %d bytes" % (f.LocalPath(), size)) |
| 403 | if too_large_files: |
| 404 | message = ( |
| 405 | 'Do not commit large files to git since git scales badly for those.\n' + |
| 406 | 'Instead put the large files in cloud storage and use DEPS to\n' + |
| 407 | 'fetch them.\n' + '\n'.join(too_large_files) |
| 408 | ) |
| 409 | return [output_api.PresubmitError( |
| 410 | 'Too large files found in commit', long_text=message + '\n')] |
| 411 | else: |
| 412 | return [] |
Tim van der Lippe | 8fdda11 | 2020-01-27 11:27:06 +0000 | [diff] [blame] | 413 | |
Tim van der Lippe | 5279f84 | 2020-01-14 16:26:38 +0000 | [diff] [blame] | 414 | |
Jack Franklin | 324f304 | 2020-09-03 11:28:29 +0100 | [diff] [blame] | 415 | def _CheckComponentBridgesUpToDate(input_api, output_api): |
| 416 | # Regenerate all bridge files - if any are out of date it will cause the git diff check to fail. |
| 417 | results = [] |
| 418 | |
| 419 | script_path = input_api.os_path.join(input_api.PresubmitLocalPath(), |
Jack Franklin | 102df67 | 2020-10-13 11:20:32 +0100 | [diff] [blame^] | 420 | 'scripts', 'component_bridges', |
Jack Franklin | 324f304 | 2020-09-03 11:28:29 +0100 | [diff] [blame] | 421 | 'regenerate-all-bridges.js') |
| 422 | |
| 423 | tsc_arguments = ['-p', 'scripts/component_bridges/tsconfig.json'] |
| 424 | results.extend( |
| 425 | _checkWithTypeScript(input_api, output_api, tsc_arguments, script_path, |
| 426 | ['--silent'])) |
| 427 | return results |
| 428 | |
| 429 | |
Tim van der Lippe | f8a8709 | 2020-09-14 13:01:18 +0100 | [diff] [blame] | 430 | def _RunCannedChecks(input_api, output_api): |
| 431 | results = [] |
| 432 | results.extend( |
| 433 | input_api.canned_checks.CheckOwnersFormat(input_api, output_api)) |
| 434 | results.extend(input_api.canned_checks.CheckOwners(input_api, output_api)) |
| 435 | results.extend( |
| 436 | input_api.canned_checks.CheckChangeHasNoCrAndHasOnlyOneEol( |
| 437 | input_api, output_api)) |
| 438 | results.extend( |
| 439 | input_api.canned_checks.CheckChangeHasNoStrayWhitespace( |
| 440 | input_api, output_api)) |
| 441 | results.extend( |
| 442 | input_api.canned_checks.CheckGenderNeutral(input_api, output_api)) |
| 443 | return results |
| 444 | |
| 445 | |
Yang Guo | 4fd355c | 2019-09-19 10:59:03 +0200 | [diff] [blame] | 446 | def _CommonChecks(input_api, output_api): |
Mathias Bynens | 032591d | 2019-10-21 11:51:31 +0200 | [diff] [blame] | 447 | """Checks common to both upload and commit.""" |
| 448 | results = [] |
Mathias Bynens | 011b007 | 2020-08-05 10:17:35 +0200 | [diff] [blame] | 449 | results.extend( |
| 450 | input_api.canned_checks.CheckAuthorizedAuthor( |
| 451 | input_api, output_api, bot_allowlist=[AUTOROLL_ACCOUNT])) |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 452 | results.extend(_CheckBuildGN(input_api, output_api)) |
Brandon Goddard | 3310437 | 2020-08-13 08:49:23 -0700 | [diff] [blame] | 453 | results.extend(_CheckExperimentTelemetry(input_api, output_api)) |
Tim van der Lippe | 4d004ec | 2020-03-03 18:32:01 +0000 | [diff] [blame] | 454 | results.extend(_CheckGeneratedFiles(input_api, output_api)) |
Tim van der Lippe | e4bdd74 | 2019-12-17 16:40:16 +0100 | [diff] [blame] | 455 | results.extend(_CheckJSON(input_api, output_api)) |
Mathias Bynens | 1b2c5e4 | 2020-06-18 08:29:21 +0200 | [diff] [blame] | 456 | results.extend(_CheckDevToolsStyleJS(input_api, output_api)) |
| 457 | results.extend(_CheckDevToolsStyleCSS(input_api, output_api)) |
Tim van der Lippe | 5497d48 | 2020-01-14 15:27:30 +0000 | [diff] [blame] | 458 | results.extend(_CheckFormat(input_api, output_api)) |
Joel Einbinder | f6f86b6 | 2019-06-10 23:19:12 +0000 | [diff] [blame] | 459 | results.extend(_CheckOptimizeSVGHashes(input_api, output_api)) |
Yang Guo | a7845d5 | 2019-10-31 11:30:23 +0100 | [diff] [blame] | 460 | results.extend(_CheckChangesAreExclusiveToDirectory(input_api, output_api)) |
Jack Franklin | 324f304 | 2020-09-03 11:28:29 +0100 | [diff] [blame] | 461 | results.extend(_CheckComponentBridgesUpToDate(input_api, output_api)) |
Tim van der Lippe | f8a8709 | 2020-09-14 13:01:18 +0100 | [diff] [blame] | 462 | # Run the canned checks from `depot_tools` after the custom DevTools checks. |
| 463 | # The canned checks for example check that lines have line endings. The |
| 464 | # DevTools presubmit checks automatically fix these issues. If we would run |
| 465 | # the canned checks before the DevTools checks, they would erroneously conclude |
| 466 | # that there are issues in the code. Since the canned checks are allowed to be |
| 467 | # ignored, a confusing message is shown that asks if the failed presubmit can |
| 468 | # be continued regardless. By fixing the issues before we reach the canned checks, |
| 469 | # we don't show the message to suppress these errors, which would otherwise be |
| 470 | # causing CQ to fail. |
| 471 | results.extend(_RunCannedChecks(input_api, output_api)) |
Tim van der Lippe | 5279f84 | 2020-01-14 16:26:38 +0000 | [diff] [blame] | 472 | results.extend(_CheckNoUncheckedFiles(input_api, output_api)) |
Tim van der Lippe | 8fdda11 | 2020-01-27 11:27:06 +0000 | [diff] [blame] | 473 | results.extend(_CheckForTooLargeFiles(input_api, output_api)) |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 474 | return results |
| 475 | |
| 476 | |
Liviu Rau | d614e09 | 2020-01-08 10:56:33 +0100 | [diff] [blame] | 477 | def CheckChangeOnUpload(input_api, output_api): |
| 478 | results = [] |
| 479 | results.extend(_CommonChecks(input_api, output_api)) |
| 480 | results.extend(_CheckDevtoolsLocalization(input_api, output_api)) |
Christy Chen | 2d6d9a6 | 2020-09-22 09:04:09 -0700 | [diff] [blame] | 481 | # Run collectStrings after localization check that cleans up unused strings |
| 482 | results.extend(_CollectStrings(input_api, output_api)) |
Liviu Rau | d614e09 | 2020-01-08 10:56:33 +0100 | [diff] [blame] | 483 | return results |
| 484 | |
| 485 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 486 | def CheckChangeOnCommit(input_api, output_api): |
Mandy Chen | f0fbdbe | 2019-08-22 23:58:37 +0000 | [diff] [blame] | 487 | results = [] |
Yang Guo | 4fd355c | 2019-09-19 10:59:03 +0200 | [diff] [blame] | 488 | results.extend(_CommonChecks(input_api, output_api)) |
e52a82bdfb5106bd658c2c5ea465e200 | 594be1e | 2019-10-29 16:02:46 -0700 | [diff] [blame] | 489 | results.extend(_CheckDevtoolsLocalization(input_api, output_api, True)) |
Christy Chen | 2d6d9a6 | 2020-09-22 09:04:09 -0700 | [diff] [blame] | 490 | # Run collectStrings after localization check that cleans up unused strings |
| 491 | results.extend(_CollectStrings(input_api, output_api)) |
Mathias Bynens | 032591d | 2019-10-21 11:51:31 +0200 | [diff] [blame] | 492 | results.extend(input_api.canned_checks.CheckChangeHasDescription(input_api, output_api)) |
Mandy Chen | f0fbdbe | 2019-08-22 23:58:37 +0000 | [diff] [blame] | 493 | return results |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 494 | |
| 495 | |
Mandy Chen | a6be46a | 2019-07-09 17:06:27 +0000 | [diff] [blame] | 496 | 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] | 497 | """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] | 498 | under a parent directory with an accepted file ending. |
Yang Guo | 75beda9 | 2019-10-28 08:29:25 +0100 | [diff] [blame] | 499 | """ |
Mandy Chen | a6be46a | 2019-07-09 17:06:27 +0000 | [diff] [blame] | 500 | local_paths = [ |
| 501 | f.AbsoluteLocalPath() for f in input_api.AffectedFiles() if all(f.Action() != action for action in excluded_actions) |
| 502 | ] |
| 503 | affected_files = [ |
Tim van der Lippe | fdbd42e | 2020-04-07 15:14:36 +0100 | [diff] [blame] | 504 | file_name for file_name in local_paths if any(parent_directory in file_name for parent_directory in parent_directories) and |
| 505 | (len(accepted_endings) is 0 or any(file_name.endswith(accepted_ending) for accepted_ending in accepted_endings)) |
Mandy Chen | a6be46a | 2019-07-09 17:06:27 +0000 | [diff] [blame] | 506 | ] |
| 507 | return affected_files |
| 508 | |
| 509 | |
Tim van der Lippe | c461712 | 2020-03-06 16:24:19 +0000 | [diff] [blame] | 510 | def _checkWithNodeScript(input_api, output_api, script_path, script_arguments=[]): # pylint: disable=invalid-name |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 511 | original_sys_path = sys.path |
| 512 | try: |
Yang Guo | 75beda9 | 2019-10-28 08:29:25 +0100 | [diff] [blame] | 513 | 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] | 514 | import devtools_paths |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 515 | finally: |
| 516 | sys.path = original_sys_path |
| 517 | |
Tim van der Lippe | c461712 | 2020-03-06 16:24:19 +0000 | [diff] [blame] | 518 | return _ExecuteSubProcess(input_api, output_api, [devtools_paths.node_path(), script_path], script_arguments, []) |
Mathias Bynens | 1b2c5e4 | 2020-06-18 08:29:21 +0200 | [diff] [blame] | 519 | |
| 520 | |
Jack Franklin | 324f304 | 2020-09-03 11:28:29 +0100 | [diff] [blame] | 521 | def _checkWithTypeScript(input_api, |
| 522 | output_api, |
| 523 | tsc_arguments, |
| 524 | script_path, |
| 525 | script_arguments=[]): # pylint: disable=invalid-name |
| 526 | original_sys_path = sys.path |
| 527 | try: |
| 528 | sys.path = sys.path + [ |
| 529 | input_api.os_path.join(input_api.PresubmitLocalPath(), 'scripts') |
| 530 | ] |
| 531 | import devtools_paths |
| 532 | finally: |
| 533 | sys.path = original_sys_path |
| 534 | |
| 535 | # First run tsc to compile the TS script that we then run in the _ExecuteSubProcess call |
| 536 | tsc_compiler_process = input_api.subprocess.Popen( |
| 537 | [ |
| 538 | devtools_paths.node_path(), |
| 539 | devtools_paths.typescript_compiler_path() |
| 540 | ] + tsc_arguments, |
| 541 | stdout=input_api.subprocess.PIPE, |
| 542 | stderr=input_api.subprocess.STDOUT) |
| 543 | |
| 544 | out, _ = tsc_compiler_process.communicate() |
| 545 | if tsc_compiler_process.returncode != 0: |
| 546 | return [ |
| 547 | output_api.PresubmitError('Error compiling briges regenerator:\n' + |
| 548 | str(out)) |
| 549 | ] |
| 550 | |
| 551 | return _checkWithNodeScript(input_api, output_api, script_path, |
| 552 | script_arguments) |
| 553 | |
| 554 | |
Mathias Bynens | 1b2c5e4 | 2020-06-18 08:29:21 +0200 | [diff] [blame] | 555 | def _getFilesToLint(input_api, output_api, lint_config_files, |
| 556 | default_linted_directories, accepted_endings, results): |
Mathias Bynens | 0ec5661 | 2020-06-19 09:14:03 +0200 | [diff] [blame] | 557 | run_full_check = False |
Mathias Bynens | 1b2c5e4 | 2020-06-18 08:29:21 +0200 | [diff] [blame] | 558 | files_to_lint = [] |
| 559 | |
| 560 | # We are changing the lint configuration; run the full check. |
| 561 | if len(lint_config_files) is not 0: |
| 562 | results.append( |
| 563 | output_api.PresubmitNotifyResult('Running full lint check')) |
Mathias Bynens | 0ec5661 | 2020-06-19 09:14:03 +0200 | [diff] [blame] | 564 | run_full_check = True |
Mathias Bynens | 1b2c5e4 | 2020-06-18 08:29:21 +0200 | [diff] [blame] | 565 | else: |
| 566 | # Only run the linter on files that are relevant, to save PRESUBMIT time. |
| 567 | files_to_lint = _getAffectedFiles(input_api, |
| 568 | default_linted_directories, ['D'], |
| 569 | accepted_endings) |
| 570 | |
Paul Lewis | 2b9224f | 2020-09-08 18:13:10 +0100 | [diff] [blame] | 571 | # Exclude front_end/third_party files. |
| 572 | files_to_lint = filter(lambda path: "third_party" not in path, |
| 573 | files_to_lint) |
| 574 | |
Mathias Bynens | 1b2c5e4 | 2020-06-18 08:29:21 +0200 | [diff] [blame] | 575 | if len(files_to_lint) is 0: |
| 576 | results.append( |
| 577 | output_api.PresubmitNotifyResult( |
| 578 | 'No affected files for lint check')) |
| 579 | |
Mathias Bynens | 0ec5661 | 2020-06-19 09:14:03 +0200 | [diff] [blame] | 580 | should_bail_out = len(files_to_lint) is 0 and not run_full_check |
| 581 | return should_bail_out, files_to_lint |