| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 # Something in chrome_private_java makes this check crash. | 59 # Something in chrome_private_java makes this check crash. |
| 60 'com.google.errorprone.bugpatterns.ClassCanBeStatic,' | 60 'com.google.errorprone.bugpatterns.ClassCanBeStatic,' |
| 61 # These crash on lots of targets. | 61 # These crash on lots of targets. |
| 62 'com.google.errorprone.bugpatterns.WrongParameterPackage,' | 62 'com.google.errorprone.bugpatterns.WrongParameterPackage,' |
| 63 'com.google.errorprone.bugpatterns.GuiceOverridesGuiceInjectableMethod,' | 63 'com.google.errorprone.bugpatterns.GuiceOverridesGuiceInjectableMethod,' |
| 64 'com.google.errorprone.bugpatterns.GuiceOverridesJavaxInjectableMethod,' | 64 'com.google.errorprone.bugpatterns.GuiceOverridesJavaxInjectableMethod,' |
| 65 'com.google.errorprone.bugpatterns.ElementsCountedInLoop' | 65 'com.google.errorprone.bugpatterns.ElementsCountedInLoop' |
| 66 ] | 66 ] |
| 67 | 67 |
| 68 def DoJavac( | 68 def DoJavac( |
| 69 classpath, classes_dir, chromium_code, | 69 bootclasspath, classpath, classes_dir, chromium_code, |
| 70 use_errorprone_path, java_files): | 70 use_errorprone_path, java_files): |
| 71 """Runs javac. | 71 """Runs javac. |
| 72 | 72 |
| 73 Builds |java_files| with the provided |classpath| and puts the generated | 73 Builds |java_files| with the provided |classpath| and puts the generated |
| 74 .class files into |classes_dir|. If |chromium_code| is true, extra lint | 74 .class files into |classes_dir|. If |chromium_code| is true, extra lint |
| 75 checking will be enabled. | 75 checking will be enabled. |
| 76 """ | 76 """ |
| 77 | 77 |
| 78 jar_inputs = [] | 78 jar_inputs = [] |
| 79 for path in classpath: | 79 for path in classpath: |
| 80 if os.path.exists(path + '.TOC'): | 80 if os.path.exists(path + '.TOC'): |
| 81 jar_inputs.append(path + '.TOC') | 81 jar_inputs.append(path + '.TOC') |
| 82 else: | 82 else: |
| 83 jar_inputs.append(path) | 83 jar_inputs.append(path) |
| 84 | 84 |
| 85 javac_args = [ | 85 javac_args = [ |
| 86 '-g', | 86 '-g', |
| 87 # Chromium only allows UTF8 source files. Being explicit avoids | 87 # Chromium only allows UTF8 source files. Being explicit avoids |
| 88 # javac pulling a default encoding from the user's environment. | 88 # javac pulling a default encoding from the user's environment. |
| 89 '-encoding', 'UTF-8', | 89 '-encoding', 'UTF-8', |
| 90 '-source', '1.7', | 90 '-source', '1.7', |
| 91 '-target', '1.7', | 91 '-target', '1.7', |
| 92 '-classpath', ':'.join(classpath), | 92 '-classpath', ':'.join(classpath), |
| 93 '-d', classes_dir] | 93 '-d', classes_dir] |
| 94 |
| 95 if bootclasspath: |
| 96 javac_args.extend(['-bootclasspath', ':'.join(bootclasspath)]) |
| 97 |
| 94 if chromium_code: | 98 if chromium_code: |
| 95 # TODO(aurimas): re-enable '-Xlint:deprecation' checks once they are fixed. | 99 # TODO(aurimas): re-enable '-Xlint:deprecation' checks once they are fixed. |
| 96 javac_args.extend(['-Xlint:unchecked']) | 100 javac_args.extend(['-Xlint:unchecked']) |
| 97 else: | 101 else: |
| 98 # XDignore.symbol.file makes javac compile against rt.jar instead of | 102 # XDignore.symbol.file makes javac compile against rt.jar instead of |
| 99 # ct.sym. This means that using a java internal package/class will not | 103 # ct.sym. This means that using a java internal package/class will not |
| 100 # trigger a compile warning or error. | 104 # trigger a compile warning or error. |
| 101 javac_args.extend(['-XDignore.symbol.file']) | 105 javac_args.extend(['-XDignore.symbol.file']) |
| 102 | 106 |
| 103 if use_errorprone_path: | 107 if use_errorprone_path: |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 | 178 |
| 175 parser.add_option( | 179 parser.add_option( |
| 176 '--src-gendirs', | 180 '--src-gendirs', |
| 177 help='Directories containing generated java files.') | 181 help='Directories containing generated java files.') |
| 178 parser.add_option( | 182 parser.add_option( |
| 179 '--java-srcjars', | 183 '--java-srcjars', |
| 180 action='append', | 184 action='append', |
| 181 default=[], | 185 default=[], |
| 182 help='List of srcjars to include in compilation.') | 186 help='List of srcjars to include in compilation.') |
| 183 parser.add_option( | 187 parser.add_option( |
| 188 '--bootclasspath', |
| 189 action='append', |
| 190 default=[], |
| 191 help='Boot classpath for javac. If this is specified multiple times, ' |
| 192 'they will all be appended to construct the classpath.') |
| 193 parser.add_option( |
| 184 '--classpath', | 194 '--classpath', |
| 185 action='append', | 195 action='append', |
| 186 help='Classpath for javac. If this is specified multiple times, they ' | 196 help='Classpath for javac. If this is specified multiple times, they ' |
| 187 'will all be appended to construct the classpath.') | 197 'will all be appended to construct the classpath.') |
| 188 parser.add_option( | 198 parser.add_option( |
| 189 '--javac-includes', | 199 '--javac-includes', |
| 190 help='A list of file patterns. If provided, only java files that match' | 200 help='A list of file patterns. If provided, only java files that match' |
| 191 'one of the patterns will be compiled.') | 201 'one of the patterns will be compiled.') |
| 192 parser.add_option( | 202 parser.add_option( |
| 193 '--jar-excluded-classes', | 203 '--jar-excluded-classes', |
| (...skipping 22 matching lines...) Expand all Loading... |
| 216 action='append', | 226 action='append', |
| 217 help='Key:value pairs to add to the .jar manifest.') | 227 help='Key:value pairs to add to the .jar manifest.') |
| 218 | 228 |
| 219 parser.add_option('--stamp', help='Path to touch on success.') | 229 parser.add_option('--stamp', help='Path to touch on success.') |
| 220 | 230 |
| 221 options, args = parser.parse_args(argv) | 231 options, args = parser.parse_args(argv) |
| 222 | 232 |
| 223 if options.main_class and not options.jar_path: | 233 if options.main_class and not options.jar_path: |
| 224 parser.error('--main-class requires --jar-path') | 234 parser.error('--main-class requires --jar-path') |
| 225 | 235 |
| 236 bootclasspath = [] |
| 237 for arg in options.bootclasspath: |
| 238 bootclasspath += build_utils.ParseGypList(arg) |
| 239 |
| 226 classpath = [] | 240 classpath = [] |
| 227 for arg in options.classpath: | 241 for arg in options.classpath: |
| 228 classpath += build_utils.ParseGypList(arg) | 242 classpath += build_utils.ParseGypList(arg) |
| 229 | 243 |
| 230 java_srcjars = [] | 244 java_srcjars = [] |
| 231 for arg in options.java_srcjars: | 245 for arg in options.java_srcjars: |
| 232 java_srcjars += build_utils.ParseGypList(arg) | 246 java_srcjars += build_utils.ParseGypList(arg) |
| 233 | 247 |
| 234 java_files = args | 248 java_files = args |
| 235 if options.src_gendirs: | 249 if options.src_gendirs: |
| 236 src_gendirs = build_utils.ParseGypList(options.src_gendirs) | 250 src_gendirs = build_utils.ParseGypList(options.src_gendirs) |
| 237 java_files += build_utils.FindInDirectories(src_gendirs, '*.java') | 251 java_files += build_utils.FindInDirectories(src_gendirs, '*.java') |
| 238 | 252 |
| 239 input_files = classpath + java_srcjars + java_files | 253 input_files = bootclasspath + classpath + java_srcjars + java_files |
| 240 with build_utils.TempDir() as temp_dir: | 254 with build_utils.TempDir() as temp_dir: |
| 241 classes_dir = os.path.join(temp_dir, 'classes') | 255 classes_dir = os.path.join(temp_dir, 'classes') |
| 242 os.makedirs(classes_dir) | 256 os.makedirs(classes_dir) |
| 243 if java_srcjars: | 257 if java_srcjars: |
| 244 java_dir = os.path.join(temp_dir, 'java') | 258 java_dir = os.path.join(temp_dir, 'java') |
| 245 os.makedirs(java_dir) | 259 os.makedirs(java_dir) |
| 246 for srcjar in java_srcjars: | 260 for srcjar in java_srcjars: |
| 247 build_utils.ExtractAll(srcjar, path=java_dir, pattern='*.java') | 261 build_utils.ExtractAll(srcjar, path=java_dir, pattern='*.java') |
| 248 java_files += build_utils.FindInDirectory(java_dir, '*.java') | 262 java_files += build_utils.FindInDirectory(java_dir, '*.java') |
| 249 | 263 |
| 250 if options.javac_includes: | 264 if options.javac_includes: |
| 251 javac_includes = build_utils.ParseGypList(options.javac_includes) | 265 javac_includes = build_utils.ParseGypList(options.javac_includes) |
| 252 filtered_java_files = [] | 266 filtered_java_files = [] |
| 253 for f in java_files: | 267 for f in java_files: |
| 254 for include in javac_includes: | 268 for include in javac_includes: |
| 255 if fnmatch.fnmatch(f, include): | 269 if fnmatch.fnmatch(f, include): |
| 256 filtered_java_files.append(f) | 270 filtered_java_files.append(f) |
| 257 break | 271 break |
| 258 java_files = filtered_java_files | 272 java_files = filtered_java_files |
| 259 | 273 |
| 260 if len(java_files) != 0: | 274 if len(java_files) != 0: |
| 261 DoJavac( | 275 DoJavac( |
| 276 bootclasspath, |
| 262 classpath, | 277 classpath, |
| 263 classes_dir, | 278 classes_dir, |
| 264 options.chromium_code, | 279 options.chromium_code, |
| 265 options.use_errorprone_path, | 280 options.use_errorprone_path, |
| 266 java_files) | 281 java_files) |
| 267 | 282 |
| 268 if options.jar_path: | 283 if options.jar_path: |
| 269 if options.main_class or options.manifest_entry: | 284 if options.main_class or options.manifest_entry: |
| 270 if options.manifest_entry: | 285 if options.manifest_entry: |
| 271 entries = map(lambda e: e.split(":"), options.manifest_entry) | 286 entries = map(lambda e: e.split(":"), options.manifest_entry) |
| (...skipping 23 matching lines...) Expand all Loading... |
| 295 input_files + build_utils.GetPythonDependencies()) | 310 input_files + build_utils.GetPythonDependencies()) |
| 296 | 311 |
| 297 if options.stamp: | 312 if options.stamp: |
| 298 build_utils.Touch(options.stamp) | 313 build_utils.Touch(options.stamp) |
| 299 | 314 |
| 300 | 315 |
| 301 if __name__ == '__main__': | 316 if __name__ == '__main__': |
| 302 sys.exit(main(sys.argv[1:])) | 317 sys.exit(main(sys.argv[1:])) |
| 303 | 318 |
| 304 | 319 |
| OLD | NEW |