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 fnmatch | 7 import fnmatch |
8 import optparse | 8 import optparse |
9 import os | 9 import os |
10 import sys | 10 import sys |
11 | 11 |
12 from util import build_utils | 12 from util import build_utils |
| 13 from util import md5_check |
13 | 14 |
14 | 15 |
15 def DoJavac(options): | 16 def DoJavac(options): |
16 output_dir = options.output_dir | 17 output_dir = options.output_dir |
17 | 18 |
18 src_dirs = build_utils.ParseGypList(options.src_dirs) | 19 src_dirs = build_utils.ParseGypList(options.src_dirs) |
19 java_files = build_utils.FindInDirectories(src_dirs, '*.java') | 20 java_files = build_utils.FindInDirectories(src_dirs, '*.java') |
20 if options.javac_includes: | 21 if options.javac_includes: |
21 javac_includes = build_utils.ParseGypList(options.javac_includes) | 22 javac_includes = build_utils.ParseGypList(options.javac_includes) |
22 filtered_java_files = [] | 23 filtered_java_files = [] |
23 for f in java_files: | 24 for f in java_files: |
24 for include in javac_includes: | 25 for include in javac_includes: |
25 if fnmatch.fnmatch(f, include): | 26 if fnmatch.fnmatch(f, include): |
26 filtered_java_files.append(f) | 27 filtered_java_files.append(f) |
27 break | 28 break |
28 java_files = filtered_java_files | 29 java_files = filtered_java_files |
29 | 30 |
30 # Compiling guava with certain orderings of input files causes a compiler | 31 # Compiling guava with certain orderings of input files causes a compiler |
31 # crash... Sorted order works, so use that. | 32 # crash... Sorted order works, so use that. |
32 # See https://code.google.com/p/guava-libraries/issues/detail?id=950 | 33 # See https://code.google.com/p/guava-libraries/issues/detail?id=950 |
33 java_files.sort() | 34 java_files.sort() |
34 | |
35 classpath = build_utils.ParseGypList(options.classpath) | 35 classpath = build_utils.ParseGypList(options.classpath) |
36 | 36 |
37 # Delete the classes directory. This ensures that all .class files in the | 37 jar_inputs = [] |
38 # output are actually from the input .java files. For example, if a .java | 38 for path in classpath: |
39 # file is deleted or an inner class is removed, the classes directory should | 39 if os.path.exists(path + '.TOC'): |
40 # not contain the corresponding old .class file after running this action. | 40 jar_inputs.append(path + '.TOC') |
41 build_utils.DeleteDirectory(output_dir) | 41 else: |
42 build_utils.MakeDirectory(output_dir) | 42 jar_inputs.append(path) |
43 | 43 |
44 cmd = [ | 44 javac_cmd = [ |
45 'javac', | 45 'javac', |
46 '-g', | 46 '-g', |
47 '-source', '1.5', | 47 '-source', '1.5', |
48 '-target', '1.5', | 48 '-target', '1.5', |
49 '-classpath', ':'.join(classpath), | 49 '-classpath', ':'.join(classpath), |
50 '-d', output_dir, | 50 '-d', output_dir, |
51 '-Xlint:unchecked', | 51 '-Xlint:unchecked', |
52 '-Xlint:deprecation', | 52 '-Xlint:deprecation', |
53 ] | 53 ] + java_files |
54 | 54 |
55 suppress_output = not options.chromium_code | 55 md5_stamp = '%s/javac.md5' % options.output_dir |
56 build_utils.CheckCallDie(cmd + java_files, suppress_output=suppress_output) | 56 md5_checker = md5_check.Md5Checker( |
| 57 stamp=md5_stamp, |
| 58 inputs=java_files + jar_inputs, |
| 59 command=javac_cmd) |
| 60 if md5_checker.IsStale(): |
| 61 # Delete the classes directory. This ensures that all .class files in the |
| 62 # output are actually from the input .java files. For example, if a .java |
| 63 # file is deleted or an inner class is removed, the classes directory should |
| 64 # not contain the corresponding old .class file after running this action. |
| 65 build_utils.DeleteDirectory(output_dir) |
| 66 build_utils.MakeDirectory(output_dir) |
| 67 suppress_output = not options.chromium_code |
| 68 build_utils.CheckCallDie(javac_cmd, suppress_output=suppress_output) |
| 69 md5_checker.Write() |
57 | 70 |
58 def main(argv): | 71 def main(argv): |
59 parser = optparse.OptionParser() | 72 parser = optparse.OptionParser() |
60 parser.add_option('--src-dirs', help='Directories containing java files.') | 73 parser.add_option('--src-dirs', help='Directories containing java files.') |
61 parser.add_option('--javac-includes', | 74 parser.add_option('--javac-includes', |
62 help='A list of file patterns. If provided, only java files that match' + | 75 help='A list of file patterns. If provided, only java files that match' + |
63 'one of the patterns will be compiled.') | 76 'one of the patterns will be compiled.') |
64 parser.add_option('--classpath', help='Classpath for javac.') | 77 parser.add_option('--classpath', help='Classpath for javac.') |
65 parser.add_option('--output-dir', help='Directory for javac output.') | 78 parser.add_option('--output-dir', help='Directory for javac output.') |
66 parser.add_option('--stamp', help='Path to touch on success.') | 79 parser.add_option('--stamp', help='Path to touch on success.') |
67 parser.add_option('--chromium-code', type='int', help='Whether code being ' | 80 parser.add_option('--chromium-code', type='int', help='Whether code being ' |
68 'compiled should be built with stricter warnings for ' | 81 'compiled should be built with stricter warnings for ' |
69 'chromium code.') | 82 'chromium code.') |
70 | 83 |
71 # TODO(newt): remove this once http://crbug.com/177552 is fixed in ninja. | 84 # TODO(newt): remove this once http://crbug.com/177552 is fixed in ninja. |
72 parser.add_option('--ignore', help='Ignored.') | 85 parser.add_option('--ignore', help='Ignored.') |
73 | 86 |
74 options, _ = parser.parse_args() | 87 options, _ = parser.parse_args() |
75 | 88 |
76 DoJavac(options) | 89 DoJavac(options) |
77 | 90 |
78 if options.stamp: | 91 if options.stamp: |
79 build_utils.Touch(options.stamp) | 92 build_utils.Touch(options.stamp) |
80 | 93 |
81 | 94 |
82 if __name__ == '__main__': | 95 if __name__ == '__main__': |
83 sys.exit(main(sys.argv)) | 96 sys.exit(main(sys.argv)) |
84 | 97 |
85 | 98 |
OLD | NEW |