1#!/usr/bin/env python 2# Copyright 2015 The Chromium Authors. All rights reserved. 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6 7import argparse 8import json 9import os 10import sys 11 12from util import build_utils 13 14 15_GCC_PREPROCESS_PATH = os.path.join( 16 os.path.dirname(__file__), 'gcc_preprocess.py') 17 18 19def ParseArgs(): 20 parser = argparse.ArgumentParser() 21 parser.add_argument('--configuration-name', required=True, 22 help='The build CONFIGURATION_NAME.') 23 parser.add_argument('--enable-multidex', action='store_true', default=False, 24 help='If passed, multidex may be enabled.') 25 parser.add_argument('--enabled-configurations', default=[], 26 help='The configuration(s) for which multidex should be ' 27 'enabled. If not specified and --enable-multidex is ' 28 'passed, multidex will be enabled for all ' 29 'configurations.') 30 parser.add_argument('--multidex-configuration-path', required=True, 31 help='The path to which the multidex configuration JSON ' 32 'should be saved.') 33 parser.add_argument('--multidex-config-java-file', required=True) 34 parser.add_argument('--multidex-config-java-stamp', required=True) 35 parser.add_argument('--multidex-config-java-template', required=True) 36 37 args = parser.parse_args() 38 39 if args.enabled_configurations: 40 args.enabled_configurations = build_utils.ParseGypList( 41 args.enabled_configurations) 42 43 return args 44 45 46def _WriteConfigJson(multidex_enabled, multidex_configuration_path): 47 config = { 48 'enabled': multidex_enabled, 49 } 50 51 with open(multidex_configuration_path, 'w') as f: 52 f.write(json.dumps(config)) 53 54 55def _GenerateMultidexConfigJava(multidex_enabled, args): 56 gcc_preprocess_cmd = [ 57 sys.executable, _GCC_PREPROCESS_PATH, 58 '--include-path=', 59 '--template', args.multidex_config_java_template, 60 '--stamp', args.multidex_config_java_stamp, 61 '--output', args.multidex_config_java_file, 62 ] 63 if multidex_enabled: 64 gcc_preprocess_cmd += [ 65 '--defines', 'ENABLE_MULTIDEX', 66 ] 67 68 build_utils.CheckOutput(gcc_preprocess_cmd) 69 70 71def main(): 72 args = ParseArgs() 73 74 multidex_enabled = ( 75 args.enable_multidex 76 and (not args.enabled_configurations 77 or args.configuration_name in args.enabled_configurations)) 78 79 _WriteConfigJson(multidex_enabled, args.multidex_configuration_path) 80 _GenerateMultidexConfigJava(multidex_enabled, args) 81 82 return 0 83 84 85if __name__ == '__main__': 86 sys.exit(main()) 87 88