blob: a813c73e54b102a63809adbfdeb7785e9f093459 [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.
Martin Stjernholmb4382ce2020-11-10 22:53:19 +000023// To make changes to this file, follow the instructions on skia.org for
24// downloading Skia and submitting changes. Modify gn_to_bp.py (or the build
25// files it uses) and submit. The autoroller will then create the updated
26// Android.bp. Or ask a Skia engineer for help.
Mike Klein308b5ac2016-12-06 16:03:52 -050027
Leon Scrogginsd87a98f2021-04-30 15:12:36 -040028package {
29 default_applicable_licenses: ["external_skia_license"],
30}
31
32// Added automatically by a large-scale-change that took the approach of
33// 'apply every license found to every target'. While this makes sure we respect
34// every license restriction, it may not be entirely correct.
35//
36// e.g. GPL in an MIT project might only apply to the contrib/ directory.
37//
38// Please consider splitting the single license below into multiple licenses,
39// taking care not to lose any license_kind information, and overriding the
40// default license using the 'licenses: [...]' property on targets as needed.
41//
42// For unused files, consider creating a 'fileGroup' with "//visibility:private"
43// to attach the license to, and including a comment whether the files may be
44// used in the current project.
45//
46// large-scale-change included anything that looked like it might be a license
47// text as a license_text. e.g. LICENSE, NOTICE, COPYING etc.
48//
49// Please consider removing redundant or irrelevant files from 'license_text:'.
50//
51// large-scale-change filtered out the below license kinds as false-positives:
52// SPDX-license-identifier-CC-BY-NC
53// SPDX-license-identifier-GPL-2.0
54// SPDX-license-identifier-LGPL-2.1
55// SPDX-license-identifier-OFL:by_exception_only
56// See: http://go/android-license-faq
57license {
58 name: "external_skia_license",
59 visibility: [":__subpackages__"],
60 license_kinds: [
61 "SPDX-license-identifier-Apache-2.0",
62 "SPDX-license-identifier-BSD",
63 "SPDX-license-identifier-CC0-1.0",
64 "SPDX-license-identifier-FTL",
65 "SPDX-license-identifier-MIT",
66 "SPDX-license-identifier-MPL",
67 "legacy_unencumbered",
68 ],
69 license_text: [
70 "LICENSE",
71 "NOTICE",
72 ],
73}
74
Leon Scroggins III6c41bf52021-01-29 15:33:00 -050075cc_defaults {
76 name: "skia_defaults",
Mike Kleinee43f6f2016-12-12 14:09:38 -050077 cflags: [
Leon Scroggins III981a31e2017-10-06 11:53:53 -040078 $cflags
79 ],
80
81 cppflags:[
82 $cflags_cc
Mike Kleinee43f6f2016-12-12 14:09:38 -050083 ],
Mike Klein308b5ac2016-12-06 16:03:52 -050084
Mike Kleinee43f6f2016-12-12 14:09:38 -050085 export_include_dirs: [
86 $export_includes
87 ],
Mike Klein27eb22b2016-12-07 12:27:56 -050088
Mike Kleinee43f6f2016-12-12 14:09:38 -050089 local_include_dirs: [
90 $local_includes
91 ],
Mike Klein27eb22b2016-12-07 12:27:56 -050092
Mike Kleinee43f6f2016-12-12 14:09:38 -050093 arch: {
94 arm: {
95 srcs: [
96 $arm_srcs
97 ],
Mike Klein27eb22b2016-12-07 12:27:56 -050098
Leon Scroggins IIIf7332d32017-08-10 09:09:54 -040099 neon: {
Mike Kleinee43f6f2016-12-12 14:09:38 -0500100 srcs: [
101 $arm_neon_srcs
102 ],
103 },
104 },
105
106 arm64: {
107 srcs: [
108 $arm64_srcs
109 ],
110 },
111
Mike Kleinee43f6f2016-12-12 14:09:38 -0500112 x86: {
113 srcs: [
114 $x86_srcs
115 ],
116 },
117
118 x86_64: {
119 srcs: [
120 $x86_srcs
121 ],
122 },
Mike Klein308b5ac2016-12-06 16:03:52 -0500123 },
Mike Klein27eb22b2016-12-07 12:27:56 -0500124
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500125 target: {
126 android: {
127 srcs: [
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500128 "third_party/vulkanmemoryallocator/GrVulkanMemoryAllocator.cpp",
129 ],
130 local_include_dirs: [
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500131 "third_party/vulkanmemoryallocator/",
132 ],
Leon Scroggins III6c41bf52021-01-29 15:33:00 -0500133 },
134 },
135}
136
137cc_library_static {
138 // Smaller version of Skia, without e.g. codecs, intended for use by RenderEngine.
139 name: "libskia_renderengine",
140 defaults: ["skia_defaults",
141 "skia_renderengine_deps"],
142 srcs: [
143 $renderengine_srcs
144 ],
145 local_include_dirs: [
146 "renderengine",
147 ],
148 export_include_dirs: [
149 "renderengine",
150 ],
151}
152
153cc_library_static {
154 name: "libskia",
155 host_supported: true,
156 cppflags:[
157 // Exceptions are necessary for SkRawCodec.
158 // FIXME: Should we split SkRawCodec into a separate target so the rest
159 // of Skia need not be compiled with exceptions?
160 "-fexceptions",
161 ],
162
163 srcs: [
164 $srcs
165 ],
166
167 target: {
168 android: {
169 srcs: [
170 $android_srcs
171 ],
172 local_include_dirs: [
173 "android",
174 ],
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500175 export_include_dirs: [
Mike Kleinc0bd9f92019-04-23 12:05:21 -0500176 "android",
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500177 ],
178 },
179 linux_glibc: {
180 cflags: [
181 "-mssse3",
182 ],
183 srcs: [
184 $linux_srcs
185 ],
186 local_include_dirs: [
Mike Kleinc0bd9f92019-04-23 12:05:21 -0500187 "linux",
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500188 ],
189 export_include_dirs: [
Mike Kleinc0bd9f92019-04-23 12:05:21 -0500190 "linux",
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500191 ],
192 },
Leon Scroggins III85e22fc2018-11-28 08:58:47 -0500193 darwin: {
194 cflags: [
195 "-mssse3",
196 ],
197 srcs: [
198 $mac_srcs
199 ],
200 local_include_dirs: [
Mike Kleinc0bd9f92019-04-23 12:05:21 -0500201 "mac",
Leon Scroggins III85e22fc2018-11-28 08:58:47 -0500202 ],
203 export_include_dirs: [
Mike Kleinc0bd9f92019-04-23 12:05:21 -0500204 "mac",
Leon Scroggins III85e22fc2018-11-28 08:58:47 -0500205 ],
206 },
Leon Scroggins IIIee0e5d02019-02-27 10:59:11 -0500207 windows: {
Martin Stjernholmb4382ce2020-11-10 22:53:19 +0000208 enabled: true,
Leon Scroggins IIIee0e5d02019-02-27 10:59:11 -0500209 cflags: [
210 "-mssse3",
211 "-Wno-unknown-pragmas",
212 ],
213 srcs: [
214 $win_srcs
215 ],
216 local_include_dirs: [
Mike Kleinc0bd9f92019-04-23 12:05:21 -0500217 "win",
Leon Scroggins IIIee0e5d02019-02-27 10:59:11 -0500218 ],
219 export_include_dirs: [
Mike Kleinc0bd9f92019-04-23 12:05:21 -0500220 "win",
Leon Scroggins IIIee0e5d02019-02-27 10:59:11 -0500221 ],
222 },
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500223 },
224
Zhizhou Yange18b7792017-12-11 10:37:44 -0800225 defaults: ["skia_deps",
226 "skia_pgo",
Leon Scroggins III6c41bf52021-01-29 15:33:00 -0500227 "skia_defaults",
Zhizhou Yange18b7792017-12-11 10:37:44 -0800228 ],
229}
230
231// Build libskia with PGO by default.
232// Location of PGO profile data is defined in build/soong/cc/pgo.go
233// and is separate from skia.
234// To turn it off, set ANDROID_PGO_NO_PROFILE_USE environment variable
235// or set enable_profile_use property to false.
236cc_defaults {
237 name: "skia_pgo",
238 pgo: {
239 instrumentation: true,
Pirama Arumuga Nainar068ccaa2018-03-05 10:20:38 -0800240 profile_file: "hwui/hwui.profdata",
Zhizhou Yange18b7792017-12-11 10:37:44 -0800241 benchmarks: ["hwui", "skia"],
Pirama Arumuga Nainar068ccaa2018-03-05 10:20:38 -0800242 enable_profile_use: true,
Zhizhou Yange18b7792017-12-11 10:37:44 -0800243 },
Derek Sollenberger5a932162017-09-21 14:25:14 -0400244}
245
Pirama Arumuga Nainarde2b95e2017-12-13 11:07:39 -0800246// "defaults" property to disable profile use for Skia tools and benchmarks.
247cc_defaults {
248 name: "skia_pgo_no_profile_use",
249 defaults: [
250 "skia_pgo",
251 ],
252 pgo: {
253 enable_profile_use: false,
254 },
255}
256
Derek Sollenberger5a932162017-09-21 14:25:14 -0400257cc_defaults {
Leon Scroggins III6c41bf52021-01-29 15:33:00 -0500258 // Subset of the larger "skia_deps", which includes only the dependencies
259 // needed for libskia_renderengine. Note that it includes libpng and libz
260 // for the purposes of MSKP captures, but we could instead leave it up to
261 // RenderEngine to provide its own SkSerializerProcs if another client
262 // wants an even smaller version of libskia.
263 name: "skia_renderengine_deps",
Mike Kleinee43f6f2016-12-12 14:09:38 -0500264 shared_libs: [
Jerome Gaillarde80251a2020-10-27 13:35:00 +0000265 "libcutils",
Mike Kleinee43f6f2016-12-12 14:09:38 -0500266 "liblog",
Mike Kleinee43f6f2016-12-12 14:09:38 -0500267 "libpng",
Mike Kleinee43f6f2016-12-12 14:09:38 -0500268 "libz",
269 ],
270 static_libs: [
Matt Saretta3091092017-02-20 12:50:52 -0500271 "libarect",
Mike Kleinee43f6f2016-12-12 14:09:38 -0500272 ],
Derek Sollenberger5a932162017-09-21 14:25:14 -0400273 group_static_libs: true,
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500274 target: {
275 android: {
276 shared_libs: [
277 "libEGL",
278 "libGLESv2",
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500279 "libvulkan",
280 "libnativewindow",
281 ],
Stan Iliev12b89162019-03-11 13:33:02 -0400282 export_shared_lib_headers: [
283 "libvulkan",
284 ],
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500285 },
Leon Scroggins III6c41bf52021-01-29 15:33:00 -0500286 },
287}
288
289cc_defaults {
290 name: "skia_deps",
291 defaults: ["skia_renderengine_deps"],
292 shared_libs: [
293 "libdng_sdk",
294 "libjpeg",
295 "libpiex",
296 "libexpat",
297 "libft2",
298 ],
299 static_libs: [
300 "libwebp-decode",
301 "libwebp-encode",
302 "libsfntly",
303 ],
304 target: {
305 android: {
306 shared_libs: [
307 "libheif",
308 ],
309 },
Leon Scroggins III85e22fc2018-11-28 08:58:47 -0500310 darwin: {
311 host_ldlibs: [
312 "-framework AppKit",
313 ],
314 },
Leon Scroggins IIIee0e5d02019-02-27 10:59:11 -0500315 windows: {
Leon Scroggins IIIee0e5d02019-02-27 10:59:11 -0500316 host_ldlibs: [
317 "-lgdi32",
318 "-loleaut32",
319 "-lole32",
320 "-lopengl32",
321 "-luuid",
322 "-lwindowscodecs",
323 ],
324 },
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500325 },
Derek Sollenberger5a932162017-09-21 14:25:14 -0400326}
327
328cc_defaults {
329 name: "skia_tool_deps",
330 defaults: [
Pirama Arumuga Nainarde2b95e2017-12-13 11:07:39 -0800331 "skia_deps",
332 "skia_pgo_no_profile_use"
Derek Sollenberger5a932162017-09-21 14:25:14 -0400333 ],
Mike Reed579c2952020-05-27 16:49:23 -0400334 shared_libs: [
Victor Chang6bd4d1c2020-11-23 19:26:59 +0000335 "libicu",
Mike Reed579c2952020-05-27 16:49:23 -0400336 "libharfbuzz_ng",
337 ],
Derek Sollenberger5a932162017-09-21 14:25:14 -0400338 static_libs: [
Derek Sollenberger5a932162017-09-21 14:25:14 -0400339 "libskia",
340 ],
341 cflags: [
Mike Reed579c2952020-05-27 16:49:23 -0400342 "-DSK_SHAPER_HARFBUZZ_AVAILABLE",
Julia Lavrova1798f4f2020-08-26 14:22:48 +0000343 "-DSK_UNICODE_AVAILABLE",
Derek Sollenberger1821a5b2018-09-11 14:48:36 -0400344 "-Wno-implicit-fallthrough",
Derek Sollenberger9a72ae12017-12-14 13:01:30 -0500345 "-Wno-unused-parameter",
346 "-Wno-unused-variable",
Derek Sollenberger5a932162017-09-21 14:25:14 -0400347 ],
Martin Stjernholmb4382ce2020-11-10 22:53:19 +0000348 target: {
349 windows: {
350 enabled: true,
351 },
352 },
Leon Scroggins III6ccd2ca2017-01-26 17:21:27 -0500353}
354
355cc_test {
356 name: "skia_dm",
357
Derek Sollenberger5a932162017-09-21 14:25:14 -0400358 defaults: [
359 "skia_tool_deps"
Leon Scroggins III6ccd2ca2017-01-26 17:21:27 -0500360 ],
361
362 local_include_dirs: [
363 $dm_includes
364 ],
365
366 srcs: [
367 $dm_srcs
368 ],
Dongwon Kang0c7861f2018-02-16 10:55:21 -0800369
370 shared_libs: [
371 "libbinder",
372 "libutils",
373 ],
Leon Scroggins III6ccd2ca2017-01-26 17:21:27 -0500374}
375
376cc_test {
377 name: "skia_nanobench",
378
Derek Sollenberger5a932162017-09-21 14:25:14 -0400379 defaults: [
380 "skia_tool_deps"
Leon Scroggins III6ccd2ca2017-01-26 17:21:27 -0500381 ],
382
383 local_include_dirs: [
384 $nanobench_includes
385 ],
386
387 srcs: [
388 $nanobench_srcs
389 ],
Pirama Arumuga Nainar68c3fac2018-01-09 21:05:55 -0800390
391 data: [
Pirama Arumuga Nainar5be3c132019-09-30 17:18:02 -0700392 "resources/**/*",
Pirama Arumuga Nainar68c3fac2018-01-09 21:05:55 -0800393 ],
Mike Kleinee43f6f2016-12-12 14:09:38 -0500394}''')
Mike Klein308b5ac2016-12-06 16:03:52 -0500395
396# We'll run GN to get the main source lists and include directories for Skia.
Leon Scroggins III6c41bf52021-01-29 15:33:00 -0500397def generate_args(target_os, enable_gpu, renderengine = False):
Leon Scroggins IIIa55445e2018-11-28 16:09:35 -0500398 d = {
Ben Wagner75626e42020-06-03 13:20:37 -0400399 'is_official_build': 'true',
Mike Klein308b5ac2016-12-06 16:03:52 -0500400
Leon Scroggins IIIa55445e2018-11-28 16:09:35 -0500401 # gn_to_bp_utils' GetArchSources will take care of architecture-specific
402 # files.
Ben Wagner75626e42020-06-03 13:20:37 -0400403 'target_cpu': '"none"',
Hal Canary23564b92018-09-07 14:33:14 -0400404
Leon Scroggins IIIa55445e2018-11-28 16:09:35 -0500405 # Use the custom FontMgr, as the framework will handle fonts.
Ben Wagner75626e42020-06-03 13:20:37 -0400406 'skia_enable_fontmgr_custom_directory': 'false',
407 'skia_enable_fontmgr_custom_embedded': 'false',
Ben Wagner75626e42020-06-03 13:20:37 -0400408 'skia_enable_fontmgr_android': 'false',
409 'skia_enable_fontmgr_win': 'false',
410 'skia_enable_fontmgr_win_gdi': 'false',
411 'skia_use_fonthost_mac': 'false',
Leon Scroggins IIIa55445e2018-11-28 16:09:35 -0500412
Nathaniel Nifong60c37e72019-10-16 11:21:47 -0400413 # enable features used in skia_nanobench
Ben Wagner75626e42020-06-03 13:20:37 -0400414 'skia_tools_require_resources': 'true',
Nathaniel Nifong60c37e72019-10-16 11:21:47 -0400415
Ben Wagner75626e42020-06-03 13:20:37 -0400416 'skia_use_fontconfig': 'false',
Ben Wagner75626e42020-06-03 13:20:37 -0400417 'skia_include_multiframe_procs': 'false',
418 'skia_libgifcodec_path': '"third_party/libgifcodec"',
Leon Scroggins IIIa55445e2018-11-28 16:09:35 -0500419 }
420 d['target_os'] = target_os
421 if target_os == '"android"':
422 d['skia_enable_tools'] = 'true'
Nathaniel Nifong0c4fbf12019-06-25 15:48:47 -0400423 d['skia_include_multiframe_procs'] = 'true'
Leon Scroggins IIIa55445e2018-11-28 16:09:35 -0500424
425 if enable_gpu:
426 d['skia_use_vulkan'] = 'true'
427 else:
428 d['skia_use_vulkan'] = 'false'
429 d['skia_enable_gpu'] = 'false'
Leon Scroggins IIIee0e5d02019-02-27 10:59:11 -0500430
431 if target_os == '"win"':
432 # The Android Windows build system does not provide FontSub.h
433 d['skia_use_xps'] = 'false'
434
435 # BUILDCONFIG.gn expects these to be set when building for Windows, but
436 # we're just creating Android.bp, so we don't need them. Populate with
Kevin Lubick22663802021-01-29 11:05:41 -0500437 # some placeholder values.
438 d['win_vc'] = '"placeholder_version"'
439 d['win_sdk_version'] = '"placeholder_version"'
440 d['win_toolchain_version'] = '"placeholder_version"'
Leon Scroggins III6c41bf52021-01-29 15:33:00 -0500441
442 if target_os == '"android"' and not renderengine:
443 d['skia_use_libheif'] = 'true'
444 else:
445 d['skia_use_libheif'] = 'false'
446
447 if renderengine:
448 d['skia_use_libpng_decode'] = 'false'
449 d['skia_use_libjpeg_turbo_decode'] = 'false'
450 d['skia_use_libjpeg_turbo_encode'] = 'false'
451 d['skia_use_libwebp_decode'] = 'false'
452 d['skia_use_libwebp_encode'] = 'false'
453 d['skia_use_libgifcodec'] = 'false'
454 d['skia_enable_pdf'] = 'false'
455 d['skia_use_freetype'] = 'false'
456 d['skia_use_fixed_gamma_text'] = 'false'
457 d['skia_use_expat'] = 'false'
458 d['skia_enable_fontmgr_custom_empty'] = 'false'
459 else:
460 d['skia_enable_android_utils'] = 'true'
461 d['skia_use_freetype'] = 'true'
462 d['skia_use_fixed_gamma_text'] = 'true'
463 d['skia_enable_fontmgr_custom_empty'] = 'true'
464
Leon Scroggins IIIa55445e2018-11-28 16:09:35 -0500465 return d
466
467gn_args = generate_args('"android"', True)
468gn_args_linux = generate_args('"linux"', False)
469gn_args_mac = generate_args('"mac"', False)
Leon Scroggins IIIee0e5d02019-02-27 10:59:11 -0500470gn_args_win = generate_args('"win"', False)
Leon Scroggins III6c41bf52021-01-29 15:33:00 -0500471gn_args_renderengine = generate_args('"android"', True, True)
Leon Scroggins III85e22fc2018-11-28 08:58:47 -0500472
Derek Sollenberger5d3f7702018-02-01 09:22:53 -0500473js = gn_to_bp_utils.GenerateJSONFromGN(gn_args)
Mike Klein308b5ac2016-12-06 16:03:52 -0500474
475def strip_slashes(lst):
Ben Wagnere1275232017-02-23 18:00:06 -0500476 return {str(p.lstrip('/')) for p in lst}
Mike Klein27eb22b2016-12-07 12:27:56 -0500477
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500478android_srcs = strip_slashes(js['targets']['//:skia']['sources'])
Leon Scroggins III981a31e2017-10-06 11:53:53 -0400479cflags = strip_slashes(js['targets']['//:skia']['cflags'])
480cflags_cc = strip_slashes(js['targets']['//:skia']['cflags_cc'])
Mike Klein308b5ac2016-12-06 16:03:52 -0500481local_includes = strip_slashes(js['targets']['//:skia']['include_dirs'])
482export_includes = strip_slashes(js['targets']['//:public']['include_dirs'])
483
Leon Scroggins III6ccd2ca2017-01-26 17:21:27 -0500484dm_srcs = strip_slashes(js['targets']['//:dm']['sources'])
485dm_includes = strip_slashes(js['targets']['//:dm']['include_dirs'])
486
487nanobench_target = js['targets']['//:nanobench']
488nanobench_srcs = strip_slashes(nanobench_target['sources'])
489nanobench_includes = strip_slashes(nanobench_target['include_dirs'])
490
Derek Sollenberger5d3f7702018-02-01 09:22:53 -0500491gn_to_bp_utils.GrabDependentValues(js, '//:dm', 'sources', dm_srcs, 'skia')
492gn_to_bp_utils.GrabDependentValues(js, '//:nanobench', 'sources',
493 nanobench_srcs, 'skia')
Mike Klein27eb22b2016-12-07 12:27:56 -0500494
Mike Kleinf536c452018-05-01 10:36:42 -0400495# skcms is a little special, kind of a second-party library.
Brian Osman35ea04d2019-05-01 11:03:36 -0400496local_includes.add("include/third_party/skcms")
497dm_includes .add("include/third_party/skcms")
Mike Kleinf536c452018-05-01 10:36:42 -0400498
Mike Kleind505b192018-09-05 15:55:25 -0400499# Android's build will choke if we list headers.
500def strip_headers(sources):
501 return {s for s in sources if not s.endswith('.h')}
502
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500503gn_to_bp_utils.GrabDependentValues(js, '//:skia', 'sources', android_srcs, None)
504android_srcs = strip_headers(android_srcs)
505
506js_linux = gn_to_bp_utils.GenerateJSONFromGN(gn_args_linux)
507linux_srcs = strip_slashes(js_linux['targets']['//:skia']['sources'])
508gn_to_bp_utils.GrabDependentValues(js_linux, '//:skia', 'sources', linux_srcs,
509 None)
510linux_srcs = strip_headers(linux_srcs)
511
Leon Scroggins III85e22fc2018-11-28 08:58:47 -0500512js_mac = gn_to_bp_utils.GenerateJSONFromGN(gn_args_mac)
513mac_srcs = strip_slashes(js_mac['targets']['//:skia']['sources'])
514gn_to_bp_utils.GrabDependentValues(js_mac, '//:skia', 'sources', mac_srcs,
515 None)
516mac_srcs = strip_headers(mac_srcs)
517
Leon Scroggins IIIee0e5d02019-02-27 10:59:11 -0500518js_win = gn_to_bp_utils.GenerateJSONFromGN(gn_args_win)
519win_srcs = strip_slashes(js_win['targets']['//:skia']['sources'])
520gn_to_bp_utils.GrabDependentValues(js_win, '//:skia', 'sources', win_srcs,
521 None)
522win_srcs = strip_headers(win_srcs)
523
Leon Scroggins III85e22fc2018-11-28 08:58:47 -0500524srcs = android_srcs.intersection(linux_srcs).intersection(mac_srcs)
Leon Scroggins IIIee0e5d02019-02-27 10:59:11 -0500525srcs = srcs.intersection(win_srcs)
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500526android_srcs = android_srcs.difference(srcs)
527linux_srcs = linux_srcs.difference(srcs)
Leon Scroggins IIIee0e5d02019-02-27 10:59:11 -0500528mac_srcs = mac_srcs.difference(srcs)
529win_srcs = win_srcs.difference(srcs)
Leon Scroggins III6c41bf52021-01-29 15:33:00 -0500530
531js_renderengine = gn_to_bp_utils.GenerateJSONFromGN(gn_args_renderengine)
532renderengine_srcs = strip_slashes(
533 js_renderengine['targets']['//:skia']['sources'])
534gn_to_bp_utils.GrabDependentValues(js_renderengine, '//:skia', 'sources',
535 renderengine_srcs, None)
536renderengine_srcs = strip_headers(renderengine_srcs)
537
Mike Kleind505b192018-09-05 15:55:25 -0400538dm_srcs = strip_headers(dm_srcs)
539nanobench_srcs = strip_headers(nanobench_srcs)
Mike Klein27eb22b2016-12-07 12:27:56 -0500540
Derek Sollenberger5d3f7702018-02-01 09:22:53 -0500541cflags = gn_to_bp_utils.CleanupCFlags(cflags)
542cflags_cc = gn_to_bp_utils.CleanupCCFlags(cflags_cc)
Leon Scroggins III981a31e2017-10-06 11:53:53 -0400543
Leon Scroggins III4f8a4672016-12-19 09:32:21 -0500544here = os.path.dirname(__file__)
Derek Sollenberger5d3f7702018-02-01 09:22:53 -0500545defs = gn_to_bp_utils.GetArchSources(os.path.join(here, 'opts.gni'))
Mike Klein308b5ac2016-12-06 16:03:52 -0500546
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500547def get_defines(json):
548 return {str(d) for d in json['targets']['//:skia']['defines']}
Leon Scroggins III6c41bf52021-01-29 15:33:00 -0500549android_defines = get_defines(js)
550linux_defines = get_defines(js_linux)
551mac_defines = get_defines(js_mac)
552win_defines = get_defines(js_win)
553renderengine_defines = get_defines(js_renderengine)
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500554
555def mkdir_if_not_exists(path):
556 if not os.path.exists(path):
Mike Kleinc0bd9f92019-04-23 12:05:21 -0500557 os.makedirs(path)
558mkdir_if_not_exists('android/include/config/')
559mkdir_if_not_exists('linux/include/config/')
560mkdir_if_not_exists('mac/include/config/')
561mkdir_if_not_exists('win/include/config/')
Leon Scroggins III6c41bf52021-01-29 15:33:00 -0500562mkdir_if_not_exists('renderengine/include/config/')
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500563
564platforms = { 'IOS', 'MAC', 'WIN', 'ANDROID', 'UNIX' }
565
566def disallow_platforms(config, desired):
567 with open(config, 'a') as f:
568 p = sorted(platforms.difference({ desired }))
569 s = '#if '
570 for i in range(len(p)):
571 s = s + 'defined(SK_BUILD_FOR_%s)' % p[i]
572 if i < len(p) - 1:
573 s += ' || '
574 if i % 2 == 1:
575 s += '\\\n '
Martin Vejdarskibeaaf472020-03-03 13:53:20 +0700576 print(s, file=f)
577 print(' #error "Only SK_BUILD_FOR_%s should be defined!"' % desired, file=f)
578 print('#endif', file=f)
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500579
580def append_to_file(config, s):
581 with open(config, 'a') as f:
Martin Vejdarskibeaaf472020-03-03 13:53:20 +0700582 print(s, file=f)
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500583
Leon Scroggins III6c41bf52021-01-29 15:33:00 -0500584def write_android_config(config_path, defines):
585 gn_to_bp_utils.WriteUserConfig(config_path, defines)
586 append_to_file(config_path, '''
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500587#ifndef SK_BUILD_FOR_ANDROID
588 #error "SK_BUILD_FOR_ANDROID must be defined!"
589#endif''')
Leon Scroggins III6c41bf52021-01-29 15:33:00 -0500590 disallow_platforms(config_path, 'ANDROID')
591
592write_android_config('android/include/config/SkUserConfig.h', android_defines)
593write_android_config('renderengine/include/config/SkUserConfig.h', renderengine_defines)
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500594
Leon Scroggins III85e22fc2018-11-28 08:58:47 -0500595def write_config(config_path, defines, platform):
596 gn_to_bp_utils.WriteUserConfig(config_path, defines)
597 append_to_file(config_path, '''
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500598// Correct SK_BUILD_FOR flags that may have been set by
Mike Klein81d35a72020-02-05 10:17:57 -0600599// SkTypes.h/Android.bp
Leon Scroggins III85e22fc2018-11-28 08:58:47 -0500600#ifndef SK_BUILD_FOR_%s
601 #define SK_BUILD_FOR_%s
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500602#endif
603#ifdef SK_BUILD_FOR_ANDROID
604 #undef SK_BUILD_FOR_ANDROID
Leon Scroggins III85e22fc2018-11-28 08:58:47 -0500605#endif''' % (platform, platform))
606 disallow_platforms(config_path, platform)
607
Mike Kleinc0bd9f92019-04-23 12:05:21 -0500608write_config('linux/include/config/SkUserConfig.h', linux_defines, 'UNIX')
609write_config('mac/include/config/SkUserConfig.h', mac_defines, 'MAC')
610write_config('win/include/config/SkUserConfig.h', win_defines, 'WIN')
Mike Klein308b5ac2016-12-06 16:03:52 -0500611
Mike Kleinee43f6f2016-12-12 14:09:38 -0500612# Turn a list of strings into the style bpfmt outputs.
Leon Scroggins III6ccd2ca2017-01-26 17:21:27 -0500613def bpfmt(indent, lst, sort=True):
614 if sort:
615 lst = sorted(lst)
616 return ('\n' + ' '*indent).join('"%s",' % v for v in lst)
Mike Klein308b5ac2016-12-06 16:03:52 -0500617
618# OK! We have everything to fill in Android.bp...
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500619with open('Android.bp', 'w') as Android_bp:
Martin Vejdarskibeaaf472020-03-03 13:53:20 +0700620 print(bp.substitute({
Mike Kleinee43f6f2016-12-12 14:09:38 -0500621 'export_includes': bpfmt(8, export_includes),
622 'local_includes': bpfmt(8, local_includes),
623 'srcs': bpfmt(8, srcs),
Leon Scroggins III981a31e2017-10-06 11:53:53 -0400624 'cflags': bpfmt(8, cflags, False),
625 'cflags_cc': bpfmt(8, cflags_cc),
Mike Klein308b5ac2016-12-06 16:03:52 -0500626
Mike Kleind505b192018-09-05 15:55:25 -0400627 'arm_srcs': bpfmt(16, strip_headers(defs['armv7'])),
628 'arm_neon_srcs': bpfmt(20, strip_headers(defs['neon'])),
629 'arm64_srcs': bpfmt(16, strip_headers(defs['arm64'] +
630 defs['crc32'])),
Mike Kleind505b192018-09-05 15:55:25 -0400631 'x86_srcs': bpfmt(16, strip_headers(defs['sse2'] +
632 defs['ssse3'] +
633 defs['sse41'] +
634 defs['sse42'] +
635 defs['avx' ] +
Mike Kleinad56c4c2020-06-05 06:57:30 -0500636 defs['hsw' ] +
637 defs['skx' ])),
Leon Scroggins III6ccd2ca2017-01-26 17:21:27 -0500638
Leon Scroggins III6ccd2ca2017-01-26 17:21:27 -0500639 'dm_includes' : bpfmt(8, dm_includes),
640 'dm_srcs' : bpfmt(8, dm_srcs),
641
642 'nanobench_includes' : bpfmt(8, nanobench_includes),
643 'nanobench_srcs' : bpfmt(8, nanobench_srcs),
Leon Scroggins IIIc41a5f52018-11-15 15:54:59 -0500644
645 'android_srcs': bpfmt(10, android_srcs),
646 'linux_srcs': bpfmt(10, linux_srcs),
Leon Scroggins III85e22fc2018-11-28 08:58:47 -0500647 'mac_srcs': bpfmt(10, mac_srcs),
Leon Scroggins IIIee0e5d02019-02-27 10:59:11 -0500648 'win_srcs': bpfmt(10, win_srcs),
Leon Scroggins III6c41bf52021-01-29 15:33:00 -0500649
650 'renderengine_srcs': bpfmt(8, renderengine_srcs),
Martin Vejdarskibeaaf472020-03-03 13:53:20 +0700651 }), file=Android_bp)