Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: third_party/WebKit/Source/devtools/PRESUBMIT.py

Issue 2538003002: DevTools: bail out presubmit early if error after node.js or formatting checks (Closed)
Patch Set: address CL feedback Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/devtools/.gitignore ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (C) 2014 Google Inc. All rights reserved. 1 # Copyright (C) 2014 Google Inc. All rights reserved.
2 # 2 #
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are 4 # modification, are permitted provided that the following conditions are
5 # met: 5 # met:
6 # 6 #
7 # * Redistributions of source code must retain the above copyright 7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer. 8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above 9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer 10 # copyright notice, this list of conditions and the following disclaimer
(...skipping 14 matching lines...) Expand all
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 28
29 """DevTools JSDoc validator presubmit script 29 """DevTools JSDoc validator presubmit script
30 30
31 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts 31 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
32 for more details about the presubmit API built into gcl. 32 for more details about the presubmit API built into gcl.
33 """ 33 """
34 34
35 from collections import namedtuple
35 import sys 36 import sys
36 37
37 compile_note = "Be sure to run your patch by the compile_frontend.py script prio r to committing!" 38 compile_note = "Be sure to run your patch by the compile_frontend.py script prio r to committing!"
38 39
40 CheckOutput = namedtuple('CheckOutput', ['results', 'has_errors'])
41
39 42
40 def _CheckNodeAndNPMModules(input_api, output_api): 43 def _CheckNodeAndNPMModules(input_api, output_api):
41 node_script_path = input_api.os_path.join(input_api.PresubmitLocalPath(), "s cripts", "install_node_deps.py") 44 node_script_path = input_api.os_path.join(input_api.PresubmitLocalPath(), "s cripts", "install_node_deps.py")
42 process = input_api.subprocess.Popen( 45 process = input_api.subprocess.Popen(
43 [input_api.python_executable, node_script_path], 46 [input_api.python_executable, node_script_path],
44 stdout=input_api.subprocess.PIPE, 47 stdout=input_api.subprocess.PIPE,
45 stderr=input_api.subprocess.STDOUT) 48 stderr=input_api.subprocess.STDOUT)
46 out, _ = process.communicate() 49 out, _ = process.communicate()
47 if process.returncode != 0: 50 if process.returncode != 0:
48 return [output_api.PresubmitError(out)] 51 return CheckOutput([output_api.PresubmitError(out)], has_errors=True)
49 return [output_api.PresubmitNotifyResult(out)] 52 return CheckOutput([output_api.PresubmitNotifyResult(out)], has_errors=False )
53
50 54
51 def _FormatDevtools(input_api, output_api): 55 def _FormatDevtools(input_api, output_api):
52 affected_front_end_files = _getAffectedFrontEndFiles(input_api) 56 affected_front_end_files = _getAffectedFrontEndFiles(input_api)
53 if len(affected_front_end_files) == 0: 57 if len(affected_front_end_files) == 0:
54 return [] 58 return CheckOutput([], has_errors=False)
55 original_sys_path = sys.path 59 original_sys_path = sys.path
56 try: 60 try:
57 sys.path = sys.path + [input_api.os_path.join(input_api.PresubmitLocalPa th(), "scripts")] 61 sys.path = sys.path + [input_api.os_path.join(input_api.PresubmitLocalPa th(), "scripts")]
58 import install_node_deps 62 import install_node_deps
59 finally: 63 finally:
60 sys.path = original_sys_path 64 sys.path = original_sys_path
61 65
62 node_path, _ = install_node_deps.resolve_node_paths() 66 node_path, _ = install_node_deps.resolve_node_paths()
63 format_path = input_api.os_path.join(input_api.PresubmitLocalPath(), "script s", "format.js") 67 format_path = input_api.os_path.join(input_api.PresubmitLocalPath(), "script s", "format.js")
64 glob_arg = "--glob=" + ",".join(affected_front_end_files) 68 glob_arg = "--glob=" + ",".join(affected_front_end_files)
65 check_formatting_process = _inputPopen(input_api, 69 check_formatting_process = _inputPopen(input_api,
66 args=[node_path, format_path] + [glob_arg, "--output-replacements-xml"]) 70 args=[node_path, format_path] + [glob_arg, "--output-replacements-xml"])
67 check_formatting_out, _ = check_formatting_process.communicate() 71 check_formatting_out, _ = check_formatting_process.communicate()
68 if check_formatting_process.returncode != 0: 72 if check_formatting_process.returncode != 0:
69 return [output_api.PresubmitError(check_formatting_out)] 73 return CheckOutput([output_api.PresubmitError(check_formatting_out)], ha s_errors=True)
70 if "</replacement>" not in check_formatting_out: 74 if "</replacement>" not in check_formatting_out:
71 return [output_api.PresubmitNotifyResult("CL is properly formatted")] 75 return CheckOutput([output_api.PresubmitNotifyResult("CL is properly for matted")], has_errors=False)
72 76
73 format_args = [node_path, format_path] + [glob_arg] 77 format_args = [node_path, format_path] + [glob_arg]
74 format_process = _inputPopen(input_api, format_args) 78 format_process = _inputPopen(input_api, format_args)
75 format_process_out, _ = format_process.communicate() 79 format_process_out, _ = format_process.communicate()
76 80
77 # Use eslint to autofix the braces 81 # Use eslint to autofix the braces
78 eslint_path = input_api.os_path.join(input_api.PresubmitLocalPath(), "node_m odules", ".bin", "eslint") 82 eslint_path = input_api.os_path.join(input_api.PresubmitLocalPath(), "node_m odules", ".bin", "eslint")
79 eslint_process = _inputPopen(input_api, 83 eslint_process = _inputPopen(input_api,
80 [node_path, eslint_path, '--no-eslintrc', '--fix', '--env=es6', 84 [node_path, eslint_path, '--no-eslintrc', '--fix', '--env=es6',
81 '--rule={"curly": [2, "multi-or-nest", "consistent"]}'] 85 '--rule={"curly": [2, "multi-or-nest", "consistent"]}']
82 + affected_front_end_files) 86 + affected_front_end_files)
83 eslint_process.communicate() 87 eslint_process.communicate()
84 88
85 # Need to run clang-format again to align the braces 89 # Need to run clang-format again to align the braces
86 reformat_process = _inputPopen(input_api, format_args) 90 reformat_process = _inputPopen(input_api, format_args)
87 reformat_process.communicate() 91 reformat_process.communicate()
88 92
89 return [output_api.PresubmitError("ERROR: Found formatting violations.\n" 93 return CheckOutput([output_api.PresubmitError("ERROR: Found formatting viola tions.\n"
90 "Ran clang-format on files changed in CL\n " 94 "Ran clang-format on files changed in CL\n "
91 "Use git status to check the formatting ch anges"), 95 "Use git status to check the formatting ch anges"),
92 output_api.PresubmitError(format_process_out)] 96 output_api.PresubmitError(format_process_out)], has_errors=True)
93 97
94 98
95 def _CheckDevtoolsStyle(input_api, output_api): 99 def _CheckDevtoolsStyle(input_api, output_api):
96 affected_front_end_files = _getAffectedFrontEndFiles(input_api) 100 affected_front_end_files = _getAffectedFrontEndFiles(input_api)
97 if len(affected_front_end_files) > 0: 101 if len(affected_front_end_files) > 0:
98 lint_path = input_api.os_path.join(input_api.PresubmitLocalPath(), 102 lint_path = input_api.os_path.join(input_api.PresubmitLocalPath(),
99 "scripts", "lint_javascript.py") 103 "scripts", "lint_javascript.py")
100 process = input_api.subprocess.Popen( 104 process = input_api.subprocess.Popen(
101 [input_api.python_executable, lint_path] + affected_front_end_files, 105 [input_api.python_executable, lint_path] + affected_front_end_files,
102 stdout=input_api.subprocess.PIPE, 106 stdout=input_api.subprocess.PIPE,
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 for line_number, line in f.ChangedContents(): 199 for line_number, line in f.ChangedContents():
196 if "/deep/" in line: 200 if "/deep/" in line:
197 results.append(output_api.PresubmitError(("%s:%d uses /deep/ sel ector") % (f.LocalPath(), line_number))) 201 results.append(output_api.PresubmitError(("%s:%d uses /deep/ sel ector") % (f.LocalPath(), line_number)))
198 if "::shadow" in line: 202 if "::shadow" in line:
199 results.append(output_api.PresubmitError(("%s:%d uses ::shadow s elector") % (f.LocalPath(), line_number))) 203 results.append(output_api.PresubmitError(("%s:%d uses ::shadow s elector") % (f.LocalPath(), line_number)))
200 return results 204 return results
201 205
202 206
203 def CheckChangeOnUpload(input_api, output_api): 207 def CheckChangeOnUpload(input_api, output_api):
204 results = [] 208 results = []
205 results.extend(_CheckNodeAndNPMModules(input_api, output_api)) 209
206 results.extend(_FormatDevtools(input_api, output_api)) 210 (node_results, has_errors) = _CheckNodeAndNPMModules(input_api, output_api)
211 results.extend(node_results)
212 if has_errors:
213 results.append(output_api.PresubmitError("ERROR: Bailed out early becaus e error using node.js/npm"))
214 return results
215
216 (format_results, has_errors) = _FormatDevtools(input_api, output_api)
217 results.extend(format_results)
218 if has_errors:
219 results.append(output_api.PresubmitError("ERROR: Bailed out early becaus e formatting errors were found"))
220 return results
221
207 results.extend(_CheckDevtoolsStyle(input_api, output_api)) 222 results.extend(_CheckDevtoolsStyle(input_api, output_api))
208 results.extend(_CompileDevtoolsFrontend(input_api, output_api)) 223 results.extend(_CompileDevtoolsFrontend(input_api, output_api))
209 results.extend(_CheckConvertSVGToPNGHashes(input_api, output_api)) 224 results.extend(_CheckConvertSVGToPNGHashes(input_api, output_api))
210 results.extend(_CheckOptimizePNGHashes(input_api, output_api)) 225 results.extend(_CheckOptimizePNGHashes(input_api, output_api))
211 results.extend(_CheckCSSViolations(input_api, output_api)) 226 results.extend(_CheckCSSViolations(input_api, output_api))
212 return results 227 return results
213 228
214 229
215 def CheckChangeOnCommit(input_api, output_api): 230 def CheckChangeOnCommit(input_api, output_api):
216 return [] 231 return []
217 232
233
218 def _getAffectedFrontEndFiles(input_api): 234 def _getAffectedFrontEndFiles(input_api):
219 local_paths = [f.AbsoluteLocalPath() for f in input_api.AffectedFiles() if f .Action() != "D"] 235 local_paths = [f.AbsoluteLocalPath() for f in input_api.AffectedFiles() if f .Action() != "D"]
220 devtools_root = input_api.PresubmitLocalPath() 236 devtools_root = input_api.PresubmitLocalPath()
221 devtools_front_end = input_api.os_path.join(devtools_root, "front_end") 237 devtools_front_end = input_api.os_path.join(devtools_root, "front_end")
222 affected_front_end_files = [file_name for file_name in local_paths if devtoo ls_front_end in file_name and file_name.endswith(".js")] 238 affected_front_end_files = [file_name for file_name in local_paths if devtoo ls_front_end in file_name and file_name.endswith(".js")]
223 return [input_api.os_path.relpath(file_name, devtools_root) for file_name in affected_front_end_files] 239 return [input_api.os_path.relpath(file_name, devtools_root) for file_name in affected_front_end_files]
224 240
241
225 def _inputPopen(input_api, args): 242 def _inputPopen(input_api, args):
226 return input_api.subprocess.Popen( 243 return input_api.subprocess.Popen(
227 args, 244 args,
228 stdout=input_api.subprocess.PIPE, 245 stdout=input_api.subprocess.PIPE,
229 stderr=input_api.subprocess.STDOUT) 246 stderr=input_api.subprocess.STDOUT)
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/devtools/.gitignore ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698