Home | History | Annotate | Download | only in skqp
      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 fmt = '''
     12 target_cpu = "{arch}"
     13 is_debug = {debug}
     14 ndk = "{android_ndk_dir}"
     15 ndk_api = {api_level}
     16 skia_enable_fontmgr_empty = true
     17 skia_enable_pdf = false
     18 skia_skqp_global_error_tolerance = 4
     19 skia_use_dng_sdk = false
     20 skia_use_expat = false
     21 skia_use_icu = false
     22 skia_use_libheif = false
     23 skia_use_lua = false
     24 skia_use_piex = false
     25 skia_use_skcms = false
     26 skia_skqp_enable_driver_correctness_workarounds = {enable_workarounds}
     27 '''
     28 
     29 def parse_args():
     30     parser = argparse.ArgumentParser(description='Generate args.gn file.')
     31     parser.add_argument('target_build_dir')
     32     parser.add_argument('android_ndk_dir' )
     33     parser.add_argument('--arch',  metavar='architecture', default='arm',
     34         help='defaults to "arm", valid values: "arm" "arm64" "x86" "x64"')
     35     parser.add_argument('--api_level', type=int, metavar='api_level',
     36         default=26, help='android API level, defaults to 26')
     37     parser.add_argument('--enable_workarounds', default=False,
     38         action='store_true', help="enable GPU work-arounds, defaults to false")
     39     parser.add_argument('--debug', default=False, action='store_true',
     40         help='compile native code in debug mode, defaults to false')
     41 
     42     # parse the args and convert bools to strings.
     43     args = parser.parse_args()
     44     gn_bool = lambda b : 'true' if b else 'false'
     45     args.enable_workarounds = gn_bool(args.enable_workarounds)
     46     args.debug = gn_bool(args.debug)
     47     args.android_ndk_dir = os.path.abspath(args.android_ndk_dir)
     48     return args
     49 
     50 def make_args_gn(out_dir, args):
     51     if not os.path.exists(out_dir):
     52         os.makedirs(out_dir)
     53     with open(os.path.join(out_dir, 'args.gn'), 'w') as o:
     54         o.write(fmt.format(**args))
     55 
     56 if __name__ == '__main__':
     57     args = parse_args()
     58     make_args_gn(args.target_build_dir, vars(args))
     59