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, return_output=False): |
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._return_output = return_output | |
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 |
(...skipping 81 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)) |
215 if runner_cmd.returncode: | 216 if self._return_output: |
216 self._fatal("Error in: " + file + ("\n" + output if output else "")) | 217 self._clean_up() |
217 elif output: | |
218 self._debug("Output: " + output) | |
219 | |
220 self._clean_up() | |
221 | 218 |
222 return runner_cmd.returncode == 0 | 219 return output |
Dan Beam
2014/07/29 19:17:16
why not just return both the output and returncode
Vitaly Pavlenko
2014/07/29 20:26:18
Done.
| |
220 else: | |
221 if runner_cmd.returncode: | |
222 self._fatal("Error in: " + file + ("\n" + output if output else "")) | |
223 elif output: | |
224 self._debug("Output: " + output) | |
225 | |
226 self._clean_up() | |
227 | |
228 return runner_cmd.returncode == 0 | |
OLD | NEW |