Chromium Code Reviews| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 48 elif error_re.match(line): | 48 elif error_re.match(line): |
| 49 line = Colorize(line, error_re, error_color) | 49 line = Colorize(line, error_re, error_color) |
| 50 elif marker_re.match(line): | 50 elif marker_re.match(line): |
| 51 line = Colorize(line, marker_re, marker_color) | 51 line = Colorize(line, marker_re, marker_color) |
| 52 return line | 52 return line |
| 53 | 53 |
| 54 return '\n'.join(map(ApplyColor, output.split('\n'))) | 54 return '\n'.join(map(ApplyColor, output.split('\n'))) |
| 55 | 55 |
| 56 | 56 |
| 57 def DoJavac( | 57 def DoJavac( |
| 58 classpath, classes_dir, chromium_code, java_files): | 58 classpath, classes_dir, chromium_code, |
| 59 use_errorprone, errorprone_path, java_files): | |
| 59 """Runs javac. | 60 """Runs javac. |
| 60 | 61 |
| 61 Builds |java_files| with the provided |classpath| and puts the generated | 62 Builds |java_files| with the provided |classpath| and puts the generated |
| 62 .class files into |classes_dir|. If |chromium_code| is true, extra lint | 63 .class files into |classes_dir|. If |chromium_code| is true, extra lint |
| 63 checking will be enabled. | 64 checking will be enabled. |
| 64 """ | 65 """ |
| 65 | 66 |
| 66 jar_inputs = [] | 67 jar_inputs = [] |
| 67 for path in classpath: | 68 for path in classpath: |
| 68 if os.path.exists(path + '.TOC'): | 69 if os.path.exists(path + '.TOC'): |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 81 '-d', classes_dir] | 82 '-d', classes_dir] |
| 82 if chromium_code: | 83 if chromium_code: |
| 83 # TODO(aurimas): re-enable '-Xlint:deprecation' checks once they are fixed. | 84 # TODO(aurimas): re-enable '-Xlint:deprecation' checks once they are fixed. |
| 84 javac_args.extend(['-Xlint:unchecked']) | 85 javac_args.extend(['-Xlint:unchecked']) |
| 85 else: | 86 else: |
| 86 # XDignore.symbol.file makes javac compile against rt.jar instead of | 87 # XDignore.symbol.file makes javac compile against rt.jar instead of |
| 87 # ct.sym. This means that using a java internal package/class will not | 88 # ct.sym. This means that using a java internal package/class will not |
| 88 # trigger a compile warning or error. | 89 # trigger a compile warning or error. |
| 89 javac_args.extend(['-XDignore.symbol.file']) | 90 javac_args.extend(['-XDignore.symbol.file']) |
| 90 | 91 |
| 91 javac_cmd = ['javac'] + javac_args + java_files | 92 if use_errorprone: |
| 93 disabled_checks = [ | |
|
jbudorick
2015/05/07 18:49:26
The contents of this if block should probably be i
raywilliams_chromium
2015/05/11 19:52:24
helper method extracted
raywilliams_chromium
2015/05/11 19:52:25
Done.
| |
| 94 # Something in chrome_private_java makes this check crash. | |
| 95 'ClassCanBeStatic', | |
| 96 # These crash on lots of targets. | |
| 97 'WrongParameterPackage', | |
| 98 'GuiceOverridesGuiceInjectableMethod', | |
| 99 'GuiceOverridesJavaxInjectableMethod', | |
| 100 'ElementsCountedInLoop', | |
| 101 ] | |
| 102 errorprone_options = [ | |
| 103 '-Xepdisable:' + ','.join( | |
| 104 ['com.google.errorprone.bugpatterns.' + s for s in disabled_checks]) | |
| 105 ] | |
| 106 assert errorprone_path != None | |
|
jbudorick
2015/05/07 18:49:26
Do we use assertions in the gyp scripts? I know we
raywilliams_chromium
2015/05/11 19:52:25
removed
raywilliams_chromium
2015/05/11 19:52:25
Done.
| |
| 107 javac_cmd = [errorprone_path] + errorprone_options | |
| 108 else: | |
| 109 javac_cmd = ['javac'] | |
| 110 | |
| 111 javac_cmd = javac_cmd + javac_args + java_files | |
| 92 | 112 |
| 93 def Compile(): | 113 def Compile(): |
| 94 build_utils.CheckOutput( | 114 build_utils.CheckOutput( |
| 95 javac_cmd, | 115 javac_cmd, |
| 96 print_stdout=chromium_code, | 116 print_stdout=chromium_code, |
| 97 stderr_filter=ColorJavacOutput) | 117 stderr_filter=ColorJavacOutput) |
| 98 | 118 |
| 99 record_path = os.path.join(classes_dir, 'javac.md5.stamp') | 119 record_path = os.path.join(classes_dir, 'javac.md5.stamp') |
| 100 md5_check.CallAndRecordIfStale( | 120 md5_check.CallAndRecordIfStale( |
| 101 Compile, | 121 Compile, |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 177 default='', | 197 default='', |
| 178 help='List of .class file patterns to exclude from the jar.') | 198 help='List of .class file patterns to exclude from the jar.') |
| 179 | 199 |
| 180 parser.add_option( | 200 parser.add_option( |
| 181 '--chromium-code', | 201 '--chromium-code', |
| 182 type='int', | 202 type='int', |
| 183 help='Whether code being compiled should be built with stricter ' | 203 help='Whether code being compiled should be built with stricter ' |
| 184 'warnings for chromium code.') | 204 'warnings for chromium code.') |
| 185 | 205 |
| 186 parser.add_option( | 206 parser.add_option( |
| 207 '--disable-errorprone', | |
|
jbudorick
2015/05/07 18:49:26
Having this as a disable flag implies that errorpr
raywilliams_chromium
2015/05/11 19:52:25
changed the disable flag to an enable flag
raywilliams_chromium
2015/05/11 19:52:25
Done.
| |
| 208 action='store_true', | |
| 209 help='Use this to disable use of the errorprone compiler. This is ' | |
| 210 'typically only used if errorprone crashes on some target or for targets ' | |
| 211 'used in building the errorpone compiler.') | |
| 212 parser.add_option( | |
| 213 '--errorprone-path', | |
| 214 help='Path to the errorprone compiler executable.') | |
| 215 | |
| 216 parser.add_option( | |
| 187 '--classes-dir', | 217 '--classes-dir', |
| 188 help='Directory for compiled .class files.') | 218 help='Directory for compiled .class files.') |
| 189 parser.add_option('--jar-path', help='Jar output path.') | 219 parser.add_option('--jar-path', help='Jar output path.') |
| 190 parser.add_option( | 220 parser.add_option( |
| 191 '--main-class', | 221 '--main-class', |
| 192 help='The class containing the main method.') | 222 help='The class containing the main method.') |
| 193 parser.add_option( | 223 parser.add_option( |
| 194 '--manifest-entry', | 224 '--manifest-entry', |
| 195 action='append', | 225 action='append', |
| 196 help='Key:value pairs to add to the .jar manifest.') | 226 help='Key:value pairs to add to the .jar manifest.') |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 for include in javac_includes: | 263 for include in javac_includes: |
| 234 if fnmatch.fnmatch(f, include): | 264 if fnmatch.fnmatch(f, include): |
| 235 filtered_java_files.append(f) | 265 filtered_java_files.append(f) |
| 236 break | 266 break |
| 237 java_files = filtered_java_files | 267 java_files = filtered_java_files |
| 238 | 268 |
| 239 DoJavac( | 269 DoJavac( |
| 240 classpath, | 270 classpath, |
| 241 classes_dir, | 271 classes_dir, |
| 242 options.chromium_code, | 272 options.chromium_code, |
| 273 options.chromium_code and not options.disable_errorprone, | |
|
jbudorick
2015/05/07 18:49:26
(this is the awkward double-negative part referred
raywilliams_chromium
2015/05/11 19:52:25
Done.
| |
| 274 options.errorprone_path, | |
| 243 java_files) | 275 java_files) |
| 244 | 276 |
| 245 if options.jar_path: | 277 if options.jar_path: |
| 246 if options.main_class or options.manifest_entry: | 278 if options.main_class or options.manifest_entry: |
| 247 if options.manifest_entry: | 279 if options.manifest_entry: |
| 248 entries = map(lambda e: e.split(":"), options.manifest_entry) | 280 entries = map(lambda e: e.split(":"), options.manifest_entry) |
| 249 else: | 281 else: |
| 250 entries = [] | 282 entries = [] |
| 251 manifest_file = os.path.join(temp_dir, 'manifest') | 283 manifest_file = os.path.join(temp_dir, 'manifest') |
| 252 CreateManifest(manifest_file, classpath, options.main_class, entries) | 284 CreateManifest(manifest_file, classpath, options.main_class, entries) |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 270 build_utils.WriteDepfile( | 302 build_utils.WriteDepfile( |
| 271 options.depfile, | 303 options.depfile, |
| 272 input_files + build_utils.GetPythonDependencies()) | 304 input_files + build_utils.GetPythonDependencies()) |
| 273 | 305 |
| 274 if options.stamp: | 306 if options.stamp: |
| 275 build_utils.Touch(options.stamp) | 307 build_utils.Touch(options.stamp) |
| 276 | 308 |
| 277 | 309 |
| 278 if __name__ == '__main__': | 310 if __name__ == '__main__': |
| 279 sys.exit(main(sys.argv[1:])) | 311 sys.exit(main(sys.argv[1:])) |
| 280 | |
| 281 | |
| OLD | NEW |