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, fatal_log_on_error=True): |
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._fatal_log_on_error = fatal_log_on_error | |
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 sys.exit(1) |
Dan Beam
2014/07/29 21:51:47
^ actually, just return the exit code rather than
Vitaly Pavlenko
2014/07/29 23:24:25
Done.
| |
132 | 133 |
133 def _run_command(self, cmd): | 134 def _run_command(self, cmd): |
134 cmd_str = " ".join(cmd) | 135 cmd_str = " ".join(cmd) |
135 self._debug("Running command: " + cmd_str) | 136 self._debug("Running command: " + cmd_str) |
136 | 137 |
137 devnull = open(os.devnull, "w") | 138 devnull = open(os.devnull, "w") |
138 return subprocess.Popen( | 139 return subprocess.Popen( |
139 cmd_str, stdout=devnull, stderr=subprocess.PIPE, shell=True) | 140 cmd_str, stdout=devnull, stderr=subprocess.PIPE, shell=True) |
140 | 141 |
141 def _check_java_path(self): | 142 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) | 206 self._debug("Args file: " + args_file) |
206 | 207 |
207 runner_args = ["--compiler-args-file=" + args_file] | 208 runner_args = ["--compiler-args-file=" + args_file] |
208 runner_cmd = self._run_jar(self._runner_jar, args=runner_args) | 209 runner_cmd = self._run_jar(self._runner_jar, args=runner_args) |
209 (_, stderr) = runner_cmd.communicate() | 210 (_, stderr) = runner_cmd.communicate() |
210 | 211 |
211 errors = stderr.strip().split("\n\n") | 212 errors = stderr.strip().split("\n\n") |
212 self._debug("Summary: " + errors.pop()) | 213 self._debug("Summary: " + errors.pop()) |
213 | 214 |
214 output = self._format_errors(map(self._fix_up_error, errors)) | 215 output = self._format_errors(map(self._fix_up_error, errors)) |
216 | |
215 if runner_cmd.returncode: | 217 if runner_cmd.returncode: |
216 self._fatal("Error in: " + file + ("\n" + output if output else "")) | 218 message = "Error in: " + file + ("\n" + output if output else "") |
219 if self._fatal_log_on_error: | |
220 self._fatal(message) | |
221 else: | |
222 self._debug(message) | |
217 elif output: | 223 elif output: |
218 self._debug("Output: " + output) | 224 self._debug("Output: " + output) |
219 | 225 |
220 self._clean_up() | 226 self._clean_up() |
221 | 227 |
222 return runner_cmd.returncode == 0 | 228 return runner_cmd.returncode == 0, output |
OLD | NEW |