xref: /aosp_15_r20/external/skia/infra/bots/recipe_modules/build/android.py (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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.joinpath('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  extra_ldflags = []
22  if configuration == 'Debug':
23    extra_cflags.append('-O1')
24
25  ndk_asset = 'android_ndk_linux'
26  ndk_path = ndk_asset
27  if 'Mac' in os:
28    ndk_asset = 'android_ndk_darwin'
29    ndk_path = ndk_asset
30  elif 'Win' in os:
31    ndk_asset = 'android_ndk_windows'
32    ndk_path = 'n'
33
34  quote = lambda x: '"%s"' % x
35  args = {
36      'ndk': quote(api.vars.workdir.joinpath(ndk_path)),
37      'target_cpu': quote(target_arch),
38      'werror': 'true',
39  }
40  env = {}
41  extra_cflags.append('-DREBUILD_IF_CHANGED_ndk_version=%s' %
42                      api.run.asset_version(ndk_asset, skia_dir))
43
44  if configuration != 'Debug':
45    args['is_debug'] = 'false'
46  if 'Dawn' in extra_tokens:
47    util.set_dawn_args_and_env(args, env, api, extra_tokens, skia_dir)
48    args['ndk_api'] = 26 #skia_use_gl=false, so use vulkan
49  if 'Vulkan' in extra_tokens and not 'Dawn' in extra_tokens:
50    args['ndk_api'] = 26
51    args['skia_enable_vulkan_debug_layers'] = 'false'
52    args['skia_use_gl'] = 'false'
53    args['skia_use_vulkan'] = 'true'
54  if 'ASAN' in extra_tokens:
55    args['sanitize'] = '"ASAN"'
56  if 'Graphite' in extra_tokens:
57    args['skia_enable_graphite'] = 'true'
58  if 'HWASAN' in extra_tokens:
59    args['sanitize'] = '"HWASAN"'
60  if 'Wuffs' in extra_tokens:
61    args['skia_use_wuffs'] = 'true'
62  if configuration == 'OptimizeForSize':
63    # build IDs are required for Bloaty if we want to use strip to ignore debug symbols.
64    # https://github.com/google/bloaty/blob/master/doc/using.md#debugging-stripped-binaries
65    extra_ldflags.append('-Wl,--build-id=sha1')
66    args.update({
67      'skia_use_runtime_icu': 'true',
68      'skia_enable_optimize_size': 'true',
69      'skia_use_jpeg_gainmaps': 'false',
70    })
71
72  # The 'FrameworkWorkarounds' bot is used to test special behavior that's
73  # normally enabled with SK_BUILD_FOR_ANDROID_FRAMEWORK.
74  if 'FrameworkWorkarounds' in extra_tokens:
75    extra_cflags.append('-DSK_SUPPORT_LEGACY_ALPHA_BITMAP_AS_COVERAGE')
76
77  # If an Android API level is specified, use that.
78  for t in extra_tokens:
79    m = re.search(r'API(\d+)', t)
80    if m and len(m.groups()) == 1:
81      args['ndk_api'] = m.groups()[0]
82      break
83
84  if extra_cflags:
85    args['extra_cflags'] = repr(extra_cflags).replace("'", '"')
86  if extra_ldflags:
87    args['extra_ldflags'] = repr(extra_ldflags).replace("'", '"')
88
89  gn_args = ' '.join('%s=%s' % (k,v) for (k,v) in sorted(args.items()))
90  gn      = skia_dir.joinpath('bin', 'gn')
91
92  with api.context(cwd=skia_dir):
93    api.run(api.step, 'fetch-gn',
94            cmd=['python3', skia_dir.joinpath('bin', 'fetch-gn')],
95            infra_step=True)
96
97    api.run(api.step, 'fetch-ninja',
98            cmd=['python3', skia_dir.joinpath('bin', 'fetch-ninja')],
99            infra_step=True)
100
101    with api.env(env):
102      api.run(api.step, 'gn gen',
103              cmd=[gn, 'gen', out_dir, '--args=' + gn_args])
104      api.run(api.step, 'ninja', cmd=['ninja', '-C', out_dir])
105
106
107ANDROID_BUILD_PRODUCTS_LIST = [
108  'dm',
109  'nanobench',
110  # The following only exists when building for OptimizeForSize
111  # This is the only target we currently measure: skbug.com/13657
112  'skottie_tool_gpu',
113]
114
115
116def copy_build_products(api, src, dst):
117  """Copy Android build products from src to dst."""
118  util.copy_listed_files(api, src, dst, ANDROID_BUILD_PRODUCTS_LIST)
119