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

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

Issue 386473002: Add dexing for libraries and apks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gn-apk-first
Patch Set: Created 6 years, 4 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/dex.py ('k') | build/config/android/internal_rules.gni » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 """Writes a build_config file. 7 """Writes a build_config file.
8 8
9 The build_config file for a target is a json file containing information about 9 The build_config file for a target is a json file containing information about
10 how to build that target based on the target's dependencies. This includes 10 how to build that target based on the target's dependencies. This includes
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 help='List of paths for dependency\'s build_config files. Some ' 65 help='List of paths for dependency\'s build_config files. Some '
66 'dependencies may not write build_config files. Missing build_config ' 66 'dependencies may not write build_config files. Missing build_config '
67 'files are handled differently based on the type of this target.') 67 'files are handled differently based on the type of this target.')
68 68
69 # android_resources/apk options 69 # android_resources/apk options
70 parser.add_option('--srcjar', help='Path to target\'s resources srcjar.') 70 parser.add_option('--srcjar', help='Path to target\'s resources srcjar.')
71 parser.add_option('--resources-zip', help='Path to target\'s resources zip.') 71 parser.add_option('--resources-zip', help='Path to target\'s resources zip.')
72 72
73 # android_library/apk options 73 # android_library/apk options
74 parser.add_option('--jar-path', help='Path to target\'s jar output.') 74 parser.add_option('--jar-path', help='Path to target\'s jar output.')
75 parser.add_option('--dex-path', help='Path to target\'s dex output.')
75 76
76 options, args = parser.parse_args(argv) 77 options, args = parser.parse_args(argv)
77 78
78 if args: 79 if args:
79 parser.error('No positional arguments should be given.') 80 parser.error('No positional arguments should be given.')
80 81
81 82
82 if not options.type in [ 83 if not options.type in [
83 'android_library', 'android_resources', 'android_apk']: 84 'android_library', 'android_resources', 'android_apk']:
84 raise Exception('Unknown type: <%s>' % options.type) 85 raise Exception('Unknown type: <%s>' % options.type)
85 86
86 87
87 required_options = ['build_config'] + { 88 required_options = ['build_config'] + {
88 'android_library': ['jar_path'], 89 'android_library': ['jar_path', 'dex_path'],
89 'android_resources': ['resources_zip'], 90 'android_resources': ['resources_zip'],
90 'android_apk': ['jar_path', 'resources_zip'] 91 'android_apk': ['jar_path', 'dex_path', 'resources_zip']
91 }[options.type] 92 }[options.type]
92 93
93 build_utils.CheckOptions(options, parser, required_options) 94 build_utils.CheckOptions(options, parser, required_options)
94 95
95 possible_deps_config_paths = build_utils.ParseGypList( 96 possible_deps_config_paths = build_utils.ParseGypList(
96 options.possible_deps_configs) 97 options.possible_deps_configs)
97 98
98 99
99 100
100 101
101 allow_unknown_deps = options.type == 'android_apk' 102 allow_unknown_deps = options.type == 'android_apk'
102 unknown_deps = [ 103 unknown_deps = [
103 c for c in possible_deps_config_paths if not os.path.exists(c)] 104 c for c in possible_deps_config_paths if not os.path.exists(c)]
104 if unknown_deps and not allow_unknown_deps: 105 if unknown_deps and not allow_unknown_deps:
105 raise Exception('Unknown deps: ' + unknown_deps) 106 raise Exception('Unknown deps: ' + unknown_deps)
106 107
107 direct_deps_config_paths = [ 108 direct_deps_config_paths = [
108 c for c in possible_deps_config_paths if not c in unknown_deps] 109 c for c in possible_deps_config_paths if not c in unknown_deps]
109 all_deps_config_paths = GetAllDepsConfigsInOrder(direct_deps_config_paths) 110 all_deps_config_paths = GetAllDepsConfigsInOrder(direct_deps_config_paths)
110 111
111 direct_deps_configs = [GetDepConfig(p) for p in direct_deps_config_paths] 112 direct_deps_configs = [GetDepConfig(p) for p in direct_deps_config_paths]
112 all_deps_configs = [GetDepConfig(p) for p in all_deps_config_paths] 113 all_deps_configs = [GetDepConfig(p) for p in all_deps_config_paths]
113 114
114 direct_library_deps = DepsOfType('android_library', direct_deps_configs) 115 direct_library_deps = DepsOfType('android_library', direct_deps_configs)
115 all_resources_deps = DepsOfType('android_resources', all_deps_configs) 116 all_resources_deps = DepsOfType('android_resources', all_deps_configs)
117 all_library_deps = DepsOfType('android_library', all_deps_configs)
116 118
117 # Initialize some common config. 119 # Initialize some common config.
118 config = { 120 config = {
119 'deps_info': { 121 'deps_info': {
120 'path': options.build_config, 122 'path': options.build_config,
121 'type': options.type, 123 'type': options.type,
122 'deps_configs': direct_deps_config_paths, 124 'deps_configs': direct_deps_config_paths,
123 } 125 }
124 } 126 }
125 deps_info = config['deps_info'] 127 deps_info = config['deps_info']
126 128
127 if options.type in ['android_library', 'android_apk']: 129 if options.type in ['android_library', 'android_apk']:
128 javac_classpath = [c['jar_path'] for c in direct_library_deps] 130 javac_classpath = [c['jar_path'] for c in direct_library_deps]
129 deps_info['resources_deps'] = [c['path'] for c in all_resources_deps] 131 deps_info['resources_deps'] = [c['path'] for c in all_resources_deps]
130 deps_info['jar_path'] = options.jar_path 132 deps_info['jar_path'] = options.jar_path
133 deps_info['dex_path'] = options.dex_path
131 config['javac'] = { 134 config['javac'] = {
132 'classpath': javac_classpath, 135 'classpath': javac_classpath,
133 } 136 }
134 # Only resources might have srcjars (normal srcjar targets are listed in 137 # Only resources might have srcjars (normal srcjar targets are listed in
135 # srcjar_deps). A resource's srcjar contains the R.java file for those 138 # srcjar_deps). A resource's srcjar contains the R.java file for those
136 # resources, and (like Android's default build system) we allow a library to 139 # resources, and (like Android's default build system) we allow a library to
137 # refer to the resources in any of its dependents. 140 # refer to the resources in any of its dependents.
138 config['javac']['srcjars'] = [ 141 config['javac']['srcjars'] = [
139 c['srcjar'] for c in all_resources_deps if 'srcjar' in c] 142 c['srcjar'] for c in all_resources_deps if 'srcjar' in c]
140 143
141 if options.type == 'android_resources' or options.type == 'android_apk': 144 if options.type == 'android_resources' or options.type == 'android_apk':
142 deps_info['resources_zip'] = options.resources_zip 145 deps_info['resources_zip'] = options.resources_zip
143 if options.srcjar: 146 if options.srcjar:
144 deps_info['srcjar'] = options.srcjar 147 deps_info['srcjar'] = options.srcjar
145 148
146 config['resources'] = {} 149 config['resources'] = {}
147 config['resources']['dependency_zips'] = [ 150 config['resources']['dependency_zips'] = [
148 c['resources_zip'] for c in all_resources_deps] 151 c['resources_zip'] for c in all_resources_deps]
149 152
153 if options.type == 'android_apk':
154 config['apk_dex'] = {}
155 dex_config = config['apk_dex']
156 # TODO(cjhopman): proguard version
157 dex_deps_files = [c['dex_path'] for c in all_library_deps]
158 dex_config['dependency_dex_files'] = dex_deps_files
159
150 build_utils.WriteJson(config, options.build_config, only_if_changed=True) 160 build_utils.WriteJson(config, options.build_config, only_if_changed=True)
151 161
152 if options.depfile: 162 if options.depfile:
153 build_utils.WriteDepfile( 163 build_utils.WriteDepfile(
154 options.depfile, 164 options.depfile,
155 all_deps_config_paths + build_utils.GetPythonDependencies()) 165 all_deps_config_paths + build_utils.GetPythonDependencies())
156 166
157 167
158 if __name__ == '__main__': 168 if __name__ == '__main__':
159 sys.exit(main(sys.argv[1:])) 169 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « build/android/gyp/dex.py ('k') | build/config/android/internal_rules.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698