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

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

Issue 2605023003: [android] Disable NewApi lint warning when building with emma coverage enabled. (Closed)
Patch Set: agrieve comment Created 3 years, 11 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
« no previous file with comments | « no previous file | build/config/android/internal_rules.gni » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright (c) 2013 The Chromium Authors. All rights reserved. 3 # Copyright (c) 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 """Runs Android's lint tool.""" 7 """Runs Android's lint tool."""
8 8
9 9
10 import argparse 10 import argparse
11 import os 11 import os
12 import re 12 import re
13 import sys 13 import sys
14 import traceback 14 import traceback
15 from xml.dom import minidom 15 from xml.dom import minidom
16 16
17 from util import build_utils 17 from util import build_utils
18 18
19 _LINT_MD_URL = 'https://chromium.googlesource.com/chromium/src/+/master/build/an droid/docs/lint.md' # pylint: disable=line-too-long 19 _LINT_MD_URL = 'https://chromium.googlesource.com/chromium/src/+/master/build/an droid/docs/lint.md' # pylint: disable=line-too-long
20 _SRC_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), 20 _SRC_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__),
21 '..', '..', '..')) 21 '..', '..', '..'))
22 22
23 23
24 def _OnStaleMd5(lint_path, config_path, processed_config_path, 24 def _OnStaleMd5(lint_path, config_path, processed_config_path,
25 manifest_path, result_path, product_dir, sources, jar_path, 25 manifest_path, result_path, product_dir, sources, jar_path,
26 cache_dir, android_sdk_version, resource_sources, 26 cache_dir, android_sdk_version, resource_sources,
27 classpath=None, can_fail_build=False, silent=False): 27 disable=None, classpath=None, can_fail_build=False,
28 silent=False):
28 def _RebasePath(path): 29 def _RebasePath(path):
29 """Returns relative path to top-level src dir. 30 """Returns relative path to top-level src dir.
30 31
31 Args: 32 Args:
32 path: A path relative to cwd. 33 path: A path relative to cwd.
33 """ 34 """
34 ret = os.path.relpath(os.path.abspath(path), _SRC_ROOT) 35 ret = os.path.relpath(os.path.abspath(path), _SRC_ROOT)
35 # If it's outside of src/, just use abspath. 36 # If it's outside of src/, just use abspath.
36 if ret.startswith('..'): 37 if ret.startswith('..'):
37 ret = os.path.abspath(path) 38 ret = os.path.abspath(path)
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 for d in src_dirs: 144 for d in src_dirs:
144 if not os.path.exists(PathInDir(d, src)): 145 if not os.path.exists(PathInDir(d, src)):
145 src_dir = d 146 src_dir = d
146 break 147 break
147 if not src_dir: 148 if not src_dir:
148 src_dir = _NewTempSubdir('SRC_ROOT') 149 src_dir = _NewTempSubdir('SRC_ROOT')
149 src_dirs.append(src_dir) 150 src_dirs.append(src_dir)
150 cmd.extend(['--sources', _RebasePath(src_dir)]) 151 cmd.extend(['--sources', _RebasePath(src_dir)])
151 os.symlink(os.path.abspath(src), PathInDir(src_dir, src)) 152 os.symlink(os.path.abspath(src), PathInDir(src_dir, src))
152 153
154 if disable:
155 cmd.extend(['--disable', ','.join(disable)])
156
153 project_dir = _NewTempSubdir('SRC_ROOT') 157 project_dir = _NewTempSubdir('SRC_ROOT')
154 if android_sdk_version: 158 if android_sdk_version:
155 # Create dummy project.properies file in a temporary "project" directory. 159 # Create dummy project.properies file in a temporary "project" directory.
156 # It is the only way to add Android SDK to the Lint's classpath. Proper 160 # It is the only way to add Android SDK to the Lint's classpath. Proper
157 # classpath is necessary for most source-level checks. 161 # classpath is necessary for most source-level checks.
158 with open(os.path.join(project_dir, 'project.properties'), 'w') \ 162 with open(os.path.join(project_dir, 'project.properties'), 'w') \
159 as propfile: 163 as propfile:
160 print >> propfile, 'target=android-{}'.format(android_sdk_version) 164 print >> propfile, 'target=android-{}'.format(android_sdk_version)
161 165
162 # Put the manifest in a temporary directory in order to avoid lint detecting 166 # Put the manifest in a temporary directory in order to avoid lint detecting
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 help='Version (API level) of the Android SDK used for ' 257 help='Version (API level) of the Android SDK used for '
254 'building.') 258 'building.')
255 parser.add_argument('--create-cache', action='store_true', 259 parser.add_argument('--create-cache', action='store_true',
256 help='Mark the lint cache file as an output rather than ' 260 help='Mark the lint cache file as an output rather than '
257 'an input.') 261 'an input.')
258 parser.add_argument('--can-fail-build', action='store_true', 262 parser.add_argument('--can-fail-build', action='store_true',
259 help='If set, script will exit with nonzero exit status' 263 help='If set, script will exit with nonzero exit status'
260 ' if lint errors are present') 264 ' if lint errors are present')
261 parser.add_argument('--config-path', 265 parser.add_argument('--config-path',
262 help='Path to lint suppressions file.') 266 help='Path to lint suppressions file.')
263 parser.add_argument('--enable', action='store_true', 267 parser.add_argument('--disable',
264 help='Run lint instead of just touching stamp.') 268 help='List of checks to disable.')
265 parser.add_argument('--jar-path', 269 parser.add_argument('--jar-path',
266 help='Jar file containing class files.') 270 help='Jar file containing class files.')
267 parser.add_argument('--java-sources-file', 271 parser.add_argument('--java-sources-file',
268 help='File containing a list of java files.') 272 help='File containing a list of java files.')
269 parser.add_argument('--manifest-path', 273 parser.add_argument('--manifest-path',
270 help='Path to AndroidManifest.xml') 274 help='Path to AndroidManifest.xml')
271 parser.add_argument('--classpath', default=[], action='append', 275 parser.add_argument('--classpath', default=[], action='append',
272 help='GYP-list of classpath .jar files') 276 help='GYP-list of classpath .jar files')
273 parser.add_argument('--processed-config-path', 277 parser.add_argument('--processed-config-path',
274 help='Path to processed lint suppressions file.') 278 help='Path to processed lint suppressions file.')
275 parser.add_argument('--resource-dir', 279 parser.add_argument('--resource-dir',
276 help='Path to resource dir.') 280 help='Path to resource dir.')
277 parser.add_argument('--resource-sources', default=[], action='append', 281 parser.add_argument('--resource-sources', default=[], action='append',
278 help='GYP-list of resource sources (directories with ' 282 help='GYP-list of resource sources (directories with '
279 'resources or archives created by resource-generating ' 283 'resources or archives created by resource-generating '
280 'tasks.') 284 'tasks.')
281 parser.add_argument('--silent', action='store_true', 285 parser.add_argument('--silent', action='store_true',
282 help='If set, script will not log anything.') 286 help='If set, script will not log anything.')
283 parser.add_argument('--src-dirs', 287 parser.add_argument('--src-dirs',
284 help='Directories containing java files.') 288 help='Directories containing java files.')
285 parser.add_argument('--stamp', 289 parser.add_argument('--stamp',
286 help='Path to touch on success.') 290 help='Path to touch on success.')
287 291
288 args = parser.parse_args(build_utils.ExpandFileArgs(sys.argv[1:])) 292 args = parser.parse_args(build_utils.ExpandFileArgs(sys.argv[1:]))
289 293
290 if args.enable: 294 sources = []
291 sources = [] 295 if args.src_dirs:
292 if args.src_dirs: 296 src_dirs = build_utils.ParseGnList(args.src_dirs)
293 src_dirs = build_utils.ParseGnList(args.src_dirs) 297 sources = build_utils.FindInDirectories(src_dirs, '*.java')
294 sources = build_utils.FindInDirectories(src_dirs, '*.java') 298 elif args.java_sources_file:
295 elif args.java_sources_file: 299 sources.extend(build_utils.ReadSourcesList(args.java_sources_file))
296 sources.extend(build_utils.ReadSourcesList(args.java_sources_file))
297 300
298 if args.config_path and not args.processed_config_path: 301 if args.config_path and not args.processed_config_path:
299 parser.error('--config-path specified without --processed-config-path') 302 parser.error('--config-path specified without --processed-config-path')
300 elif args.processed_config_path and not args.config_path: 303 elif args.processed_config_path and not args.config_path:
301 parser.error('--processed-config-path specified without --config-path') 304 parser.error('--processed-config-path specified without --config-path')
302 305
303 input_paths = [ 306 input_paths = [
304 args.lint_path, 307 args.lint_path,
305 args.platform_xml_path, 308 args.platform_xml_path,
306 ] 309 ]
307 if args.config_path: 310 if args.config_path:
308 input_paths.append(args.config_path) 311 input_paths.append(args.config_path)
309 if args.jar_path: 312 if args.jar_path:
310 input_paths.append(args.jar_path) 313 input_paths.append(args.jar_path)
311 if args.manifest_path: 314 if args.manifest_path:
312 input_paths.append(args.manifest_path) 315 input_paths.append(args.manifest_path)
313 if sources: 316 if sources:
314 input_paths.extend(sources) 317 input_paths.extend(sources)
315 classpath = [] 318 classpath = []
316 for gyp_list in args.classpath: 319 for gyp_list in args.classpath:
317 classpath.extend(build_utils.ParseGnList(gyp_list)) 320 classpath.extend(build_utils.ParseGnList(gyp_list))
318 input_paths.extend(classpath) 321 input_paths.extend(classpath)
319 322
320 resource_sources = [] 323 resource_sources = []
321 if args.resource_dir: 324 if args.resource_dir:
322 # Backward compatibility with GYP 325 # Backward compatibility with GYP
323 resource_sources += [ args.resource_dir ] 326 resource_sources += [ args.resource_dir ]
324 327
325 for gyp_list in args.resource_sources: 328 for gyp_list in args.resource_sources:
326 resource_sources += build_utils.ParseGnList(gyp_list) 329 resource_sources += build_utils.ParseGnList(gyp_list)
327 330
328 for resource_source in resource_sources: 331 for resource_source in resource_sources:
329 if os.path.isdir(resource_source): 332 if os.path.isdir(resource_source):
330 input_paths.extend(build_utils.FindInDirectory(resource_source, '*')) 333 input_paths.extend(build_utils.FindInDirectory(resource_source, '*'))
331 else: 334 else:
332 input_paths.append(resource_source) 335 input_paths.append(resource_source)
333 336
334 input_strings = [ 337 input_strings = [
335 args.can_fail_build, 338 args.can_fail_build,
336 args.silent, 339 args.silent,
337 ] 340 ]
338 if args.android_sdk_version: 341 if args.android_sdk_version:
339 input_strings.append(args.android_sdk_version) 342 input_strings.append(args.android_sdk_version)
340 if args.processed_config_path: 343 if args.processed_config_path:
341 input_strings.append(args.processed_config_path) 344 input_strings.append(args.processed_config_path)
342 345
343 output_paths = [ args.result_path ] 346 disable = []
347 if args.disable:
348 disable = build_utils.ParseGnList(args.disable)
349 input_strings.extend(disable)
344 350
345 build_utils.CallAndWriteDepfileIfStale( 351 output_paths = [ args.result_path ]
346 lambda: _OnStaleMd5(args.lint_path, 352
347 args.config_path, 353 build_utils.CallAndWriteDepfileIfStale(
348 args.processed_config_path, 354 lambda: _OnStaleMd5(args.lint_path,
349 args.manifest_path, args.result_path, 355 args.config_path,
350 args.product_dir, sources, 356 args.processed_config_path,
351 args.jar_path, 357 args.manifest_path, args.result_path,
352 args.cache_dir, 358 args.product_dir, sources,
353 args.android_sdk_version, 359 args.jar_path,
354 resource_sources, 360 args.cache_dir,
355 classpath=classpath, 361 args.android_sdk_version,
356 can_fail_build=args.can_fail_build, 362 resource_sources,
357 silent=args.silent), 363 disable=disable,
358 args, 364 classpath=classpath,
359 input_paths=input_paths, 365 can_fail_build=args.can_fail_build,
360 input_strings=input_strings, 366 silent=args.silent),
361 output_paths=output_paths, 367 args,
362 depfile_deps=classpath) 368 input_paths=input_paths,
369 input_strings=input_strings,
370 output_paths=output_paths,
371 depfile_deps=classpath)
363 372
364 373
365 if __name__ == '__main__': 374 if __name__ == '__main__':
366 sys.exit(main()) 375 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | build/config/android/internal_rules.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698