Chromium Code Reviews| 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): | 23 result_path, product_dir, sources, jar_path, resource_dir): |
| 24 | 24 |
| 25 def _RelativizePath(path): | 25 def _RelativizePath(path): |
| 26 """Returns relative path to top-level src dir. | 26 """Returns relative path to top-level src dir. |
| 27 | 27 |
| 28 Args: | 28 Args: |
| 29 path: A path relative to cwd. | 29 path: A path relative to cwd. |
| 30 """ | 30 """ |
| 31 return os.path.relpath(os.path.abspath(path), _SRC_ROOT) | 31 return os.path.relpath(os.path.abspath(path), _SRC_ROOT) |
| 32 | 32 |
| 33 def _ProcessConfigFile(): | 33 def _ProcessConfigFile(): |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 for src in sources: | 100 for src in sources: |
| 101 src_dir = None | 101 src_dir = None |
| 102 for d in src_dirs: | 102 for d in src_dirs: |
| 103 if not os.path.exists(PathInDir(d, src)): | 103 if not os.path.exists(PathInDir(d, src)): |
| 104 src_dir = d | 104 src_dir = d |
| 105 break | 105 break |
| 106 if not src_dir: | 106 if not src_dir: |
| 107 src_dir = NewSourceDir() | 107 src_dir = NewSourceDir() |
| 108 os.symlink(os.path.abspath(src), PathInDir(src_dir, src)) | 108 os.symlink(os.path.abspath(src), PathInDir(src_dir, src)) |
| 109 | 109 |
| 110 cmd.extend(['--resources', _RelativizePath(resource_dir)]) | |
| 110 cmd.append(_RelativizePath(os.path.join(manifest_path, os.pardir))) | 111 cmd.append(_RelativizePath(os.path.join(manifest_path, os.pardir))) |
| 111 | 112 |
| 112 if os.path.exists(result_path): | 113 if os.path.exists(result_path): |
| 113 os.remove(result_path) | 114 os.remove(result_path) |
| 114 | 115 |
| 115 try: | 116 try: |
| 116 build_utils.CheckOutput(cmd, cwd=_SRC_ROOT) | 117 build_utils.CheckOutput(cmd, cwd=_SRC_ROOT) |
| 117 except build_utils.CalledProcessError as e: | 118 except build_utils.CalledProcessError as e: |
| 118 # There is a problem with lint usage | 119 # There is a problem with lint usage |
| 119 if not os.path.exists(result_path): | 120 if not os.path.exists(result_path): |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 parser.add_option('--lint-path', help='Path to lint executable.') | 158 parser.add_option('--lint-path', help='Path to lint executable.') |
| 158 parser.add_option('--config-path', help='Path to lint suppressions file.') | 159 parser.add_option('--config-path', help='Path to lint suppressions file.') |
| 159 parser.add_option('--processed-config-path', | 160 parser.add_option('--processed-config-path', |
| 160 help='Path to processed lint suppressions file.') | 161 help='Path to processed lint suppressions file.') |
| 161 parser.add_option('--manifest-path', help='Path to AndroidManifest.xml') | 162 parser.add_option('--manifest-path', help='Path to AndroidManifest.xml') |
| 162 parser.add_option('--result-path', help='Path to XML lint result file.') | 163 parser.add_option('--result-path', help='Path to XML lint result file.') |
| 163 parser.add_option('--product-dir', help='Path to product dir.') | 164 parser.add_option('--product-dir', help='Path to product dir.') |
| 164 parser.add_option('--src-dirs', help='Directories containing java files.') | 165 parser.add_option('--src-dirs', help='Directories containing java files.') |
| 165 parser.add_option('--java-files', help='Paths to java files.') | 166 parser.add_option('--java-files', help='Paths to java files.') |
| 166 parser.add_option('--jar-path', help='Jar file containing class files.') | 167 parser.add_option('--jar-path', help='Jar file containing class files.') |
| 168 parser.add_option('--resource-dir', help='Path to resource dir.') | |
|
cjhopman
2015/02/11 02:05:09
I think my slight preference would be that --resou
mikecase (-- gone --)
2015/02/11 19:04:24
Done.
| |
| 167 parser.add_option('--stamp', help='Path to touch on success.') | 169 parser.add_option('--stamp', help='Path to touch on success.') |
| 168 parser.add_option('--enable', action='store_true', | 170 parser.add_option('--enable', action='store_true', |
| 169 help='Run lint instead of just touching stamp.') | 171 help='Run lint instead of just touching stamp.') |
| 170 | 172 |
| 171 options, _ = parser.parse_args() | 173 options, _ = parser.parse_args() |
| 172 | 174 |
| 173 build_utils.CheckOptions( | 175 build_utils.CheckOptions( |
| 174 options, parser, required=['lint_path', 'config_path', | 176 options, parser, required=['lint_path', 'config_path', |
| 175 'processed_config_path', 'manifest_path', | 177 'processed_config_path', 'manifest_path', |
| 176 'result_path', 'product_dir', | 178 'result_path', 'product_dir', |
| 177 'jar_path']) | 179 'jar_path', 'resource_dir']) |
| 178 | 180 |
| 179 rc = 0 | 181 rc = 0 |
| 180 | 182 |
| 181 if options.enable: | 183 if options.enable: |
| 182 sources = [] | 184 sources = [] |
| 183 if options.src_dirs: | 185 if options.src_dirs: |
| 184 src_dirs = build_utils.ParseGypList(options.src_dirs) | 186 src_dirs = build_utils.ParseGypList(options.src_dirs) |
| 185 sources = build_utils.FindInDirectories(src_dirs, '*.java') | 187 sources = build_utils.FindInDirectories(src_dirs, '*.java') |
| 186 elif options.java_files: | 188 elif options.java_files: |
| 187 sources = build_utils.ParseGypList(options.java_files) | 189 sources = build_utils.ParseGypList(options.java_files) |
| 188 else: | 190 else: |
| 189 print 'One of --src-dirs or --java-files must be specified.' | 191 print 'One of --src-dirs or --java-files must be specified.' |
| 190 return 1 | 192 return 1 |
| 191 rc = _RunLint(options.lint_path, options.config_path, | 193 rc = _RunLint(options.lint_path, options.config_path, |
| 192 options.processed_config_path, | 194 options.processed_config_path, |
| 193 options.manifest_path, options.result_path, | 195 options.manifest_path, options.result_path, |
| 194 options.product_dir, sources, options.jar_path) | 196 options.product_dir, sources, options.jar_path, |
| 197 options.resource_dir) | |
| 195 | 198 |
| 196 if options.depfile: | 199 if options.depfile: |
| 197 build_utils.WriteDepfile( | 200 build_utils.WriteDepfile( |
| 198 options.depfile, | 201 options.depfile, |
| 199 build_utils.GetPythonDependencies()) | 202 build_utils.GetPythonDependencies()) |
| 200 | 203 |
| 201 if options.stamp and not rc: | 204 if options.stamp and not rc: |
| 202 build_utils.Touch(options.stamp) | 205 build_utils.Touch(options.stamp) |
| 203 | 206 |
| 204 return rc | 207 return rc |
| 205 | 208 |
| 206 | 209 |
| 207 if __name__ == '__main__': | 210 if __name__ == '__main__': |
| 208 sys.exit(main()) | 211 sys.exit(main()) |
| OLD | NEW |