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