• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.slave_dir.join(ndk_path)),
36      'target_cpu': quote(target_arch),
37      'werror': 'true',
38  }
39  extra_cflags.append('-DDUMMY_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  if 'ASAN' in extra_tokens:
48    args['sanitize'] = '"ASAN"'
49  if 'Wuffs' in extra_tokens:
50    args['skia_use_wuffs'] = 'true'
51
52  # If an Android API level is specified, use that.
53  for t in extra_tokens:
54    m = re.search(r'API(\d+)', t)
55    if m and len(m.groups()) == 1:
56      args['ndk_api'] = m.groups()[0]
57      break
58
59  if extra_cflags:
60    args['extra_cflags'] = repr(extra_cflags).replace("'", '"')
61
62  gn_args = ' '.join('%s=%s' % (k,v) for (k,v) in sorted(args.iteritems()))
63  gn      = skia_dir.join('bin', 'gn')
64
65  with api.context(cwd=skia_dir):
66    api.run(api.python, 'fetch-gn',
67            script=skia_dir.join('bin', 'fetch-gn'),
68            infra_step=True)
69
70    # If this is the SkQP build, set up the environment and run the script
71    # to build the universal APK. This should only run the skqp branches.
72    if 'SKQP' in extra_tokens:
73      output_binary = out_dir.join('run_testlab')
74      build_target = skia_dir.join('infra', 'cts', 'run_testlab.go')
75      build_cmd = ['go', 'build', '-o', output_binary, build_target]
76      with api.context(env=api.infra.go_env):
77        api.run(api.step, 'build firebase runner', cmd=build_cmd)
78
79      # Build the APK.
80      ndk_asset = 'android_ndk_linux'
81      sdk_asset = 'android_sdk_linux'
82      android_ndk = api.vars.slave_dir.join(ndk_asset)
83      android_home = api.vars.slave_dir.join(sdk_asset, 'android-sdk')
84      env = {
85        'ANDROID_NDK': android_ndk,
86        'ANDROID_HOME': android_home,
87        'APK_OUTPUT_DIR': out_dir,
88      }
89
90      mk_universal = skia_dir.join('tools', 'skqp', 'make_universal_apk')
91      with api.context(env=env):
92        api.run(api.step, 'make_universal', cmd=[mk_universal])
93    else:
94      api.run(api.step, 'gn gen',
95              cmd=[gn, 'gen', out_dir, '--args=' + gn_args])
96      api.run(api.step, 'ninja', cmd=['ninja', '-C', out_dir])
97
98
99ANDROID_BUILD_PRODUCTS_LIST = [
100  'dm',
101  'nanobench',
102  'skpbench',
103]
104
105
106def copy_build_products(api, src, dst):
107  """Copy Android build products from src to dst."""
108  util.copy_listed_files(api, src, dst, ANDROID_BUILD_PRODUCTS_LIST)
109