blob: 02bd638c4b0fad0ae4cedc0435bd9125f4bb5233 [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 ],
Derek Sollenberger5d3f7702018-02-01 09:22:53 -050090 },
91
92 x86_64: {
93 srcs: [
94 $x86_srcs
95 ],
96 },
97 },
98
99 shared_libs: [
100 "libandroid",
101 "libEGL",
102 "libGLESv2",
103 "liblog",
104 "libvulkan",
105 "libz",
106 ],
107 static_libs: [
108 "libjpeg_static_ndk",
Derek Sollenbergerea4aa7e2018-03-21 10:51:12 -0400109 "libjsoncpp_ndk",
Derek Sollenberger5d3f7702018-02-01 09:22:53 -0500110 "libpng_ndk",
111 "libwebp-decode",
112 "libwebp-encode",
113 ]
114}''')
115
116# We'll run GN to get the main source lists and include directories for Skia.
117gn_args = {
Derek Sollenberger5d3f7702018-02-01 09:22:53 -0500118 'target_cpu': '"none"',
119 'target_os': '"android"',
Derek Sollenberger82831b12018-02-05 11:51:29 -0500120
121 # setup skqp
122 'is_debug': 'false',
Derek Sollenberger5d3f7702018-02-01 09:22:53 -0500123 'ndk_api': '26',
Hal Canaryac7f23c2018-11-26 14:07:41 -0500124 'skia_skqp_global_error_tolerance': '8',
Derek Sollenberger5d3f7702018-02-01 09:22:53 -0500125
126 # setup vulkan
127 'skia_use_vulkan': 'true',
128 'skia_vulkan_header': '"Skia_Vulkan_Android.h"',
129
130 # enable/disable skia subsystems
131 'skia_enable_fontmgr_empty': 'true',
132 'skia_enable_pdf': 'false',
Florin Malita87ccf332018-05-04 12:23:24 -0400133 'skia_enable_skottie': 'false',
Derek Sollenberger5d3f7702018-02-01 09:22:53 -0500134 'skia_use_expat': 'false',
135 'skia_use_dng_sdk': 'false',
136 'skia_use_icu': 'false',
137 'skia_use_lua': 'false',
138 'skia_use_piex': 'false',
Derek Sollenberger5d3f7702018-02-01 09:22:53 -0500139
140 # specify that the Android.bp will supply the necessary components
141 'skia_use_system_expat': 'true', # removed this when gn is fixed
142 'skia_use_system_libpng': 'true',
143 'skia_use_system_jsoncpp': 'true',
144 'skia_use_system_libwebp': 'true',
145 'skia_use_system_libjpeg_turbo': 'true',
146 'skia_use_system_zlib': 'true',
147}
148
149js = gn_to_bp_utils.GenerateJSONFromGN(gn_args)
150
151def strip_slashes(lst):
152 return {str(p.lstrip('/')) for p in lst}
153
154srcs = strip_slashes(js['targets']['//:libskqp_app']['sources'])
155cflags = strip_slashes(js['targets']['//:libskqp_app']['cflags'])
156cflags_cc = strip_slashes(js['targets']['//:libskqp_app']['cflags_cc'])
157local_includes = strip_slashes(js['targets']['//:libskqp_app']['include_dirs'])
158defines = {str(d) for d in js['targets']['//:libskqp_app']['defines']}
159
160gn_to_bp_utils.GrabDependentValues(js, '//:libskqp_app', 'sources', srcs, None)
161gn_to_bp_utils.GrabDependentValues(js, '//:libskqp_app', 'include_dirs',
162 local_includes, 'freetype')
163gn_to_bp_utils.GrabDependentValues(js, '//:libskqp_app', 'defines',
164 defines, None)
165
166# No need to list headers or other extra flags.
167srcs = {s for s in srcs if not s.endswith('.h')}
168cflags = gn_to_bp_utils.CleanupCFlags(cflags)
169cflags_cc = gn_to_bp_utils.CleanupCCFlags(cflags_cc)
170
171# We need to add the include path to the vulkan defines and header file set in
172# then skia_vulkan_header gn arg that is used for framework builds.
173local_includes.add("platform_tools/android/vulkan")
174
175# Get architecture specific source files
176defs = gn_to_bp_utils.GetArchSources(os.path.join(skia_gn_dir, 'opts.gni'))
177
178# Add source file until fix lands in
179# https://skia-review.googlesource.com/c/skia/+/101820
180srcs.add("src/ports/SkFontMgr_empty_factory.cpp")
181
182# Turn a list of strings into the style bpfmt outputs.
183def bpfmt(indent, lst, sort=True):
184 if sort:
185 lst = sorted(lst)
186 return ('\n' + ' '*indent).join('"%s",' % v for v in lst)
187
188# Most defines go into SkUserConfig.h, where they're seen by Skia and its users.
189gn_to_bp_utils.WriteUserConfig('include/config/SkUserConfig.h', defines)
190
191# OK! We have everything to fill in Android.bp...
192with open('Android.bp', 'w') as f:
193 print >>f, bp.substitute({
194 'local_includes': bpfmt(8, local_includes),
195 'srcs': bpfmt(8, srcs),
196 'cflags': bpfmt(8, cflags, False),
197 'cflags_cc': bpfmt(8, cflags_cc),
198
199 'arm_srcs': bpfmt(16, defs['armv7']),
200 'arm_neon_srcs': bpfmt(20, defs['neon']),
201 'arm64_srcs': bpfmt(16, defs['arm64'] +
202 defs['crc32']),
203 'none_srcs': bpfmt(16, defs['none']),
204 'x86_srcs': bpfmt(16, defs['sse2'] +
205 defs['ssse3'] +
206 defs['sse41'] +
207 defs['sse42'] +
208 defs['avx' ]),
209 })
210