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 | |
| 43 | def _CheckChangesAreExclusiveToDirectory(input_api, output_api): |
| 44 | def IsParentDir(file, dir): |
| 45 | while file != '': |
| 46 | if file == dir: |
| 47 | return True |
| 48 | file = input_api.os_path.dirname(file) |
Yang Guo | a7845d5 | 2019-10-31 11:30:23 +0100 | [diff] [blame] | 49 | return False |
| 50 | |
| 51 | def FileIsInDir(file, dirs): |
| 52 | for dir in dirs: |
| 53 | if IsParentDir(file, dir): |
| 54 | return True |
| 55 | |
| 56 | affected_files = input_api.LocalPaths() |
Yang Guo | a7845d5 | 2019-10-31 11:30:23 +0100 | [diff] [blame] | 57 | num_affected = len(affected_files) |
| 58 | for dirs in EXCLUSIVE_CHANGE_DIRECTORIES: |
| 59 | affected_in_dir = filter(lambda f: FileIsInDir(f, dirs), affected_files) |
| 60 | num_in_dir = len(affected_in_dir) |
| 61 | if num_in_dir == 0: |
| 62 | continue |
Tim van der Lippe | ebb94a9 | 2019-11-19 17:07:53 +0000 | [diff] [blame^] | 63 | # Addition of new third_party folders must have a new entry in `.gitignore` |
| 64 | if '.gitignore' in affected_files: |
| 65 | num_in_dir = num_in_dir + 1 |
Yang Guo | a7845d5 | 2019-10-31 11:30:23 +0100 | [diff] [blame] | 66 | if num_in_dir < num_affected: |
| 67 | return [ |
| 68 | output_api.PresubmitError( |
| 69 | 'CLs that affect files in "%s" should be limited to these files/directories.' % ', '.join(dirs)) |
| 70 | ] |
| 71 | return [] |
| 72 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 73 | |
| 74 | def _CheckBuildGN(input_api, output_api): |
Yang Guo | 75beda9 | 2019-10-28 08:29:25 +0100 | [diff] [blame] | 75 | script_path = input_api.os_path.join(input_api.PresubmitLocalPath(), 'scripts', 'check_gn.js') |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 76 | return _checkWithNodeScript(input_api, output_api, script_path) |
| 77 | |
| 78 | |
| 79 | def _CheckFormat(input_api, output_api): |
| 80 | |
| 81 | def popen(args): |
| 82 | return input_api.subprocess.Popen(args=args, stdout=input_api.subprocess.PIPE, stderr=input_api.subprocess.STDOUT) |
| 83 | |
| 84 | affected_files = _getAffectedJSFiles(input_api) |
| 85 | if len(affected_files) == 0: |
| 86 | return [] |
| 87 | original_sys_path = sys.path |
| 88 | try: |
Yang Guo | 75beda9 | 2019-10-28 08:29:25 +0100 | [diff] [blame] | 89 | 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] | 90 | import devtools_paths |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 91 | finally: |
| 92 | sys.path = original_sys_path |
| 93 | |
| 94 | ignore_files = [] |
| 95 | eslint_ignore_path = input_api.os_path.join(input_api.PresubmitLocalPath(), '.eslintignore') |
| 96 | with open(eslint_ignore_path, 'r') as ignore_manifest: |
| 97 | for line in ignore_manifest: |
Ingvar Stepanyan | b532f3f | 2019-10-22 12:32:59 +0100 | [diff] [blame] | 98 | ignore_files.append(input_api.os_path.normpath(line.strip())) |
Mathias Bynens | 032591d | 2019-10-21 11:51:31 +0200 | [diff] [blame] | 99 | formattable_files = [ |
| 100 | affected_file for affected_file in affected_files if all(ignore_file not in affected_file for ignore_file in ignore_files) |
| 101 | ] |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 102 | if len(formattable_files) == 0: |
| 103 | return [] |
| 104 | |
| 105 | check_formatting_process = popen(['git', 'cl', 'format', '--js', '--dry-run'] + formattable_files) |
| 106 | check_formatting_process.communicate() |
| 107 | if check_formatting_process.returncode == 0: |
| 108 | return [] |
| 109 | |
| 110 | format_args = ['git', 'cl', 'format', '--js'] + formattable_files |
| 111 | format_process = popen(format_args) |
| 112 | format_out, _ = format_process.communicate() |
| 113 | if format_process.returncode != 0: |
| 114 | return [output_api.PresubmitError(format_out)] |
| 115 | |
| 116 | # Use eslint to autofix the braces. |
| 117 | # Also fix semicolon to avoid confusing clang-format. |
Mathias Bynens | 032591d | 2019-10-21 11:51:31 +0200 | [diff] [blame] | 118 | eslint_process = popen( |
| 119 | [devtools_paths.node_path(), devtools_paths.eslint_path(), '--config', '.eslintrc.js', '--fix'] + affected_files) |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 120 | eslint_process.communicate() |
| 121 | |
| 122 | # Need to run clang-format again to align the braces |
| 123 | popen(format_args).communicate() |
| 124 | |
| 125 | return [ |
Yang Guo | 5a805ab | 2019-10-31 13:53:28 +0100 | [diff] [blame] | 126 | output_api.PresubmitError('ERROR: Found formatting violations.\n' |
Yang Guo | 75beda9 | 2019-10-28 08:29:25 +0100 | [diff] [blame] | 127 | 'Ran clang-format on diff\n' |
| 128 | 'Use git status to check the formatting changes'), |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 129 | output_api.PresubmitError(format_out), |
| 130 | ] |
| 131 | |
| 132 | |
e52a82bdfb5106bd658c2c5ea465e200 | 594be1e | 2019-10-29 16:02:46 -0700 | [diff] [blame] | 133 | 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] | 134 | devtools_root = input_api.PresubmitLocalPath() |
e52a82bdfb5106bd658c2c5ea465e200 | 402078e | 2019-11-08 10:42:01 -0800 | [diff] [blame] | 135 | script_path = input_api.os_path.join(devtools_root, 'scripts', 'test', 'run_localization_check.py') |
e52a82bdfb5106bd658c2c5ea465e200 | 594be1e | 2019-10-29 16:02:46 -0700 | [diff] [blame] | 136 | if check_all_files == True: |
e52a82bdfb5106bd658c2c5ea465e200 | 402078e | 2019-11-08 10:42:01 -0800 | [diff] [blame] | 137 | # Scan all files and fix any errors |
| 138 | args = ['--autofix', '--a'] |
e52a82bdfb5106bd658c2c5ea465e200 | 594be1e | 2019-10-29 16:02:46 -0700 | [diff] [blame] | 139 | else: |
e52a82bdfb5106bd658c2c5ea465e200 | 402078e | 2019-11-08 10:42:01 -0800 | [diff] [blame] | 140 | devtools_front_end = input_api.os_path.join(devtools_root, 'front_end') |
| 141 | affected_front_end_files = _getAffectedFiles(input_api, [devtools_front_end], ['D'], |
| 142 | ['.js', '.grdp', '.grd', 'module.json']) |
| 143 | |
| 144 | if len(affected_front_end_files) == 0: |
| 145 | return [] |
| 146 | # Scan only added or modified files with specific extensions. |
| 147 | args = [ |
| 148 | '--autofix', |
| 149 | '--files', |
| 150 | ] + affected_front_end_files |
| 151 | process = input_api.subprocess.Popen( |
| 152 | [input_api.python_executable, script_path] + args, stdout=input_api.subprocess.PIPE, stderr=input_api.subprocess.STDOUT) |
| 153 | out, _ = process.communicate() |
| 154 | if process.returncode != 0: |
| 155 | return [output_api.PresubmitError(out)] |
| 156 | return [output_api.PresubmitNotifyResult(out)] |
Mandy Chen | 465b4f7 | 2019-03-21 22:52:54 +0000 | [diff] [blame] | 157 | |
| 158 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 159 | def _CheckDevtoolsStyle(input_api, output_api): |
Yang Guo | 75beda9 | 2019-10-28 08:29:25 +0100 | [diff] [blame] | 160 | lint_path = input_api.os_path.join(input_api.PresubmitLocalPath(), 'scripts', 'test', 'run_lint_check.py') |
Tim van der Lippe | c85c312 | 2019-09-19 11:27:04 +0000 | [diff] [blame] | 161 | process = input_api.subprocess.Popen([input_api.python_executable, lint_path], |
| 162 | stdout=input_api.subprocess.PIPE, |
| 163 | stderr=input_api.subprocess.STDOUT) |
| 164 | out, _ = process.communicate() |
| 165 | if process.returncode != 0: |
| 166 | return [output_api.PresubmitError(out)] |
| 167 | return [output_api.PresubmitNotifyResult(out)] |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 168 | |
| 169 | |
Joel Einbinder | f6f86b6 | 2019-06-10 23:19:12 +0000 | [diff] [blame] | 170 | def _CheckOptimizeSVGHashes(input_api, output_api): |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 171 | if not input_api.platform.startswith('linux'): |
| 172 | return [] |
| 173 | |
| 174 | original_sys_path = sys.path |
| 175 | try: |
| 176 | sys.path = sys.path + [input_api.os_path.join(input_api.PresubmitLocalPath(), 'scripts', 'build')] |
| 177 | import devtools_file_hashes |
| 178 | finally: |
| 179 | sys.path = original_sys_path |
| 180 | |
| 181 | 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] | 182 | images_src_path = input_api.os_path.join('devtools', 'front_end', 'Images', 'src') |
| 183 | image_source_file_paths = [path for path in absolute_local_paths if images_src_path in path and path.endswith('.svg')] |
| 184 | image_sources_path = input_api.os_path.join(input_api.PresubmitLocalPath(), 'front_end', 'Images', 'src') |
| 185 | hashes_file_name = 'optimize_svg.hashes' |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 186 | hashes_file_path = input_api.os_path.join(image_sources_path, hashes_file_name) |
| 187 | invalid_hash_file_paths = devtools_file_hashes.files_with_invalid_hashes(hashes_file_path, image_source_file_paths) |
| 188 | if len(invalid_hash_file_paths) == 0: |
| 189 | return [] |
| 190 | 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] | 191 | file_paths_str = ', '.join(invalid_hash_file_names) |
| 192 | error_message = 'The following SVG files should be optimized using optimize_svg_images script before uploading: \n - %s' % file_paths_str |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 193 | return [output_api.PresubmitError(error_message)] |
| 194 | |
| 195 | |
| 196 | def _CheckCSSViolations(input_api, output_api): |
| 197 | results = [] |
| 198 | for f in input_api.AffectedFiles(include_deletes=False): |
Yang Guo | 75beda9 | 2019-10-28 08:29:25 +0100 | [diff] [blame] | 199 | if not f.LocalPath().endswith('.css'): |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 200 | continue |
| 201 | for line_number, line in f.ChangedContents(): |
Yang Guo | 75beda9 | 2019-10-28 08:29:25 +0100 | [diff] [blame] | 202 | if '/deep/' in line: |
| 203 | results.append(output_api.PresubmitError(('%s:%d uses /deep/ selector') % (f.LocalPath(), line_number))) |
| 204 | if '::shadow' in line: |
| 205 | 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] | 206 | return results |
| 207 | |
Mathias Bynens | 032591d | 2019-10-21 11:51:31 +0200 | [diff] [blame] | 208 | |
Yang Guo | 4fd355c | 2019-09-19 10:59:03 +0200 | [diff] [blame] | 209 | def _CommonChecks(input_api, output_api): |
Mathias Bynens | 032591d | 2019-10-21 11:51:31 +0200 | [diff] [blame] | 210 | """Checks common to both upload and commit.""" |
| 211 | results = [] |
| 212 | results.extend(input_api.canned_checks.CheckOwnersFormat(input_api, output_api)) |
| 213 | results.extend(input_api.canned_checks.CheckOwners(input_api, output_api)) |
| 214 | results.extend(input_api.canned_checks.CheckChangeHasNoCrAndHasOnlyOneEol(input_api, output_api)) |
| 215 | results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace(input_api, output_api)) |
| 216 | results.extend(input_api.canned_checks.CheckGenderNeutral(input_api, output_api)) |
Mathias Bynens | 032591d | 2019-10-21 11:51:31 +0200 | [diff] [blame] | 217 | return results |
| 218 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 219 | |
| 220 | def CheckChangeOnUpload(input_api, output_api): |
| 221 | results = [] |
Yang Guo | 4fd355c | 2019-09-19 10:59:03 +0200 | [diff] [blame] | 222 | results.extend(_CommonChecks(input_api, output_api)) |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 223 | results.extend(_CheckBuildGN(input_api, output_api)) |
| 224 | results.extend(_CheckFormat(input_api, output_api)) |
| 225 | results.extend(_CheckDevtoolsStyle(input_api, output_api)) |
Joel Einbinder | f6f86b6 | 2019-06-10 23:19:12 +0000 | [diff] [blame] | 226 | results.extend(_CheckOptimizeSVGHashes(input_api, output_api)) |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 227 | results.extend(_CheckCSSViolations(input_api, output_api)) |
e52a82bdfb5106bd658c2c5ea465e200 | 594be1e | 2019-10-29 16:02:46 -0700 | [diff] [blame] | 228 | results.extend(_CheckDevtoolsLocalization(input_api, output_api)) |
Yang Guo | a7845d5 | 2019-10-31 11:30:23 +0100 | [diff] [blame] | 229 | results.extend(_CheckChangesAreExclusiveToDirectory(input_api, output_api)) |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 230 | return results |
| 231 | |
| 232 | |
| 233 | def CheckChangeOnCommit(input_api, output_api): |
Mandy Chen | f0fbdbe | 2019-08-22 23:58:37 +0000 | [diff] [blame] | 234 | results = [] |
Yang Guo | 4fd355c | 2019-09-19 10:59:03 +0200 | [diff] [blame] | 235 | results.extend(_CommonChecks(input_api, output_api)) |
e52a82bdfb5106bd658c2c5ea465e200 | 594be1e | 2019-10-29 16:02:46 -0700 | [diff] [blame] | 236 | results.extend(_CheckDevtoolsLocalization(input_api, output_api, True)) |
Yang Guo | a7845d5 | 2019-10-31 11:30:23 +0100 | [diff] [blame] | 237 | results.extend(_CheckChangesAreExclusiveToDirectory(input_api, output_api)) |
Mathias Bynens | 032591d | 2019-10-21 11:51:31 +0200 | [diff] [blame] | 238 | results.extend(input_api.canned_checks.CheckChangeHasDescription(input_api, output_api)) |
Mandy Chen | f0fbdbe | 2019-08-22 23:58:37 +0000 | [diff] [blame] | 239 | return results |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 240 | |
| 241 | |
Mandy Chen | a6be46a | 2019-07-09 17:06:27 +0000 | [diff] [blame] | 242 | 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] | 243 | """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] | 244 | under a parent directory with an accepted file ending. |
Yang Guo | 75beda9 | 2019-10-28 08:29:25 +0100 | [diff] [blame] | 245 | """ |
Mandy Chen | a6be46a | 2019-07-09 17:06:27 +0000 | [diff] [blame] | 246 | local_paths = [ |
| 247 | f.AbsoluteLocalPath() for f in input_api.AffectedFiles() if all(f.Action() != action for action in excluded_actions) |
| 248 | ] |
| 249 | affected_files = [ |
| 250 | file_name for file_name in local_paths |
| 251 | if any(parent_directory in file_name for parent_directory in parent_directories) and any( |
| 252 | file_name.endswith(accepted_ending) for accepted_ending in accepted_endings) |
| 253 | ] |
| 254 | return affected_files |
| 255 | |
| 256 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 257 | def _getAffectedFrontEndFiles(input_api): |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 258 | devtools_root = input_api.PresubmitLocalPath() |
Yang Guo | 75beda9 | 2019-10-28 08:29:25 +0100 | [diff] [blame] | 259 | devtools_front_end = input_api.os_path.join(devtools_root, 'front_end') |
| 260 | affected_front_end_files = _getAffectedFiles(input_api, [devtools_front_end], ['D'], ['.js']) |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 261 | return [input_api.os_path.relpath(file_name, devtools_root) for file_name in affected_front_end_files] |
| 262 | |
| 263 | |
| 264 | def _getAffectedJSFiles(input_api): |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 265 | devtools_root = input_api.PresubmitLocalPath() |
Yang Guo | 75beda9 | 2019-10-28 08:29:25 +0100 | [diff] [blame] | 266 | devtools_front_end = input_api.os_path.join(devtools_root, 'front_end') |
| 267 | devtools_scripts = input_api.os_path.join(devtools_root, 'scripts') |
| 268 | 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] | 269 | return [input_api.os_path.relpath(file_name, devtools_root) for file_name in affected_js_files] |
| 270 | |
| 271 | |
Lorne Mitchell | c56ff2d | 2019-05-28 23:35:03 +0000 | [diff] [blame] | 272 | 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] | 273 | original_sys_path = sys.path |
| 274 | try: |
Yang Guo | 75beda9 | 2019-10-28 08:29:25 +0100 | [diff] [blame] | 275 | 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] | 276 | import devtools_paths |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 277 | finally: |
| 278 | sys.path = original_sys_path |
| 279 | |
Yang Guo | d817698 | 2019-10-04 20:30:35 +0000 | [diff] [blame] | 280 | node_path = devtools_paths.node_path() |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 281 | |
Lorne Mitchell | c56ff2d | 2019-05-28 23:35:03 +0000 | [diff] [blame] | 282 | if script_arguments is None: |
| 283 | script_arguments = [] |
Mandy Chen | 465b4f7 | 2019-03-21 22:52:54 +0000 | [diff] [blame] | 284 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 285 | process = input_api.subprocess.Popen( |
Lorne Mitchell | c56ff2d | 2019-05-28 23:35:03 +0000 | [diff] [blame] | 286 | [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] | 287 | out, _ = process.communicate() |
| 288 | |
| 289 | if process.returncode != 0: |
| 290 | return [output_api.PresubmitError(out)] |
| 291 | return [output_api.PresubmitNotifyResult(out)] |