blob: 24ee2bfeadf1821bb787ed73e492f0562e70ef1d [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 ],
Leon Scroggins III74663e72017-11-30 14:42:58 -050080 cflags: [
Leon Scroggins III6d892f52017-12-01 09:48:10 -050081 // Clang seems to think new/malloc will only be 4-byte aligned
82 // on x86 Android. We're pretty sure it's actually 8-byte
83 // alignment. tests/OverAlignedTest.cpp has more information,
84 // and should fail if we're wrong.
Leon Scroggins III74663e72017-11-30 14:42:58 -050085 "-Wno-over-aligned"
86 ],
Mike Kleinee43f6f2016-12-12 14:09:38 -050087 },
88
89 x86_64: {
90 srcs: [
91 $x86_srcs
92 ],
93 },
Mike Klein308b5ac2016-12-06 16:03:52 -050094 },
Mike Klein27eb22b2016-12-07 12:27:56 -050095
Zhizhou Yange18b7792017-12-11 10:37:44 -080096 defaults: ["skia_deps",
97 "skia_pgo",
98 ],
99}
100
101// Build libskia with PGO by default.
102// Location of PGO profile data is defined in build/soong/cc/pgo.go
103// and is separate from skia.
104// To turn it off, set ANDROID_PGO_NO_PROFILE_USE environment variable
105// or set enable_profile_use property to false.
106cc_defaults {
107 name: "skia_pgo",
108 pgo: {
109 instrumentation: true,
Pirama Arumuga Nainar068ccaa2018-03-05 10:20:38 -0800110 profile_file: "hwui/hwui.profdata",
Zhizhou Yange18b7792017-12-11 10:37:44 -0800111 benchmarks: ["hwui", "skia"],
Pirama Arumuga Nainar068ccaa2018-03-05 10:20:38 -0800112 enable_profile_use: true,
Zhizhou Yange18b7792017-12-11 10:37:44 -0800113 },
Derek Sollenberger5a932162017-09-21 14:25:14 -0400114}
115
Pirama Arumuga Nainarde2b95e2017-12-13 11:07:39 -0800116// "defaults" property to disable profile use for Skia tools and benchmarks.
117cc_defaults {
118 name: "skia_pgo_no_profile_use",
119 defaults: [
120 "skia_pgo",
121 ],
122 pgo: {
123 enable_profile_use: false,
124 },
125}
126
Derek Sollenberger5a932162017-09-21 14:25:14 -0400127cc_defaults {
128 name: "skia_deps",
Mike Kleinee43f6f2016-12-12 14:09:38 -0500129 shared_libs: [
130 "libEGL",
131 "libGLESv2",
132 "libdng_sdk",
133 "libexpat",
134 "libft2",
Leon Scroggins III04be2b52017-08-17 15:13:20 -0400135 "libheif",
Mike Kleinee43f6f2016-12-12 14:09:38 -0500136 "libicui18n",
137 "libicuuc",
138 "libjpeg",
139 "liblog",
140 "libpiex",
141 "libpng",
142 "libvulkan",
143 "libz",
Derek Sollenberger488f0d62017-03-03 15:48:33 -0500144 "libcutils",
Stan Iliev7e910df2017-06-02 10:29:21 -0400145 "libnativewindow",
Mike Kleinee43f6f2016-12-12 14:09:38 -0500146 ],
147 static_libs: [
Matt Saretta3091092017-02-20 12:50:52 -0500148 "libarect",
Mike Kleinee43f6f2016-12-12 14:09:38 -0500149 "libsfntly",
150 "libwebp-decode",
151 "libwebp-encode",
152 ],
Derek Sollenberger5a932162017-09-21 14:25:14 -0400153 group_static_libs: true,
154}
155
156cc_defaults {
157 name: "skia_tool_deps",
158 defaults: [
Pirama Arumuga Nainarde2b95e2017-12-13 11:07:39 -0800159 "skia_deps",
160 "skia_pgo_no_profile_use"
Derek Sollenberger5a932162017-09-21 14:25:14 -0400161 ],
162 static_libs: [
163 "libjsoncpp",
164 "libskia",
165 ],
166 cflags: [
Derek Sollenberger9a72ae12017-12-14 13:01:30 -0500167 "-Wno-unused-parameter",
168 "-Wno-unused-variable",
Derek Sollenberger5a932162017-09-21 14:25:14 -0400169 ],
Leon Scroggins III6ccd2ca2017-01-26 17:21:27 -0500170}
171
172cc_test {
173 name: "skia_dm",
174
Derek Sollenberger5a932162017-09-21 14:25:14 -0400175 defaults: [
176 "skia_tool_deps"
Leon Scroggins III6ccd2ca2017-01-26 17:21:27 -0500177 ],
178
179 local_include_dirs: [
180 $dm_includes
181 ],
182
183 srcs: [
184 $dm_srcs
185 ],
Dongwon Kang0c7861f2018-02-16 10:55:21 -0800186
187 shared_libs: [
188 "libbinder",
189 "libutils",
190 ],
Leon Scroggins III6ccd2ca2017-01-26 17:21:27 -0500191}
192
193cc_test {
194 name: "skia_nanobench",
195
Derek Sollenberger5a932162017-09-21 14:25:14 -0400196 defaults: [
197 "skia_tool_deps"
Leon Scroggins III6ccd2ca2017-01-26 17:21:27 -0500198 ],
199
200 local_include_dirs: [
201 $nanobench_includes
202 ],
203
204 srcs: [
205 $nanobench_srcs
206 ],
Pirama Arumuga Nainar68c3fac2018-01-09 21:05:55 -0800207
208 data: [
209 "resources/*",
210 ],
Mike Kleinee43f6f2016-12-12 14:09:38 -0500211}''')
Mike Klein308b5ac2016-12-06 16:03:52 -0500212
213# We'll run GN to get the main source lists and include directories for Skia.
214gn_args = {
Florin Malita87ccf332018-05-04 12:23:24 -0400215 'is_official_build': 'true',
216 'skia_enable_tools': 'true',
217 'skia_enable_skottie': 'false', # requires rapidjson third-party
218 'skia_use_libheif': 'true',
219 'skia_use_vulkan': 'true',
220 'target_cpu': '"none"',
221 'target_os': '"android"',
222 'skia_vulkan_header': '"Skia_Vulkan_Android.h"',
Mike Klein308b5ac2016-12-06 16:03:52 -0500223}
Mike Klein308b5ac2016-12-06 16:03:52 -0500224
Derek Sollenberger5d3f7702018-02-01 09:22:53 -0500225js = gn_to_bp_utils.GenerateJSONFromGN(gn_args)
Mike Klein308b5ac2016-12-06 16:03:52 -0500226
227def strip_slashes(lst):
Ben Wagnere1275232017-02-23 18:00:06 -0500228 return {str(p.lstrip('/')) for p in lst}
Mike Klein27eb22b2016-12-07 12:27:56 -0500229
Mike Klein308b5ac2016-12-06 16:03:52 -0500230srcs = strip_slashes(js['targets']['//:skia']['sources'])
Leon Scroggins III981a31e2017-10-06 11:53:53 -0400231cflags = strip_slashes(js['targets']['//:skia']['cflags'])
232cflags_cc = strip_slashes(js['targets']['//:skia']['cflags_cc'])
Mike Klein308b5ac2016-12-06 16:03:52 -0500233local_includes = strip_slashes(js['targets']['//:skia']['include_dirs'])
234export_includes = strip_slashes(js['targets']['//:public']['include_dirs'])
Derek Sollenberger5d3f7702018-02-01 09:22:53 -0500235defines = [str(d) for d in js['targets']['//:skia']['defines']]
Mike Klein308b5ac2016-12-06 16:03:52 -0500236
Leon Scroggins III6ccd2ca2017-01-26 17:21:27 -0500237dm_srcs = strip_slashes(js['targets']['//:dm']['sources'])
238dm_includes = strip_slashes(js['targets']['//:dm']['include_dirs'])
239
240nanobench_target = js['targets']['//:nanobench']
241nanobench_srcs = strip_slashes(nanobench_target['sources'])
242nanobench_includes = strip_slashes(nanobench_target['include_dirs'])
243
Derek Sollenberger5d3f7702018-02-01 09:22:53 -0500244gn_to_bp_utils.GrabDependentValues(js, '//:skia', 'sources', srcs, None)
245gn_to_bp_utils.GrabDependentValues(js, '//:dm', 'sources', dm_srcs, 'skia')
246gn_to_bp_utils.GrabDependentValues(js, '//:nanobench', 'sources',
247 nanobench_srcs, 'skia')
Mike Klein27eb22b2016-12-07 12:27:56 -0500248
Mike Kleinf536c452018-05-01 10:36:42 -0400249# skcms is a little special, kind of a second-party library.
Mike Kleinf536c452018-05-01 10:36:42 -0400250local_includes.add("third_party/skcms")
251dm_includes .add("third_party/skcms")
252
Greg Daniel18dbfd02018-05-29 10:46:51 -0400253# need to manually include the vulkanmemoryallocator headers. If HWUI ever needs
254# direct access to the allocator we need to add it to export_includes as well.
255srcs.add("third_party/vulkanmemoryallocator/GrVulkanMemoryAllocator.cpp")
256local_includes.add("third_party/vulkanmemoryallocator/")
257
Mike Klein27eb22b2016-12-07 12:27:56 -0500258# No need to list headers.
Ben Wagnere1275232017-02-23 18:00:06 -0500259srcs = {s for s in srcs if not s.endswith('.h')}
260dm_srcs = {s for s in dm_srcs if not s.endswith('.h')}
261nanobench_srcs = {s for s in nanobench_srcs if not s.endswith('.h')}
Mike Klein27eb22b2016-12-07 12:27:56 -0500262
Derek Sollenberger5d3f7702018-02-01 09:22:53 -0500263cflags = gn_to_bp_utils.CleanupCFlags(cflags)
264cflags_cc = gn_to_bp_utils.CleanupCCFlags(cflags_cc)
Leon Scroggins III981a31e2017-10-06 11:53:53 -0400265
Greg Danielafb7ec72017-12-07 12:48:30 -0500266# We need to add the include path to the vulkan defines and header file set in
267# then skia_vulkan_header gn arg that is used for framework builds.
268local_includes.add("platform_tools/android/vulkan")
269export_includes.add("platform_tools/android/vulkan")
270
Leon Scroggins III4f8a4672016-12-19 09:32:21 -0500271here = os.path.dirname(__file__)
Derek Sollenberger5d3f7702018-02-01 09:22:53 -0500272defs = gn_to_bp_utils.GetArchSources(os.path.join(here, 'opts.gni'))
Mike Klein308b5ac2016-12-06 16:03:52 -0500273
Derek Sollenberger5d3f7702018-02-01 09:22:53 -0500274gn_to_bp_utils.WriteUserConfig('include/config/SkUserConfig.h', defines)
Mike Klein308b5ac2016-12-06 16:03:52 -0500275
Mike Kleinee43f6f2016-12-12 14:09:38 -0500276# Turn a list of strings into the style bpfmt outputs.
Leon Scroggins III6ccd2ca2017-01-26 17:21:27 -0500277def bpfmt(indent, lst, sort=True):
278 if sort:
279 lst = sorted(lst)
280 return ('\n' + ' '*indent).join('"%s",' % v for v in lst)
Mike Klein308b5ac2016-12-06 16:03:52 -0500281
282# OK! We have everything to fill in Android.bp...
283with open('Android.bp', 'w') as f:
284 print >>f, bp.substitute({
Mike Kleinee43f6f2016-12-12 14:09:38 -0500285 'export_includes': bpfmt(8, export_includes),
286 'local_includes': bpfmt(8, local_includes),
287 'srcs': bpfmt(8, srcs),
Leon Scroggins III981a31e2017-10-06 11:53:53 -0400288 'cflags': bpfmt(8, cflags, False),
289 'cflags_cc': bpfmt(8, cflags_cc),
Mike Klein308b5ac2016-12-06 16:03:52 -0500290
Derek Sollenberger5d3f7702018-02-01 09:22:53 -0500291 'arm_srcs': bpfmt(16, defs['armv7']),
292 'arm_neon_srcs': bpfmt(20, defs['neon']),
293 'arm64_srcs': bpfmt(16, defs['arm64'] +
294 defs['crc32']),
295 'none_srcs': bpfmt(16, defs['none']),
296 'x86_srcs': bpfmt(16, defs['sse2'] +
297 defs['ssse3'] +
298 defs['sse41'] +
299 defs['sse42'] +
Mike Klein1b9b7d52018-02-27 10:37:40 -0500300 defs['avx' ] +
301 defs['hsw' ]),
Leon Scroggins III6ccd2ca2017-01-26 17:21:27 -0500302
Leon Scroggins III6ccd2ca2017-01-26 17:21:27 -0500303 'dm_includes' : bpfmt(8, dm_includes),
304 'dm_srcs' : bpfmt(8, dm_srcs),
305
306 'nanobench_includes' : bpfmt(8, nanobench_includes),
307 'nanobench_srcs' : bpfmt(8, nanobench_srcs),
Mike Klein308b5ac2016-12-06 16:03:52 -0500308 })