blob: 244335879aef838955b7d97f5c36eedc7126fb7c [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
Mike Klein308b5ac2016-12-06 16:03:52 -050010import os
11import pprint
12import string
13import subprocess
Mike Klein308b5ac2016-12-06 16:03:52 -050014import tempfile
15
Derek Sollenberger5d3f7702018-02-01 09:22:53 -050016import gn_to_bp_utils
17
Mike Klein308b5ac2016-12-06 16:03:52 -050018# First we start off with a template for Android.bp,
19# with holes for source lists and include directories.
20bp = string.Template('''// This file is autogenerated by gn_to_bp.py.
21
Derek Sollenberger5a932162017-09-21 14:25:14 -040022cc_library_static {
Mike Kleinee43f6f2016-12-12 14:09:38 -050023 name: "libskia",
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -050024 host_supported: true,
Mike Kleinee43f6f2016-12-12 14:09:38 -050025 cflags: [
Leon Scroggins III981a31e2017-10-06 11:53:53 -040026 $cflags
27 ],
28
29 cppflags:[
30 $cflags_cc
Mike Kleinee43f6f2016-12-12 14:09:38 -050031 ],
Mike Klein308b5ac2016-12-06 16:03:52 -050032
Mike Kleinee43f6f2016-12-12 14:09:38 -050033 export_include_dirs: [
34 $export_includes
35 ],
Mike Klein27eb22b2016-12-07 12:27:56 -050036
Mike Kleinee43f6f2016-12-12 14:09:38 -050037 local_include_dirs: [
38 $local_includes
39 ],
Mike Klein27eb22b2016-12-07 12:27:56 -050040
Mike Kleinee43f6f2016-12-12 14:09:38 -050041 srcs: [
42 $srcs
43 ],
Mike Klein308b5ac2016-12-06 16:03:52 -050044
Mike Kleinee43f6f2016-12-12 14:09:38 -050045 arch: {
46 arm: {
47 srcs: [
48 $arm_srcs
49 ],
Mike Klein27eb22b2016-12-07 12:27:56 -050050
Leon Scroggins IIIf7332d32017-08-10 09:09:54 -040051 neon: {
Mike Kleinee43f6f2016-12-12 14:09:38 -050052 srcs: [
53 $arm_neon_srcs
54 ],
55 },
56 },
57
58 arm64: {
59 srcs: [
60 $arm64_srcs
61 ],
62 },
63
64 mips: {
65 srcs: [
Mike Klein40a82bd2016-12-20 17:34:29 -050066 $none_srcs
Mike Kleinee43f6f2016-12-12 14:09:38 -050067 ],
68 },
69
70 mips64: {
71 srcs: [
Mike Klein40a82bd2016-12-20 17:34:29 -050072 $none_srcs
Mike Kleinee43f6f2016-12-12 14:09:38 -050073 ],
74 },
75
76 x86: {
77 srcs: [
78 $x86_srcs
79 ],
80 },
81
82 x86_64: {
83 srcs: [
84 $x86_srcs
85 ],
86 },
Mike Klein308b5ac2016-12-06 16:03:52 -050087 },
Mike Klein27eb22b2016-12-07 12:27:56 -050088
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -050089 target: {
90 android: {
91 srcs: [
92 $android_srcs
93 "third_party/vulkanmemoryallocator/GrVulkanMemoryAllocator.cpp",
94 ],
95 local_include_dirs: [
Mike Kleinc0bd9f92019-04-23 12:05:21 -050096 "android",
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -050097 "third_party/vulkanmemoryallocator/",
98 ],
99 export_include_dirs: [
Mike Kleinc0bd9f92019-04-23 12:05:21 -0500100 "android",
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500101 ],
102 },
103 linux_glibc: {
104 cflags: [
105 "-mssse3",
106 ],
107 srcs: [
108 $linux_srcs
109 ],
110 local_include_dirs: [
Mike Kleinc0bd9f92019-04-23 12:05:21 -0500111 "linux",
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500112 ],
113 export_include_dirs: [
Mike Kleinc0bd9f92019-04-23 12:05:21 -0500114 "linux",
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500115 ],
116 },
Leon Scroggins III85e22fc2018-11-28 08:58:47 -0500117 darwin: {
118 cflags: [
119 "-mssse3",
120 ],
121 srcs: [
122 $mac_srcs
123 ],
124 local_include_dirs: [
Mike Kleinc0bd9f92019-04-23 12:05:21 -0500125 "mac",
Leon Scroggins III85e22fc2018-11-28 08:58:47 -0500126 ],
127 export_include_dirs: [
Mike Kleinc0bd9f92019-04-23 12:05:21 -0500128 "mac",
Leon Scroggins III85e22fc2018-11-28 08:58:47 -0500129 ],
130 },
Leon Scroggins IIIee0e5d02019-02-27 10:59:11 -0500131 windows: {
132 cflags: [
133 "-mssse3",
134 "-Wno-unknown-pragmas",
135 ],
136 srcs: [
137 $win_srcs
138 ],
139 local_include_dirs: [
Mike Kleinc0bd9f92019-04-23 12:05:21 -0500140 "win",
Leon Scroggins IIIee0e5d02019-02-27 10:59:11 -0500141 ],
142 export_include_dirs: [
Mike Kleinc0bd9f92019-04-23 12:05:21 -0500143 "win",
Leon Scroggins IIIee0e5d02019-02-27 10:59:11 -0500144 ],
145 },
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500146 },
147
Zhizhou Yange18b7792017-12-11 10:37:44 -0800148 defaults: ["skia_deps",
149 "skia_pgo",
150 ],
151}
152
153// Build libskia with PGO by default.
154// Location of PGO profile data is defined in build/soong/cc/pgo.go
155// and is separate from skia.
156// To turn it off, set ANDROID_PGO_NO_PROFILE_USE environment variable
157// or set enable_profile_use property to false.
158cc_defaults {
159 name: "skia_pgo",
160 pgo: {
161 instrumentation: true,
Pirama Arumuga Nainar068ccaa2018-03-05 10:20:38 -0800162 profile_file: "hwui/hwui.profdata",
Zhizhou Yange18b7792017-12-11 10:37:44 -0800163 benchmarks: ["hwui", "skia"],
Pirama Arumuga Nainar068ccaa2018-03-05 10:20:38 -0800164 enable_profile_use: true,
Zhizhou Yange18b7792017-12-11 10:37:44 -0800165 },
Derek Sollenberger5a932162017-09-21 14:25:14 -0400166}
167
Pirama Arumuga Nainarde2b95e2017-12-13 11:07:39 -0800168// "defaults" property to disable profile use for Skia tools and benchmarks.
169cc_defaults {
170 name: "skia_pgo_no_profile_use",
171 defaults: [
172 "skia_pgo",
173 ],
174 pgo: {
175 enable_profile_use: false,
176 },
177}
178
Derek Sollenberger5a932162017-09-21 14:25:14 -0400179cc_defaults {
180 name: "skia_deps",
Mike Kleinee43f6f2016-12-12 14:09:38 -0500181 shared_libs: [
Derek Sollenberger3de76842019-01-08 13:36:38 -0500182 "libandroidicu",
Mike Kleinee43f6f2016-12-12 14:09:38 -0500183 "libdng_sdk",
184 "libexpat",
185 "libft2",
Mike Kleinee43f6f2016-12-12 14:09:38 -0500186 "libjpeg",
187 "liblog",
188 "libpiex",
189 "libpng",
Mike Kleinee43f6f2016-12-12 14:09:38 -0500190 "libz",
191 ],
192 static_libs: [
Matt Saretta3091092017-02-20 12:50:52 -0500193 "libarect",
Mike Kleinee43f6f2016-12-12 14:09:38 -0500194 "libsfntly",
195 "libwebp-decode",
196 "libwebp-encode",
197 ],
Derek Sollenberger5a932162017-09-21 14:25:14 -0400198 group_static_libs: true,
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500199 target: {
200 android: {
201 shared_libs: [
Leon Scroggins IIIee0e5d02019-02-27 10:59:11 -0500202 "libcutils",
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500203 "libEGL",
204 "libGLESv2",
205 "libheif",
206 "libvulkan",
207 "libnativewindow",
208 ],
Stan Iliev12b89162019-03-11 13:33:02 -0400209 export_shared_lib_headers: [
210 "libvulkan",
211 ],
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500212 },
Leon Scroggins IIIee0e5d02019-02-27 10:59:11 -0500213 host: {
214 static_libs: [
215 "libcutils",
216 ],
217 },
Leon Scroggins III85e22fc2018-11-28 08:58:47 -0500218 darwin: {
219 host_ldlibs: [
220 "-framework AppKit",
221 ],
222 },
Leon Scroggins IIIee0e5d02019-02-27 10:59:11 -0500223 windows: {
Yi Kong003334c2019-03-18 03:39:12 -0700224 // clang-r353983 emits error when building Skia for Windows. Do not
225 // build it for now until the compiler issue is addressed.
226 // enabled: true,
Leon Scroggins IIIee0e5d02019-02-27 10:59:11 -0500227 host_ldlibs: [
228 "-lgdi32",
229 "-loleaut32",
230 "-lole32",
231 "-lopengl32",
232 "-luuid",
233 "-lwindowscodecs",
234 ],
235 },
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500236 },
Derek Sollenberger5a932162017-09-21 14:25:14 -0400237}
238
239cc_defaults {
240 name: "skia_tool_deps",
241 defaults: [
Pirama Arumuga Nainarde2b95e2017-12-13 11:07:39 -0800242 "skia_deps",
243 "skia_pgo_no_profile_use"
Derek Sollenberger5a932162017-09-21 14:25:14 -0400244 ],
245 static_libs: [
Derek Sollenberger5a932162017-09-21 14:25:14 -0400246 "libskia",
247 ],
248 cflags: [
Derek Sollenberger1821a5b2018-09-11 14:48:36 -0400249 "-Wno-implicit-fallthrough",
Derek Sollenberger9a72ae12017-12-14 13:01:30 -0500250 "-Wno-unused-parameter",
251 "-Wno-unused-variable",
Derek Sollenberger5a932162017-09-21 14:25:14 -0400252 ],
Leon Scroggins III6ccd2ca2017-01-26 17:21:27 -0500253}
254
255cc_test {
256 name: "skia_dm",
257
Derek Sollenberger5a932162017-09-21 14:25:14 -0400258 defaults: [
259 "skia_tool_deps"
Leon Scroggins III6ccd2ca2017-01-26 17:21:27 -0500260 ],
261
262 local_include_dirs: [
263 $dm_includes
264 ],
265
266 srcs: [
267 $dm_srcs
268 ],
Dongwon Kang0c7861f2018-02-16 10:55:21 -0800269
270 shared_libs: [
271 "libbinder",
272 "libutils",
273 ],
Leon Scroggins III6ccd2ca2017-01-26 17:21:27 -0500274}
275
276cc_test {
277 name: "skia_nanobench",
278
Derek Sollenberger5a932162017-09-21 14:25:14 -0400279 defaults: [
280 "skia_tool_deps"
Leon Scroggins III6ccd2ca2017-01-26 17:21:27 -0500281 ],
282
283 local_include_dirs: [
284 $nanobench_includes
285 ],
286
287 srcs: [
288 $nanobench_srcs
289 ],
Pirama Arumuga Nainar68c3fac2018-01-09 21:05:55 -0800290
291 data: [
Pirama Arumuga Nainar5be3c132019-09-30 17:18:02 -0700292 "resources/**/*",
Pirama Arumuga Nainar68c3fac2018-01-09 21:05:55 -0800293 ],
Mike Kleinee43f6f2016-12-12 14:09:38 -0500294}''')
Mike Klein308b5ac2016-12-06 16:03:52 -0500295
296# We'll run GN to get the main source lists and include directories for Skia.
Leon Scroggins IIIa55445e2018-11-28 16:09:35 -0500297def generate_args(target_os, enable_gpu):
298 d = {
299 'is_official_build': 'true',
Mike Klein308b5ac2016-12-06 16:03:52 -0500300
Leon Scroggins IIIa55445e2018-11-28 16:09:35 -0500301 # gn_to_bp_utils' GetArchSources will take care of architecture-specific
302 # files.
303 'target_cpu': '"none"',
Hal Canary23564b92018-09-07 14:33:14 -0400304
Leon Scroggins IIIa55445e2018-11-28 16:09:35 -0500305 # Use the custom FontMgr, as the framework will handle fonts.
306 'skia_enable_fontmgr_custom': 'false',
307 'skia_enable_fontmgr_custom_empty': 'true',
308 'skia_enable_fontmgr_android': 'false',
Leon Scroggins III631dbc82019-03-04 13:54:02 -0500309 'skia_enable_fontmgr_win': 'false',
310 'skia_enable_fontmgr_win_gdi': 'false',
Leon Scroggins IIIa55445e2018-11-28 16:09:35 -0500311 'skia_use_fonthost_mac': 'false',
312
Nathaniel Nifong60c37e72019-10-16 11:21:47 -0400313 # enable features used in skia_nanobench
314 'skia_enable_sksl_interpreter': 'true',
315 'skia_tools_require_resources': 'true',
316
Leon Scroggins IIIa55445e2018-11-28 16:09:35 -0500317 'skia_use_freetype': 'true',
318 'skia_use_fontconfig': 'false',
319 'skia_use_fixed_gamma_text': 'true',
Nathaniel Nifong0c4fbf12019-06-25 15:48:47 -0400320 'skia_include_multiframe_procs': 'false',
Leon Scroggins IIIa55445e2018-11-28 16:09:35 -0500321 }
322 d['target_os'] = target_os
323 if target_os == '"android"':
324 d['skia_enable_tools'] = 'true'
325 d['skia_use_libheif'] = 'true'
Nathaniel Nifong0c4fbf12019-06-25 15:48:47 -0400326 d['skia_include_multiframe_procs'] = 'true'
Leon Scroggins IIIa55445e2018-11-28 16:09:35 -0500327 else:
328 d['skia_use_libheif'] = 'false'
329
330 if enable_gpu:
331 d['skia_use_vulkan'] = 'true'
332 else:
333 d['skia_use_vulkan'] = 'false'
334 d['skia_enable_gpu'] = 'false'
Leon Scroggins IIIee0e5d02019-02-27 10:59:11 -0500335
336 if target_os == '"win"':
337 # The Android Windows build system does not provide FontSub.h
338 d['skia_use_xps'] = 'false'
339
340 # BUILDCONFIG.gn expects these to be set when building for Windows, but
341 # we're just creating Android.bp, so we don't need them. Populate with
342 # some dummy values.
343 d['win_vc'] = '"dummy_version"'
344 d['win_sdk_version'] = '"dummy_version"'
Hal Canaryf72728e2019-07-10 11:24:52 -0400345 d['win_toolchain_version'] = '"dummy_version"'
Leon Scroggins IIIa55445e2018-11-28 16:09:35 -0500346 return d
347
348gn_args = generate_args('"android"', True)
349gn_args_linux = generate_args('"linux"', False)
350gn_args_mac = generate_args('"mac"', False)
Leon Scroggins IIIee0e5d02019-02-27 10:59:11 -0500351gn_args_win = generate_args('"win"', False)
Leon Scroggins III85e22fc2018-11-28 08:58:47 -0500352
Derek Sollenberger5d3f7702018-02-01 09:22:53 -0500353js = gn_to_bp_utils.GenerateJSONFromGN(gn_args)
Mike Klein308b5ac2016-12-06 16:03:52 -0500354
355def strip_slashes(lst):
Ben Wagnere1275232017-02-23 18:00:06 -0500356 return {str(p.lstrip('/')) for p in lst}
Mike Klein27eb22b2016-12-07 12:27:56 -0500357
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500358android_srcs = strip_slashes(js['targets']['//:skia']['sources'])
Leon Scroggins III981a31e2017-10-06 11:53:53 -0400359cflags = strip_slashes(js['targets']['//:skia']['cflags'])
360cflags_cc = strip_slashes(js['targets']['//:skia']['cflags_cc'])
Mike Klein308b5ac2016-12-06 16:03:52 -0500361local_includes = strip_slashes(js['targets']['//:skia']['include_dirs'])
362export_includes = strip_slashes(js['targets']['//:public']['include_dirs'])
363
Leon Scroggins III6ccd2ca2017-01-26 17:21:27 -0500364dm_srcs = strip_slashes(js['targets']['//:dm']['sources'])
365dm_includes = strip_slashes(js['targets']['//:dm']['include_dirs'])
366
367nanobench_target = js['targets']['//:nanobench']
368nanobench_srcs = strip_slashes(nanobench_target['sources'])
369nanobench_includes = strip_slashes(nanobench_target['include_dirs'])
370
Derek Sollenberger5d3f7702018-02-01 09:22:53 -0500371gn_to_bp_utils.GrabDependentValues(js, '//:dm', 'sources', dm_srcs, 'skia')
372gn_to_bp_utils.GrabDependentValues(js, '//:nanobench', 'sources',
373 nanobench_srcs, 'skia')
Mike Klein27eb22b2016-12-07 12:27:56 -0500374
Mike Kleinf536c452018-05-01 10:36:42 -0400375# skcms is a little special, kind of a second-party library.
Brian Osman35ea04d2019-05-01 11:03:36 -0400376local_includes.add("include/third_party/skcms")
377dm_includes .add("include/third_party/skcms")
Mike Kleinf536c452018-05-01 10:36:42 -0400378
Mike Kleind505b192018-09-05 15:55:25 -0400379# Android's build will choke if we list headers.
380def strip_headers(sources):
381 return {s for s in sources if not s.endswith('.h')}
382
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500383gn_to_bp_utils.GrabDependentValues(js, '//:skia', 'sources', android_srcs, None)
384android_srcs = strip_headers(android_srcs)
385
386js_linux = gn_to_bp_utils.GenerateJSONFromGN(gn_args_linux)
387linux_srcs = strip_slashes(js_linux['targets']['//:skia']['sources'])
388gn_to_bp_utils.GrabDependentValues(js_linux, '//:skia', 'sources', linux_srcs,
389 None)
390linux_srcs = strip_headers(linux_srcs)
391
Leon Scroggins III85e22fc2018-11-28 08:58:47 -0500392js_mac = gn_to_bp_utils.GenerateJSONFromGN(gn_args_mac)
393mac_srcs = strip_slashes(js_mac['targets']['//:skia']['sources'])
394gn_to_bp_utils.GrabDependentValues(js_mac, '//:skia', 'sources', mac_srcs,
395 None)
396mac_srcs = strip_headers(mac_srcs)
397
Leon Scroggins IIIee0e5d02019-02-27 10:59:11 -0500398js_win = gn_to_bp_utils.GenerateJSONFromGN(gn_args_win)
399win_srcs = strip_slashes(js_win['targets']['//:skia']['sources'])
400gn_to_bp_utils.GrabDependentValues(js_win, '//:skia', 'sources', win_srcs,
401 None)
402win_srcs = strip_headers(win_srcs)
403
Leon Scroggins III85e22fc2018-11-28 08:58:47 -0500404srcs = android_srcs.intersection(linux_srcs).intersection(mac_srcs)
Leon Scroggins IIIee0e5d02019-02-27 10:59:11 -0500405srcs = srcs.intersection(win_srcs)
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500406android_srcs = android_srcs.difference(srcs)
407linux_srcs = linux_srcs.difference(srcs)
Leon Scroggins IIIee0e5d02019-02-27 10:59:11 -0500408mac_srcs = mac_srcs.difference(srcs)
409win_srcs = win_srcs.difference(srcs)
Mike Kleind505b192018-09-05 15:55:25 -0400410dm_srcs = strip_headers(dm_srcs)
411nanobench_srcs = strip_headers(nanobench_srcs)
Mike Klein27eb22b2016-12-07 12:27:56 -0500412
Derek Sollenberger5d3f7702018-02-01 09:22:53 -0500413cflags = gn_to_bp_utils.CleanupCFlags(cflags)
414cflags_cc = gn_to_bp_utils.CleanupCCFlags(cflags_cc)
Leon Scroggins III981a31e2017-10-06 11:53:53 -0400415
Leon Scroggins III4f8a4672016-12-19 09:32:21 -0500416here = os.path.dirname(__file__)
Derek Sollenberger5d3f7702018-02-01 09:22:53 -0500417defs = gn_to_bp_utils.GetArchSources(os.path.join(here, 'opts.gni'))
Mike Klein308b5ac2016-12-06 16:03:52 -0500418
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500419def get_defines(json):
420 return {str(d) for d in json['targets']['//:skia']['defines']}
421android_defines = get_defines(js)
422linux_defines = get_defines(js_linux)
Leon Scroggins III85e22fc2018-11-28 08:58:47 -0500423mac_defines = get_defines(js_mac)
Leon Scroggins IIIee0e5d02019-02-27 10:59:11 -0500424win_defines = get_defines(js_win)
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500425
426def mkdir_if_not_exists(path):
427 if not os.path.exists(path):
Mike Kleinc0bd9f92019-04-23 12:05:21 -0500428 os.makedirs(path)
429mkdir_if_not_exists('android/include/config/')
430mkdir_if_not_exists('linux/include/config/')
431mkdir_if_not_exists('mac/include/config/')
432mkdir_if_not_exists('win/include/config/')
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500433
434platforms = { 'IOS', 'MAC', 'WIN', 'ANDROID', 'UNIX' }
435
436def disallow_platforms(config, desired):
437 with open(config, 'a') as f:
438 p = sorted(platforms.difference({ desired }))
439 s = '#if '
440 for i in range(len(p)):
441 s = s + 'defined(SK_BUILD_FOR_%s)' % p[i]
442 if i < len(p) - 1:
443 s += ' || '
444 if i % 2 == 1:
445 s += '\\\n '
446 print >>f, s
447 print >>f, ' #error "Only SK_BUILD_FOR_%s should be defined!"' % desired
448 print >>f, '#endif'
449
450def append_to_file(config, s):
451 with open(config, 'a') as f:
452 print >>f, s
453
Mike Kleinc0bd9f92019-04-23 12:05:21 -0500454android_config = 'android/include/config/SkUserConfig.h'
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500455gn_to_bp_utils.WriteUserConfig(android_config, android_defines)
456append_to_file(android_config, '''
457#ifndef SK_BUILD_FOR_ANDROID
458 #error "SK_BUILD_FOR_ANDROID must be defined!"
459#endif''')
460disallow_platforms(android_config, 'ANDROID')
461
Leon Scroggins III85e22fc2018-11-28 08:58:47 -0500462def write_config(config_path, defines, platform):
463 gn_to_bp_utils.WriteUserConfig(config_path, defines)
464 append_to_file(config_path, '''
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500465// Correct SK_BUILD_FOR flags that may have been set by
466// SkPreConfig.h/Android.bp
Leon Scroggins III85e22fc2018-11-28 08:58:47 -0500467#ifndef SK_BUILD_FOR_%s
468 #define SK_BUILD_FOR_%s
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500469#endif
470#ifdef SK_BUILD_FOR_ANDROID
471 #undef SK_BUILD_FOR_ANDROID
Leon Scroggins III85e22fc2018-11-28 08:58:47 -0500472#endif''' % (platform, platform))
473 disallow_platforms(config_path, platform)
474
Mike Kleinc0bd9f92019-04-23 12:05:21 -0500475write_config('linux/include/config/SkUserConfig.h', linux_defines, 'UNIX')
476write_config('mac/include/config/SkUserConfig.h', mac_defines, 'MAC')
477write_config('win/include/config/SkUserConfig.h', win_defines, 'WIN')
Mike Klein308b5ac2016-12-06 16:03:52 -0500478
Mike Kleinee43f6f2016-12-12 14:09:38 -0500479# Turn a list of strings into the style bpfmt outputs.
Leon Scroggins III6ccd2ca2017-01-26 17:21:27 -0500480def bpfmt(indent, lst, sort=True):
481 if sort:
482 lst = sorted(lst)
483 return ('\n' + ' '*indent).join('"%s",' % v for v in lst)
Mike Klein308b5ac2016-12-06 16:03:52 -0500484
485# OK! We have everything to fill in Android.bp...
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500486with open('Android.bp', 'w') as Android_bp:
487 print >>Android_bp, bp.substitute({
Mike Kleinee43f6f2016-12-12 14:09:38 -0500488 'export_includes': bpfmt(8, export_includes),
489 'local_includes': bpfmt(8, local_includes),
490 'srcs': bpfmt(8, srcs),
Leon Scroggins III981a31e2017-10-06 11:53:53 -0400491 'cflags': bpfmt(8, cflags, False),
492 'cflags_cc': bpfmt(8, cflags_cc),
Mike Klein308b5ac2016-12-06 16:03:52 -0500493
Mike Kleind505b192018-09-05 15:55:25 -0400494 'arm_srcs': bpfmt(16, strip_headers(defs['armv7'])),
495 'arm_neon_srcs': bpfmt(20, strip_headers(defs['neon'])),
496 'arm64_srcs': bpfmt(16, strip_headers(defs['arm64'] +
497 defs['crc32'])),
498 'none_srcs': bpfmt(16, strip_headers(defs['none'])),
499 'x86_srcs': bpfmt(16, strip_headers(defs['sse2'] +
500 defs['ssse3'] +
501 defs['sse41'] +
502 defs['sse42'] +
503 defs['avx' ] +
504 defs['hsw' ])),
Leon Scroggins III6ccd2ca2017-01-26 17:21:27 -0500505
Leon Scroggins III6ccd2ca2017-01-26 17:21:27 -0500506 'dm_includes' : bpfmt(8, dm_includes),
507 'dm_srcs' : bpfmt(8, dm_srcs),
508
509 'nanobench_includes' : bpfmt(8, nanobench_includes),
510 'nanobench_srcs' : bpfmt(8, nanobench_srcs),
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500511
512 'android_srcs': bpfmt(10, android_srcs),
513 'linux_srcs': bpfmt(10, linux_srcs),
Leon Scroggins III85e22fc2018-11-28 08:58:47 -0500514 'mac_srcs': bpfmt(10, mac_srcs),
Leon Scroggins IIIee0e5d02019-02-27 10:59:11 -0500515 'win_srcs': bpfmt(10, win_srcs),
Mike Klein308b5ac2016-12-06 16:03:52 -0500516 })