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

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

Issue 1433873004: GN: Enable proguard for apks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review nites Created 5 years, 1 month 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/util/proguard_util.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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 # android library options 185 # android library options
186 parser.add_option('--dex-path', help='Path to target\'s dex output.') 186 parser.add_option('--dex-path', help='Path to target\'s dex output.')
187 187
188 # native library options 188 # native library options
189 parser.add_option('--native-libs', help='List of top-level native libs.') 189 parser.add_option('--native-libs', help='List of top-level native libs.')
190 parser.add_option('--readelf-path', help='Path to toolchain\'s readelf.') 190 parser.add_option('--readelf-path', help='Path to toolchain\'s readelf.')
191 191
192 parser.add_option('--tested-apk-config', 192 parser.add_option('--tested-apk-config',
193 help='Path to the build config of the tested apk (for an instrumentation ' 193 help='Path to the build config of the tested apk (for an instrumentation '
194 'test apk).') 194 'test apk).')
195 parser.add_option('--proguard-enabled', action='store_true',
196 help='Whether proguard is enabled for this apk.')
197 parser.add_option('--proguard-info',
198 help='Path to the proguard .info output for this apk.')
195 199
196 options, args = parser.parse_args(argv) 200 options, args = parser.parse_args(argv)
197 201
198 if args: 202 if args:
199 parser.error('No positional arguments should be given.') 203 parser.error('No positional arguments should be given.')
200 204
201 required_options_map = { 205 required_options_map = {
202 'java_library': ['build_config', 'jar_path'], 206 'java_library': ['build_config', 'jar_path'],
203 'android_assets': ['build_config'], 207 'android_assets': ['build_config'],
204 'android_resources': ['build_config', 'resources_zip'], 208 'android_resources': ['build_config', 'resources_zip'],
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 348
345 if options.type == 'android_apk' or options.type == 'resource_rewriter': 349 if options.type == 'android_apk' or options.type == 'resource_rewriter':
346 config['resources']['extra_package_names'] = [ 350 config['resources']['extra_package_names'] = [
347 c['package_name'] for c in all_resources_deps if 'package_name' in c] 351 c['package_name'] for c in all_resources_deps if 'package_name' in c]
348 config['resources']['extra_r_text_files'] = [ 352 config['resources']['extra_r_text_files'] = [
349 c['r_text'] for c in all_resources_deps if 'r_text' in c] 353 c['r_text'] for c in all_resources_deps if 'r_text' in c]
350 354
351 if options.type in ['android_apk', 'deps_dex']: 355 if options.type in ['android_apk', 'deps_dex']:
352 deps_dex_files = [c['dex_path'] for c in all_library_deps] 356 deps_dex_files = [c['dex_path'] for c in all_library_deps]
353 357
358 proguard_enabled = options.proguard_enabled
359 if options.type == 'android_apk':
360 deps_info['proguard_enabled'] = proguard_enabled
361
362 if proguard_enabled:
363 deps_info['proguard_info'] = options.proguard_info
364 config['proguard'] = {}
365 proguard_config = config['proguard']
366 proguard_config['input_paths'] = [options.jar_path] + java_full_classpath
367 proguard_config['tested_apk_info'] = ''
368
354 # An instrumentation test apk should exclude the dex files that are in the apk 369 # An instrumentation test apk should exclude the dex files that are in the apk
355 # under test. 370 # under test.
356 if options.type == 'android_apk' and options.tested_apk_config: 371 if options.type == 'android_apk' and options.tested_apk_config:
357 tested_apk_deps = Deps([options.tested_apk_config]) 372 tested_apk_deps = Deps([options.tested_apk_config])
358 tested_apk_library_deps = tested_apk_deps.All('java_library') 373 tested_apk_library_deps = tested_apk_deps.All('java_library')
359 tested_apk_deps_dex_files = [c['dex_path'] for c in tested_apk_library_deps] 374 tested_apk_deps_dex_files = [c['dex_path'] for c in tested_apk_library_deps]
360 deps_dex_files = [ 375 deps_dex_files = [
361 p for p in deps_dex_files if not p in tested_apk_deps_dex_files] 376 p for p in deps_dex_files if not p in tested_apk_deps_dex_files]
362 377
363 tested_apk_config = GetDepConfig(options.tested_apk_config) 378 tested_apk_config = GetDepConfig(options.tested_apk_config)
364 expected_tested_package = tested_apk_config['package_name'] 379 expected_tested_package = tested_apk_config['package_name']
365 AndroidManifest(options.android_manifest).CheckInstrumentation( 380 AndroidManifest(options.android_manifest).CheckInstrumentation(
366 expected_tested_package) 381 expected_tested_package)
382 if tested_apk_config['proguard_enabled']:
383 proguard_config['tested_apk_info'] = tested_apk_config['proguard_info']
384 assert proguard_enabled, ('proguard must be enabled for instrumentation'
385 ' apks if it\'s enabled for the tested apk')
367 386
368 # Dependencies for the final dex file of an apk or a 'deps_dex'. 387 # Dependencies for the final dex file of an apk or a 'deps_dex'.
369 if options.type in ['android_apk', 'deps_dex']: 388 if options.type in ['android_apk', 'deps_dex']:
370 config['final_dex'] = {} 389 config['final_dex'] = {}
371 dex_config = config['final_dex'] 390 dex_config = config['final_dex']
372 # TODO(cjhopman): proguard version 391 if proguard_enabled:
392 # When proguard is enabled, the proguarded jar contains the code for all
393 # of the dependencies.
394 deps_dex_files = []
373 dex_config['dependency_dex_files'] = deps_dex_files 395 dex_config['dependency_dex_files'] = deps_dex_files
374 396
375 if options.type == 'android_apk': 397 if options.type == 'android_apk':
376 config['dist_jar'] = { 398 config['dist_jar'] = {
377 'dependency_jars': [ 399 'dependency_jars': [
378 c['jar_path'] for c in all_library_deps 400 c['jar_path'] for c in all_library_deps
379 ] 401 ]
380 } 402 }
381 manifest = AndroidManifest(options.android_manifest) 403 manifest = AndroidManifest(options.android_manifest)
382 deps_info['package_name'] = manifest.GetPackageName() 404 deps_info['package_name'] = manifest.GetPackageName()
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 build_utils.WriteJson(config, options.build_config, only_if_changed=True) 447 build_utils.WriteJson(config, options.build_config, only_if_changed=True)
426 448
427 if options.depfile: 449 if options.depfile:
428 build_utils.WriteDepfile( 450 build_utils.WriteDepfile(
429 options.depfile, 451 options.depfile,
430 deps.AllConfigPaths() + build_utils.GetPythonDependencies()) 452 deps.AllConfigPaths() + build_utils.GetPythonDependencies())
431 453
432 454
433 if __name__ == '__main__': 455 if __name__ == '__main__':
434 sys.exit(main(sys.argv[1:])) 456 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « build/android/gyp/util/proguard_util.py ('k') | build/config/android/internal_rules.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698