OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Gathers information about APKs.""" | 5 """Gathers information about APKs.""" |
6 | 6 |
7 import collections | 7 import collections |
| 8 import constants |
8 import logging | 9 import logging |
9 import os | 10 import os |
10 import pickle | 11 import pickle |
11 import re | 12 import re |
12 | 13 |
13 from pylib import cmd_helper | 14 from pylib import cmd_helper |
14 | 15 |
15 | 16 |
16 # If you change the cached output of proguard, increment this number | 17 # If you change the cached output of proguard, increment this number |
17 PICKLE_FORMAT_VERSION = 1 | 18 PICKLE_FORMAT_VERSION = 1 |
18 | 19 |
19 def GetPackageNameForApk(apk_path): | 20 def GetPackageNameForApk(apk_path): |
20 """Returns the package name of the apk file.""" | 21 """Returns the package name of the apk file.""" |
21 aapt_output = cmd_helper.GetCmdOutput( | 22 aapt_output = cmd_helper.GetCmdOutput( |
22 ['aapt', 'dump', 'badging', apk_path]).split('\n') | 23 ['aapt', 'dump', 'badging', apk_path]).split('\n') |
23 package_name_re = re.compile(r'package: .*name=\'(\S*)\'') | 24 package_name_re = re.compile(r'package: .*name=\'(\S*)\'') |
24 for line in aapt_output: | 25 for line in aapt_output: |
25 m = package_name_re.match(line) | 26 m = package_name_re.match(line) |
26 if m: | 27 if m: |
27 return m.group(1) | 28 return m.group(1) |
28 raise Exception('Failed to determine package name of %s' % apk_path) | 29 raise Exception('Failed to determine package name of %s' % apk_path) |
29 | 30 |
30 | 31 |
31 class ApkInfo(object): | 32 class ApkInfo(object): |
32 """Helper class for inspecting APKs.""" | 33 """Helper class for inspecting APKs.""" |
33 | 34 |
34 def __init__(self, apk_path, jar_path): | 35 def __init__(self, apk_path, jar_path): |
35 self._PROGUARD_PATH = os.path.join(os.environ['ANDROID_SDK_ROOT'], | 36 sdk_root = os.getenv('ANDROID_SDK_ROOT', constants.ANDROID_SDK_ROOT) |
| 37 self._PROGUARD_PATH = os.path.join(sdk_root, |
36 'tools/proguard/bin/proguard.sh') | 38 'tools/proguard/bin/proguard.sh') |
37 if not os.path.exists(self._PROGUARD_PATH): | 39 if not os.path.exists(self._PROGUARD_PATH): |
38 self._PROGUARD_PATH = os.path.join(os.environ['ANDROID_BUILD_TOP'], | 40 self._PROGUARD_PATH = os.path.join(os.environ['ANDROID_BUILD_TOP'], |
39 'external/proguard/bin/proguard.sh') | 41 'external/proguard/bin/proguard.sh') |
40 self._PROGUARD_CLASS_RE = re.compile(r'\s*?- Program class:\s*([\S]+)$') | 42 self._PROGUARD_CLASS_RE = re.compile(r'\s*?- Program class:\s*([\S]+)$') |
41 self._PROGUARD_METHOD_RE = re.compile(r'\s*?- Method:\s*(\S*)[(].*$') | 43 self._PROGUARD_METHOD_RE = re.compile(r'\s*?- Method:\s*(\S*)[(].*$') |
42 self._PROGUARD_ANNOTATION_RE = re.compile(r'\s*?- Annotation \[L(\S*);\]:$') | 44 self._PROGUARD_ANNOTATION_RE = re.compile(r'\s*?- Annotation \[L(\S*);\]:$') |
43 self._PROGUARD_ANNOTATION_CONST_RE = ( | 45 self._PROGUARD_ANNOTATION_CONST_RE = ( |
44 re.compile(r'\s*?- Constant element value.*$')) | 46 re.compile(r'\s*?- Constant element value.*$')) |
45 self._PROGUARD_ANNOTATION_VALUE_RE = re.compile(r'\s*?- \S+? \[(.*)\]$') | 47 self._PROGUARD_ANNOTATION_VALUE_RE = re.compile(r'\s*?- \S+? \[(.*)\]$') |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 if self._IsTestMethod(test) and self._AnnotationsMatchFilters( | 180 if self._IsTestMethod(test) and self._AnnotationsMatchFilters( |
179 annotation_filter_list, annotations)] | 181 annotation_filter_list, annotations)] |
180 | 182 |
181 def GetTestMethods(self): | 183 def GetTestMethods(self): |
182 """Returns a list of all test methods in this apk as Class#testMethod.""" | 184 """Returns a list of all test methods in this apk as Class#testMethod.""" |
183 return self._test_methods | 185 return self._test_methods |
184 | 186 |
185 @staticmethod | 187 @staticmethod |
186 def IsPythonDrivenTest(test): | 188 def IsPythonDrivenTest(test): |
187 return 'pythonDrivenTests' in test | 189 return 'pythonDrivenTests' in test |
OLD | NEW |