OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright 2014 The Chromium Authors. All rights reserved. | 3 # Copyright 2014 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 """Generates the obfuscated jar and test jar for an apk. | 7 """Generates the obfuscated jar and test jar for an apk. |
8 | 8 |
9 If proguard is not enabled or 'Release' is not in the configuration name, | 9 If proguard is not enabled or 'Release' is not in the configuration name, |
10 obfuscation will be a no-op. | 10 obfuscation will be a no-op. |
11 """ | 11 """ |
12 | 12 |
13 import fnmatch | |
14 import optparse | 13 import optparse |
15 import os | 14 import os |
16 import sys | 15 import sys |
17 import zipfile | |
18 | 16 |
19 from util import build_utils | 17 from util import build_utils |
20 | 18 |
21 def ParseArgs(argv): | 19 def ParseArgs(argv): |
22 parser = optparse.OptionParser() | 20 parser = optparse.OptionParser() |
23 parser.add_option('--android-sdk', help='path to the Android SDK folder') | 21 parser.add_option('--android-sdk', help='path to the Android SDK folder') |
24 parser.add_option('--android-sdk-tools', | 22 parser.add_option('--android-sdk-tools', |
25 help='path to the Android SDK build tools folder') | 23 help='path to the Android SDK build tools folder') |
26 parser.add_option('--android-sdk-jar', | 24 parser.add_option('--android-sdk-jar', |
27 help='path to Android SDK\'s android.jar') | 25 help='path to Android SDK\'s android.jar') |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 | 77 |
80 def main(argv): | 78 def main(argv): |
81 options, _ = ParseArgs(argv) | 79 options, _ = ParseArgs(argv) |
82 | 80 |
83 library_classpath = [options.android_sdk_jar] | 81 library_classpath = [options.android_sdk_jar] |
84 input_jars = build_utils.ParseGypList(options.input_jars_paths) | 82 input_jars = build_utils.ParseGypList(options.input_jars_paths) |
85 | 83 |
86 dependency_class_filters = [ | 84 dependency_class_filters = [ |
87 '*R.class', '*R$*.class', '*Manifest.class', '*BuildConfig.class'] | 85 '*R.class', '*R$*.class', '*Manifest.class', '*BuildConfig.class'] |
88 | 86 |
89 def DependencyClassFilter(name): | |
90 for name_filter in dependency_class_filters: | |
91 if fnmatch.fnmatch(name, name_filter): | |
92 return False | |
93 return True | |
94 | |
95 if options.testapp: | 87 if options.testapp: |
96 with zipfile.ZipFile(options.test_jar_path, 'w') as test_jar: | 88 build_utils.MergeZips( |
97 for jar in input_jars: | 89 options.test_jar_path, input_jars, dependency_class_filters) |
98 with zipfile.ZipFile(jar, 'r') as jar_zip: | |
99 for name in filter(DependencyClassFilter, jar_zip.namelist()): | |
100 with jar_zip.open(name) as zip_entry: | |
101 test_jar.writestr(name, zip_entry.read()) | |
102 | 90 |
103 if options.configuration_name == 'Release' and options.proguard_enabled: | 91 if options.configuration_name == 'Release' and options.proguard_enabled: |
104 proguard_cmd = [ | 92 proguard_cmd = [ |
105 'java', '-jar', options.proguard_jar_path, | 93 'java', '-jar', options.proguard_jar_path, |
106 '-forceprocessing', | 94 '-forceprocessing', |
107 '-libraryjars', ':'.join(library_classpath), | 95 '-libraryjars', ':'.join(library_classpath), |
108 '-dump', options.obfuscated_jar_path + '.dump', | 96 '-dump', options.obfuscated_jar_path + '.dump', |
109 '-printseeds', options.obfuscated_jar_path + '.seeds', | 97 '-printseeds', options.obfuscated_jar_path + '.seeds', |
110 '-printusage', options.obfuscated_jar_path + '.usage', | 98 '-printusage', options.obfuscated_jar_path + '.usage', |
111 '-printmapping', options.obfuscated_jar_path + '.mapping', | 99 '-printmapping', options.obfuscated_jar_path + '.mapping', |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 for f in output_files: | 148 for f in output_files: |
161 if os.path.exists(f): | 149 if os.path.exists(f): |
162 os.remove(f) | 150 os.remove(f) |
163 build_utils.Touch(f) | 151 build_utils.Touch(f) |
164 | 152 |
165 if options.stamp: | 153 if options.stamp: |
166 build_utils.Touch(options.stamp) | 154 build_utils.Touch(options.stamp) |
167 | 155 |
168 if __name__ == '__main__': | 156 if __name__ == '__main__': |
169 sys.exit(main(sys.argv[1:])) | 157 sys.exit(main(sys.argv[1:])) |
OLD | NEW |