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

Side by Side Diff: third_party/closure_compiler/checker.py

Issue 421253006: Add ChromeCodingConvention.java to Closure Compiler to preserve getInstance() type (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@A_typechecking_about
Patch Set: remove exit_on_fatal flag Created 6 years, 4 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
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 from collections import defaultdict 5 from collections import defaultdict
6 import os 6 import os
7 import re 7 import re
8 import subprocess 8 import subprocess
9 import sys 9 import sys
10 import tempfile 10 import tempfile
11 11
12 12
13 13
14 class LineNumber(object): 14 class LineNumber(object):
15 def __init__(self, file, line_number): 15 def __init__(self, file, line_number):
16 self.file = file 16 self.file = file
17 self.line_number = int(line_number) 17 self.line_number = int(line_number)
18 18
19 19
20 class FileCache(object): 20 class FileCache(object):
21 _cache = defaultdict(str) 21 _cache = defaultdict(str)
22 22
23 def _read(self, file): 23 def _read(self, file):
24 file = os.path.abspath(file) 24 file = os.path.abspath(file)
25 self._cache[file] = self._cache[file] or open(file, "r").read() 25 self._cache[file] = self._cache[file] or open(file, "r").read()
26 return self._cache[file] 26 return self._cache[file]
27 27
28 @staticmethod 28 @staticmethod
29 def read(file): 29 def read(file):
30 return FileCache()._read(file) 30 return FileCache()._read(file)
31 31
32 32
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 118
119 self._debug("Deleting temporary files: " + ", ".join(self._temp_files)) 119 self._debug("Deleting temporary files: " + ", ".join(self._temp_files))
120 for f in self._temp_files: 120 for f in self._temp_files:
121 os.remove(f) 121 os.remove(f)
122 self._temp_files = [] 122 self._temp_files = []
123 123
124 def _debug(self, msg, error=False): 124 def _debug(self, msg, error=False):
125 if self._verbose: 125 if self._verbose:
126 print "(INFO) " + msg 126 print "(INFO) " + msg
127 127
128 def _fatal(self, msg): 128 def _fatal(self, msg):
Dan Beam 2014/07/29 23:49:08 change to _error, _fatal no longer makes as much s
Vitaly Pavlenko 2014/07/30 00:01:37 Done.
129 print >> sys.stderr, "(FATAL) " + msg 129 print >> sys.stderr, "(FATAL) " + msg
Dan Beam 2014/07/29 23:49:08 (ERROR)
Vitaly Pavlenko 2014/07/30 00:01:37 Done.
130 self._clean_up() 130 self._clean_up()
131 sys.exit(1)
132 131
133 def _run_command(self, cmd): 132 def _run_command(self, cmd):
134 cmd_str = " ".join(cmd) 133 cmd_str = " ".join(cmd)
135 self._debug("Running command: " + cmd_str) 134 self._debug("Running command: " + cmd_str)
136 135
137 devnull = open(os.devnull, "w") 136 devnull = open(os.devnull, "w")
138 return subprocess.Popen( 137 return subprocess.Popen(
139 cmd_str, stdout=devnull, stderr=subprocess.PIPE, shell=True) 138 cmd_str, stdout=devnull, stderr=subprocess.PIPE, shell=True)
140 139
141 def _check_java_path(self): 140 def _check_java_path(self):
Dan Beam 2014/07/29 23:49:08 if not self._found_java: proc = self._run_comman
Vitaly Pavlenko 2014/07/30 00:01:36 Done.
142 if self._found_java: 141 if self._found_java:
143 return 142 return
144 143
145 proc = self._run_command(["which", "java"]) 144 proc = self._run_command(["which", "java"])
146 proc.communicate() 145 proc.communicate()
147 if proc.returncode == 0: 146 if proc.returncode == 0:
148 self._found_java = True 147 self._found_java = True
149 else: 148 else:
150 self._fatal("Cannot find java (`which java` => %s)" % proc.returncode) 149 self._fatal("Cannot find java (`which java` => %s)" % proc.returncode)
151 150
(...skipping 18 matching lines...) Expand all
170 errors = filter(None, errors) 169 errors = filter(None, errors)
171 contents = ("\n" + "## ").join("\n\n".join(errors).splitlines()) 170 contents = ("\n" + "## ").join("\n\n".join(errors).splitlines())
172 return "## " + contents if contents else "" 171 return "## " + contents if contents else ""
173 172
174 def _create_temp_file(self, contents): 173 def _create_temp_file(self, contents):
175 with tempfile.NamedTemporaryFile(mode='wt', delete=False) as tmp_file: 174 with tempfile.NamedTemporaryFile(mode='wt', delete=False) as tmp_file:
176 self._temp_files.append(tmp_file.name) 175 self._temp_files.append(tmp_file.name)
177 tmp_file.write(contents) 176 tmp_file.write(contents)
178 return tmp_file.name 177 return tmp_file.name
179 178
180 def check(self, file, depends=[], externs=[]): 179 def check(self, file, depends=[], externs=[]):
Dan Beam 2014/07/29 23:49:08 if not self._check_java_path(): return 1, ""
Vitaly Pavlenko 2014/07/30 00:01:36 Done.
181 self._debug("FILE: " + file) 180 self._debug("FILE: " + file)
182 181
183 if file.endswith("_externs.js"): 182 if file.endswith("_externs.js"):
184 self._debug("Skipping externs: " + file) 183 self._debug("Skipping externs: " + file)
185 return 184 return
186 185
187 self._file_arg = file 186 self._file_arg = file
188 187
189 tmp_dir = tempfile.gettempdir() 188 tmp_dir = tempfile.gettempdir()
190 rel_path = lambda f: os.path.join(os.path.relpath(os.getcwd(), tmp_dir), f) 189 rel_path = lambda f: os.path.join(os.path.relpath(os.getcwd(), tmp_dir), f)
(...skipping 14 matching lines...) Expand all
205 self._debug("Args file: " + args_file) 204 self._debug("Args file: " + args_file)
206 205
207 runner_args = ["--compiler-args-file=" + args_file] 206 runner_args = ["--compiler-args-file=" + args_file]
208 runner_cmd = self._run_jar(self._runner_jar, args=runner_args) 207 runner_cmd = self._run_jar(self._runner_jar, args=runner_args)
209 (_, stderr) = runner_cmd.communicate() 208 (_, stderr) = runner_cmd.communicate()
210 209
211 errors = stderr.strip().split("\n\n") 210 errors = stderr.strip().split("\n\n")
212 self._debug("Summary: " + errors.pop()) 211 self._debug("Summary: " + errors.pop())
213 212
214 output = self._format_errors(map(self._fix_up_error, errors)) 213 output = self._format_errors(map(self._fix_up_error, errors))
214
215 if runner_cmd.returncode: 215 if runner_cmd.returncode:
216 self._fatal("Error in: " + file + ("\n" + output if output else "")) 216 self._fatal("Error in: " + file + ("\n" + output if output else ""))
217 elif output: 217 elif output:
218 self._debug("Output: " + output) 218 self._debug("Output: " + output)
219 219
220 self._clean_up() 220 self._clean_up()
221 221
222 return runner_cmd.returncode == 0 222 return runner_cmd.returncode == 0, output
Dan Beam 2014/07/29 23:49:08 return runner_cmd.returncode, output
Vitaly Pavlenko 2014/07/30 00:01:37 Done.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698