Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 1 | #!/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 | |
| 10 | import json |
| 11 | import os |
| 12 | import pprint |
| 13 | import string |
| 14 | import subprocess |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 15 | import tempfile |
| 16 | |
Derek Sollenberger | 5d3f770 | 2018-02-01 09:22:53 -0500 | [diff] [blame] | 17 | import gn_to_bp_utils |
| 18 | |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 19 | # First we start off with a template for Android.bp, |
| 20 | # with holes for source lists and include directories. |
| 21 | bp = string.Template('''// This file is autogenerated by gn_to_bp.py. |
| 22 | |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 23 | cc_library_static { |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 24 | name: "libskia", |
| 25 | cflags: [ |
Leon Scroggins III | 981a31e | 2017-10-06 11:53:53 -0400 | [diff] [blame] | 26 | $cflags |
| 27 | ], |
| 28 | |
| 29 | cppflags:[ |
| 30 | $cflags_cc |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 31 | ], |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 32 | |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 33 | export_include_dirs: [ |
| 34 | $export_includes |
| 35 | ], |
Mike Klein | 27eb22b | 2016-12-07 12:27:56 -0500 | [diff] [blame] | 36 | |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 37 | local_include_dirs: [ |
| 38 | $local_includes |
| 39 | ], |
Mike Klein | 27eb22b | 2016-12-07 12:27:56 -0500 | [diff] [blame] | 40 | |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 41 | srcs: [ |
| 42 | $srcs |
| 43 | ], |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 44 | |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 45 | arch: { |
| 46 | arm: { |
| 47 | srcs: [ |
| 48 | $arm_srcs |
| 49 | ], |
Mike Klein | 27eb22b | 2016-12-07 12:27:56 -0500 | [diff] [blame] | 50 | |
Leon Scroggins III | f7332d3 | 2017-08-10 09:09:54 -0400 | [diff] [blame] | 51 | neon: { |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 52 | srcs: [ |
| 53 | $arm_neon_srcs |
| 54 | ], |
| 55 | }, |
| 56 | }, |
| 57 | |
| 58 | arm64: { |
| 59 | srcs: [ |
| 60 | $arm64_srcs |
| 61 | ], |
| 62 | }, |
| 63 | |
| 64 | mips: { |
| 65 | srcs: [ |
Mike Klein | 40a82bd | 2016-12-20 17:34:29 -0500 | [diff] [blame] | 66 | $none_srcs |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 67 | ], |
| 68 | }, |
| 69 | |
| 70 | mips64: { |
| 71 | srcs: [ |
Mike Klein | 40a82bd | 2016-12-20 17:34:29 -0500 | [diff] [blame] | 72 | $none_srcs |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 73 | ], |
| 74 | }, |
| 75 | |
| 76 | x86: { |
| 77 | srcs: [ |
| 78 | $x86_srcs |
| 79 | ], |
| 80 | }, |
| 81 | |
| 82 | x86_64: { |
| 83 | srcs: [ |
| 84 | $x86_srcs |
| 85 | ], |
| 86 | }, |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 87 | }, |
Mike Klein | 27eb22b | 2016-12-07 12:27:56 -0500 | [diff] [blame] | 88 | |
Zhizhou Yang | e18b779 | 2017-12-11 10:37:44 -0800 | [diff] [blame] | 89 | 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. |
| 99 | cc_defaults { |
| 100 | name: "skia_pgo", |
| 101 | pgo: { |
| 102 | instrumentation: true, |
Pirama Arumuga Nainar | 068ccaa | 2018-03-05 10:20:38 -0800 | [diff] [blame] | 103 | profile_file: "hwui/hwui.profdata", |
Zhizhou Yang | e18b779 | 2017-12-11 10:37:44 -0800 | [diff] [blame] | 104 | benchmarks: ["hwui", "skia"], |
Pirama Arumuga Nainar | 068ccaa | 2018-03-05 10:20:38 -0800 | [diff] [blame] | 105 | enable_profile_use: true, |
Zhizhou Yang | e18b779 | 2017-12-11 10:37:44 -0800 | [diff] [blame] | 106 | }, |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 107 | } |
| 108 | |
Pirama Arumuga Nainar | de2b95e | 2017-12-13 11:07:39 -0800 | [diff] [blame] | 109 | // "defaults" property to disable profile use for Skia tools and benchmarks. |
| 110 | cc_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 Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 120 | cc_defaults { |
| 121 | name: "skia_deps", |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 122 | shared_libs: [ |
| 123 | "libEGL", |
| 124 | "libGLESv2", |
| 125 | "libdng_sdk", |
| 126 | "libexpat", |
| 127 | "libft2", |
Leon Scroggins III | 04be2b5 | 2017-08-17 15:13:20 -0400 | [diff] [blame] | 128 | "libheif", |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 129 | "libicui18n", |
| 130 | "libicuuc", |
| 131 | "libjpeg", |
| 132 | "liblog", |
| 133 | "libpiex", |
| 134 | "libpng", |
| 135 | "libvulkan", |
| 136 | "libz", |
Derek Sollenberger | 488f0d6 | 2017-03-03 15:48:33 -0500 | [diff] [blame] | 137 | "libcutils", |
Stan Iliev | 7e910df | 2017-06-02 10:29:21 -0400 | [diff] [blame] | 138 | "libnativewindow", |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 139 | ], |
| 140 | static_libs: [ |
Matt Sarett | a309109 | 2017-02-20 12:50:52 -0500 | [diff] [blame] | 141 | "libarect", |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 142 | "libsfntly", |
| 143 | "libwebp-decode", |
| 144 | "libwebp-encode", |
| 145 | ], |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 146 | group_static_libs: true, |
| 147 | } |
| 148 | |
| 149 | cc_defaults { |
| 150 | name: "skia_tool_deps", |
| 151 | defaults: [ |
Pirama Arumuga Nainar | de2b95e | 2017-12-13 11:07:39 -0800 | [diff] [blame] | 152 | "skia_deps", |
| 153 | "skia_pgo_no_profile_use" |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 154 | ], |
| 155 | static_libs: [ |
| 156 | "libjsoncpp", |
| 157 | "libskia", |
| 158 | ], |
| 159 | cflags: [ |
Derek Sollenberger | 1821a5b | 2018-09-11 14:48:36 -0400 | [diff] [blame] | 160 | "-Wno-implicit-fallthrough", |
Derek Sollenberger | 9a72ae1 | 2017-12-14 13:01:30 -0500 | [diff] [blame] | 161 | "-Wno-unused-parameter", |
| 162 | "-Wno-unused-variable", |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 163 | ], |
Leon Scroggins III | 6ccd2ca | 2017-01-26 17:21:27 -0500 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | cc_test { |
| 167 | name: "skia_dm", |
| 168 | |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 169 | defaults: [ |
| 170 | "skia_tool_deps" |
Leon Scroggins III | 6ccd2ca | 2017-01-26 17:21:27 -0500 | [diff] [blame] | 171 | ], |
| 172 | |
| 173 | local_include_dirs: [ |
| 174 | $dm_includes |
| 175 | ], |
| 176 | |
| 177 | srcs: [ |
| 178 | $dm_srcs |
| 179 | ], |
Dongwon Kang | 0c7861f | 2018-02-16 10:55:21 -0800 | [diff] [blame] | 180 | |
| 181 | shared_libs: [ |
| 182 | "libbinder", |
| 183 | "libutils", |
| 184 | ], |
Leon Scroggins III | 6ccd2ca | 2017-01-26 17:21:27 -0500 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | cc_test { |
| 188 | name: "skia_nanobench", |
| 189 | |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 190 | defaults: [ |
| 191 | "skia_tool_deps" |
Leon Scroggins III | 6ccd2ca | 2017-01-26 17:21:27 -0500 | [diff] [blame] | 192 | ], |
| 193 | |
| 194 | local_include_dirs: [ |
| 195 | $nanobench_includes |
| 196 | ], |
| 197 | |
| 198 | srcs: [ |
| 199 | $nanobench_srcs |
| 200 | ], |
Pirama Arumuga Nainar | 68c3fac | 2018-01-09 21:05:55 -0800 | [diff] [blame] | 201 | |
| 202 | data: [ |
| 203 | "resources/*", |
| 204 | ], |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 205 | }''') |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 206 | |
| 207 | # We'll run GN to get the main source lists and include directories for Skia. |
| 208 | gn_args = { |
Leon Scroggins III | be85c19 | 2018-11-13 13:50:12 -0500 | [diff] [blame] | 209 | '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 Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 218 | } |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 219 | |
Hal Canary | 23564b9 | 2018-09-07 14:33:14 -0400 | [diff] [blame] | 220 | extra_userconfig_defines = [ |
Hal Canary | 23564b9 | 2018-09-07 14:33:14 -0400 | [diff] [blame] | 221 | ] |
| 222 | |
Derek Sollenberger | 5d3f770 | 2018-02-01 09:22:53 -0500 | [diff] [blame] | 223 | js = gn_to_bp_utils.GenerateJSONFromGN(gn_args) |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 224 | |
| 225 | def strip_slashes(lst): |
Ben Wagner | e127523 | 2017-02-23 18:00:06 -0500 | [diff] [blame] | 226 | return {str(p.lstrip('/')) for p in lst} |
Mike Klein | 27eb22b | 2016-12-07 12:27:56 -0500 | [diff] [blame] | 227 | |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 228 | srcs = strip_slashes(js['targets']['//:skia']['sources']) |
Leon Scroggins III | 981a31e | 2017-10-06 11:53:53 -0400 | [diff] [blame] | 229 | cflags = strip_slashes(js['targets']['//:skia']['cflags']) |
| 230 | cflags_cc = strip_slashes(js['targets']['//:skia']['cflags_cc']) |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 231 | local_includes = strip_slashes(js['targets']['//:skia']['include_dirs']) |
| 232 | export_includes = strip_slashes(js['targets']['//:public']['include_dirs']) |
Derek Sollenberger | 5d3f770 | 2018-02-01 09:22:53 -0500 | [diff] [blame] | 233 | defines = [str(d) for d in js['targets']['//:skia']['defines']] |
Hal Canary | 23564b9 | 2018-09-07 14:33:14 -0400 | [diff] [blame] | 234 | defines += extra_userconfig_defines |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 235 | |
Leon Scroggins III | 6ccd2ca | 2017-01-26 17:21:27 -0500 | [diff] [blame] | 236 | dm_srcs = strip_slashes(js['targets']['//:dm']['sources']) |
| 237 | dm_includes = strip_slashes(js['targets']['//:dm']['include_dirs']) |
| 238 | |
| 239 | nanobench_target = js['targets']['//:nanobench'] |
| 240 | nanobench_srcs = strip_slashes(nanobench_target['sources']) |
| 241 | nanobench_includes = strip_slashes(nanobench_target['include_dirs']) |
| 242 | |
Derek Sollenberger | 5d3f770 | 2018-02-01 09:22:53 -0500 | [diff] [blame] | 243 | gn_to_bp_utils.GrabDependentValues(js, '//:skia', 'sources', srcs, None) |
| 244 | gn_to_bp_utils.GrabDependentValues(js, '//:dm', 'sources', dm_srcs, 'skia') |
| 245 | gn_to_bp_utils.GrabDependentValues(js, '//:nanobench', 'sources', |
| 246 | nanobench_srcs, 'skia') |
Mike Klein | 27eb22b | 2016-12-07 12:27:56 -0500 | [diff] [blame] | 247 | |
Mike Klein | f536c45 | 2018-05-01 10:36:42 -0400 | [diff] [blame] | 248 | # skcms is a little special, kind of a second-party library. |
Mike Klein | f536c45 | 2018-05-01 10:36:42 -0400 | [diff] [blame] | 249 | local_includes.add("third_party/skcms") |
| 250 | dm_includes .add("third_party/skcms") |
| 251 | |
Greg Daniel | 18dbfd0 | 2018-05-29 10:46:51 -0400 | [diff] [blame] | 252 | # 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. |
| 254 | srcs.add("third_party/vulkanmemoryallocator/GrVulkanMemoryAllocator.cpp") |
| 255 | local_includes.add("third_party/vulkanmemoryallocator/") |
| 256 | |
Mike Klein | d505b19 | 2018-09-05 15:55:25 -0400 | [diff] [blame] | 257 | # Android's build will choke if we list headers. |
| 258 | def strip_headers(sources): |
| 259 | return {s for s in sources if not s.endswith('.h')} |
| 260 | |
| 261 | srcs = strip_headers(srcs) |
| 262 | dm_srcs = strip_headers(dm_srcs) |
| 263 | nanobench_srcs = strip_headers(nanobench_srcs) |
Mike Klein | 27eb22b | 2016-12-07 12:27:56 -0500 | [diff] [blame] | 264 | |
Derek Sollenberger | 5d3f770 | 2018-02-01 09:22:53 -0500 | [diff] [blame] | 265 | cflags = gn_to_bp_utils.CleanupCFlags(cflags) |
| 266 | cflags_cc = gn_to_bp_utils.CleanupCCFlags(cflags_cc) |
Leon Scroggins III | 981a31e | 2017-10-06 11:53:53 -0400 | [diff] [blame] | 267 | |
Leon Scroggins III | 4f8a467 | 2016-12-19 09:32:21 -0500 | [diff] [blame] | 268 | here = os.path.dirname(__file__) |
Derek Sollenberger | 5d3f770 | 2018-02-01 09:22:53 -0500 | [diff] [blame] | 269 | defs = gn_to_bp_utils.GetArchSources(os.path.join(here, 'opts.gni')) |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 270 | |
Derek Sollenberger | 5d3f770 | 2018-02-01 09:22:53 -0500 | [diff] [blame] | 271 | gn_to_bp_utils.WriteUserConfig('include/config/SkUserConfig.h', defines) |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 272 | |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 273 | # Turn a list of strings into the style bpfmt outputs. |
Leon Scroggins III | 6ccd2ca | 2017-01-26 17:21:27 -0500 | [diff] [blame] | 274 | def bpfmt(indent, lst, sort=True): |
| 275 | if sort: |
| 276 | lst = sorted(lst) |
| 277 | return ('\n' + ' '*indent).join('"%s",' % v for v in lst) |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 278 | |
| 279 | # OK! We have everything to fill in Android.bp... |
| 280 | with open('Android.bp', 'w') as f: |
| 281 | print >>f, bp.substitute({ |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 282 | 'export_includes': bpfmt(8, export_includes), |
| 283 | 'local_includes': bpfmt(8, local_includes), |
| 284 | 'srcs': bpfmt(8, srcs), |
Leon Scroggins III | 981a31e | 2017-10-06 11:53:53 -0400 | [diff] [blame] | 285 | 'cflags': bpfmt(8, cflags, False), |
| 286 | 'cflags_cc': bpfmt(8, cflags_cc), |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 287 | |
Mike Klein | d505b19 | 2018-09-05 15:55:25 -0400 | [diff] [blame] | 288 | '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 III | 6ccd2ca | 2017-01-26 17:21:27 -0500 | [diff] [blame] | 299 | |
Leon Scroggins III | 6ccd2ca | 2017-01-26 17:21:27 -0500 | [diff] [blame] | 300 | '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 Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 305 | }) |