OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright 2013 The Chromium Authors. All rights reserved. | 3 # Copyright 2013 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 import optparse | 7 import optparse |
8 import os | 8 import os |
9 import shutil | 9 import shutil |
10 import re | 10 import re |
11 import sys | 11 import sys |
12 import textwrap | 12 import textwrap |
13 | 13 |
14 from util import build_utils | 14 from util import build_utils |
15 from util import md5_check | |
16 | 15 |
17 import jar | 16 import jar |
18 | 17 |
19 sys.path.append(build_utils.COLORAMA_ROOT) | 18 sys.path.append(build_utils.COLORAMA_ROOT) |
20 import colorama | 19 import colorama |
21 | 20 |
22 | 21 |
23 def ColorJavacOutput(output): | 22 def ColorJavacOutput(output): |
24 fileline_prefix = r'(?P<fileline>(?P<file>[-.\w/\\]+.java):(?P<line>[0-9]+):)' | 23 fileline_prefix = r'(?P<fileline>(?P<file>[-.\w/\\]+.java):(?P<line>[0-9]+):)' |
25 warning_re = re.compile( | 24 warning_re = re.compile( |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 | 204 |
206 java_files = _FilterJavaFiles(java_files, options.javac_includes) | 205 java_files = _FilterJavaFiles(java_files, options.javac_includes) |
207 | 206 |
208 runtime_classpath = options.classpath | 207 runtime_classpath = options.classpath |
209 compile_classpath = runtime_classpath | 208 compile_classpath = runtime_classpath |
210 if options.use_ijars: | 209 if options.use_ijars: |
211 ijar_re = re.compile(r'\.jar$') | 210 ijar_re = re.compile(r'\.jar$') |
212 compile_classpath = ( | 211 compile_classpath = ( |
213 [ijar_re.sub('.interface.jar', p) for p in runtime_classpath]) | 212 [ijar_re.sub('.interface.jar', p) for p in runtime_classpath]) |
214 | 213 |
215 javac_args = [ | 214 javac_cmd = ['javac'] |
| 215 if options.use_errorprone_path: |
| 216 javac_cmd = [options.use_errorprone_path] + ERRORPRONE_OPTIONS |
| 217 |
| 218 javac_cmd.extend(( |
216 '-g', | 219 '-g', |
217 # Chromium only allows UTF8 source files. Being explicit avoids | 220 # Chromium only allows UTF8 source files. Being explicit avoids |
218 # javac pulling a default encoding from the user's environment. | 221 # javac pulling a default encoding from the user's environment. |
219 '-encoding', 'UTF-8', | 222 '-encoding', 'UTF-8', |
220 '-classpath', ':'.join(compile_classpath), | 223 '-classpath', ':'.join(compile_classpath), |
221 ] | 224 )) |
222 | 225 |
223 if options.bootclasspath: | 226 if options.bootclasspath: |
224 javac_args.extend([ | 227 javac_cmd.extend([ |
225 '-bootclasspath', ':'.join(options.bootclasspath), | 228 '-bootclasspath', ':'.join(options.bootclasspath), |
226 '-source', '1.7', | 229 '-source', '1.7', |
227 '-target', '1.7', | 230 '-target', '1.7', |
228 ]) | 231 ]) |
229 | 232 |
230 if options.chromium_code: | 233 if options.chromium_code: |
231 # TODO(aurimas): re-enable '-Xlint:deprecation' checks once they are fixed. | 234 # TODO(aurimas): re-enable '-Xlint:deprecation' checks once they are fixed. |
232 javac_args.extend(['-Xlint:unchecked']) | 235 javac_cmd.extend(['-Xlint:unchecked']) |
233 else: | 236 else: |
234 # XDignore.symbol.file makes javac compile against rt.jar instead of | 237 # XDignore.symbol.file makes javac compile against rt.jar instead of |
235 # ct.sym. This means that using a java internal package/class will not | 238 # ct.sym. This means that using a java internal package/class will not |
236 # trigger a compile warning or error. | 239 # trigger a compile warning or error. |
237 javac_args.extend(['-XDignore.symbol.file']) | 240 javac_cmd.extend(['-XDignore.symbol.file']) |
238 | |
239 javac_cmd = ['javac'] | |
240 if options.use_errorprone_path: | |
241 javac_cmd = [options.use_errorprone_path] + ERRORPRONE_OPTIONS | |
242 | 241 |
243 # Compute the list of paths that when changed, we need to rebuild. | 242 # Compute the list of paths that when changed, we need to rebuild. |
244 input_paths = options.bootclasspath + options.java_srcjars + java_files | 243 input_paths = options.bootclasspath + options.java_srcjars + java_files |
245 # TODO(agrieve): Remove this .TOC heuristic once GYP is no more. | 244 # TODO(agrieve): Remove this .TOC heuristic once GYP is no more. |
246 if not options.use_ijars: | 245 if not options.use_ijars: |
247 for path in compile_classpath: | 246 for path in compile_classpath: |
248 if os.path.exists(path + '.TOC'): | 247 if os.path.exists(path + '.TOC'): |
249 input_paths.append(path + '.TOC') | 248 input_paths.append(path + '.TOC') |
250 else: | 249 else: |
251 input_paths.append(path) | 250 input_paths.append(path) |
252 python_deps = build_utils.GetPythonDependencies() | |
253 | 251 |
254 def OnStaleMd5(): | 252 def on_stale_md5(): |
255 with build_utils.TempDir() as temp_dir: | 253 with build_utils.TempDir() as temp_dir: |
256 if options.java_srcjars: | 254 if options.java_srcjars: |
257 java_dir = os.path.join(temp_dir, 'java') | 255 java_dir = os.path.join(temp_dir, 'java') |
258 os.makedirs(java_dir) | 256 os.makedirs(java_dir) |
259 for srcjar in options.java_srcjars: | 257 for srcjar in options.java_srcjars: |
260 build_utils.ExtractAll(srcjar, path=java_dir, pattern='*.java') | 258 build_utils.ExtractAll(srcjar, path=java_dir, pattern='*.java') |
261 jar_srcs = build_utils.FindInDirectory(java_dir, '*.java') | 259 jar_srcs = build_utils.FindInDirectory(java_dir, '*.java') |
262 java_files.extend(_FilterJavaFiles(jar_srcs, options.javac_includes)) | 260 java_files.extend(_FilterJavaFiles(jar_srcs, options.javac_includes)) |
263 | 261 |
264 classes_dir = os.path.join(temp_dir, 'classes') | 262 classes_dir = os.path.join(temp_dir, 'classes') |
265 os.makedirs(classes_dir) | 263 os.makedirs(classes_dir) |
266 | 264 |
267 if java_files: | 265 if java_files: |
268 # Don't include the output directory in the initial set of args since it | 266 # Don't include the output directory in the initial set of args since it |
269 # being in a temp dir makes it unstable (breaks md5 stamping). | 267 # being in a temp dir makes it unstable (breaks md5 stamping). |
270 cmd = javac_cmd + javac_args + ['-d', classes_dir] + java_files | 268 cmd = javac_cmd + ['-d', classes_dir] + java_files |
271 | 269 |
272 build_utils.CheckOutput( | 270 build_utils.CheckOutput( |
273 cmd, | 271 cmd, |
274 print_stdout=options.chromium_code, | 272 print_stdout=options.chromium_code, |
275 stderr_filter=ColorJavacOutput) | 273 stderr_filter=ColorJavacOutput) |
276 | 274 |
277 if options.main_class or options.manifest_entry: | 275 if options.main_class or options.manifest_entry: |
278 entries = [] | 276 entries = [] |
279 if options.manifest_entry: | 277 if options.manifest_entry: |
280 entries = [e.split(':') for e in options.manifest_entry] | 278 entries = [e.split(':') for e in options.manifest_entry] |
281 manifest_file = os.path.join(temp_dir, 'manifest') | 279 manifest_file = os.path.join(temp_dir, 'manifest') |
282 _CreateManifest(manifest_file, runtime_classpath, options.main_class, | 280 _CreateManifest(manifest_file, runtime_classpath, options.main_class, |
283 entries) | 281 entries) |
284 else: | 282 else: |
285 manifest_file = None | 283 manifest_file = None |
286 jar.JarDirectory(classes_dir, | 284 jar.JarDirectory(classes_dir, |
287 options.jar_excluded_classes, | 285 options.jar_excluded_classes, |
288 options.jar_path, | 286 options.jar_path, |
289 manifest_file=manifest_file) | 287 manifest_file=manifest_file) |
290 | 288 |
291 if options.stamp: | |
292 build_utils.Touch(options.stamp) | |
293 | |
294 if options.depfile: | |
295 build_utils.WriteDepfile(options.depfile, input_paths + python_deps) | |
296 | |
297 | 289 |
298 # List python deps in input_strings rather than input_paths since the contents | 290 # List python deps in input_strings rather than input_paths since the contents |
299 # of them does not change what gets written to the depsfile. | 291 # of them does not change what gets written to the depsfile. |
300 md5_check.CallAndRecordIfStale( | 292 build_utils.CallAndWriteDepfileIfStale( |
301 OnStaleMd5, | 293 on_stale_md5, |
302 record_path=options.jar_path + '.javac.md5.stamp', | 294 options, |
303 input_paths=input_paths, | 295 input_paths=input_paths, |
304 input_strings=javac_cmd + javac_args + python_deps, | 296 input_strings=javac_cmd, |
305 force=not os.path.exists(options.jar_path)) | 297 output_paths=[options.jar_path]) |
306 | |
307 | 298 |
308 | 299 |
309 if __name__ == '__main__': | 300 if __name__ == '__main__': |
310 sys.exit(main(sys.argv[1:])) | 301 sys.exit(main(sys.argv[1:])) |
311 | |
312 | |
OLD | NEW |