Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: build/android/gyp/javac.py

Issue 1136573002: Use the Errorprone Compiler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changed default to disabled Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 def GetErrorproneCommand():
jbudorick 2015/05/15 18:37:12 This should not be done with a local function.
raywilliams_chromium 2015/05/18 19:53:23 Done.
93 disabled_checks = [
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 = [
jbudorick 2015/05/15 18:37:12 errorprone_options can just be a constant, right?
raywilliams_chromium 2015/05/18 19:53:24 Hmm... I don't think python has constants. I can k
jbudorick 2015/05/18 19:58:32 Python doesn't have constants in that the interpre
raywilliams_chromium 2015/05/18 20:50:23 cool - extracted constant and re-tested to make su
raywilliams_chromium 2015/05/18 20:50:23 Done.
103 '-Xepdisable:' + ','.join(
104 ['com.google.errorprone.bugpatterns.' + s for s in disabled_checks])
105 ]
106 return [errorprone_path] + errorprone_options
107
108 if use_errorprone:
109 javac_cmd = GetErrorproneCommand()
110 else:
111 javac_cmd = ['javac']
112
113 javac_cmd = javac_cmd + javac_args + java_files
92 114
93 def Compile(): 115 def Compile():
94 build_utils.CheckOutput( 116 build_utils.CheckOutput(
95 javac_cmd, 117 javac_cmd,
96 print_stdout=chromium_code, 118 print_stdout=chromium_code,
97 stderr_filter=ColorJavacOutput) 119 stderr_filter=ColorJavacOutput)
98 120
99 record_path = os.path.join(classes_dir, 'javac.md5.stamp') 121 record_path = os.path.join(classes_dir, 'javac.md5.stamp')
100 md5_check.CallAndRecordIfStale( 122 md5_check.CallAndRecordIfStale(
101 Compile, 123 Compile,
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 '--jar-excluded-classes', 198 '--jar-excluded-classes',
177 default='', 199 default='',
178 help='List of .class file patterns to exclude from the jar.') 200 help='List of .class file patterns to exclude from the jar.')
179 201
180 parser.add_option( 202 parser.add_option(
181 '--chromium-code', 203 '--chromium-code',
182 type='int', 204 type='int',
183 help='Whether code being compiled should be built with stricter ' 205 help='Whether code being compiled should be built with stricter '
184 'warnings for chromium code.') 206 'warnings for chromium code.')
185 207
186 parser.add_option( 208 parser.add_option(
jbudorick 2015/05/15 18:37:12 Do we need both of these options? Passing --enable
raywilliams_chromium 2015/05/18 19:53:23 Done.
raywilliams_chromium 2015/05/18 19:53:23 Good idea :)
209 '--enable-errorprone',
210 action='store_true',
211 help='Use this to enable use of the errorprone 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
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 options.enable_errorprone,
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 19 matching lines...) Expand all
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 312
281 313
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698