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

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

Issue 1418243003: Add GN template for android_assets(). Use it in content_shell_apk. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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
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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 'files are handled differently based on the type of this target.') 122 'files are handled differently based on the type of this target.')
123 123
124 # android_resources options 124 # android_resources options
125 parser.add_option('--srcjar', help='Path to target\'s resources srcjar.') 125 parser.add_option('--srcjar', help='Path to target\'s resources srcjar.')
126 parser.add_option('--resources-zip', help='Path to target\'s resources zip.') 126 parser.add_option('--resources-zip', help='Path to target\'s resources zip.')
127 parser.add_option('--r-text', help='Path to target\'s R.txt file.') 127 parser.add_option('--r-text', help='Path to target\'s R.txt file.')
128 parser.add_option('--package-name', 128 parser.add_option('--package-name',
129 help='Java package name for these resources.') 129 help='Java package name for these resources.')
130 parser.add_option('--android-manifest', help='Path to android manifest.') 130 parser.add_option('--android-manifest', help='Path to android manifest.')
131 131
132 # android_assets options
133 parser.add_option('--assets', help='List of asset\'s sources.')
134 parser.add_option('--disable-asset-compression', action='store_true',
135 help='Whether to enable asset compression.')
136
132 # java library options 137 # java library options
133 parser.add_option('--jar-path', help='Path to target\'s jar output.') 138 parser.add_option('--jar-path', help='Path to target\'s jar output.')
134 parser.add_option('--supports-android', action='store_true', 139 parser.add_option('--supports-android', action='store_true',
135 help='Whether this library supports running on the Android platform.') 140 help='Whether this library supports running on the Android platform.')
136 parser.add_option('--requires-android', action='store_true', 141 parser.add_option('--requires-android', action='store_true',
137 help='Whether this library requires running on the Android platform.') 142 help='Whether this library requires running on the Android platform.')
138 parser.add_option('--bypass-platform-checks', action='store_true', 143 parser.add_option('--bypass-platform-checks', action='store_true',
139 help='Bypass checks for support/require Android platform.') 144 help='Bypass checks for support/require Android platform.')
140 145
141 # android library options 146 # android library options
142 parser.add_option('--dex-path', help='Path to target\'s dex output.') 147 parser.add_option('--dex-path', help='Path to target\'s dex output.')
143 148
144 # native library options 149 # native library options
145 parser.add_option('--native-libs', help='List of top-level native libs.') 150 parser.add_option('--native-libs', help='List of top-level native libs.')
146 parser.add_option('--readelf-path', help='Path to toolchain\'s readelf.') 151 parser.add_option('--readelf-path', help='Path to toolchain\'s readelf.')
147 152
148 parser.add_option('--tested-apk-config', 153 parser.add_option('--tested-apk-config',
149 help='Path to the build config of the tested apk (for an instrumentation ' 154 help='Path to the build config of the tested apk (for an instrumentation '
150 'test apk).') 155 'test apk).')
151 156
152 options, args = parser.parse_args(argv) 157 options, args = parser.parse_args(argv)
153 158
154 if args: 159 if args:
155 parser.error('No positional arguments should be given.') 160 parser.error('No positional arguments should be given.')
156 161
157 162 required_options_map = {
158 if not options.type in [ 163 'java_library': ['build_config', 'jar_path'],
159 'java_library', 'android_resources', 'android_apk', 'deps_dex']: 164 'android_assets': ['build_config', 'assets'],
165 'android_resources': ['build_config', 'resources_zip'],
166 'android_apk': ['build_config', 'jar_path', 'dex_path', 'resources_zip'],
167 'deps_dex': ['build_config', 'dex_path']
168 }
169 required_options = required_options_map.get(options.type)
170 if not required_options:
160 raise Exception('Unknown type: <%s>' % options.type) 171 raise Exception('Unknown type: <%s>' % options.type)
161 172
162 required_options = ['build_config'] + {
163 'java_library': ['jar_path'],
164 'android_resources': ['resources_zip'],
165 'android_apk': ['jar_path', 'dex_path', 'resources_zip'],
166 'deps_dex': ['dex_path']
167 }[options.type]
168
169 if options.native_libs: 173 if options.native_libs:
170 required_options.append('readelf_path') 174 required_options.append('readelf_path')
171 175
172 build_utils.CheckOptions(options, parser, required_options) 176 build_utils.CheckOptions(options, parser, required_options)
173 177
174 if options.type == 'java_library': 178 if options.type == 'java_library':
175 if options.supports_android and not options.dex_path: 179 if options.supports_android and not options.dex_path:
176 raise Exception('java_library that supports Android requires a dex path.') 180 raise Exception('java_library that supports Android requires a dex path.')
177 181
178 if options.requires_android and not options.supports_android: 182 if options.requires_android and not options.supports_android:
179 raise Exception( 183 raise Exception(
180 '--supports-android is required when using --requires-android') 184 '--supports-android is required when using --requires-android')
181 185
182 possible_deps_config_paths = build_utils.ParseGypList( 186 possible_deps_config_paths = build_utils.ParseGypList(
183 options.possible_deps_configs) 187 options.possible_deps_configs)
184 188
185 allow_unknown_deps = (options.type == 'android_apk' or 189 allow_unknown_deps = (options.type in
186 options.type == 'android_resources') 190 ('android_apk', 'android_assets', 'android_resources'))
187 unknown_deps = [ 191 unknown_deps = [
188 c for c in possible_deps_config_paths if not os.path.exists(c)] 192 c for c in possible_deps_config_paths if not os.path.exists(c)]
189 if unknown_deps and not allow_unknown_deps: 193 if unknown_deps and not allow_unknown_deps:
190 raise Exception('Unknown deps: ' + str(unknown_deps)) 194 raise Exception('Unknown deps: ' + str(unknown_deps))
191 195
192 direct_deps_config_paths = [ 196 direct_deps_config_paths = [
193 c for c in possible_deps_config_paths if not c in unknown_deps] 197 c for c in possible_deps_config_paths if not c in unknown_deps]
194 198
195 deps = Deps(direct_deps_config_paths) 199 deps = Deps(direct_deps_config_paths)
196 direct_library_deps = deps.Direct('java_library') 200 direct_library_deps = deps.Direct('java_library')
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 # srcjar_deps). A resource's srcjar contains the R.java file for those 259 # srcjar_deps). A resource's srcjar contains the R.java file for those
256 # resources, and (like Android's default build system) we allow a library to 260 # resources, and (like Android's default build system) we allow a library to
257 # refer to the resources in any of its dependents. 261 # refer to the resources in any of its dependents.
258 config['javac']['srcjars'] = [ 262 config['javac']['srcjars'] = [
259 c['srcjar'] for c in direct_resources_deps if 'srcjar' in c] 263 c['srcjar'] for c in direct_resources_deps if 'srcjar' in c]
260 264
261 if options.type == 'android_apk': 265 if options.type == 'android_apk':
262 # Apks will get their resources srcjar explicitly passed to the java step. 266 # Apks will get their resources srcjar explicitly passed to the java step.
263 config['javac']['srcjars'] = [] 267 config['javac']['srcjars'] = []
264 268
269 if options.type == 'android_assets':
270 deps_info['assets'] = {
271 'paths': build_utils.ParseGypList(options.assets),
272 'enable_compression': not options.disable_asset_compression
273 }
pkotwicz 2015/10/24 03:46:03 Nit: New line
agrieve 2015/10/25 17:32:09 Done.
265 if options.type == 'android_resources': 274 if options.type == 'android_resources':
266 deps_info['resources_zip'] = options.resources_zip 275 deps_info['resources_zip'] = options.resources_zip
267 if options.srcjar: 276 if options.srcjar:
268 deps_info['srcjar'] = options.srcjar 277 deps_info['srcjar'] = options.srcjar
269 if options.android_manifest: 278 if options.android_manifest:
270 manifest = AndroidManifest(options.android_manifest) 279 manifest = AndroidManifest(options.android_manifest)
271 deps_info['package_name'] = manifest.GetPackageName() 280 deps_info['package_name'] = manifest.GetPackageName()
272 if options.package_name: 281 if options.package_name:
273 deps_info['package_name'] = options.package_name 282 deps_info['package_name'] = options.package_name
274 if options.r_text: 283 if options.r_text:
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 if not library_paths: 360 if not library_paths:
352 prev_config = build_utils.ReadJson(options.build_config) 361 prev_config = build_utils.ReadJson(options.build_config)
353 java_libraries_list_holder[0] = ( 362 java_libraries_list_holder[0] = (
354 prev_config['native']['java_libraries_list']) 363 prev_config['native']['java_libraries_list'])
355 library_paths.extend(prev_config['native']['libraries']) 364 library_paths.extend(prev_config['native']['libraries'])
356 365
357 config['native'] = { 366 config['native'] = {
358 'libraries': library_paths, 367 'libraries': library_paths,
359 'java_libraries_list': java_libraries_list_holder[0], 368 'java_libraries_list': java_libraries_list_holder[0],
360 } 369 }
370 all_assets = deps.All('android_assets')
371 config['merged_assets'] = [a['assets'] for a in all_assets if 'assets' in a]
pkotwicz 2015/10/24 03:46:03 I think that you can make things slightly clearer
agrieve 2015/10/25 17:32:09 I like that this would make for a shallower tree,
361 372
362 build_utils.WriteJson(config, options.build_config, only_if_changed=True) 373 build_utils.WriteJson(config, options.build_config, only_if_changed=True)
363 374
364 if options.depfile: 375 if options.depfile:
365 build_utils.WriteDepfile( 376 build_utils.WriteDepfile(
366 options.depfile, 377 options.depfile,
367 deps.AllConfigPaths() + build_utils.GetPythonDependencies()) 378 deps.AllConfigPaths() + build_utils.GetPythonDependencies())
368 379
369 380
370 if __name__ == '__main__': 381 if __name__ == '__main__':
371 sys.exit(main(sys.argv[1:])) 382 sys.exit(main(sys.argv[1:]))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698