blob: f4e2bfe13c54c6ce0d78b60868a6d5fd22eb4593 [file] [log] [blame]
Derek Sollenberger5d3f7702018-02-01 09:22:53 -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 argparse
11import json
12import os
13import pprint
14import string
15import subprocess
16import sys
17import tempfile
18
19root_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)),
20 os.pardir, os.pardir)
21skia_gn_dir = os.path.join(root_dir, 'gn')
22sys.path.insert(0, skia_gn_dir)
23
24import gn_to_bp_utils
25
26# First we start off with a template for Android.bp,
27# with holes for source lists and include directories.
28bp = string.Template('''// This file is autogenerated by tools/skqp/gn_to_bp.py.
29
30cc_library_shared {
31 name: "libskqp_app",
32 sdk_version: "26",
33 stl: "libc++_static",
Derek Sollenbergerd3962222018-04-02 12:17:37 -040034 compile_multilib: "both",
Derek Sollenberger5d3f7702018-02-01 09:22:53 -050035 tags: ["tests", "optional"],
36
37 cflags: [
38 $cflags
39 "-Wno-unused-parameter",
40 "-Wno-unused-variable",
41 ],
42
43 cppflags:[
44 $cflags_cc
45 ],
46
47 local_include_dirs: [
48 $local_includes
49 ],
50
51 srcs: [
52 $srcs
53 ],
54
55 arch: {
56 arm: {
57 srcs: [
58 $arm_srcs
59 ],
60
61 neon: {
62 srcs: [
63 $arm_neon_srcs
64 ],
65 },
66 },
67
68 arm64: {
69 srcs: [
70 $arm64_srcs
71 ],
72 },
73
74 mips: {
75 srcs: [
76 $none_srcs
77 ],
78 },
79
80 mips64: {
81 srcs: [
82 $none_srcs
83 ],
84 },
85
86 x86: {
87 srcs: [
88 $x86_srcs
89 ],
90 cflags: [
91 // Clang seems to think new/malloc will only be 4-byte aligned
92 // on x86 Android. We're pretty sure it's actually 8-byte
93 // alignment. tests/OverAlignedTest.cpp has more information,
94 // and should fail if we're wrong.
95 "-Wno-over-aligned"
96 ],
97 },
98
99 x86_64: {
100 srcs: [
101 $x86_srcs
102 ],
103 },
104 },
105
106 shared_libs: [
107 "libandroid",
108 "libEGL",
109 "libGLESv2",
110 "liblog",
111 "libvulkan",
112 "libz",
113 ],
114 static_libs: [
115 "libjpeg_static_ndk",
Derek Sollenbergerea4aa7e2018-03-21 10:51:12 -0400116 "libjsoncpp_ndk",
Derek Sollenberger5d3f7702018-02-01 09:22:53 -0500117 "libpng_ndk",
118 "libwebp-decode",
119 "libwebp-encode",
120 ]
121}''')
122
123# We'll run GN to get the main source lists and include directories for Skia.
124gn_args = {
Derek Sollenberger5d3f7702018-02-01 09:22:53 -0500125 'target_cpu': '"none"',
126 'target_os': '"android"',
Derek Sollenberger82831b12018-02-05 11:51:29 -0500127
128 # setup skqp
129 'is_debug': 'false',
Derek Sollenberger5d3f7702018-02-01 09:22:53 -0500130 'ndk_api': '26',
Derek Sollenberger82831b12018-02-05 11:51:29 -0500131 'skia_skqp_global_error_tolerance': '4',
Derek Sollenberger5d3f7702018-02-01 09:22:53 -0500132
133 # setup vulkan
134 'skia_use_vulkan': 'true',
135 'skia_vulkan_header': '"Skia_Vulkan_Android.h"',
136
137 # enable/disable skia subsystems
138 'skia_enable_fontmgr_empty': 'true',
139 'skia_enable_pdf': 'false',
Florin Malita87ccf332018-05-04 12:23:24 -0400140 'skia_enable_skottie': 'false',
Derek Sollenberger5d3f7702018-02-01 09:22:53 -0500141 'skia_use_expat': 'false',
142 'skia_use_dng_sdk': 'false',
143 'skia_use_icu': 'false',
144 'skia_use_lua': 'false',
145 'skia_use_piex': 'false',
Derek Sollenberger5d3f7702018-02-01 09:22:53 -0500146
147 # specify that the Android.bp will supply the necessary components
148 'skia_use_system_expat': 'true', # removed this when gn is fixed
149 'skia_use_system_libpng': 'true',
150 'skia_use_system_jsoncpp': 'true',
151 'skia_use_system_libwebp': 'true',
152 'skia_use_system_libjpeg_turbo': 'true',
153 'skia_use_system_zlib': 'true',
154}
155
156js = gn_to_bp_utils.GenerateJSONFromGN(gn_args)
157
158def strip_slashes(lst):
159 return {str(p.lstrip('/')) for p in lst}
160
161srcs = strip_slashes(js['targets']['//:libskqp_app']['sources'])
162cflags = strip_slashes(js['targets']['//:libskqp_app']['cflags'])
163cflags_cc = strip_slashes(js['targets']['//:libskqp_app']['cflags_cc'])
164local_includes = strip_slashes(js['targets']['//:libskqp_app']['include_dirs'])
165defines = {str(d) for d in js['targets']['//:libskqp_app']['defines']}
166
167gn_to_bp_utils.GrabDependentValues(js, '//:libskqp_app', 'sources', srcs, None)
168gn_to_bp_utils.GrabDependentValues(js, '//:libskqp_app', 'include_dirs',
169 local_includes, 'freetype')
170gn_to_bp_utils.GrabDependentValues(js, '//:libskqp_app', 'defines',
171 defines, None)
172
173# No need to list headers or other extra flags.
174srcs = {s for s in srcs if not s.endswith('.h')}
175cflags = gn_to_bp_utils.CleanupCFlags(cflags)
176cflags_cc = gn_to_bp_utils.CleanupCCFlags(cflags_cc)
177
178# We need to add the include path to the vulkan defines and header file set in
179# then skia_vulkan_header gn arg that is used for framework builds.
180local_includes.add("platform_tools/android/vulkan")
181
182# Get architecture specific source files
183defs = gn_to_bp_utils.GetArchSources(os.path.join(skia_gn_dir, 'opts.gni'))
184
185# Add source file until fix lands in
186# https://skia-review.googlesource.com/c/skia/+/101820
187srcs.add("src/ports/SkFontMgr_empty_factory.cpp")
188
189# Turn a list of strings into the style bpfmt outputs.
190def bpfmt(indent, lst, sort=True):
191 if sort:
192 lst = sorted(lst)
193 return ('\n' + ' '*indent).join('"%s",' % v for v in lst)
194
195# Most defines go into SkUserConfig.h, where they're seen by Skia and its users.
196gn_to_bp_utils.WriteUserConfig('include/config/SkUserConfig.h', defines)
197
198# OK! We have everything to fill in Android.bp...
199with open('Android.bp', 'w') as f:
200 print >>f, bp.substitute({
201 'local_includes': bpfmt(8, local_includes),
202 'srcs': bpfmt(8, srcs),
203 'cflags': bpfmt(8, cflags, False),
204 'cflags_cc': bpfmt(8, cflags_cc),
205
206 'arm_srcs': bpfmt(16, defs['armv7']),
207 'arm_neon_srcs': bpfmt(20, defs['neon']),
208 'arm64_srcs': bpfmt(16, defs['arm64'] +
209 defs['crc32']),
210 'none_srcs': bpfmt(16, defs['none']),
211 'x86_srcs': bpfmt(16, defs['sse2'] +
212 defs['ssse3'] +
213 defs['sse41'] +
214 defs['sse42'] +
215 defs['avx' ]),
216 })
217