| OLD | NEW |
| 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 optparse | 10 import optparse |
| 11 import os | 11 import os |
| 12 import sys | 12 import sys |
| 13 from xml.dom import minidom | 13 from xml.dom import minidom |
| 14 | 14 |
| 15 from util import build_utils | 15 from util import build_utils |
| 16 | 16 |
| 17 | 17 |
| 18 _SRC_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), | 18 _SRC_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), |
| 19 '..', '..', '..')) | 19 '..', '..', '..')) |
| 20 | 20 |
| 21 | 21 |
| 22 def _RunLint(lint_path, config_path, processed_config_path, manifest_path, | 22 def _RunLint(lint_path, config_path, processed_config_path, manifest_path, |
| 23 result_path, product_dir, sources, jar_path, resource_dir=None): | 23 result_path, product_dir, sources, jar_path, resource_dir=None, |
| 24 can_fail_build=False): |
| 24 | 25 |
| 25 def _RelativizePath(path): | 26 def _RelativizePath(path): |
| 26 """Returns relative path to top-level src dir. | 27 """Returns relative path to top-level src dir. |
| 27 | 28 |
| 28 Args: | 29 Args: |
| 29 path: A path relative to cwd. | 30 path: A path relative to cwd. |
| 30 """ | 31 """ |
| 31 return os.path.relpath(os.path.abspath(path), _SRC_ROOT) | 32 return os.path.relpath(os.path.abspath(path), _SRC_ROOT) |
| 32 | 33 |
| 33 def _ProcessConfigFile(): | 34 def _ProcessConfigFile(): |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 ' - Wanna suppress these issues?\n' | 141 ' - Wanna suppress these issues?\n' |
| 141 ' 1. Read comment in %s\n' | 142 ' 1. Read comment in %s\n' |
| 142 ' 2. Run "python %s %s"\n' % | 143 ' 2. Run "python %s %s"\n' % |
| 143 (num_issues, | 144 (num_issues, |
| 144 _RelativizePath(result_path), | 145 _RelativizePath(result_path), |
| 145 _RelativizePath(config_path), | 146 _RelativizePath(config_path), |
| 146 _RelativizePath(os.path.join(_SRC_ROOT, 'build', 'android', | 147 _RelativizePath(os.path.join(_SRC_ROOT, 'build', 'android', |
| 147 'lint', 'suppress.py')), | 148 'lint', 'suppress.py')), |
| 148 _RelativizePath(result_path))) | 149 _RelativizePath(result_path))) |
| 149 print >> sys.stderr, msg | 150 print >> sys.stderr, msg |
| 150 # Lint errors do not fail the build. | 151 return 1 if can_fail_build else 0 |
| 151 return 0 | |
| 152 | 152 |
| 153 return 0 | 153 return 0 |
| 154 | 154 |
| 155 | 155 |
| 156 def main(): | 156 def main(): |
| 157 parser = optparse.OptionParser() | 157 parser = optparse.OptionParser() |
| 158 build_utils.AddDepfileOption(parser) | 158 build_utils.AddDepfileOption(parser) |
| 159 parser.add_option('--lint-path', help='Path to lint executable.') | 159 parser.add_option('--lint-path', help='Path to lint executable.') |
| 160 parser.add_option('--config-path', help='Path to lint suppressions file.') | 160 parser.add_option('--config-path', help='Path to lint suppressions file.') |
| 161 parser.add_option('--processed-config-path', | 161 parser.add_option('--processed-config-path', |
| 162 help='Path to processed lint suppressions file.') | 162 help='Path to processed lint suppressions file.') |
| 163 parser.add_option('--manifest-path', help='Path to AndroidManifest.xml') | 163 parser.add_option('--manifest-path', help='Path to AndroidManifest.xml') |
| 164 parser.add_option('--result-path', help='Path to XML lint result file.') | 164 parser.add_option('--result-path', help='Path to XML lint result file.') |
| 165 parser.add_option('--product-dir', help='Path to product dir.') | 165 parser.add_option('--product-dir', help='Path to product dir.') |
| 166 parser.add_option('--src-dirs', help='Directories containing java files.') | 166 parser.add_option('--src-dirs', help='Directories containing java files.') |
| 167 parser.add_option('--java-files', help='Paths to java files.') | 167 parser.add_option('--java-files', help='Paths to java files.') |
| 168 parser.add_option('--jar-path', help='Jar file containing class files.') | 168 parser.add_option('--jar-path', help='Jar file containing class files.') |
| 169 parser.add_option('--resource-dir', help='Path to resource dir.') | 169 parser.add_option('--resource-dir', help='Path to resource dir.') |
| 170 parser.add_option('--can-fail-build', action='store_true', |
| 171 help='If set, script will exit with nonzero exit status' |
| 172 ' if lint errors are present') |
| 170 parser.add_option('--stamp', help='Path to touch on success.') | 173 parser.add_option('--stamp', help='Path to touch on success.') |
| 171 parser.add_option('--enable', action='store_true', | 174 parser.add_option('--enable', action='store_true', |
| 172 help='Run lint instead of just touching stamp.') | 175 help='Run lint instead of just touching stamp.') |
| 173 | 176 |
| 174 options, _ = parser.parse_args() | 177 options, _ = parser.parse_args() |
| 175 | 178 |
| 176 build_utils.CheckOptions( | 179 build_utils.CheckOptions( |
| 177 options, parser, required=['lint_path', 'config_path', | 180 options, parser, required=['lint_path', 'config_path', |
| 178 'processed_config_path', 'manifest_path', | 181 'processed_config_path', 'manifest_path', |
| 179 'result_path', 'product_dir', | 182 'result_path', 'product_dir', |
| 180 'jar_path']) | 183 'jar_path']) |
| 181 | 184 |
| 182 rc = 0 | 185 rc = 0 |
| 183 | 186 |
| 184 if options.enable: | 187 if options.enable: |
| 185 sources = [] | 188 sources = [] |
| 186 if options.src_dirs: | 189 if options.src_dirs: |
| 187 src_dirs = build_utils.ParseGypList(options.src_dirs) | 190 src_dirs = build_utils.ParseGypList(options.src_dirs) |
| 188 sources = build_utils.FindInDirectories(src_dirs, '*.java') | 191 sources = build_utils.FindInDirectories(src_dirs, '*.java') |
| 189 elif options.java_files: | 192 elif options.java_files: |
| 190 sources = build_utils.ParseGypList(options.java_files) | 193 sources = build_utils.ParseGypList(options.java_files) |
| 191 else: | 194 else: |
| 192 print 'One of --src-dirs or --java-files must be specified.' | 195 print 'One of --src-dirs or --java-files must be specified.' |
| 193 return 1 | 196 return 1 |
| 194 rc = _RunLint(options.lint_path, options.config_path, | 197 rc = _RunLint(options.lint_path, options.config_path, |
| 195 options.processed_config_path, | 198 options.processed_config_path, |
| 196 options.manifest_path, options.result_path, | 199 options.manifest_path, options.result_path, |
| 197 options.product_dir, sources, options.jar_path, | 200 options.product_dir, sources, options.jar_path, |
| 198 options.resource_dir) | 201 options.resource_dir, options.can_fail_build) |
| 199 | 202 |
| 200 if options.depfile: | 203 if options.depfile: |
| 201 build_utils.WriteDepfile( | 204 build_utils.WriteDepfile( |
| 202 options.depfile, | 205 options.depfile, |
| 203 build_utils.GetPythonDependencies()) | 206 build_utils.GetPythonDependencies()) |
| 204 | 207 |
| 205 if options.stamp and not rc: | 208 if options.stamp and not rc: |
| 206 build_utils.Touch(options.stamp) | 209 build_utils.Touch(options.stamp) |
| 207 | 210 |
| 208 return rc | 211 return rc |
| 209 | 212 |
| 210 | 213 |
| 211 if __name__ == '__main__': | 214 if __name__ == '__main__': |
| 212 sys.exit(main()) | 215 sys.exit(main()) |
| OLD | NEW |