blob: e941a5be10245dd73ed2b64c944be4c2b0dbd4e7 [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
10import json
11import os
12import pprint
13import string
14import subprocess
Mike Klein308b5ac2016-12-06 16:03:52 -050015import tempfile
16
Derek Sollenberger5d3f7702018-02-01 09:22:53 -050017import gn_to_bp_utils
18
Mike Klein308b5ac2016-12-06 16:03:52 -050019# First we start off with a template for Android.bp,
20# with holes for source lists and include directories.
21bp = string.Template('''// This file is autogenerated by gn_to_bp.py.
22
Derek Sollenberger5a932162017-09-21 14:25:14 -040023cc_library_static {
Mike Kleinee43f6f2016-12-12 14:09:38 -050024 name: "libskia",
25 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
Zhizhou Yange18b7792017-12-11 10:37:44 -080089 defaults: ["skia_deps",
90 "skia_pgo",
91 ],
92}
93
94// Build libskia with PGO by default.
95// Location of PGO profile data is defined in build/soong/cc/pgo.go
96// and is separate from skia.
97// To turn it off, set ANDROID_PGO_NO_PROFILE_USE environment variable
98// or set enable_profile_use property to false.
99cc_defaults {
100 name: "skia_pgo",
101 pgo: {
102 instrumentation: true,
Pirama Arumuga Nainar068ccaa2018-03-05 10:20:38 -0800103 profile_file: "hwui/hwui.profdata",
Zhizhou Yange18b7792017-12-11 10:37:44 -0800104 benchmarks: ["hwui", "skia"],
Pirama Arumuga Nainar068ccaa2018-03-05 10:20:38 -0800105 enable_profile_use: true,
Zhizhou Yange18b7792017-12-11 10:37:44 -0800106 },
Derek Sollenberger5a932162017-09-21 14:25:14 -0400107}
108
Pirama Arumuga Nainarde2b95e2017-12-13 11:07:39 -0800109// "defaults" property to disable profile use for Skia tools and benchmarks.
110cc_defaults {
111 name: "skia_pgo_no_profile_use",
112 defaults: [
113 "skia_pgo",
114 ],
115 pgo: {
116 enable_profile_use: false,
117 },
118}
119
Derek Sollenberger5a932162017-09-21 14:25:14 -0400120cc_defaults {
121 name: "skia_deps",
Mike Kleinee43f6f2016-12-12 14:09:38 -0500122 shared_libs: [
123 "libEGL",
124 "libGLESv2",
125 "libdng_sdk",
126 "libexpat",
127 "libft2",
Leon Scroggins III04be2b52017-08-17 15:13:20 -0400128 "libheif",
Mike Kleinee43f6f2016-12-12 14:09:38 -0500129 "libicui18n",
130 "libicuuc",
131 "libjpeg",
132 "liblog",
133 "libpiex",
134 "libpng",
135 "libvulkan",
136 "libz",
Derek Sollenberger488f0d62017-03-03 15:48:33 -0500137 "libcutils",
Stan Iliev7e910df2017-06-02 10:29:21 -0400138 "libnativewindow",
Mike Kleinee43f6f2016-12-12 14:09:38 -0500139 ],
140 static_libs: [
Matt Saretta3091092017-02-20 12:50:52 -0500141 "libarect",
Mike Kleinee43f6f2016-12-12 14:09:38 -0500142 "libsfntly",
143 "libwebp-decode",
144 "libwebp-encode",
145 ],
Derek Sollenberger5a932162017-09-21 14:25:14 -0400146 group_static_libs: true,
147}
148
149cc_defaults {
150 name: "skia_tool_deps",
151 defaults: [
Pirama Arumuga Nainarde2b95e2017-12-13 11:07:39 -0800152 "skia_deps",
153 "skia_pgo_no_profile_use"
Derek Sollenberger5a932162017-09-21 14:25:14 -0400154 ],
155 static_libs: [
156 "libjsoncpp",
157 "libskia",
158 ],
159 cflags: [
Derek Sollenberger1821a5b2018-09-11 14:48:36 -0400160 "-Wno-implicit-fallthrough",
Derek Sollenberger9a72ae12017-12-14 13:01:30 -0500161 "-Wno-unused-parameter",
162 "-Wno-unused-variable",
Derek Sollenberger5a932162017-09-21 14:25:14 -0400163 ],
Leon Scroggins III6ccd2ca2017-01-26 17:21:27 -0500164}
165
166cc_test {
167 name: "skia_dm",
168
Derek Sollenberger5a932162017-09-21 14:25:14 -0400169 defaults: [
170 "skia_tool_deps"
Leon Scroggins III6ccd2ca2017-01-26 17:21:27 -0500171 ],
172
173 local_include_dirs: [
174 $dm_includes
175 ],
176
177 srcs: [
178 $dm_srcs
179 ],
Dongwon Kang0c7861f2018-02-16 10:55:21 -0800180
181 shared_libs: [
182 "libbinder",
183 "libutils",
184 ],
Leon Scroggins III6ccd2ca2017-01-26 17:21:27 -0500185}
186
187cc_test {
188 name: "skia_nanobench",
189
Derek Sollenberger5a932162017-09-21 14:25:14 -0400190 defaults: [
191 "skia_tool_deps"
Leon Scroggins III6ccd2ca2017-01-26 17:21:27 -0500192 ],
193
194 local_include_dirs: [
195 $nanobench_includes
196 ],
197
198 srcs: [
199 $nanobench_srcs
200 ],
Pirama Arumuga Nainar68c3fac2018-01-09 21:05:55 -0800201
202 data: [
203 "resources/*",
204 ],
Mike Kleinee43f6f2016-12-12 14:09:38 -0500205}''')
Mike Klein308b5ac2016-12-06 16:03:52 -0500206
207# We'll run GN to get the main source lists and include directories for Skia.
208gn_args = {
Leon Scroggins IIIbe85c192018-11-13 13:50:12 -0500209 'is_official_build': 'true',
210 'skia_enable_tools': 'true',
211 'skia_use_libheif': 'true',
212 'skia_use_vulkan': 'true',
213 'target_cpu': '"none"',
214 'target_os': '"android"',
215 'skia_enable_fontmgr_custom': 'false',
216 'skia_enable_fontmgr_custom_empty': 'true',
217 'skia_enable_fontmgr_android': 'false',
Mike Klein308b5ac2016-12-06 16:03:52 -0500218}
Mike Klein308b5ac2016-12-06 16:03:52 -0500219
Hal Canary23564b92018-09-07 14:33:14 -0400220extra_userconfig_defines = [
Hal Canary23564b92018-09-07 14:33:14 -0400221]
222
Derek Sollenberger5d3f7702018-02-01 09:22:53 -0500223js = gn_to_bp_utils.GenerateJSONFromGN(gn_args)
Mike Klein308b5ac2016-12-06 16:03:52 -0500224
225def strip_slashes(lst):
Ben Wagnere1275232017-02-23 18:00:06 -0500226 return {str(p.lstrip('/')) for p in lst}
Mike Klein27eb22b2016-12-07 12:27:56 -0500227
Mike Klein308b5ac2016-12-06 16:03:52 -0500228srcs = strip_slashes(js['targets']['//:skia']['sources'])
Leon Scroggins III981a31e2017-10-06 11:53:53 -0400229cflags = strip_slashes(js['targets']['//:skia']['cflags'])
230cflags_cc = strip_slashes(js['targets']['//:skia']['cflags_cc'])
Mike Klein308b5ac2016-12-06 16:03:52 -0500231local_includes = strip_slashes(js['targets']['//:skia']['include_dirs'])
232export_includes = strip_slashes(js['targets']['//:public']['include_dirs'])
Derek Sollenberger5d3f7702018-02-01 09:22:53 -0500233defines = [str(d) for d in js['targets']['//:skia']['defines']]
Hal Canary23564b92018-09-07 14:33:14 -0400234defines += extra_userconfig_defines
Mike Klein308b5ac2016-12-06 16:03:52 -0500235
Leon Scroggins III6ccd2ca2017-01-26 17:21:27 -0500236dm_srcs = strip_slashes(js['targets']['//:dm']['sources'])
237dm_includes = strip_slashes(js['targets']['//:dm']['include_dirs'])
238
239nanobench_target = js['targets']['//:nanobench']
240nanobench_srcs = strip_slashes(nanobench_target['sources'])
241nanobench_includes = strip_slashes(nanobench_target['include_dirs'])
242
Derek Sollenberger5d3f7702018-02-01 09:22:53 -0500243gn_to_bp_utils.GrabDependentValues(js, '//:skia', 'sources', srcs, None)
244gn_to_bp_utils.GrabDependentValues(js, '//:dm', 'sources', dm_srcs, 'skia')
245gn_to_bp_utils.GrabDependentValues(js, '//:nanobench', 'sources',
246 nanobench_srcs, 'skia')
Mike Klein27eb22b2016-12-07 12:27:56 -0500247
Mike Kleinf536c452018-05-01 10:36:42 -0400248# skcms is a little special, kind of a second-party library.
Mike Kleinf536c452018-05-01 10:36:42 -0400249local_includes.add("third_party/skcms")
250dm_includes .add("third_party/skcms")
251
Greg Daniel18dbfd02018-05-29 10:46:51 -0400252# need to manually include the vulkanmemoryallocator headers. If HWUI ever needs
253# direct access to the allocator we need to add it to export_includes as well.
254srcs.add("third_party/vulkanmemoryallocator/GrVulkanMemoryAllocator.cpp")
255local_includes.add("third_party/vulkanmemoryallocator/")
256
Mike Kleind505b192018-09-05 15:55:25 -0400257# Android's build will choke if we list headers.
258def strip_headers(sources):
259 return {s for s in sources if not s.endswith('.h')}
260
261srcs = strip_headers(srcs)
262dm_srcs = strip_headers(dm_srcs)
263nanobench_srcs = strip_headers(nanobench_srcs)
Mike Klein27eb22b2016-12-07 12:27:56 -0500264
Derek Sollenberger5d3f7702018-02-01 09:22:53 -0500265cflags = gn_to_bp_utils.CleanupCFlags(cflags)
266cflags_cc = gn_to_bp_utils.CleanupCCFlags(cflags_cc)
Leon Scroggins III981a31e2017-10-06 11:53:53 -0400267
Leon Scroggins III4f8a4672016-12-19 09:32:21 -0500268here = os.path.dirname(__file__)
Derek Sollenberger5d3f7702018-02-01 09:22:53 -0500269defs = gn_to_bp_utils.GetArchSources(os.path.join(here, 'opts.gni'))
Mike Klein308b5ac2016-12-06 16:03:52 -0500270
Derek Sollenberger5d3f7702018-02-01 09:22:53 -0500271gn_to_bp_utils.WriteUserConfig('include/config/SkUserConfig.h', defines)
Mike Klein308b5ac2016-12-06 16:03:52 -0500272
Mike Kleinee43f6f2016-12-12 14:09:38 -0500273# Turn a list of strings into the style bpfmt outputs.
Leon Scroggins III6ccd2ca2017-01-26 17:21:27 -0500274def bpfmt(indent, lst, sort=True):
275 if sort:
276 lst = sorted(lst)
277 return ('\n' + ' '*indent).join('"%s",' % v for v in lst)
Mike Klein308b5ac2016-12-06 16:03:52 -0500278
279# OK! We have everything to fill in Android.bp...
280with open('Android.bp', 'w') as f:
281 print >>f, bp.substitute({
Mike Kleinee43f6f2016-12-12 14:09:38 -0500282 'export_includes': bpfmt(8, export_includes),
283 'local_includes': bpfmt(8, local_includes),
284 'srcs': bpfmt(8, srcs),
Leon Scroggins III981a31e2017-10-06 11:53:53 -0400285 'cflags': bpfmt(8, cflags, False),
286 'cflags_cc': bpfmt(8, cflags_cc),
Mike Klein308b5ac2016-12-06 16:03:52 -0500287
Mike Kleind505b192018-09-05 15:55:25 -0400288 'arm_srcs': bpfmt(16, strip_headers(defs['armv7'])),
289 'arm_neon_srcs': bpfmt(20, strip_headers(defs['neon'])),
290 'arm64_srcs': bpfmt(16, strip_headers(defs['arm64'] +
291 defs['crc32'])),
292 'none_srcs': bpfmt(16, strip_headers(defs['none'])),
293 'x86_srcs': bpfmt(16, strip_headers(defs['sse2'] +
294 defs['ssse3'] +
295 defs['sse41'] +
296 defs['sse42'] +
297 defs['avx' ] +
298 defs['hsw' ])),
Leon Scroggins III6ccd2ca2017-01-26 17:21:27 -0500299
Leon Scroggins III6ccd2ca2017-01-26 17:21:27 -0500300 'dm_includes' : bpfmt(8, dm_includes),
301 'dm_srcs' : bpfmt(8, dm_srcs),
302
303 'nanobench_includes' : bpfmt(8, nanobench_includes),
304 'nanobench_srcs' : bpfmt(8, nanobench_srcs),
Mike Klein308b5ac2016-12-06 16:03:52 -0500305 })