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 shutil | 10 import shutil |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
45 if warning_re.match(line): | 45 if warning_re.match(line): |
46 line = Colorize(line, warning_re, warning_color) | 46 line = Colorize(line, warning_re, warning_color) |
47 elif error_re.match(line): | 47 elif error_re.match(line): |
48 line = Colorize(line, error_re, error_color) | 48 line = Colorize(line, error_re, error_color) |
49 elif marker_re.match(line): | 49 elif marker_re.match(line): |
50 line = Colorize(line, marker_re, marker_color) | 50 line = Colorize(line, marker_re, marker_color) |
51 return line | 51 return line |
52 | 52 |
53 return '\n'.join(map(ApplyColor, output.split('\n'))) | 53 return '\n'.join(map(ApplyColor, output.split('\n'))) |
54 | 54 |
55 | |
55 def DoJavac( | 56 def DoJavac( |
56 classpath, javac_includes, classes_dir, chromium_code, java_files): | 57 classpath, classes_dir, chromium_code, java_files): |
57 if javac_includes: | 58 """Runs javac. |
58 javac_includes = build_utils.ParseGypList(javac_includes) | 59 |
59 filtered_java_files = [] | 60 Builds |java_files| with the provided |classpath| and puts the generated |
60 for f in java_files: | 61 .class files into |classes_dir|. If |chromium_code| is true, extra lint |
61 for include in javac_includes: | 62 checking will be enabled. |
62 if fnmatch.fnmatch(f, include): | 63 """ |
63 filtered_java_files.append(f) | |
64 break | |
65 java_files = filtered_java_files | |
66 | 64 |
67 # Compiling guava with certain orderings of input files causes a compiler | 65 # Compiling guava with certain orderings of input files causes a compiler |
68 # crash... Sorted order works, so use that. | 66 # crash... Sorted order works, so use that. |
69 # See https://code.google.com/p/guava-libraries/issues/detail?id=950 | 67 # See https://code.google.com/p/guava-libraries/issues/detail?id=950 |
68 # TODO(cjhopman): Remove this when we have update guava or the compiler to a | |
69 # version without this problem. | |
70 java_files.sort() | 70 java_files.sort() |
71 classpath = build_utils.ParseGypList(classpath) | |
72 | 71 |
73 jar_inputs = [] | 72 jar_inputs = [] |
74 for path in classpath: | 73 for path in classpath: |
75 if os.path.exists(path + '.TOC'): | 74 if os.path.exists(path + '.TOC'): |
76 jar_inputs.append(path + '.TOC') | 75 jar_inputs.append(path + '.TOC') |
77 else: | 76 else: |
78 jar_inputs.append(path) | 77 jar_inputs.append(path) |
79 | 78 |
80 javac_args = [ | 79 javac_args = [ |
81 '-g', | 80 '-g', |
(...skipping 18 matching lines...) Expand all Loading... | |
100 stderr_filter=ColorJavacOutput) | 99 stderr_filter=ColorJavacOutput) |
101 | 100 |
102 record_path = os.path.join(classes_dir, 'javac.md5.stamp') | 101 record_path = os.path.join(classes_dir, 'javac.md5.stamp') |
103 md5_check.CallAndRecordIfStale( | 102 md5_check.CallAndRecordIfStale( |
104 Compile, | 103 Compile, |
105 record_path=record_path, | 104 record_path=record_path, |
106 input_paths=java_files + jar_inputs, | 105 input_paths=java_files + jar_inputs, |
107 input_strings=javac_cmd) | 106 input_strings=javac_cmd) |
108 | 107 |
109 | 108 |
110 def main(): | 109 def main(argv): |
111 colorama.init() | 110 colorama.init() |
112 | 111 |
112 argv = build_utils.ExpandFileArgs(argv) | |
113 | |
113 parser = optparse.OptionParser() | 114 parser = optparse.OptionParser() |
114 build_utils.AddDepfileOption(parser) | 115 build_utils.AddDepfileOption(parser) |
115 | 116 |
116 parser.add_option( | 117 parser.add_option( |
117 '--src-gendirs', | 118 '--src-gendirs', |
118 help='Directories containing generated java files.') | 119 help='Directories containing generated java files.') |
119 parser.add_option('--classpath', help='Classpath for javac.') | 120 parser.add_option( |
121 '--java-srcjars', | |
122 help='List of srcjars to include in compilation.') | |
123 classpath_args = [] | |
124 parser.add_option( | |
125 '--classpath', | |
126 type='string', | |
127 action='callback', | |
128 callback=lambda _1, _2, v, _3 : classpath_args.append(v), | |
Nico
2014/07/01 18:24:51
Isn't this just `action='append'`?
cjhopman
2014/07/01 22:14:01
Done.
| |
129 help='Classpath for javac. If this is specified multiple times, they ' | |
130 'will all be appended to construct the classpath.') | |
120 parser.add_option( | 131 parser.add_option( |
121 '--javac-includes', | 132 '--javac-includes', |
122 help='A list of file patterns. If provided, only java files that match' + | 133 help='A list of file patterns. If provided, only java files that match' |
123 'one of the patterns will be compiled.') | 134 'one of the patterns will be compiled.') |
124 parser.add_option( | 135 parser.add_option( |
125 '--jar-excluded-classes', | 136 '--jar-excluded-classes', |
137 default='', | |
126 help='List of .class file patterns to exclude from the jar.') | 138 help='List of .class file patterns to exclude from the jar.') |
127 | 139 |
128 parser.add_option( | 140 parser.add_option( |
129 '--chromium-code', | 141 '--chromium-code', |
130 type='int', | 142 type='int', |
131 help='Whether code being compiled should be built with stricter ' | 143 help='Whether code being compiled should be built with stricter ' |
132 'warnings for chromium code.') | 144 'warnings for chromium code.') |
133 | 145 |
134 parser.add_option( | 146 parser.add_option( |
135 '--classes-dir', | 147 '--classes-dir', |
136 help='Directory for compiled .class files.') | 148 help='Directory for compiled .class files.') |
137 parser.add_option('--jar-path', help='Jar output path.') | 149 parser.add_option('--jar-path', help='Jar output path.') |
138 | 150 |
139 parser.add_option('--stamp', help='Path to touch on success.') | 151 parser.add_option('--stamp', help='Path to touch on success.') |
140 | 152 |
141 options, args = parser.parse_args() | 153 options, args = parser.parse_args(argv) |
154 | |
155 classpath = [] | |
156 for arg in classpath_args: | |
157 classpath += build_utils.ParseGypList(arg) | |
142 | 158 |
143 java_files = args | 159 java_files = args |
144 if options.src_gendirs: | 160 if options.src_gendirs: |
145 src_gendirs = build_utils.ParseGypList(options.src_gendirs) | 161 src_gendirs = build_utils.ParseGypList(options.src_gendirs) |
146 java_files += build_utils.FindInDirectories(src_gendirs, '*.java') | 162 java_files += build_utils.FindInDirectories(src_gendirs, '*.java') |
147 | 163 |
148 with build_utils.TempDir() as classes_dir: | 164 with build_utils.TempDir() as temp_dir: |
165 classes_dir = os.path.join(temp_dir, 'classes') | |
166 os.makedirs(classes_dir) | |
167 if options.java_srcjars: | |
168 java_dir = os.path.join(temp_dir, 'java') | |
169 os.makedirs(java_dir) | |
170 for srcjar in build_utils.ParseGypList(options.java_srcjars): | |
171 build_utils.ExtractAll(srcjar, path=java_dir) | |
172 java_files += build_utils.FindInDirectory(java_dir, '*.java') | |
173 | |
174 if options.javac_includes: | |
175 javac_includes = build_utils.ParseGypList(options.javac_includes) | |
176 filtered_java_files = [] | |
177 for f in java_files: | |
178 for include in javac_includes: | |
179 if fnmatch.fnmatch(f, include): | |
180 filtered_java_files.append(f) | |
181 break | |
182 java_files = filtered_java_files | |
Nico
2014/07/01 18:24:51
This changes how gyp does things too, right? If so
cjhopman
2014/07/01 22:14:01
the javac_includes is just moved here from the beg
| |
183 | |
149 DoJavac( | 184 DoJavac( |
150 options.classpath, | 185 classpath, |
151 options.javac_includes, | |
152 classes_dir, | 186 classes_dir, |
153 options.chromium_code, | 187 options.chromium_code, |
154 java_files) | 188 java_files) |
155 | 189 |
156 if options.jar_path: | 190 if options.jar_path: |
157 jar.JarDirectory(classes_dir, | 191 jar.JarDirectory(classes_dir, |
158 build_utils.ParseGypList(options.jar_excluded_classes), | 192 build_utils.ParseGypList(options.jar_excluded_classes), |
159 options.jar_path) | 193 options.jar_path) |
160 | 194 |
161 if options.classes_dir: | 195 if options.classes_dir: |
162 # Delete the old classes directory. This ensures that all .class files in | 196 # Delete the old classes directory. This ensures that all .class files in |
163 # the output are actually from the input .java files. For example, if a | 197 # the output are actually from the input .java files. For example, if a |
164 # .java file is deleted or an inner class is removed, the classes | 198 # .java file is deleted or an inner class is removed, the classes |
165 # directory should not contain the corresponding old .class file after | 199 # directory should not contain the corresponding old .class file after |
166 # running this action. | 200 # running this action. |
167 build_utils.DeleteDirectory(options.classes_dir) | 201 build_utils.DeleteDirectory(options.classes_dir) |
168 shutil.copytree(classes_dir, options.classes_dir) | 202 shutil.copytree(classes_dir, options.classes_dir) |
169 | 203 |
170 if options.depfile: | 204 if options.depfile: |
171 build_utils.WriteDepfile( | 205 build_utils.WriteDepfile( |
172 options.depfile, | 206 options.depfile, |
173 build_utils.GetPythonDependencies()) | 207 classpath + build_utils.GetPythonDependencies()) |
174 | 208 |
175 if options.stamp: | 209 if options.stamp: |
176 build_utils.Touch(options.stamp) | 210 build_utils.Touch(options.stamp) |
177 | 211 |
178 | 212 |
179 if __name__ == '__main__': | 213 if __name__ == '__main__': |
180 sys.exit(main()) | 214 sys.exit(main(sys.argv[1:])) |
181 | 215 |
182 | 216 |
OLD | NEW |