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

Side by Side Diff: build/android/gyp/apk_obfuscate.py

Issue 2101243005: Add a snapshot of flutter/engine/src/build to our sdk (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: add README.dart Created 4 years, 5 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/gyp/apk_install.py ('k') | build/android/gyp/copy_ex.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 #
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
5 # found in the LICENSE file.
6
7 """Generates the obfuscated jar and test jar for an apk.
8
9 If proguard is not enabled or 'Release' is not in the configuration name,
10 obfuscation will be a no-op.
11 """
12
13 import optparse
14 import os
15 import sys
16
17 from util import build_utils
18 from util import proguard_util
19
20
21 def ParseArgs(argv):
22 parser = optparse.OptionParser()
23 parser.add_option('--android-sdk', help='path to the Android SDK folder')
24 parser.add_option('--android-sdk-tools',
25 help='path to the Android SDK build tools folder')
26 parser.add_option('--android-sdk-jar',
27 help='path to Android SDK\'s android.jar')
28 parser.add_option('--proguard-jar-path',
29 help='Path to proguard.jar in the sdk')
30 parser.add_option('--input-jars-paths',
31 help='Path to jars to include in obfuscated jar')
32
33 parser.add_option('--proguard-configs',
34 help='Paths to proguard config files')
35
36 parser.add_option('--configuration-name',
37 help='Gyp configuration name (i.e. Debug, Release)')
38 parser.add_option('--proguard-enabled', action='store_true',
39 help='Set if proguard is enabled for this target.')
40
41 parser.add_option('--obfuscated-jar-path',
42 help='Output path for obfuscated jar.')
43
44 parser.add_option('--testapp', action='store_true',
45 help='Set this if building an instrumentation test apk')
46 parser.add_option('--tested-apk-obfuscated-jar-path',
47 help='Path to obfusctated jar of the tested apk')
48 parser.add_option('--test-jar-path',
49 help='Output path for jar containing all the test apk\'s '
50 'code.')
51
52 parser.add_option('--stamp', help='File to touch on success')
53
54 (options, args) = parser.parse_args(argv)
55
56 if args:
57 parser.error('No positional arguments should be given. ' + str(args))
58
59 # Check that required options have been provided.
60 required_options = (
61 'android_sdk',
62 'android_sdk_tools',
63 'android_sdk_jar',
64 'proguard_jar_path',
65 'input_jars_paths',
66 'configuration_name',
67 'obfuscated_jar_path',
68 )
69
70 if options.testapp:
71 required_options += (
72 'test_jar_path',
73 )
74
75 build_utils.CheckOptions(options, parser, required=required_options)
76 return options, args
77
78
79 def DoProguard(options):
80 proguard = proguard_util.ProguardCmdBuilder(options.proguard_jar_path)
81 proguard.outjar(options.obfuscated_jar_path)
82
83 library_classpath = [options.android_sdk_jar]
84 input_jars = build_utils.ParseGypList(options.input_jars_paths)
85
86 exclude_paths = []
87 configs = build_utils.ParseGypList(options.proguard_configs)
88 if options.tested_apk_obfuscated_jar_path:
89 # configs should only contain the process_resources.py generated config.
90 assert len(configs) == 1, (
91 'test apks should not have custom proguard configs: ' + str(configs))
92 tested_jar_info = build_utils.ReadJson(
93 options.tested_apk_obfuscated_jar_path + '.info')
94 exclude_paths = tested_jar_info['inputs']
95 configs = tested_jar_info['configs']
96
97 proguard.is_test(True)
98 proguard.mapping(options.tested_apk_obfuscated_jar_path + '.mapping')
99 library_classpath.append(options.tested_apk_obfuscated_jar_path)
100
101 proguard.libraryjars(library_classpath)
102 proguard_injars = [p for p in input_jars if p not in exclude_paths]
103 proguard.injars(proguard_injars)
104 proguard.configs(configs)
105
106 proguard.CheckOutput()
107
108 this_info = {
109 'inputs': proguard_injars,
110 'configs': configs
111 }
112
113 build_utils.WriteJson(
114 this_info, options.obfuscated_jar_path + '.info')
115
116
117 def main(argv):
118 options, _ = ParseArgs(argv)
119
120 input_jars = build_utils.ParseGypList(options.input_jars_paths)
121
122 if options.testapp:
123 dependency_class_filters = [
124 '*R.class', '*R$*.class', '*Manifest.class', '*BuildConfig.class']
125 build_utils.MergeZips(
126 options.test_jar_path, input_jars, dependency_class_filters)
127
128 if options.configuration_name == 'Release' and options.proguard_enabled:
129 DoProguard(options)
130 else:
131 output_files = [
132 options.obfuscated_jar_path,
133 options.obfuscated_jar_path + '.info',
134 options.obfuscated_jar_path + '.dump',
135 options.obfuscated_jar_path + '.seeds',
136 options.obfuscated_jar_path + '.usage',
137 options.obfuscated_jar_path + '.mapping']
138 for f in output_files:
139 if os.path.exists(f):
140 os.remove(f)
141 build_utils.Touch(f)
142
143 if options.stamp:
144 build_utils.Touch(options.stamp)
145
146 if __name__ == '__main__':
147 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « build/android/gyp/apk_install.py ('k') | build/android/gyp/copy_ex.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698