1 #! /usr/bin/env python 2 3 # Copyright 2018 Google Inc. 4 # Use of this source code is governed by a BSD-style license that can be 5 # found in the LICENSE file. 6 7 import argparse 8 import os 9 import sys 10 11 from skqp_gn_args import SkqpGnArgs 12 13 fmt = ''' 14 target_cpu = "{arch}" 15 ndk = "{android_ndk_dir}" 16 is_debug = {debug} 17 ndk_api = {api_level} 18 ''' 19 20 def parse_args(): 21 parser = argparse.ArgumentParser(description='Generate args.gn file.') 22 parser.add_argument('target_build_dir') 23 parser.add_argument('android_ndk_dir' ) 24 parser.add_argument('--arch', metavar='architecture', default='arm', 25 help='defaults to "arm", valid values: "arm" "arm64" "x86" "x64"') 26 parser.add_argument('--api_level', type=int, metavar='api_level', 27 default=26, help='android API level, defaults to 26') 28 parser.add_argument('--enable_workarounds', default=False, 29 action='store_true', help="enable GPU work-arounds, defaults to false") 30 parser.add_argument('--debug', default=False, action='store_true', 31 help='compile native code in debug mode, defaults to false') 32 33 # parse the args and convert bools to strings. 34 args = parser.parse_args() 35 gn_bool = lambda b : 'true' if b else 'false' 36 args.enable_workarounds = gn_bool(args.enable_workarounds) 37 args.debug = gn_bool(args.debug) 38 args.android_ndk_dir = os.path.abspath(args.android_ndk_dir) 39 return args 40 41 def write_gn(o, args): 42 o.write(fmt.format(**args)) 43 for k, v in SkqpGnArgs.iteritems(): 44 o.write('%s = %s\n' % (k,v) ) 45 46 def make_args_gn(out_dir, args): 47 if out_dir == '-': 48 write_gn(sys.stdout, args) 49 return 50 if not os.path.exists(out_dir): 51 os.makedirs(out_dir) 52 with open(os.path.join(out_dir, 'args.gn'), 'w') as o: 53 write_gn(o, args) 54 55 if __name__ == '__main__': 56 args = parse_args() 57 make_args_gn(args.target_build_dir, vars(args)) 58