• 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.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 'HWASAN' in extra_tokens:
51    args['sanitize'] = '"HWASAN"'
52  if 'Wuffs' in extra_tokens:
53    args['skia_use_wuffs'] = 'true'
54
55  # If an Android API level is specified, use that.
56  for t in extra_tokens:
57    m = re.search(r'API(\d+)', t)
58    if m and len(m.groups()) == 1:
59      args['ndk_api'] = m.groups()[0]
60      break
61
62  if extra_cflags:
63    args['extra_cflags'] = repr(extra_cflags).replace("'", '"')
64
65  gn_args = ' '.join('%s=%s' % (k,v) for (k,v) in sorted(args.items()))
66  gn      = skia_dir.join('bin', 'gn')
67
68  with api.context(cwd=skia_dir):
69    api.run(api.python, 'fetch-gn',
70            script=skia_dir.join('bin', 'fetch-gn'),
71            infra_step=True)
72
73    api.run(api.step, 'gn gen',
74            cmd=[gn, 'gen', out_dir, '--args=' + gn_args])
75    api.run(api.step, 'ninja', cmd=['ninja', '-C', out_dir])
76
77
78ANDROID_BUILD_PRODUCTS_LIST = [
79  'dm',
80  'nanobench',
81  'skpbench',
82]
83
84
85def copy_build_products(api, src, dst):
86  """Copy Android build products from src to dst."""
87  util.copy_listed_files(api, src, dst, ANDROID_BUILD_PRODUCTS_LIST)
88