blob: 0dfada3ea222a904e42d3e242304c2f196b25918 [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,
110 profile_file: "skia/skia.profdata",
111 benchmarks: ["hwui", "skia"],
Pirama Arumuga Nainar4108f652018-02-13 12:33:29 -0800112 // Bugs: http://b/73127367, http://b/73257154, http://b/73249590
113 // Turn off PGO for Skia until toolchain bug is fixed.
114 enable_profile_use: false,
Zhizhou Yange18b7792017-12-11 10:37:44 -0800115 },
Derek Sollenberger5a932162017-09-21 14:25:14 -0400116}
117
Pirama Arumuga Nainarde2b95e2017-12-13 11:07:39 -0800118// "defaults" property to disable profile use for Skia tools and benchmarks.
119cc_defaults {
120 name: "skia_pgo_no_profile_use",
121 defaults: [
122 "skia_pgo",
123 ],
124 pgo: {
125 enable_profile_use: false,
126 },
127}
128
Derek Sollenberger5a932162017-09-21 14:25:14 -0400129cc_defaults {
130 name: "skia_deps",
Mike Kleinee43f6f2016-12-12 14:09:38 -0500131 shared_libs: [
132 "libEGL",
133 "libGLESv2",
134 "libdng_sdk",
135 "libexpat",
136 "libft2",
Leon Scroggins III04be2b52017-08-17 15:13:20 -0400137 "libheif",
Mike Kleinee43f6f2016-12-12 14:09:38 -0500138 "libicui18n",
139 "libicuuc",
140 "libjpeg",
141 "liblog",
142 "libpiex",
143 "libpng",
144 "libvulkan",
145 "libz",
Derek Sollenberger488f0d62017-03-03 15:48:33 -0500146 "libcutils",
Stan Iliev7e910df2017-06-02 10:29:21 -0400147 "libnativewindow",
Mike Kleinee43f6f2016-12-12 14:09:38 -0500148 ],
149 static_libs: [
Matt Saretta3091092017-02-20 12:50:52 -0500150 "libarect",
Mike Kleinee43f6f2016-12-12 14:09:38 -0500151 "libsfntly",
152 "libwebp-decode",
153 "libwebp-encode",
154 ],
Derek Sollenberger5a932162017-09-21 14:25:14 -0400155 group_static_libs: true,
156}
157
158cc_defaults {
159 name: "skia_tool_deps",
160 defaults: [
Pirama Arumuga Nainarde2b95e2017-12-13 11:07:39 -0800161 "skia_deps",
162 "skia_pgo_no_profile_use"
Derek Sollenberger5a932162017-09-21 14:25:14 -0400163 ],
164 static_libs: [
165 "libjsoncpp",
166 "libskia",
167 ],
168 cflags: [
Derek Sollenberger9a72ae12017-12-14 13:01:30 -0500169 "-Wno-unused-parameter",
170 "-Wno-unused-variable",
Derek Sollenberger5a932162017-09-21 14:25:14 -0400171 ],
Leon Scroggins III6ccd2ca2017-01-26 17:21:27 -0500172}
173
174cc_test {
175 name: "skia_dm",
176
Derek Sollenberger5a932162017-09-21 14:25:14 -0400177 defaults: [
178 "skia_tool_deps"
Leon Scroggins III6ccd2ca2017-01-26 17:21:27 -0500179 ],
180
181 local_include_dirs: [
182 $dm_includes
183 ],
184
185 srcs: [
186 $dm_srcs
187 ],
Dongwon Kang0c7861f2018-02-16 10:55:21 -0800188
189 shared_libs: [
190 "libbinder",
191 "libutils",
192 ],
Leon Scroggins III6ccd2ca2017-01-26 17:21:27 -0500193}
194
195cc_test {
196 name: "skia_nanobench",
197
Derek Sollenberger5a932162017-09-21 14:25:14 -0400198 defaults: [
199 "skia_tool_deps"
Leon Scroggins III6ccd2ca2017-01-26 17:21:27 -0500200 ],
201
202 local_include_dirs: [
203 $nanobench_includes
204 ],
205
206 srcs: [
207 $nanobench_srcs
208 ],
Pirama Arumuga Nainar68c3fac2018-01-09 21:05:55 -0800209
210 data: [
211 "resources/*",
212 ],
Mike Kleinee43f6f2016-12-12 14:09:38 -0500213}''')
Mike Klein308b5ac2016-12-06 16:03:52 -0500214
215# We'll run GN to get the main source lists and include directories for Skia.
216gn_args = {
Mike Kleine459afd2017-03-03 09:21:30 -0500217 'is_official_build': 'true',
Mike Kleine459afd2017-03-03 09:21:30 -0500218 'skia_enable_tools': 'true',
Leon Scroggins III04be2b52017-08-17 15:13:20 -0400219 'skia_use_libheif': 'true',
Mike Kleine459afd2017-03-03 09:21:30 -0500220 'skia_use_vulkan': 'true',
221 'target_cpu': '"none"',
222 'target_os': '"android"',
Greg Danielafb7ec72017-12-07 12:48:30 -0500223 'skia_vulkan_header': '"Skia_Vulkan_Android.h"',
Mike Klein308b5ac2016-12-06 16:03:52 -0500224}
Mike Klein308b5ac2016-12-06 16:03:52 -0500225
Derek Sollenberger5d3f7702018-02-01 09:22:53 -0500226js = gn_to_bp_utils.GenerateJSONFromGN(gn_args)
Mike Klein308b5ac2016-12-06 16:03:52 -0500227
228def strip_slashes(lst):
Ben Wagnere1275232017-02-23 18:00:06 -0500229 return {str(p.lstrip('/')) for p in lst}
Mike Klein27eb22b2016-12-07 12:27:56 -0500230
Mike Klein308b5ac2016-12-06 16:03:52 -0500231srcs = strip_slashes(js['targets']['//:skia']['sources'])
Leon Scroggins III981a31e2017-10-06 11:53:53 -0400232cflags = strip_slashes(js['targets']['//:skia']['cflags'])
233cflags_cc = strip_slashes(js['targets']['//:skia']['cflags_cc'])
Mike Klein308b5ac2016-12-06 16:03:52 -0500234local_includes = strip_slashes(js['targets']['//:skia']['include_dirs'])
235export_includes = strip_slashes(js['targets']['//:public']['include_dirs'])
Derek Sollenberger5d3f7702018-02-01 09:22:53 -0500236defines = [str(d) for d in js['targets']['//:skia']['defines']]
Mike Klein308b5ac2016-12-06 16:03:52 -0500237
Leon Scroggins III6ccd2ca2017-01-26 17:21:27 -0500238dm_srcs = strip_slashes(js['targets']['//:dm']['sources'])
239dm_includes = strip_slashes(js['targets']['//:dm']['include_dirs'])
240
241nanobench_target = js['targets']['//:nanobench']
242nanobench_srcs = strip_slashes(nanobench_target['sources'])
243nanobench_includes = strip_slashes(nanobench_target['include_dirs'])
244
Derek Sollenberger5d3f7702018-02-01 09:22:53 -0500245gn_to_bp_utils.GrabDependentValues(js, '//:skia', 'sources', srcs, None)
246gn_to_bp_utils.GrabDependentValues(js, '//:dm', 'sources', dm_srcs, 'skia')
247gn_to_bp_utils.GrabDependentValues(js, '//:nanobench', 'sources',
248 nanobench_srcs, 'skia')
Mike Klein27eb22b2016-12-07 12:27:56 -0500249
250# No need to list headers.
Ben Wagnere1275232017-02-23 18:00:06 -0500251srcs = {s for s in srcs if not s.endswith('.h')}
252dm_srcs = {s for s in dm_srcs if not s.endswith('.h')}
253nanobench_srcs = {s for s in nanobench_srcs if not s.endswith('.h')}
Mike Klein27eb22b2016-12-07 12:27:56 -0500254
Derek Sollenberger5d3f7702018-02-01 09:22:53 -0500255cflags = gn_to_bp_utils.CleanupCFlags(cflags)
256cflags_cc = gn_to_bp_utils.CleanupCCFlags(cflags_cc)
Leon Scroggins III981a31e2017-10-06 11:53:53 -0400257
Greg Danielafb7ec72017-12-07 12:48:30 -0500258# We need to add the include path to the vulkan defines and header file set in
259# then skia_vulkan_header gn arg that is used for framework builds.
260local_includes.add("platform_tools/android/vulkan")
261export_includes.add("platform_tools/android/vulkan")
262
Leon Scroggins III4f8a4672016-12-19 09:32:21 -0500263here = os.path.dirname(__file__)
Derek Sollenberger5d3f7702018-02-01 09:22:53 -0500264defs = gn_to_bp_utils.GetArchSources(os.path.join(here, 'opts.gni'))
Mike Klein308b5ac2016-12-06 16:03:52 -0500265
Derek Sollenberger5d3f7702018-02-01 09:22:53 -0500266gn_to_bp_utils.WriteUserConfig('include/config/SkUserConfig.h', defines)
Mike Klein308b5ac2016-12-06 16:03:52 -0500267
Mike Kleinee43f6f2016-12-12 14:09:38 -0500268# Turn a list of strings into the style bpfmt outputs.
Leon Scroggins III6ccd2ca2017-01-26 17:21:27 -0500269def bpfmt(indent, lst, sort=True):
270 if sort:
271 lst = sorted(lst)
272 return ('\n' + ' '*indent).join('"%s",' % v for v in lst)
Mike Klein308b5ac2016-12-06 16:03:52 -0500273
274# OK! We have everything to fill in Android.bp...
275with open('Android.bp', 'w') as f:
276 print >>f, bp.substitute({
Mike Kleinee43f6f2016-12-12 14:09:38 -0500277 'export_includes': bpfmt(8, export_includes),
278 'local_includes': bpfmt(8, local_includes),
279 'srcs': bpfmt(8, srcs),
Leon Scroggins III981a31e2017-10-06 11:53:53 -0400280 'cflags': bpfmt(8, cflags, False),
281 'cflags_cc': bpfmt(8, cflags_cc),
Mike Klein308b5ac2016-12-06 16:03:52 -0500282
Derek Sollenberger5d3f7702018-02-01 09:22:53 -0500283 'arm_srcs': bpfmt(16, defs['armv7']),
284 'arm_neon_srcs': bpfmt(20, defs['neon']),
285 'arm64_srcs': bpfmt(16, defs['arm64'] +
286 defs['crc32']),
287 'none_srcs': bpfmt(16, defs['none']),
288 'x86_srcs': bpfmt(16, defs['sse2'] +
289 defs['ssse3'] +
290 defs['sse41'] +
291 defs['sse42'] +
Mike Klein5cc94cc2018-03-07 17:04:18 +0000292 defs['avx' ]),
Leon Scroggins III6ccd2ca2017-01-26 17:21:27 -0500293
Leon Scroggins III6ccd2ca2017-01-26 17:21:27 -0500294 'dm_includes' : bpfmt(8, dm_includes),
295 'dm_srcs' : bpfmt(8, dm_srcs),
296
297 'nanobench_includes' : bpfmt(8, nanobench_includes),
298 'nanobench_srcs' : bpfmt(8, nanobench_srcs),
Mike Klein308b5ac2016-12-06 16:03:52 -0500299 })