Debian Codegraph @

infra/bots/recipe_modules/build/android.py

raw
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
6 import re
7
8 from . import util
9
10 def 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 'is_trivial_abi': 'true',
37 'ndk': quote(api.vars.workdir.joinpath(ndk_path)),
38 'target_cpu': quote(target_arch),
39 'werror': 'true',
40 }
41 env = {}
42 extra_cflags.append('-DREBUILD_IF_CHANGED_ndk_version=%s' %
43 api.run.asset_version(ndk_asset, skia_dir))
44
45 if configuration != 'Debug':
46 args['is_debug'] = 'false'
47 if 'Dawn' in extra_tokens:
48 util.set_dawn_args_and_env(args, env, api, extra_tokens, skia_dir)
49 args['ndk_api'] = 26 #skia_use_gl=false, so use vulkan
50 if 'Vulkan' in extra_tokens and not 'Dawn' in extra_tokens:
51 args['ndk_api'] = 26
52 args['skia_enable_vulkan_debug_layers'] = 'false'
53 args['skia_use_gl'] = 'false'
54 args['skia_use_vulkan'] = 'true'
55 if 'ASAN' in extra_tokens:
56 args['sanitize'] = '"ASAN"'
57 if 'Graphite' in extra_tokens:
58 args['skia_enable_graphite'] = 'true'
59 if 'HWASAN' in extra_tokens:
60 args['sanitize'] = '"HWASAN"'
61 if 'Wuffs' in extra_tokens:
62 args['skia_use_wuffs'] = 'true'
63 if configuration == 'OptimizeForSize':
64 # build IDs are required for Bloaty if we want to use strip to ignore debug symbols.
65 # https://github.com/google/bloaty/blob/master/doc/using.md#debugging-stripped-binaries
66 extra_ldflags.append('-Wl,--build-id=sha1')
67 args.update({
68 'skia_use_runtime_icu': 'true',
69 'skia_enable_optimize_size': 'true',
70 'skia_use_jpeg_gainmaps': 'false',
71 })
72
73 # The 'FrameworkWorkarounds' bot is used to test special behavior that's
74 # normally enabled with SK_BUILD_FOR_ANDROID_FRAMEWORK.
75 if 'FrameworkWorkarounds' in extra_tokens:
76 extra_cflags.append('-DSK_SUPPORT_LEGACY_ALPHA_BITMAP_AS_COVERAGE')
77
78 # If an Android API level is specified, use that.
79 for t in extra_tokens:
80 m = re.search(r'API(\d+)', t)
81 if m and len(m.groups()) == 1:
82 args['ndk_api'] = m.groups()[0]
83 break
84
85 if extra_cflags:
86 args['extra_cflags'] = repr(extra_cflags).replace("'", '"')
87 if extra_ldflags:
88 args['extra_ldflags'] = repr(extra_ldflags).replace("'", '"')
89
90 gn_args = ' '.join('%s=%s' % (k,v) for (k,v) in sorted(args.items()))
91 gn = skia_dir.joinpath('bin', 'gn')
92
93 ninja_root = skia_dir.joinpath('third_party', 'ninja')
94 ninja = skia_dir.joinpath(ninja_root, 'ninja')
95
96 # Putting ninja on the path makes it easier for subcommands to find it
97 # (e.g. when building Dawn via CMake+ninja)
98 # Importantly, this needs to go *after* depot_tools, so we append it
99 existing_path = env.get('PATH', '%(PATH)s')
100 env['PATH'] = api.path.pathsep.join([existing_path, str(ninja_root)])
101
102 with api.context(cwd=skia_dir):
103 api.run(api.step, 'fetch-gn',
104 cmd=['python3', skia_dir.joinpath('bin', 'fetch-gn')],
105 infra_step=True)
106
107 api.run(api.step, 'fetch-ninja',
108 cmd=['python3', skia_dir.joinpath('bin', 'fetch-ninja')],
109 infra_step=True)
110
111 with api.env(env):
112 api.run(api.step, 'gn gen',
113 cmd=[gn, 'gen', out_dir, '--args=' + gn_args])
114 api.run(api.step, 'ninja', cmd=[ninja, '-C', out_dir])
115
116
117 ANDROID_BUILD_PRODUCTS_LIST = [
118 'dm',
119 'nanobench',
120 # The following only exists when building for OptimizeForSize
121 # This is the only target we currently measure: skbug.com/40044745
122 'skottie_tool_gpu',
123 ]
124
125
126 def copy_build_products(api, src, dst):
127 """Copy Android build products from src to dst."""
128 util.copy_listed_files(api, src, dst, ANDROID_BUILD_PRODUCTS_LIST)