blob: 4256993fe23b58194abceae45875d9acee800d25 [file] [log] [blame]
Mike Klein308b5ac2016-12-06 16:03:52 -05001#!/usr/bin/env python
2#
3# Copyright 2016 Google Inc.
4#
5# Use of this source code is governed by a BSD-style license that can be
6# found in the LICENSE file.
7
8# Generate Android.bp for Skia from GN configuration.
9
Martin Vejdarskibeaaf472020-03-03 13:53:20 +070010from __future__ import print_function
11
Mike Klein308b5ac2016-12-06 16:03:52 -050012import os
13import pprint
14import string
15import subprocess
Mike Klein308b5ac2016-12-06 16:03:52 -050016import tempfile
17
Derek Sollenberger5d3f7702018-02-01 09:22:53 -050018import gn_to_bp_utils
19
Mike Klein308b5ac2016-12-06 16:03:52 -050020# First we start off with a template for Android.bp,
21# with holes for source lists and include directories.
22bp = string.Template('''// This file is autogenerated by gn_to_bp.py.
23
Derek Sollenberger5a932162017-09-21 14:25:14 -040024cc_library_static {
Mike Kleinee43f6f2016-12-12 14:09:38 -050025 name: "libskia",
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -050026 host_supported: true,
Mike Kleinee43f6f2016-12-12 14:09:38 -050027 cflags: [
Leon Scroggins III981a31e2017-10-06 11:53:53 -040028 $cflags
29 ],
30
31 cppflags:[
32 $cflags_cc
Mike Kleinee43f6f2016-12-12 14:09:38 -050033 ],
Mike Klein308b5ac2016-12-06 16:03:52 -050034
Mike Kleinee43f6f2016-12-12 14:09:38 -050035 export_include_dirs: [
36 $export_includes
37 ],
Mike Klein27eb22b2016-12-07 12:27:56 -050038
Mike Kleinee43f6f2016-12-12 14:09:38 -050039 local_include_dirs: [
40 $local_includes
41 ],
Mike Klein27eb22b2016-12-07 12:27:56 -050042
Mike Kleinee43f6f2016-12-12 14:09:38 -050043 srcs: [
44 $srcs
45 ],
Mike Klein308b5ac2016-12-06 16:03:52 -050046
Mike Kleinee43f6f2016-12-12 14:09:38 -050047 arch: {
48 arm: {
49 srcs: [
50 $arm_srcs
51 ],
Mike Klein27eb22b2016-12-07 12:27:56 -050052
Leon Scroggins IIIf7332d32017-08-10 09:09:54 -040053 neon: {
Mike Kleinee43f6f2016-12-12 14:09:38 -050054 srcs: [
55 $arm_neon_srcs
56 ],
57 },
58 },
59
60 arm64: {
61 srcs: [
62 $arm64_srcs
63 ],
64 },
65
Mike Kleinee43f6f2016-12-12 14:09:38 -050066 x86: {
67 srcs: [
68 $x86_srcs
69 ],
70 },
71
72 x86_64: {
73 srcs: [
74 $x86_srcs
75 ],
76 },
Mike Klein308b5ac2016-12-06 16:03:52 -050077 },
Mike Klein27eb22b2016-12-07 12:27:56 -050078
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -050079 target: {
80 android: {
81 srcs: [
82 $android_srcs
83 "third_party/vulkanmemoryallocator/GrVulkanMemoryAllocator.cpp",
84 ],
85 local_include_dirs: [
Mike Kleinc0bd9f92019-04-23 12:05:21 -050086 "android",
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -050087 "third_party/vulkanmemoryallocator/",
88 ],
89 export_include_dirs: [
Mike Kleinc0bd9f92019-04-23 12:05:21 -050090 "android",
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -050091 ],
92 },
93 linux_glibc: {
94 cflags: [
95 "-mssse3",
96 ],
97 srcs: [
98 $linux_srcs
99 ],
100 local_include_dirs: [
Mike Kleinc0bd9f92019-04-23 12:05:21 -0500101 "linux",
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500102 ],
103 export_include_dirs: [
Mike Kleinc0bd9f92019-04-23 12:05:21 -0500104 "linux",
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500105 ],
106 },
Leon Scroggins III85e22fc2018-11-28 08:58:47 -0500107 darwin: {
108 cflags: [
109 "-mssse3",
110 ],
111 srcs: [
112 $mac_srcs
113 ],
114 local_include_dirs: [
Mike Kleinc0bd9f92019-04-23 12:05:21 -0500115 "mac",
Leon Scroggins III85e22fc2018-11-28 08:58:47 -0500116 ],
117 export_include_dirs: [
Mike Kleinc0bd9f92019-04-23 12:05:21 -0500118 "mac",
Leon Scroggins III85e22fc2018-11-28 08:58:47 -0500119 ],
120 },
Leon Scroggins IIIee0e5d02019-02-27 10:59:11 -0500121 windows: {
122 cflags: [
123 "-mssse3",
124 "-Wno-unknown-pragmas",
125 ],
126 srcs: [
127 $win_srcs
128 ],
129 local_include_dirs: [
Mike Kleinc0bd9f92019-04-23 12:05:21 -0500130 "win",
Leon Scroggins IIIee0e5d02019-02-27 10:59:11 -0500131 ],
132 export_include_dirs: [
Mike Kleinc0bd9f92019-04-23 12:05:21 -0500133 "win",
Leon Scroggins IIIee0e5d02019-02-27 10:59:11 -0500134 ],
135 },
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500136 },
137
Zhizhou Yange18b7792017-12-11 10:37:44 -0800138 defaults: ["skia_deps",
139 "skia_pgo",
140 ],
141}
142
143// Build libskia with PGO by default.
144// Location of PGO profile data is defined in build/soong/cc/pgo.go
145// and is separate from skia.
146// To turn it off, set ANDROID_PGO_NO_PROFILE_USE environment variable
147// or set enable_profile_use property to false.
148cc_defaults {
149 name: "skia_pgo",
150 pgo: {
151 instrumentation: true,
Pirama Arumuga Nainar068ccaa2018-03-05 10:20:38 -0800152 profile_file: "hwui/hwui.profdata",
Zhizhou Yange18b7792017-12-11 10:37:44 -0800153 benchmarks: ["hwui", "skia"],
Pirama Arumuga Nainar068ccaa2018-03-05 10:20:38 -0800154 enable_profile_use: true,
Zhizhou Yange18b7792017-12-11 10:37:44 -0800155 },
Derek Sollenberger5a932162017-09-21 14:25:14 -0400156}
157
Pirama Arumuga Nainarde2b95e2017-12-13 11:07:39 -0800158// "defaults" property to disable profile use for Skia tools and benchmarks.
159cc_defaults {
160 name: "skia_pgo_no_profile_use",
161 defaults: [
162 "skia_pgo",
163 ],
164 pgo: {
165 enable_profile_use: false,
166 },
167}
168
Derek Sollenberger5a932162017-09-21 14:25:14 -0400169cc_defaults {
170 name: "skia_deps",
Mike Kleinee43f6f2016-12-12 14:09:38 -0500171 shared_libs: [
Mike Kleinee43f6f2016-12-12 14:09:38 -0500172 "libdng_sdk",
173 "libexpat",
174 "libft2",
Mike Kleinee43f6f2016-12-12 14:09:38 -0500175 "libjpeg",
176 "liblog",
177 "libpiex",
178 "libpng",
Mike Kleinee43f6f2016-12-12 14:09:38 -0500179 "libz",
180 ],
181 static_libs: [
Matt Saretta3091092017-02-20 12:50:52 -0500182 "libarect",
Mike Kleinee43f6f2016-12-12 14:09:38 -0500183 "libsfntly",
184 "libwebp-decode",
185 "libwebp-encode",
186 ],
Derek Sollenberger5a932162017-09-21 14:25:14 -0400187 group_static_libs: true,
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500188 target: {
189 android: {
190 shared_libs: [
Leon Scroggins IIIee0e5d02019-02-27 10:59:11 -0500191 "libcutils",
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500192 "libEGL",
193 "libGLESv2",
194 "libheif",
195 "libvulkan",
196 "libnativewindow",
197 ],
Stan Iliev12b89162019-03-11 13:33:02 -0400198 export_shared_lib_headers: [
199 "libvulkan",
200 ],
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500201 },
Leon Scroggins IIIee0e5d02019-02-27 10:59:11 -0500202 host: {
203 static_libs: [
204 "libcutils",
205 ],
206 },
Leon Scroggins III85e22fc2018-11-28 08:58:47 -0500207 darwin: {
208 host_ldlibs: [
209 "-framework AppKit",
210 ],
211 },
Leon Scroggins IIIee0e5d02019-02-27 10:59:11 -0500212 windows: {
Leon Scroggins IIIa09d2322020-02-14 16:07:56 -0500213 enabled: true,
Leon Scroggins IIIee0e5d02019-02-27 10:59:11 -0500214 host_ldlibs: [
215 "-lgdi32",
216 "-loleaut32",
217 "-lole32",
218 "-lopengl32",
219 "-luuid",
220 "-lwindowscodecs",
221 ],
222 },
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500223 },
Derek Sollenberger5a932162017-09-21 14:25:14 -0400224}
225
226cc_defaults {
227 name: "skia_tool_deps",
228 defaults: [
Pirama Arumuga Nainarde2b95e2017-12-13 11:07:39 -0800229 "skia_deps",
230 "skia_pgo_no_profile_use"
Derek Sollenberger5a932162017-09-21 14:25:14 -0400231 ],
Mike Reed579c2952020-05-27 16:49:23 -0400232 shared_libs: [
233 "libandroidicu",
234 "libharfbuzz_ng",
235 ],
Derek Sollenberger5a932162017-09-21 14:25:14 -0400236 static_libs: [
Derek Sollenberger5a932162017-09-21 14:25:14 -0400237 "libskia",
238 ],
239 cflags: [
Mike Reed579c2952020-05-27 16:49:23 -0400240 "-DSK_SHAPER_HARFBUZZ_AVAILABLE",
Derek Sollenberger1821a5b2018-09-11 14:48:36 -0400241 "-Wno-implicit-fallthrough",
Derek Sollenberger9a72ae12017-12-14 13:01:30 -0500242 "-Wno-unused-parameter",
243 "-Wno-unused-variable",
Derek Sollenberger5a932162017-09-21 14:25:14 -0400244 ],
Leon Scroggins III6ccd2ca2017-01-26 17:21:27 -0500245}
246
247cc_test {
248 name: "skia_dm",
249
Derek Sollenberger5a932162017-09-21 14:25:14 -0400250 defaults: [
251 "skia_tool_deps"
Leon Scroggins III6ccd2ca2017-01-26 17:21:27 -0500252 ],
253
254 local_include_dirs: [
255 $dm_includes
256 ],
257
258 srcs: [
259 $dm_srcs
260 ],
Dongwon Kang0c7861f2018-02-16 10:55:21 -0800261
262 shared_libs: [
263 "libbinder",
264 "libutils",
265 ],
Leon Scroggins III6ccd2ca2017-01-26 17:21:27 -0500266}
267
268cc_test {
269 name: "skia_nanobench",
270
Derek Sollenberger5a932162017-09-21 14:25:14 -0400271 defaults: [
272 "skia_tool_deps"
Leon Scroggins III6ccd2ca2017-01-26 17:21:27 -0500273 ],
274
275 local_include_dirs: [
276 $nanobench_includes
277 ],
278
279 srcs: [
280 $nanobench_srcs
281 ],
Pirama Arumuga Nainar68c3fac2018-01-09 21:05:55 -0800282
283 data: [
Pirama Arumuga Nainar5be3c132019-09-30 17:18:02 -0700284 "resources/**/*",
Pirama Arumuga Nainar68c3fac2018-01-09 21:05:55 -0800285 ],
Mike Kleinee43f6f2016-12-12 14:09:38 -0500286}''')
Mike Klein308b5ac2016-12-06 16:03:52 -0500287
288# We'll run GN to get the main source lists and include directories for Skia.
Leon Scroggins IIIa55445e2018-11-28 16:09:35 -0500289def generate_args(target_os, enable_gpu):
290 d = {
Ben Wagner75626e42020-06-03 13:20:37 -0400291 'is_official_build': 'true',
Mike Klein308b5ac2016-12-06 16:03:52 -0500292
Leon Scroggins IIIa55445e2018-11-28 16:09:35 -0500293 # gn_to_bp_utils' GetArchSources will take care of architecture-specific
294 # files.
Ben Wagner75626e42020-06-03 13:20:37 -0400295 'target_cpu': '"none"',
Hal Canary23564b92018-09-07 14:33:14 -0400296
Ben Wagner75626e42020-06-03 13:20:37 -0400297 'skia_enable_android_utils': 'true',
Leon Scroggins IIIa55445e2018-11-28 16:09:35 -0500298 # Use the custom FontMgr, as the framework will handle fonts.
Ben Wagner75626e42020-06-03 13:20:37 -0400299 'skia_enable_fontmgr_custom_directory': 'false',
300 'skia_enable_fontmgr_custom_embedded': 'false',
301 'skia_enable_fontmgr_custom_empty': 'true',
302 'skia_enable_fontmgr_android': 'false',
303 'skia_enable_fontmgr_win': 'false',
304 'skia_enable_fontmgr_win_gdi': 'false',
305 'skia_use_fonthost_mac': 'false',
Leon Scroggins IIIa55445e2018-11-28 16:09:35 -0500306
Nathaniel Nifong60c37e72019-10-16 11:21:47 -0400307 # enable features used in skia_nanobench
Ben Wagner75626e42020-06-03 13:20:37 -0400308 'skia_enable_sksl_interpreter': 'true',
309 'skia_tools_require_resources': 'true',
Nathaniel Nifong60c37e72019-10-16 11:21:47 -0400310
Ben Wagner75626e42020-06-03 13:20:37 -0400311 'skia_use_freetype': 'true',
312 'skia_use_fontconfig': 'false',
313 'skia_use_fixed_gamma_text': 'true',
314 'skia_include_multiframe_procs': 'false',
315 'skia_libgifcodec_path': '"third_party/libgifcodec"',
Leon Scroggins IIIa55445e2018-11-28 16:09:35 -0500316 }
317 d['target_os'] = target_os
318 if target_os == '"android"':
319 d['skia_enable_tools'] = 'true'
320 d['skia_use_libheif'] = 'true'
Nathaniel Nifong0c4fbf12019-06-25 15:48:47 -0400321 d['skia_include_multiframe_procs'] = 'true'
Leon Scroggins IIIa55445e2018-11-28 16:09:35 -0500322 else:
323 d['skia_use_libheif'] = 'false'
324
325 if enable_gpu:
326 d['skia_use_vulkan'] = 'true'
327 else:
328 d['skia_use_vulkan'] = 'false'
329 d['skia_enable_gpu'] = 'false'
Leon Scroggins IIIee0e5d02019-02-27 10:59:11 -0500330
331 if target_os == '"win"':
332 # The Android Windows build system does not provide FontSub.h
333 d['skia_use_xps'] = 'false'
334
335 # BUILDCONFIG.gn expects these to be set when building for Windows, but
336 # we're just creating Android.bp, so we don't need them. Populate with
337 # some dummy values.
338 d['win_vc'] = '"dummy_version"'
339 d['win_sdk_version'] = '"dummy_version"'
Hal Canaryf72728e2019-07-10 11:24:52 -0400340 d['win_toolchain_version'] = '"dummy_version"'
Leon Scroggins IIIa55445e2018-11-28 16:09:35 -0500341 return d
342
343gn_args = generate_args('"android"', True)
344gn_args_linux = generate_args('"linux"', False)
345gn_args_mac = generate_args('"mac"', False)
Leon Scroggins IIIee0e5d02019-02-27 10:59:11 -0500346gn_args_win = generate_args('"win"', False)
Leon Scroggins III85e22fc2018-11-28 08:58:47 -0500347
Derek Sollenberger5d3f7702018-02-01 09:22:53 -0500348js = gn_to_bp_utils.GenerateJSONFromGN(gn_args)
Mike Klein308b5ac2016-12-06 16:03:52 -0500349
350def strip_slashes(lst):
Ben Wagnere1275232017-02-23 18:00:06 -0500351 return {str(p.lstrip('/')) for p in lst}
Mike Klein27eb22b2016-12-07 12:27:56 -0500352
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500353android_srcs = strip_slashes(js['targets']['//:skia']['sources'])
Leon Scroggins III981a31e2017-10-06 11:53:53 -0400354cflags = strip_slashes(js['targets']['//:skia']['cflags'])
355cflags_cc = strip_slashes(js['targets']['//:skia']['cflags_cc'])
Mike Klein308b5ac2016-12-06 16:03:52 -0500356local_includes = strip_slashes(js['targets']['//:skia']['include_dirs'])
357export_includes = strip_slashes(js['targets']['//:public']['include_dirs'])
358
Leon Scroggins III6ccd2ca2017-01-26 17:21:27 -0500359dm_srcs = strip_slashes(js['targets']['//:dm']['sources'])
360dm_includes = strip_slashes(js['targets']['//:dm']['include_dirs'])
361
362nanobench_target = js['targets']['//:nanobench']
363nanobench_srcs = strip_slashes(nanobench_target['sources'])
364nanobench_includes = strip_slashes(nanobench_target['include_dirs'])
365
Derek Sollenberger5d3f7702018-02-01 09:22:53 -0500366gn_to_bp_utils.GrabDependentValues(js, '//:dm', 'sources', dm_srcs, 'skia')
367gn_to_bp_utils.GrabDependentValues(js, '//:nanobench', 'sources',
368 nanobench_srcs, 'skia')
Mike Klein27eb22b2016-12-07 12:27:56 -0500369
Mike Kleinf536c452018-05-01 10:36:42 -0400370# skcms is a little special, kind of a second-party library.
Brian Osman35ea04d2019-05-01 11:03:36 -0400371local_includes.add("include/third_party/skcms")
372dm_includes .add("include/third_party/skcms")
Mike Kleinf536c452018-05-01 10:36:42 -0400373
Mike Kleind505b192018-09-05 15:55:25 -0400374# Android's build will choke if we list headers.
375def strip_headers(sources):
376 return {s for s in sources if not s.endswith('.h')}
377
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500378gn_to_bp_utils.GrabDependentValues(js, '//:skia', 'sources', android_srcs, None)
379android_srcs = strip_headers(android_srcs)
380
381js_linux = gn_to_bp_utils.GenerateJSONFromGN(gn_args_linux)
382linux_srcs = strip_slashes(js_linux['targets']['//:skia']['sources'])
383gn_to_bp_utils.GrabDependentValues(js_linux, '//:skia', 'sources', linux_srcs,
384 None)
385linux_srcs = strip_headers(linux_srcs)
386
Leon Scroggins III85e22fc2018-11-28 08:58:47 -0500387js_mac = gn_to_bp_utils.GenerateJSONFromGN(gn_args_mac)
388mac_srcs = strip_slashes(js_mac['targets']['//:skia']['sources'])
389gn_to_bp_utils.GrabDependentValues(js_mac, '//:skia', 'sources', mac_srcs,
390 None)
391mac_srcs = strip_headers(mac_srcs)
392
Leon Scroggins IIIee0e5d02019-02-27 10:59:11 -0500393js_win = gn_to_bp_utils.GenerateJSONFromGN(gn_args_win)
394win_srcs = strip_slashes(js_win['targets']['//:skia']['sources'])
395gn_to_bp_utils.GrabDependentValues(js_win, '//:skia', 'sources', win_srcs,
396 None)
397win_srcs = strip_headers(win_srcs)
398
Leon Scroggins III85e22fc2018-11-28 08:58:47 -0500399srcs = android_srcs.intersection(linux_srcs).intersection(mac_srcs)
Leon Scroggins IIIee0e5d02019-02-27 10:59:11 -0500400srcs = srcs.intersection(win_srcs)
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500401android_srcs = android_srcs.difference(srcs)
402linux_srcs = linux_srcs.difference(srcs)
Leon Scroggins IIIee0e5d02019-02-27 10:59:11 -0500403mac_srcs = mac_srcs.difference(srcs)
404win_srcs = win_srcs.difference(srcs)
Mike Kleind505b192018-09-05 15:55:25 -0400405dm_srcs = strip_headers(dm_srcs)
406nanobench_srcs = strip_headers(nanobench_srcs)
Mike Klein27eb22b2016-12-07 12:27:56 -0500407
Derek Sollenberger5d3f7702018-02-01 09:22:53 -0500408cflags = gn_to_bp_utils.CleanupCFlags(cflags)
409cflags_cc = gn_to_bp_utils.CleanupCCFlags(cflags_cc)
Leon Scroggins III981a31e2017-10-06 11:53:53 -0400410
Leon Scroggins III4f8a4672016-12-19 09:32:21 -0500411here = os.path.dirname(__file__)
Derek Sollenberger5d3f7702018-02-01 09:22:53 -0500412defs = gn_to_bp_utils.GetArchSources(os.path.join(here, 'opts.gni'))
Mike Klein308b5ac2016-12-06 16:03:52 -0500413
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500414def get_defines(json):
415 return {str(d) for d in json['targets']['//:skia']['defines']}
416android_defines = get_defines(js)
417linux_defines = get_defines(js_linux)
Leon Scroggins III85e22fc2018-11-28 08:58:47 -0500418mac_defines = get_defines(js_mac)
Leon Scroggins IIIee0e5d02019-02-27 10:59:11 -0500419win_defines = get_defines(js_win)
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500420
421def mkdir_if_not_exists(path):
422 if not os.path.exists(path):
Mike Kleinc0bd9f92019-04-23 12:05:21 -0500423 os.makedirs(path)
424mkdir_if_not_exists('android/include/config/')
425mkdir_if_not_exists('linux/include/config/')
426mkdir_if_not_exists('mac/include/config/')
427mkdir_if_not_exists('win/include/config/')
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500428
429platforms = { 'IOS', 'MAC', 'WIN', 'ANDROID', 'UNIX' }
430
431def disallow_platforms(config, desired):
432 with open(config, 'a') as f:
433 p = sorted(platforms.difference({ desired }))
434 s = '#if '
435 for i in range(len(p)):
436 s = s + 'defined(SK_BUILD_FOR_%s)' % p[i]
437 if i < len(p) - 1:
438 s += ' || '
439 if i % 2 == 1:
440 s += '\\\n '
Martin Vejdarskibeaaf472020-03-03 13:53:20 +0700441 print(s, file=f)
442 print(' #error "Only SK_BUILD_FOR_%s should be defined!"' % desired, file=f)
443 print('#endif', file=f)
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500444
445def append_to_file(config, s):
446 with open(config, 'a') as f:
Martin Vejdarskibeaaf472020-03-03 13:53:20 +0700447 print(s, file=f)
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500448
Mike Kleinc0bd9f92019-04-23 12:05:21 -0500449android_config = 'android/include/config/SkUserConfig.h'
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500450gn_to_bp_utils.WriteUserConfig(android_config, android_defines)
451append_to_file(android_config, '''
452#ifndef SK_BUILD_FOR_ANDROID
453 #error "SK_BUILD_FOR_ANDROID must be defined!"
454#endif''')
455disallow_platforms(android_config, 'ANDROID')
456
Leon Scroggins III85e22fc2018-11-28 08:58:47 -0500457def write_config(config_path, defines, platform):
458 gn_to_bp_utils.WriteUserConfig(config_path, defines)
459 append_to_file(config_path, '''
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500460// Correct SK_BUILD_FOR flags that may have been set by
Mike Klein81d35a72020-02-05 10:17:57 -0600461// SkTypes.h/Android.bp
Leon Scroggins III85e22fc2018-11-28 08:58:47 -0500462#ifndef SK_BUILD_FOR_%s
463 #define SK_BUILD_FOR_%s
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500464#endif
465#ifdef SK_BUILD_FOR_ANDROID
466 #undef SK_BUILD_FOR_ANDROID
Leon Scroggins III85e22fc2018-11-28 08:58:47 -0500467#endif''' % (platform, platform))
468 disallow_platforms(config_path, platform)
469
Mike Kleinc0bd9f92019-04-23 12:05:21 -0500470write_config('linux/include/config/SkUserConfig.h', linux_defines, 'UNIX')
471write_config('mac/include/config/SkUserConfig.h', mac_defines, 'MAC')
472write_config('win/include/config/SkUserConfig.h', win_defines, 'WIN')
Mike Klein308b5ac2016-12-06 16:03:52 -0500473
Mike Kleinee43f6f2016-12-12 14:09:38 -0500474# Turn a list of strings into the style bpfmt outputs.
Leon Scroggins III6ccd2ca2017-01-26 17:21:27 -0500475def bpfmt(indent, lst, sort=True):
476 if sort:
477 lst = sorted(lst)
478 return ('\n' + ' '*indent).join('"%s",' % v for v in lst)
Mike Klein308b5ac2016-12-06 16:03:52 -0500479
480# OK! We have everything to fill in Android.bp...
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500481with open('Android.bp', 'w') as Android_bp:
Martin Vejdarskibeaaf472020-03-03 13:53:20 +0700482 print(bp.substitute({
Mike Kleinee43f6f2016-12-12 14:09:38 -0500483 'export_includes': bpfmt(8, export_includes),
484 'local_includes': bpfmt(8, local_includes),
485 'srcs': bpfmt(8, srcs),
Leon Scroggins III981a31e2017-10-06 11:53:53 -0400486 'cflags': bpfmt(8, cflags, False),
487 'cflags_cc': bpfmt(8, cflags_cc),
Mike Klein308b5ac2016-12-06 16:03:52 -0500488
Mike Kleind505b192018-09-05 15:55:25 -0400489 'arm_srcs': bpfmt(16, strip_headers(defs['armv7'])),
490 'arm_neon_srcs': bpfmt(20, strip_headers(defs['neon'])),
491 'arm64_srcs': bpfmt(16, strip_headers(defs['arm64'] +
492 defs['crc32'])),
Mike Kleind505b192018-09-05 15:55:25 -0400493 'x86_srcs': bpfmt(16, strip_headers(defs['sse2'] +
494 defs['ssse3'] +
495 defs['sse41'] +
496 defs['sse42'] +
497 defs['avx' ] +
Mike Kleinad56c4c2020-06-05 06:57:30 -0500498 defs['hsw' ] +
499 defs['skx' ])),
Leon Scroggins III6ccd2ca2017-01-26 17:21:27 -0500500
Leon Scroggins III6ccd2ca2017-01-26 17:21:27 -0500501 'dm_includes' : bpfmt(8, dm_includes),
502 'dm_srcs' : bpfmt(8, dm_srcs),
503
504 'nanobench_includes' : bpfmt(8, nanobench_includes),
505 'nanobench_srcs' : bpfmt(8, nanobench_srcs),
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500506
507 'android_srcs': bpfmt(10, android_srcs),
508 'linux_srcs': bpfmt(10, linux_srcs),
Leon Scroggins III85e22fc2018-11-28 08:58:47 -0500509 'mac_srcs': bpfmt(10, mac_srcs),
Leon Scroggins IIIee0e5d02019-02-27 10:59:11 -0500510 'win_srcs': bpfmt(10, win_srcs),
Martin Vejdarskibeaaf472020-03-03 13:53:20 +0700511 }), file=Android_bp)