| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 import os | 5 import os |
| 6 import re | 6 import re |
| 7 import tempfile | 7 import tempfile |
| 8 | 8 |
| 9 from pylib import constants | 9 from pylib import constants |
| 10 from pylib import cmd_helper | 10 from pylib import cmd_helper |
| 11 | 11 |
| 12 | 12 |
| 13 _PROGUARD_CLASS_RE = re.compile(r'\s*?- Program class:\s*([\S]+)$') | 13 _PROGUARD_CLASS_RE = re.compile(r'\s*?- Program class:\s*([\S]+)$') |
| 14 _PROGUARD_SUPERCLASS_RE = re.compile(r'\s*? Superclass:\s*([\S]+)$') | 14 _PROGUARD_SUPERCLASS_RE = re.compile(r'\s*? Superclass:\s*([\S]+)$') |
| 15 _PROGUARD_SECTION_RE = re.compile( |
| 16 r'^(?:Interfaces|Constant Pool|Fields|Methods|Class file attributes) ' |
| 17 r'\(count = \d+\):$') |
| 15 _PROGUARD_METHOD_RE = re.compile(r'\s*?- Method:\s*(\S*)[(].*$') | 18 _PROGUARD_METHOD_RE = re.compile(r'\s*?- Method:\s*(\S*)[(].*$') |
| 16 _PROGUARD_ANNOTATION_RE = re.compile(r'\s*?- Annotation \[L(\S*);\]:$') | 19 _PROGUARD_ANNOTATION_RE = re.compile(r'\s*?- Annotation \[L(\S*);\]:$') |
| 17 _PROGUARD_ANNOTATION_CONST_RE = ( | 20 _PROGUARD_ANNOTATION_CONST_RE = ( |
| 18 re.compile(r'\s*?- Constant element value.*$')) | 21 re.compile(r'\s*?- Constant element value.*$')) |
| 19 _PROGUARD_ANNOTATION_VALUE_RE = re.compile(r'\s*?- \S+? \[(.*)\]$') | 22 _PROGUARD_ANNOTATION_VALUE_RE = re.compile(r'\s*?- \S+? \[(.*)\]$') |
| 20 | 23 |
| 21 _PROGUARD_PATH_SDK = os.path.join( | 24 _PROGUARD_PATH_SDK = os.path.join( |
| 22 constants.ANDROID_SDK_ROOT, 'tools', 'proguard', 'lib', 'proguard.jar') | 25 constants.ANDROID_SDK_ROOT, 'tools', 'proguard', 'lib', 'proguard.jar') |
| 23 _PROGUARD_PATH_BUILT = ( | 26 _PROGUARD_PATH_BUILT = ( |
| 24 os.path.join(os.environ['ANDROID_BUILD_TOP'], 'external', 'proguard', | 27 os.path.join(os.environ['ANDROID_BUILD_TOP'], 'external', 'proguard', |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 } | 74 } |
| 72 | 75 |
| 73 annotation = None | 76 annotation = None |
| 74 annotation_has_value = False | 77 annotation_has_value = False |
| 75 class_result = None | 78 class_result = None |
| 76 method_result = None | 79 method_result = None |
| 77 | 80 |
| 78 for line in proguard_output: | 81 for line in proguard_output: |
| 79 line = line.strip('\r\n') | 82 line = line.strip('\r\n') |
| 80 | 83 |
| 81 if len(line) == 0: | |
| 82 annotation = None | |
| 83 annotation_has_value = False | |
| 84 method_result = None | |
| 85 continue | |
| 86 | |
| 87 m = _PROGUARD_CLASS_RE.match(line) | 84 m = _PROGUARD_CLASS_RE.match(line) |
| 88 if m: | 85 if m: |
| 89 class_result = { | 86 class_result = { |
| 90 'class': m.group(1).replace('/', '.'), | 87 'class': m.group(1).replace('/', '.'), |
| 91 'superclass': '', | 88 'superclass': '', |
| 92 'annotations': {}, | 89 'annotations': {}, |
| 93 'methods': [], | 90 'methods': [], |
| 94 } | 91 } |
| 95 results['classes'].append(class_result) | 92 results['classes'].append(class_result) |
| 96 annotation = None | 93 annotation = None |
| 97 annotation_has_value = False | 94 annotation_has_value = False |
| 98 method_result = None | 95 method_result = None |
| 99 continue | 96 continue |
| 100 | 97 |
| 101 if not class_result: | 98 if not class_result: |
| 102 continue | 99 continue |
| 103 | 100 |
| 104 m = _PROGUARD_SUPERCLASS_RE.match(line) | 101 m = _PROGUARD_SUPERCLASS_RE.match(line) |
| 105 if m: | 102 if m: |
| 106 class_result['superclass'] = m.group(1).replace('/', '.') | 103 class_result['superclass'] = m.group(1).replace('/', '.') |
| 107 continue | 104 continue |
| 108 | 105 |
| 106 m = _PROGUARD_SECTION_RE.match(line) |
| 107 if m: |
| 108 annotation = None |
| 109 annotation_has_value = False |
| 110 method_result = None |
| 111 continue |
| 112 |
| 109 m = _PROGUARD_METHOD_RE.match(line) | 113 m = _PROGUARD_METHOD_RE.match(line) |
| 110 if m: | 114 if m: |
| 111 method_result = { | 115 method_result = { |
| 112 'method': m.group(1), | 116 'method': m.group(1), |
| 113 'annotations': {}, | 117 'annotations': {}, |
| 114 } | 118 } |
| 115 class_result['methods'].append(method_result) | 119 class_result['methods'].append(method_result) |
| 116 annotation = None | 120 annotation = None |
| 117 annotation_has_value = False | 121 annotation_has_value = False |
| 118 continue | 122 continue |
| (...skipping 16 matching lines...) Expand all Loading... |
| 135 m = _PROGUARD_ANNOTATION_VALUE_RE.match(line) | 139 m = _PROGUARD_ANNOTATION_VALUE_RE.match(line) |
| 136 if m: | 140 if m: |
| 137 if method_result: | 141 if method_result: |
| 138 method_result['annotations'][annotation] = m.group(1) | 142 method_result['annotations'][annotation] = m.group(1) |
| 139 else: | 143 else: |
| 140 class_result['annotations'][annotation] = m.group(1) | 144 class_result['annotations'][annotation] = m.group(1) |
| 141 annotation_has_value = None | 145 annotation_has_value = None |
| 142 | 146 |
| 143 return results | 147 return results |
| 144 | 148 |
| OLD | NEW |