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

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

Issue 2717833002: DevTools: use git cl format --js for PRESUBMIT check (Closed)
Patch Set: fix Created 3 years, 9 months 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 | « no previous file | third_party/WebKit/Source/devtools/package.json » ('j') | 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 13 matching lines...) Expand all
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
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 """DevTools JSDoc validator presubmit script 28 """DevTools JSDoc validator presubmit script
29 29
30 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts 30 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
31 for more details about the presubmit API built into gcl. 31 for more details about the presubmit API built into gcl.
32 """ 32 """
33 33
34 from collections import namedtuple
35 import sys 34 import sys
36 35
37 CheckOutput = namedtuple('CheckOutput', ['results', 'has_errors'])
38
39 36
40 def _CheckNodeAndNPMModules(input_api, output_api): 37 def _CheckNodeAndNPMModules(input_api, output_api):
41 node_script_path = input_api.os_path.join(input_api.PresubmitLocalPath(), "s cripts", "install_node_deps.py") 38 node_script_path = input_api.os_path.join(input_api.PresubmitLocalPath(), "s cripts", "install_node_deps.py")
42 process = input_api.subprocess.Popen( 39 process = input_api.subprocess.Popen(
43 [input_api.python_executable, node_script_path], stdout=input_api.subpro cess.PIPE, stderr=input_api.subprocess.STDOUT) 40 [input_api.python_executable, node_script_path], stdout=input_api.subpro cess.PIPE, stderr=input_api.subprocess.STDOUT)
44 out, _ = process.communicate() 41 out, _ = process.communicate()
45 if process.returncode != 0: 42 if process.returncode != 0:
46 return CheckOutput([output_api.PresubmitError(out)], has_errors=True) 43 return [output_api.PresubmitError(out)]
47 return CheckOutput([output_api.PresubmitNotifyResult(out)], has_errors=False ) 44 return [output_api.PresubmitNotifyResult(out)]
48 45
49 46
50 def _FormatDevtools(input_api, output_api): 47 def _CheckFormat(input_api, output_api):
48
49 def popen(args):
50 return input_api.subprocess.Popen(args=args, stdout=input_api.subprocess .PIPE, stderr=input_api.subprocess.STDOUT)
51
51 affected_files = _getAffectedJSFiles(input_api) 52 affected_files = _getAffectedJSFiles(input_api)
52 if len(affected_files) == 0: 53 if len(affected_files) == 0:
53 return CheckOutput([], has_errors=False) 54 return []
54 original_sys_path = sys.path 55 original_sys_path = sys.path
55 try: 56 try:
56 sys.path = sys.path + [input_api.os_path.join(input_api.PresubmitLocalPa th(), "scripts")] 57 sys.path = sys.path + [input_api.os_path.join(input_api.PresubmitLocalPa th(), "scripts")]
57 import install_node_deps 58 import install_node_deps
58 finally: 59 finally:
59 sys.path = original_sys_path 60 sys.path = original_sys_path
60 61
61 node_path, _ = install_node_deps.resolve_node_paths() 62 node_path, _ = install_node_deps.resolve_node_paths()
62 format_path = input_api.os_path.join(input_api.PresubmitLocalPath(), "script s", "format.js")
63 glob_arg = "--glob=" + ",".join(affected_files)
64 check_formatting_process = _inputPopen(input_api, args=[node_path, format_pa th] + [glob_arg, "--output-replacements-xml"])
65 check_formatting_out, _ = check_formatting_process.communicate()
66 if check_formatting_process.returncode != 0:
67 return CheckOutput([output_api.PresubmitError(check_formatting_out)], ha s_errors=True)
68 if "</replacement>" not in check_formatting_out:
69 return CheckOutput([output_api.PresubmitNotifyResult("CL is properly for matted")], has_errors=False)
70 63
71 format_args = [node_path, format_path] + [glob_arg] 64 check_formatting_process = popen(['git', 'cl', 'format', '--js', '--dry-run' , input_api.PresubmitLocalPath()])
72 format_process = _inputPopen(input_api, format_args) 65 check_formatting_process.communicate()
73 format_process_out, _ = format_process.communicate() 66 if check_formatting_process.returncode == 0:
67 return []
68
69 format_args = ['git', 'cl', 'format', '--js', input_api.PresubmitLocalPath() ]
70 format_process = popen(format_args)
71 format_out, _ = format_process.communicate()
72 if format_process.returncode != 0:
73 return [output_api.PresubmitError(format_out)]
74 74
75 # Use eslint to autofix the braces 75 # Use eslint to autofix the braces
76 eslint_path = input_api.os_path.join(input_api.PresubmitLocalPath(), "node_m odules", ".bin", "eslint") 76 eslint_path = input_api.os_path.join(input_api.PresubmitLocalPath(), "node_m odules", ".bin", "eslint")
77 eslint_process = _inputPopen( 77 eslint_process = popen([
78 input_api, 78 node_path, eslint_path, '--no-eslintrc', '--fix', '--env=es6', '--rule={ "curly": [2, "multi-or-nest", "consistent"]}'
79 [node_path, eslint_path, '--no-eslintrc', '--fix', '--env=es6', '--rule= {"curly": [2, "multi-or-nest", "consistent"]}'] + 79 ] + affected_files)
80 affected_files)
81 eslint_process.communicate() 80 eslint_process.communicate()
82 81
83 # Need to run clang-format again to align the braces 82 # Need to run clang-format again to align the braces
84 reformat_process = _inputPopen(input_api, format_args) 83 popen(format_args).communicate()
85 reformat_process.communicate()
86 84
87 return CheckOutput( 85 return [
88 [ 86 output_api.PresubmitError("ERROR: Found formatting violations in third_p arty/WebKit/Source/devtools.\n"
89 output_api.PresubmitError("ERROR: Found formatting violations.\n" 87 "Ran clang-format on diff\n"
90 "Ran clang-format on files changed in CL\n " 88 "Use git status to check the formatting change s"),
91 "Use git status to check the formatting ch anges"), 89 output_api.PresubmitError(format_out),
92 output_api.PresubmitError(format_process_out) 90 ]
93 ],
94 has_errors=True)
95 91
96 92
97 def _CheckDevtoolsStyle(input_api, output_api): 93 def _CheckDevtoolsStyle(input_api, output_api):
98 affected_front_end_files = _getAffectedFrontEndFiles(input_api) 94 affected_front_end_files = _getAffectedFrontEndFiles(input_api)
99 if len(affected_front_end_files) > 0: 95 if len(affected_front_end_files) > 0:
100 lint_path = input_api.os_path.join(input_api.PresubmitLocalPath(), "scri pts", "lint_javascript.py") 96 lint_path = input_api.os_path.join(input_api.PresubmitLocalPath(), "scri pts", "lint_javascript.py")
101 process = input_api.subprocess.Popen( 97 process = input_api.subprocess.Popen(
102 [input_api.python_executable, lint_path] + affected_front_end_files, 98 [input_api.python_executable, lint_path] + affected_front_end_files,
103 stdout=input_api.subprocess.PIPE, 99 stdout=input_api.subprocess.PIPE,
104 stderr=input_api.subprocess.STDOUT) 100 stderr=input_api.subprocess.STDOUT)
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 for line_number, line in f.ChangedContents(): 177 for line_number, line in f.ChangedContents():
182 if "/deep/" in line: 178 if "/deep/" in line:
183 results.append(output_api.PresubmitError(("%s:%d uses /deep/ sel ector") % (f.LocalPath(), line_number))) 179 results.append(output_api.PresubmitError(("%s:%d uses /deep/ sel ector") % (f.LocalPath(), line_number)))
184 if "::shadow" in line: 180 if "::shadow" in line:
185 results.append(output_api.PresubmitError(("%s:%d uses ::shadow s elector") % (f.LocalPath(), line_number))) 181 results.append(output_api.PresubmitError(("%s:%d uses ::shadow s elector") % (f.LocalPath(), line_number)))
186 return results 182 return results
187 183
188 184
189 def CheckChangeOnUpload(input_api, output_api): 185 def CheckChangeOnUpload(input_api, output_api):
190 results = [] 186 results = []
191 187 results.extend(_CheckNodeAndNPMModules(input_api, output_api))
192 (node_results, has_errors) = _CheckNodeAndNPMModules(input_api, output_api) 188 results.extend(_CheckFormat(input_api, output_api))
193 results.extend(node_results)
194 if has_errors:
195 results.append(output_api.PresubmitError("ERROR: Bailed out early becaus e error using node.js/npm"))
196 return results
197
198 (format_results, has_errors) = _FormatDevtools(input_api, output_api)
199 results.extend(format_results)
200 if has_errors:
201 results.append(output_api.PresubmitError("ERROR: Bailed out early becaus e formatting errors were found"))
202 return results
203
204 results.extend(_CheckDevtoolsStyle(input_api, output_api)) 189 results.extend(_CheckDevtoolsStyle(input_api, output_api))
205 results.extend(_CompileDevtoolsFrontend(input_api, output_api)) 190 results.extend(_CompileDevtoolsFrontend(input_api, output_api))
206 results.extend(_CheckConvertSVGToPNGHashes(input_api, output_api)) 191 results.extend(_CheckConvertSVGToPNGHashes(input_api, output_api))
207 results.extend(_CheckOptimizePNGHashes(input_api, output_api)) 192 results.extend(_CheckOptimizePNGHashes(input_api, output_api))
208 results.extend(_CheckCSSViolations(input_api, output_api)) 193 results.extend(_CheckCSSViolations(input_api, output_api))
209 return results 194 return results
210 195
211 196
212 def CheckChangeOnCommit(input_api, output_api): 197 def CheckChangeOnCommit(input_api, output_api):
213 return [] 198 return []
(...skipping 12 matching lines...) Expand all
226 def _getAffectedJSFiles(input_api): 211 def _getAffectedJSFiles(input_api):
227 local_paths = [f.AbsoluteLocalPath() for f in input_api.AffectedFiles() if f .Action() != "D"] 212 local_paths = [f.AbsoluteLocalPath() for f in input_api.AffectedFiles() if f .Action() != "D"]
228 devtools_root = input_api.PresubmitLocalPath() 213 devtools_root = input_api.PresubmitLocalPath()
229 devtools_front_end = input_api.os_path.join(devtools_root, "front_end") 214 devtools_front_end = input_api.os_path.join(devtools_root, "front_end")
230 devtools_scripts = input_api.os_path.join(devtools_root, "scripts") 215 devtools_scripts = input_api.os_path.join(devtools_root, "scripts")
231 affected_js_files = [ 216 affected_js_files = [
232 file_name for file_name in local_paths 217 file_name for file_name in local_paths
233 if (devtools_front_end in file_name or devtools_scripts in file_name) an d file_name.endswith(".js") 218 if (devtools_front_end in file_name or devtools_scripts in file_name) an d file_name.endswith(".js")
234 ] 219 ]
235 return [input_api.os_path.relpath(file_name, devtools_root) for file_name in affected_js_files] 220 return [input_api.os_path.relpath(file_name, devtools_root) for file_name in affected_js_files]
236
237
238 def _inputPopen(input_api, args):
239 return input_api.subprocess.Popen(args, stdout=input_api.subprocess.PIPE, st derr=input_api.subprocess.STDOUT)
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/devtools/package.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698