1# Copyright 2018 The Chromium Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5 6import re 7 8from . import util 9 10def compile_fn(api, checkout_root, out_dir): 11 skia_dir = checkout_root.join('skia') 12 compiler = api.vars.builder_cfg.get('compiler') 13 configuration = api.vars.builder_cfg.get('configuration') 14 extra_tokens = api.vars.extra_tokens 15 os = api.vars.builder_cfg.get('os') 16 target_arch = api.vars.builder_cfg.get('target_arch') 17 18 assert compiler == 'Clang' # At this rate we might not ever support GCC. 19 20 extra_cflags = [] 21 if configuration == 'Debug': 22 extra_cflags.append('-O1') 23 24 ndk_asset = 'android_ndk_linux' 25 ndk_path = ndk_asset 26 if 'Mac' in os: 27 ndk_asset = 'android_ndk_darwin' 28 ndk_path = ndk_asset 29 elif 'Win' in os: 30 ndk_asset = 'android_ndk_windows' 31 ndk_path = 'n' 32 33 quote = lambda x: '"%s"' % x 34 args = { 35 'ndk': quote(api.vars.workdir.join(ndk_path)), 36 'target_cpu': quote(target_arch), 37 'werror': 'true', 38 } 39 extra_cflags.append('-DREBUILD_IF_CHANGED_ndk_version=%s' % 40 api.run.asset_version(ndk_asset, skia_dir)) 41 42 if configuration != 'Debug': 43 args['is_debug'] = 'false' 44 if 'Vulkan' in extra_tokens: 45 args['ndk_api'] = 24 46 args['skia_enable_vulkan_debug_layers'] = 'false' 47 args['skia_use_gl'] = 'false' 48 if 'ASAN' in extra_tokens: 49 args['sanitize'] = '"ASAN"' 50 if 'Wuffs' in extra_tokens: 51 args['skia_use_wuffs'] = 'true' 52 53 # If an Android API level is specified, use that. 54 for t in extra_tokens: 55 m = re.search(r'API(\d+)', t) 56 if m and len(m.groups()) == 1: 57 args['ndk_api'] = m.groups()[0] 58 break 59 60 if extra_cflags: 61 args['extra_cflags'] = repr(extra_cflags).replace("'", '"') 62 63 gn_args = ' '.join('%s=%s' % (k,v) for (k,v) in sorted(args.iteritems())) 64 gn = skia_dir.join('bin', 'gn') 65 66 with api.context(cwd=skia_dir): 67 api.run(api.python, 'fetch-gn', 68 script=skia_dir.join('bin', 'fetch-gn'), 69 infra_step=True) 70 71 # If this is the SkQP build, set up the environment and run the script 72 # to build the universal APK. This should only run the skqp branches. 73 if 'SKQP' in extra_tokens: 74 output_binary = out_dir.join('run_testlab') 75 build_target = skia_dir.join('infra', 'cts', 'run_testlab.go') 76 build_cmd = ['go', 'build', '-o', output_binary, build_target] 77 with api.context(env=api.infra.go_env): 78 api.run(api.step, 'build firebase runner', cmd=build_cmd) 79 80 # Build the APK. 81 ndk_asset = 'android_ndk_linux' 82 sdk_asset = 'android_sdk_linux' 83 android_ndk = api.vars.workdir.join(ndk_asset) 84 android_home = api.vars.workdir.join(sdk_asset, 'android-sdk') 85 env = { 86 'ANDROID_NDK': android_ndk, 87 'ANDROID_HOME': android_home, 88 'APK_OUTPUT_DIR': out_dir, 89 } 90 91 mk_universal = skia_dir.join('tools', 'skqp', 'make_universal_apk') 92 with api.context(env=env): 93 api.run(api.step, 'make_universal', cmd=[mk_universal]) 94 else: 95 api.run(api.step, 'gn gen', 96 cmd=[gn, 'gen', out_dir, '--args=' + gn_args]) 97 api.run(api.step, 'ninja', cmd=['ninja', '-C', out_dir]) 98 99 100ANDROID_BUILD_PRODUCTS_LIST = [ 101 'dm', 102 'nanobench', 103 'skpbench', 104] 105 106 107def copy_build_products(api, src, dst): 108 """Copy Android build products from src to dst.""" 109 util.copy_listed_files(api, src, dst, ANDROID_BUILD_PRODUCTS_LIST) 110