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
8
9def compile_fn(api, checkout_root, out_dir):
10  skia_dir      = checkout_root.join('skia')
11  compiler      = api.vars.builder_cfg.get('compiler')
12  configuration = api.vars.builder_cfg.get('configuration')
13  extra_tokens  = api.vars.extra_tokens
14  os            = api.vars.builder_cfg.get('os')
15  target_arch   = api.vars.builder_cfg.get('target_arch')
16
17  assert compiler == 'Clang'  # At this rate we might not ever support GCC.
18
19  extra_cflags = []
20  if configuration == 'Debug':
21    extra_cflags.append('-O1')
22
23  ndk_asset = 'android_ndk_linux'
24  ndk_path = ndk_asset
25  if 'Mac' in os:
26    ndk_asset = 'android_ndk_darwin'
27    ndk_path = ndk_asset
28  elif 'Win' in os:
29    ndk_asset = 'android_ndk_windows'
30    ndk_path = 'n'
31
32  quote = lambda x: '"%s"' % x
33  args = {
34      'ndk': quote(api.vars.slave_dir.join(ndk_path)),
35      'target_cpu': quote(target_arch),
36  }
37  extra_cflags.append('-DDUMMY_ndk_version=%s' %
38                      api.run.asset_version(ndk_asset, skia_dir))
39
40  if configuration != 'Debug':
41    args['is_debug'] = 'false'
42  if 'Vulkan' in extra_tokens:
43    args['ndk_api'] = 24
44    args['skia_enable_vulkan_debug_layers'] = 'false'
45  if 'ASAN' in extra_tokens:
46    args['sanitize'] = '"ASAN"'
47    if target_arch == 'arm' and 'ndk_api' not in args:
48      args['ndk_api'] = 21
49
50  # If an Android API level is specified, use that.
51  for t in extra_tokens:
52    m = re.search(r'API(\d+)', t)
53    if m and len(m.groups()) == 1:
54      args['ndk_api'] = m.groups()[0]
55      break
56
57  if extra_cflags:
58    args['extra_cflags'] = repr(extra_cflags).replace("'", '"')
59
60  gn_args = ' '.join('%s=%s' % (k,v) for (k,v) in sorted(args.iteritems()))
61  gn      = skia_dir.join('bin', 'gn')
62
63  with api.context(cwd=skia_dir):
64    api.run(api.python, 'fetch-gn',
65            script=skia_dir.join('bin', 'fetch-gn'),
66            infra_step=True)
67
68    # If this is the SkQP build, set up the environment and run the script
69    # to build the universal APK. This should only run the skqp branches.
70    if 'SKQP' in extra_tokens:
71      output_binary = out_dir.join('run_testlab')
72      build_target = skia_dir.join('infra', 'cts', 'run_testlab.go')
73      build_cmd = ['go', 'build', '-o', output_binary, build_target]
74      with api.context(env=api.infra.go_env):
75        api.run(api.step, 'build firebase runner', cmd=build_cmd)
76
77      # Build the APK.
78      ndk_asset = 'android_ndk_linux'
79      sdk_asset = 'android_sdk_linux'
80      android_ndk = api.vars.slave_dir.join(ndk_asset)
81      android_home = api.vars.slave_dir.join(sdk_asset, 'android-sdk')
82      env = {
83        'ANDROID_NDK': android_ndk,
84        'ANDROID_HOME': android_home,
85        'APK_OUTPUT_DIR': out_dir,
86      }
87
88      mk_universal = skia_dir.join('tools', 'skqp', 'make_universal_apk')
89      with api.context(env=env):
90        api.run(api.step, 'make_universal', cmd=[mk_universal])
91    else:
92      api.run(api.step, 'gn gen',
93              cmd=[gn, 'gen', out_dir, '--args=' + gn_args])
94      api.run(api.step, 'ninja', cmd=['ninja', '-C', out_dir])
95
96
97def copy_extra_build_products(api, src, dst):
98  pass
99