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

Side by Side Diff: build/android/pylib/utils/proguard.py

Issue 1353673004: Add some unit tests for pylib.utils.proguard (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Split into separate tests Created 5 years, 3 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 | « build/android/pylib/constants/__init__.py ('k') | build/android/pylib/utils/proguard_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 devil.utils import cmd_helper 9 from devil.utils import cmd_helper
10 from pylib import constants 10 from pylib import constants
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 60
61 with tempfile.NamedTemporaryFile() as proguard_output: 61 with tempfile.NamedTemporaryFile() as proguard_output:
62 cmd_helper.RunCmd(['java', '-jar', 62 cmd_helper.RunCmd(['java', '-jar',
63 _PROGUARD_PATH, 63 _PROGUARD_PATH,
64 '-injars', jar_path, 64 '-injars', jar_path,
65 '-dontshrink', 65 '-dontshrink',
66 '-dontoptimize', 66 '-dontoptimize',
67 '-dontobfuscate', 67 '-dontobfuscate',
68 '-dontpreverify', 68 '-dontpreverify',
69 '-dump', proguard_output.name]) 69 '-dump', proguard_output.name])
70 return Parse(proguard_output)
70 71
72 def Parse(proguard_output):
73 results = {
74 'classes': [],
75 }
71 76
72 results = { 77 annotation = None
73 'classes': [], 78 annotation_has_value = False
74 } 79 class_result = None
80 method_result = None
75 81
76 annotation = None 82 for line in proguard_output:
77 annotation_has_value = False 83 line = line.strip('\r\n')
78 class_result = None
79 method_result = None
80 84
81 for line in proguard_output: 85 m = _PROGUARD_CLASS_RE.match(line)
82 line = line.strip('\r\n') 86 if m:
87 class_result = {
88 'class': m.group(1).replace('/', '.'),
89 'superclass': '',
90 'annotations': {},
91 'methods': [],
92 }
93 results['classes'].append(class_result)
94 annotation = None
95 annotation_has_value = False
96 method_result = None
97 continue
83 98
84 m = _PROGUARD_CLASS_RE.match(line) 99 if not class_result:
85 if m: 100 continue
86 class_result = {
87 'class': m.group(1).replace('/', '.'),
88 'superclass': '',
89 'annotations': {},
90 'methods': [],
91 }
92 results['classes'].append(class_result)
93 annotation = None
94 annotation_has_value = False
95 method_result = None
96 continue
97 101
98 if not class_result: 102 m = _PROGUARD_SUPERCLASS_RE.match(line)
99 continue 103 if m:
104 class_result['superclass'] = m.group(1).replace('/', '.')
105 continue
100 106
101 m = _PROGUARD_SUPERCLASS_RE.match(line) 107 m = _PROGUARD_SECTION_RE.match(line)
102 if m: 108 if m:
103 class_result['superclass'] = m.group(1).replace('/', '.') 109 annotation = None
104 continue 110 annotation_has_value = False
111 method_result = None
112 continue
105 113
106 m = _PROGUARD_SECTION_RE.match(line) 114 m = _PROGUARD_METHOD_RE.match(line)
107 if m: 115 if m:
108 annotation = None 116 method_result = {
109 annotation_has_value = False 117 'method': m.group(1),
110 method_result = None 118 'annotations': {},
111 continue 119 }
120 class_result['methods'].append(method_result)
121 annotation = None
122 annotation_has_value = False
123 continue
112 124
113 m = _PROGUARD_METHOD_RE.match(line) 125 m = _PROGUARD_ANNOTATION_RE.match(line)
114 if m: 126 if m:
115 method_result = { 127 # Ignore the annotation package.
116 'method': m.group(1), 128 annotation = m.group(1).split('/')[-1]
117 'annotations': {}, 129 if method_result:
118 } 130 method_result['annotations'][annotation] = None
119 class_result['methods'].append(method_result) 131 else:
120 annotation = None 132 class_result['annotations'][annotation] = None
121 annotation_has_value = False 133 continue
122 continue
123 134
124 m = _PROGUARD_ANNOTATION_RE.match(line) 135 if annotation:
125 if m: 136 if not annotation_has_value:
126 # Ignore the annotation package. 137 m = _PROGUARD_ANNOTATION_CONST_RE.match(line)
127 annotation = m.group(1).split('/')[-1] 138 annotation_has_value = bool(m)
128 if method_result: 139 else:
129 method_result['annotations'][annotation] = None 140 m = _PROGUARD_ANNOTATION_VALUE_RE.match(line)
130 else: 141 if m:
131 class_result['annotations'][annotation] = None 142 if method_result:
132 continue 143 method_result['annotations'][annotation] = m.group(1)
133 144 else:
134 if annotation: 145 class_result['annotations'][annotation] = m.group(1)
135 if not annotation_has_value: 146 annotation_has_value = None
136 m = _PROGUARD_ANNOTATION_CONST_RE.match(line)
137 annotation_has_value = bool(m)
138 else:
139 m = _PROGUARD_ANNOTATION_VALUE_RE.match(line)
140 if m:
141 if method_result:
142 method_result['annotations'][annotation] = m.group(1)
143 else:
144 class_result['annotations'][annotation] = m.group(1)
145 annotation_has_value = None
146
147 return results 147 return results
148
OLDNEW
« no previous file with comments | « build/android/pylib/constants/__init__.py ('k') | build/android/pylib/utils/proguard_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698