OLD | NEW |
---|---|
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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 _found_java = False | 98 _found_java = False |
99 | 99 |
100 _jar_command = [ | 100 _jar_command = [ |
101 "java", | 101 "java", |
102 "-jar", | 102 "-jar", |
103 "-Xms1024m", | 103 "-Xms1024m", |
104 "-server", | 104 "-server", |
105 "-XX:+TieredCompilation" | 105 "-XX:+TieredCompilation" |
106 ] | 106 ] |
107 | 107 |
108 def __init__(self, verbose=False): | 108 def __init__(self, verbose=False, exit_on_fatal=True): |
Dan Beam
2014/07/29 23:27:44
remove this parameter
Vitaly Pavlenko
2014/07/29 23:42:26
Done.
| |
109 current_dir = os.path.join(os.path.dirname(__file__)) | 109 current_dir = os.path.join(os.path.dirname(__file__)) |
110 self._compiler_jar = os.path.join(current_dir, "lib", "compiler.jar") | 110 self._compiler_jar = os.path.join(current_dir, "lib", "compiler.jar") |
111 self._runner_jar = os.path.join(current_dir, "runner", "runner.jar") | 111 self._runner_jar = os.path.join(current_dir, "runner", "runner.jar") |
112 self._temp_files = [] | 112 self._temp_files = [] |
113 self._verbose = verbose | 113 self._verbose = verbose |
114 self._exit_on_fatal = exit_on_fatal | |
114 | 115 |
115 def _clean_up(self): | 116 def _clean_up(self): |
116 if not self._temp_files: | 117 if not self._temp_files: |
117 return | 118 return |
118 | 119 |
119 self._debug("Deleting temporary files: " + ", ".join(self._temp_files)) | 120 self._debug("Deleting temporary files: " + ", ".join(self._temp_files)) |
120 for f in self._temp_files: | 121 for f in self._temp_files: |
121 os.remove(f) | 122 os.remove(f) |
122 self._temp_files = [] | 123 self._temp_files = [] |
123 | 124 |
124 def _debug(self, msg, error=False): | 125 def _debug(self, msg, error=False): |
125 if self._verbose: | 126 if self._verbose: |
126 print "(INFO) " + msg | 127 print "(INFO) " + msg |
127 | 128 |
128 def _fatal(self, msg): | 129 def _fatal(self, msg): |
129 print >> sys.stderr, "(FATAL) " + msg | 130 print >> sys.stderr, "(FATAL) " + msg |
130 self._clean_up() | 131 self._clean_up() |
131 sys.exit(1) | 132 if self._exit_on_fatal: |
133 sys.exit(1) | |
134 else: | |
135 return 1 | |
Dan Beam
2014/07/29 23:27:44
i meant return 1 as the exit code of calling check
Vitaly Pavlenko
2014/07/29 23:42:26
Done.
| |
132 | 136 |
133 def _run_command(self, cmd): | 137 def _run_command(self, cmd): |
134 cmd_str = " ".join(cmd) | 138 cmd_str = " ".join(cmd) |
135 self._debug("Running command: " + cmd_str) | 139 self._debug("Running command: " + cmd_str) |
136 | 140 |
137 devnull = open(os.devnull, "w") | 141 devnull = open(os.devnull, "w") |
138 return subprocess.Popen( | 142 return subprocess.Popen( |
139 cmd_str, stdout=devnull, stderr=subprocess.PIPE, shell=True) | 143 cmd_str, stdout=devnull, stderr=subprocess.PIPE, shell=True) |
140 | 144 |
141 def _check_java_path(self): | 145 def _check_java_path(self): |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
205 self._debug("Args file: " + args_file) | 209 self._debug("Args file: " + args_file) |
206 | 210 |
207 runner_args = ["--compiler-args-file=" + args_file] | 211 runner_args = ["--compiler-args-file=" + args_file] |
208 runner_cmd = self._run_jar(self._runner_jar, args=runner_args) | 212 runner_cmd = self._run_jar(self._runner_jar, args=runner_args) |
209 (_, stderr) = runner_cmd.communicate() | 213 (_, stderr) = runner_cmd.communicate() |
210 | 214 |
211 errors = stderr.strip().split("\n\n") | 215 errors = stderr.strip().split("\n\n") |
212 self._debug("Summary: " + errors.pop()) | 216 self._debug("Summary: " + errors.pop()) |
213 | 217 |
214 output = self._format_errors(map(self._fix_up_error, errors)) | 218 output = self._format_errors(map(self._fix_up_error, errors)) |
219 | |
215 if runner_cmd.returncode: | 220 if runner_cmd.returncode: |
216 self._fatal("Error in: " + file + ("\n" + output if output else "")) | 221 message = "Error in: " + file + ("\n" + output if output else "") |
222 if self._exit_on_fatal: | |
223 self._fatal(message) | |
224 else: | |
225 self._debug(message) | |
217 elif output: | 226 elif output: |
218 self._debug("Output: " + output) | 227 self._debug("Output: " + output) |
219 | 228 |
220 self._clean_up() | 229 self._clean_up() |
221 | 230 |
222 return runner_cmd.returncode == 0 | 231 return runner_cmd.returncode == 0, output |
OLD | NEW |