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 | |
Martin Vejdarski | beaaf47 | 2020-03-03 13:53:20 +0700 | [diff] [blame] | 10 | from __future__ import print_function |
| 11 | |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 12 | import os |
| 13 | import pprint |
| 14 | import string |
| 15 | import subprocess |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 16 | import tempfile |
| 17 | |
Derek Sollenberger | 5d3f770 | 2018-02-01 09:22:53 -0500 | [diff] [blame] | 18 | import gn_to_bp_utils |
| 19 | |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 20 | # First we start off with a template for Android.bp, |
| 21 | # with holes for source lists and include directories. |
| 22 | bp = string.Template('''// This file is autogenerated by gn_to_bp.py. |
Martin Stjernholm | b4382ce | 2020-11-10 22:53:19 +0000 | [diff] [blame] | 23 | // To make changes to this file, follow the instructions on skia.org for |
| 24 | // downloading Skia and submitting changes. Modify gn_to_bp.py (or the build |
| 25 | // files it uses) and submit. The autoroller will then create the updated |
| 26 | // Android.bp. Or ask a Skia engineer for help. |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 27 | |
Leon Scroggins | d87a98f | 2021-04-30 15:12:36 -0400 | [diff] [blame] | 28 | package { |
| 29 | default_applicable_licenses: ["external_skia_license"], |
| 30 | } |
| 31 | |
| 32 | // Added automatically by a large-scale-change that took the approach of |
| 33 | // 'apply every license found to every target'. While this makes sure we respect |
| 34 | // every license restriction, it may not be entirely correct. |
| 35 | // |
| 36 | // e.g. GPL in an MIT project might only apply to the contrib/ directory. |
| 37 | // |
| 38 | // Please consider splitting the single license below into multiple licenses, |
| 39 | // taking care not to lose any license_kind information, and overriding the |
| 40 | // default license using the 'licenses: [...]' property on targets as needed. |
| 41 | // |
| 42 | // For unused files, consider creating a 'fileGroup' with "//visibility:private" |
| 43 | // to attach the license to, and including a comment whether the files may be |
| 44 | // used in the current project. |
| 45 | // |
| 46 | // large-scale-change included anything that looked like it might be a license |
| 47 | // text as a license_text. e.g. LICENSE, NOTICE, COPYING etc. |
| 48 | // |
| 49 | // Please consider removing redundant or irrelevant files from 'license_text:'. |
| 50 | // |
| 51 | // large-scale-change filtered out the below license kinds as false-positives: |
| 52 | // SPDX-license-identifier-CC-BY-NC |
| 53 | // SPDX-license-identifier-GPL-2.0 |
| 54 | // SPDX-license-identifier-LGPL-2.1 |
| 55 | // SPDX-license-identifier-OFL:by_exception_only |
| 56 | // See: http://go/android-license-faq |
| 57 | license { |
| 58 | name: "external_skia_license", |
| 59 | visibility: [":__subpackages__"], |
| 60 | license_kinds: [ |
| 61 | "SPDX-license-identifier-Apache-2.0", |
| 62 | "SPDX-license-identifier-BSD", |
| 63 | "SPDX-license-identifier-CC0-1.0", |
| 64 | "SPDX-license-identifier-FTL", |
| 65 | "SPDX-license-identifier-MIT", |
| 66 | "SPDX-license-identifier-MPL", |
| 67 | "legacy_unencumbered", |
| 68 | ], |
| 69 | license_text: [ |
| 70 | "LICENSE", |
| 71 | "NOTICE", |
| 72 | ], |
| 73 | } |
| 74 | |
Leon Scroggins III | 6c41bf5 | 2021-01-29 15:33:00 -0500 | [diff] [blame] | 75 | cc_defaults { |
| 76 | name: "skia_defaults", |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 77 | cflags: [ |
Leon Scroggins III | 981a31e | 2017-10-06 11:53:53 -0400 | [diff] [blame] | 78 | $cflags |
| 79 | ], |
| 80 | |
| 81 | cppflags:[ |
| 82 | $cflags_cc |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 83 | ], |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 84 | |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 85 | export_include_dirs: [ |
| 86 | $export_includes |
| 87 | ], |
Mike Klein | 27eb22b | 2016-12-07 12:27:56 -0500 | [diff] [blame] | 88 | |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 89 | local_include_dirs: [ |
| 90 | $local_includes |
| 91 | ], |
Mike Klein | 27eb22b | 2016-12-07 12:27:56 -0500 | [diff] [blame] | 92 | |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 93 | arch: { |
| 94 | arm: { |
| 95 | srcs: [ |
| 96 | $arm_srcs |
| 97 | ], |
Mike Klein | 27eb22b | 2016-12-07 12:27:56 -0500 | [diff] [blame] | 98 | |
Leon Scroggins III | f7332d3 | 2017-08-10 09:09:54 -0400 | [diff] [blame] | 99 | neon: { |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 100 | srcs: [ |
| 101 | $arm_neon_srcs |
| 102 | ], |
| 103 | }, |
| 104 | }, |
| 105 | |
| 106 | arm64: { |
| 107 | srcs: [ |
| 108 | $arm64_srcs |
| 109 | ], |
| 110 | }, |
| 111 | |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 112 | x86: { |
| 113 | srcs: [ |
| 114 | $x86_srcs |
| 115 | ], |
| 116 | }, |
| 117 | |
| 118 | x86_64: { |
| 119 | srcs: [ |
| 120 | $x86_srcs |
| 121 | ], |
| 122 | }, |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 123 | }, |
Mike Klein | 27eb22b | 2016-12-07 12:27:56 -0500 | [diff] [blame] | 124 | |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 125 | target: { |
| 126 | android: { |
| 127 | srcs: [ |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 128 | "third_party/vulkanmemoryallocator/GrVulkanMemoryAllocator.cpp", |
| 129 | ], |
| 130 | local_include_dirs: [ |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 131 | "third_party/vulkanmemoryallocator/", |
| 132 | ], |
Leon Scroggins III | 6c41bf5 | 2021-01-29 15:33:00 -0500 | [diff] [blame] | 133 | }, |
| 134 | }, |
| 135 | } |
| 136 | |
| 137 | cc_library_static { |
| 138 | // Smaller version of Skia, without e.g. codecs, intended for use by RenderEngine. |
| 139 | name: "libskia_renderengine", |
| 140 | defaults: ["skia_defaults", |
| 141 | "skia_renderengine_deps"], |
| 142 | srcs: [ |
| 143 | $renderengine_srcs |
| 144 | ], |
| 145 | local_include_dirs: [ |
| 146 | "renderengine", |
| 147 | ], |
| 148 | export_include_dirs: [ |
| 149 | "renderengine", |
| 150 | ], |
| 151 | } |
| 152 | |
| 153 | cc_library_static { |
| 154 | name: "libskia", |
| 155 | host_supported: true, |
| 156 | cppflags:[ |
| 157 | // Exceptions are necessary for SkRawCodec. |
| 158 | // FIXME: Should we split SkRawCodec into a separate target so the rest |
| 159 | // of Skia need not be compiled with exceptions? |
| 160 | "-fexceptions", |
| 161 | ], |
| 162 | |
| 163 | srcs: [ |
| 164 | $srcs |
| 165 | ], |
| 166 | |
| 167 | target: { |
| 168 | android: { |
| 169 | srcs: [ |
| 170 | $android_srcs |
| 171 | ], |
| 172 | local_include_dirs: [ |
| 173 | "android", |
| 174 | ], |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 175 | export_include_dirs: [ |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 176 | "android", |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 177 | ], |
| 178 | }, |
| 179 | linux_glibc: { |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 180 | srcs: [ |
| 181 | $linux_srcs |
| 182 | ], |
| 183 | local_include_dirs: [ |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 184 | "linux", |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 185 | ], |
| 186 | export_include_dirs: [ |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 187 | "linux", |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 188 | ], |
| 189 | }, |
Leon Scroggins III | 85e22fc | 2018-11-28 08:58:47 -0500 | [diff] [blame] | 190 | darwin: { |
Leon Scroggins III | 85e22fc | 2018-11-28 08:58:47 -0500 | [diff] [blame] | 191 | srcs: [ |
| 192 | $mac_srcs |
| 193 | ], |
| 194 | local_include_dirs: [ |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 195 | "mac", |
Leon Scroggins III | 85e22fc | 2018-11-28 08:58:47 -0500 | [diff] [blame] | 196 | ], |
| 197 | export_include_dirs: [ |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 198 | "mac", |
Leon Scroggins III | 85e22fc | 2018-11-28 08:58:47 -0500 | [diff] [blame] | 199 | ], |
| 200 | }, |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 201 | windows: { |
Martin Stjernholm | b4382ce | 2020-11-10 22:53:19 +0000 | [diff] [blame] | 202 | enabled: true, |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 203 | cflags: [ |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 204 | "-Wno-unknown-pragmas", |
| 205 | ], |
| 206 | srcs: [ |
| 207 | $win_srcs |
| 208 | ], |
| 209 | local_include_dirs: [ |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 210 | "win", |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 211 | ], |
| 212 | export_include_dirs: [ |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 213 | "win", |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 214 | ], |
| 215 | }, |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 216 | }, |
| 217 | |
Zhizhou Yang | e18b779 | 2017-12-11 10:37:44 -0800 | [diff] [blame] | 218 | defaults: ["skia_deps", |
| 219 | "skia_pgo", |
Leon Scroggins III | 6c41bf5 | 2021-01-29 15:33:00 -0500 | [diff] [blame] | 220 | "skia_defaults", |
Zhizhou Yang | e18b779 | 2017-12-11 10:37:44 -0800 | [diff] [blame] | 221 | ], |
| 222 | } |
| 223 | |
| 224 | // Build libskia with PGO by default. |
| 225 | // Location of PGO profile data is defined in build/soong/cc/pgo.go |
| 226 | // and is separate from skia. |
| 227 | // To turn it off, set ANDROID_PGO_NO_PROFILE_USE environment variable |
| 228 | // or set enable_profile_use property to false. |
| 229 | cc_defaults { |
| 230 | name: "skia_pgo", |
| 231 | pgo: { |
| 232 | instrumentation: true, |
Pirama Arumuga Nainar | 068ccaa | 2018-03-05 10:20:38 -0800 | [diff] [blame] | 233 | profile_file: "hwui/hwui.profdata", |
Zhizhou Yang | e18b779 | 2017-12-11 10:37:44 -0800 | [diff] [blame] | 234 | benchmarks: ["hwui", "skia"], |
Pirama Arumuga Nainar | 068ccaa | 2018-03-05 10:20:38 -0800 | [diff] [blame] | 235 | enable_profile_use: true, |
Zhizhou Yang | e18b779 | 2017-12-11 10:37:44 -0800 | [diff] [blame] | 236 | }, |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 237 | } |
| 238 | |
Pirama Arumuga Nainar | de2b95e | 2017-12-13 11:07:39 -0800 | [diff] [blame] | 239 | // "defaults" property to disable profile use for Skia tools and benchmarks. |
| 240 | cc_defaults { |
| 241 | name: "skia_pgo_no_profile_use", |
| 242 | defaults: [ |
| 243 | "skia_pgo", |
| 244 | ], |
| 245 | pgo: { |
| 246 | enable_profile_use: false, |
| 247 | }, |
| 248 | } |
| 249 | |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 250 | cc_defaults { |
Leon Scroggins III | 6c41bf5 | 2021-01-29 15:33:00 -0500 | [diff] [blame] | 251 | // Subset of the larger "skia_deps", which includes only the dependencies |
| 252 | // needed for libskia_renderengine. Note that it includes libpng and libz |
| 253 | // for the purposes of MSKP captures, but we could instead leave it up to |
| 254 | // RenderEngine to provide its own SkSerializerProcs if another client |
| 255 | // wants an even smaller version of libskia. |
| 256 | name: "skia_renderengine_deps", |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 257 | shared_libs: [ |
Jerome Gaillard | e80251a | 2020-10-27 13:35:00 +0000 | [diff] [blame] | 258 | "libcutils", |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 259 | "liblog", |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 260 | "libpng", |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 261 | "libz", |
| 262 | ], |
| 263 | static_libs: [ |
Matt Sarett | a309109 | 2017-02-20 12:50:52 -0500 | [diff] [blame] | 264 | "libarect", |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 265 | ], |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 266 | group_static_libs: true, |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 267 | target: { |
| 268 | android: { |
| 269 | shared_libs: [ |
| 270 | "libEGL", |
| 271 | "libGLESv2", |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 272 | "libvulkan", |
| 273 | "libnativewindow", |
| 274 | ], |
Stan Iliev | 12b8916 | 2019-03-11 13:33:02 -0400 | [diff] [blame] | 275 | export_shared_lib_headers: [ |
| 276 | "libvulkan", |
| 277 | ], |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 278 | }, |
Leon Scroggins III | 6c41bf5 | 2021-01-29 15:33:00 -0500 | [diff] [blame] | 279 | }, |
| 280 | } |
| 281 | |
| 282 | cc_defaults { |
| 283 | name: "skia_deps", |
| 284 | defaults: ["skia_renderengine_deps"], |
| 285 | shared_libs: [ |
| 286 | "libdng_sdk", |
| 287 | "libjpeg", |
| 288 | "libpiex", |
| 289 | "libexpat", |
| 290 | "libft2", |
| 291 | ], |
| 292 | static_libs: [ |
| 293 | "libwebp-decode", |
| 294 | "libwebp-encode", |
| 295 | "libsfntly", |
| 296 | ], |
| 297 | target: { |
| 298 | android: { |
| 299 | shared_libs: [ |
| 300 | "libheif", |
| 301 | ], |
| 302 | }, |
Leon Scroggins III | 85e22fc | 2018-11-28 08:58:47 -0500 | [diff] [blame] | 303 | darwin: { |
| 304 | host_ldlibs: [ |
| 305 | "-framework AppKit", |
| 306 | ], |
| 307 | }, |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 308 | windows: { |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 309 | host_ldlibs: [ |
| 310 | "-lgdi32", |
| 311 | "-loleaut32", |
| 312 | "-lole32", |
| 313 | "-lopengl32", |
| 314 | "-luuid", |
| 315 | "-lwindowscodecs", |
| 316 | ], |
| 317 | }, |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 318 | }, |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | cc_defaults { |
| 322 | name: "skia_tool_deps", |
| 323 | defaults: [ |
Pirama Arumuga Nainar | de2b95e | 2017-12-13 11:07:39 -0800 | [diff] [blame] | 324 | "skia_deps", |
| 325 | "skia_pgo_no_profile_use" |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 326 | ], |
Mike Reed | 579c295 | 2020-05-27 16:49:23 -0400 | [diff] [blame] | 327 | shared_libs: [ |
Victor Chang | 6bd4d1c | 2020-11-23 19:26:59 +0000 | [diff] [blame] | 328 | "libicu", |
Mike Reed | 579c295 | 2020-05-27 16:49:23 -0400 | [diff] [blame] | 329 | "libharfbuzz_ng", |
| 330 | ], |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 331 | static_libs: [ |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 332 | "libskia", |
| 333 | ], |
| 334 | cflags: [ |
Mike Reed | 579c295 | 2020-05-27 16:49:23 -0400 | [diff] [blame] | 335 | "-DSK_SHAPER_HARFBUZZ_AVAILABLE", |
Julia Lavrova | 1798f4f | 2020-08-26 14:22:48 +0000 | [diff] [blame] | 336 | "-DSK_UNICODE_AVAILABLE", |
Derek Sollenberger | 1821a5b | 2018-09-11 14:48:36 -0400 | [diff] [blame] | 337 | "-Wno-implicit-fallthrough", |
Derek Sollenberger | 9a72ae1 | 2017-12-14 13:01:30 -0500 | [diff] [blame] | 338 | "-Wno-unused-parameter", |
| 339 | "-Wno-unused-variable", |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 340 | ], |
Martin Stjernholm | b4382ce | 2020-11-10 22:53:19 +0000 | [diff] [blame] | 341 | target: { |
| 342 | windows: { |
| 343 | enabled: true, |
| 344 | }, |
| 345 | }, |
Leon Scroggins III | 6ccd2ca | 2017-01-26 17:21:27 -0500 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | cc_test { |
| 349 | name: "skia_dm", |
| 350 | |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 351 | defaults: [ |
| 352 | "skia_tool_deps" |
Leon Scroggins III | 6ccd2ca | 2017-01-26 17:21:27 -0500 | [diff] [blame] | 353 | ], |
| 354 | |
| 355 | local_include_dirs: [ |
| 356 | $dm_includes |
| 357 | ], |
| 358 | |
| 359 | srcs: [ |
| 360 | $dm_srcs |
| 361 | ], |
Dongwon Kang | 0c7861f | 2018-02-16 10:55:21 -0800 | [diff] [blame] | 362 | |
| 363 | shared_libs: [ |
| 364 | "libbinder", |
| 365 | "libutils", |
| 366 | ], |
Leon Scroggins III | 6ccd2ca | 2017-01-26 17:21:27 -0500 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | cc_test { |
| 370 | name: "skia_nanobench", |
| 371 | |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 372 | defaults: [ |
| 373 | "skia_tool_deps" |
Leon Scroggins III | 6ccd2ca | 2017-01-26 17:21:27 -0500 | [diff] [blame] | 374 | ], |
| 375 | |
| 376 | local_include_dirs: [ |
| 377 | $nanobench_includes |
| 378 | ], |
| 379 | |
| 380 | srcs: [ |
| 381 | $nanobench_srcs |
| 382 | ], |
Pirama Arumuga Nainar | 68c3fac | 2018-01-09 21:05:55 -0800 | [diff] [blame] | 383 | |
| 384 | data: [ |
Pirama Arumuga Nainar | 5be3c13 | 2019-09-30 17:18:02 -0700 | [diff] [blame] | 385 | "resources/**/*", |
Pirama Arumuga Nainar | 68c3fac | 2018-01-09 21:05:55 -0800 | [diff] [blame] | 386 | ], |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 387 | }''') |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 388 | |
| 389 | # We'll run GN to get the main source lists and include directories for Skia. |
Leon Scroggins III | 6c41bf5 | 2021-01-29 15:33:00 -0500 | [diff] [blame] | 390 | def generate_args(target_os, enable_gpu, renderengine = False): |
Leon Scroggins III | a55445e | 2018-11-28 16:09:35 -0500 | [diff] [blame] | 391 | d = { |
Ben Wagner | 75626e4 | 2020-06-03 13:20:37 -0400 | [diff] [blame] | 392 | 'is_official_build': 'true', |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 393 | |
Leon Scroggins III | a55445e | 2018-11-28 16:09:35 -0500 | [diff] [blame] | 394 | # gn_to_bp_utils' GetArchSources will take care of architecture-specific |
| 395 | # files. |
Ben Wagner | 75626e4 | 2020-06-03 13:20:37 -0400 | [diff] [blame] | 396 | 'target_cpu': '"none"', |
Hal Canary | 23564b9 | 2018-09-07 14:33:14 -0400 | [diff] [blame] | 397 | |
Leon Scroggins III | a55445e | 2018-11-28 16:09:35 -0500 | [diff] [blame] | 398 | # Use the custom FontMgr, as the framework will handle fonts. |
Ben Wagner | 75626e4 | 2020-06-03 13:20:37 -0400 | [diff] [blame] | 399 | 'skia_enable_fontmgr_custom_directory': 'false', |
| 400 | 'skia_enable_fontmgr_custom_embedded': 'false', |
Ben Wagner | 75626e4 | 2020-06-03 13:20:37 -0400 | [diff] [blame] | 401 | 'skia_enable_fontmgr_android': 'false', |
| 402 | 'skia_enable_fontmgr_win': 'false', |
| 403 | 'skia_enable_fontmgr_win_gdi': 'false', |
| 404 | 'skia_use_fonthost_mac': 'false', |
Leon Scroggins III | a55445e | 2018-11-28 16:09:35 -0500 | [diff] [blame] | 405 | |
Nathaniel Nifong | 60c37e7 | 2019-10-16 11:21:47 -0400 | [diff] [blame] | 406 | # enable features used in skia_nanobench |
Ben Wagner | 75626e4 | 2020-06-03 13:20:37 -0400 | [diff] [blame] | 407 | 'skia_tools_require_resources': 'true', |
Nathaniel Nifong | 60c37e7 | 2019-10-16 11:21:47 -0400 | [diff] [blame] | 408 | |
Ben Wagner | 75626e4 | 2020-06-03 13:20:37 -0400 | [diff] [blame] | 409 | 'skia_use_fontconfig': 'false', |
Ben Wagner | 75626e4 | 2020-06-03 13:20:37 -0400 | [diff] [blame] | 410 | 'skia_include_multiframe_procs': 'false', |
| 411 | 'skia_libgifcodec_path': '"third_party/libgifcodec"', |
Leon Scroggins III | a55445e | 2018-11-28 16:09:35 -0500 | [diff] [blame] | 412 | } |
| 413 | d['target_os'] = target_os |
| 414 | if target_os == '"android"': |
| 415 | d['skia_enable_tools'] = 'true' |
Nathaniel Nifong | 0c4fbf1 | 2019-06-25 15:48:47 -0400 | [diff] [blame] | 416 | d['skia_include_multiframe_procs'] = 'true' |
Leon Scroggins III | a55445e | 2018-11-28 16:09:35 -0500 | [diff] [blame] | 417 | |
| 418 | if enable_gpu: |
| 419 | d['skia_use_vulkan'] = 'true' |
| 420 | else: |
| 421 | d['skia_use_vulkan'] = 'false' |
| 422 | d['skia_enable_gpu'] = 'false' |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 423 | |
| 424 | if target_os == '"win"': |
| 425 | # The Android Windows build system does not provide FontSub.h |
| 426 | d['skia_use_xps'] = 'false' |
| 427 | |
| 428 | # BUILDCONFIG.gn expects these to be set when building for Windows, but |
| 429 | # we're just creating Android.bp, so we don't need them. Populate with |
Kevin Lubick | 2266380 | 2021-01-29 11:05:41 -0500 | [diff] [blame] | 430 | # some placeholder values. |
| 431 | d['win_vc'] = '"placeholder_version"' |
| 432 | d['win_sdk_version'] = '"placeholder_version"' |
| 433 | d['win_toolchain_version'] = '"placeholder_version"' |
Leon Scroggins III | 6c41bf5 | 2021-01-29 15:33:00 -0500 | [diff] [blame] | 434 | |
| 435 | if target_os == '"android"' and not renderengine: |
| 436 | d['skia_use_libheif'] = 'true' |
| 437 | else: |
| 438 | d['skia_use_libheif'] = 'false' |
| 439 | |
| 440 | if renderengine: |
| 441 | d['skia_use_libpng_decode'] = 'false' |
| 442 | d['skia_use_libjpeg_turbo_decode'] = 'false' |
| 443 | d['skia_use_libjpeg_turbo_encode'] = 'false' |
| 444 | d['skia_use_libwebp_decode'] = 'false' |
| 445 | d['skia_use_libwebp_encode'] = 'false' |
| 446 | d['skia_use_libgifcodec'] = 'false' |
| 447 | d['skia_enable_pdf'] = 'false' |
| 448 | d['skia_use_freetype'] = 'false' |
| 449 | d['skia_use_fixed_gamma_text'] = 'false' |
| 450 | d['skia_use_expat'] = 'false' |
| 451 | d['skia_enable_fontmgr_custom_empty'] = 'false' |
| 452 | else: |
| 453 | d['skia_enable_android_utils'] = 'true' |
| 454 | d['skia_use_freetype'] = 'true' |
| 455 | d['skia_use_fixed_gamma_text'] = 'true' |
| 456 | d['skia_enable_fontmgr_custom_empty'] = 'true' |
| 457 | |
Leon Scroggins III | a55445e | 2018-11-28 16:09:35 -0500 | [diff] [blame] | 458 | return d |
| 459 | |
| 460 | gn_args = generate_args('"android"', True) |
| 461 | gn_args_linux = generate_args('"linux"', False) |
| 462 | gn_args_mac = generate_args('"mac"', False) |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 463 | gn_args_win = generate_args('"win"', False) |
Leon Scroggins III | 6c41bf5 | 2021-01-29 15:33:00 -0500 | [diff] [blame] | 464 | gn_args_renderengine = generate_args('"android"', True, True) |
Leon Scroggins III | 85e22fc | 2018-11-28 08:58:47 -0500 | [diff] [blame] | 465 | |
Derek Sollenberger | 5d3f770 | 2018-02-01 09:22:53 -0500 | [diff] [blame] | 466 | js = gn_to_bp_utils.GenerateJSONFromGN(gn_args) |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 467 | |
| 468 | def strip_slashes(lst): |
Ben Wagner | e127523 | 2017-02-23 18:00:06 -0500 | [diff] [blame] | 469 | return {str(p.lstrip('/')) for p in lst} |
Mike Klein | 27eb22b | 2016-12-07 12:27:56 -0500 | [diff] [blame] | 470 | |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 471 | android_srcs = strip_slashes(js['targets']['//:skia']['sources']) |
Leon Scroggins III | 981a31e | 2017-10-06 11:53:53 -0400 | [diff] [blame] | 472 | cflags = strip_slashes(js['targets']['//:skia']['cflags']) |
| 473 | cflags_cc = strip_slashes(js['targets']['//:skia']['cflags_cc']) |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 474 | local_includes = strip_slashes(js['targets']['//:skia']['include_dirs']) |
| 475 | export_includes = strip_slashes(js['targets']['//:public']['include_dirs']) |
| 476 | |
Leon Scroggins III | 6ccd2ca | 2017-01-26 17:21:27 -0500 | [diff] [blame] | 477 | dm_srcs = strip_slashes(js['targets']['//:dm']['sources']) |
| 478 | dm_includes = strip_slashes(js['targets']['//:dm']['include_dirs']) |
| 479 | |
| 480 | nanobench_target = js['targets']['//:nanobench'] |
| 481 | nanobench_srcs = strip_slashes(nanobench_target['sources']) |
| 482 | nanobench_includes = strip_slashes(nanobench_target['include_dirs']) |
| 483 | |
Derek Sollenberger | 5d3f770 | 2018-02-01 09:22:53 -0500 | [diff] [blame] | 484 | gn_to_bp_utils.GrabDependentValues(js, '//:dm', 'sources', dm_srcs, 'skia') |
| 485 | gn_to_bp_utils.GrabDependentValues(js, '//:nanobench', 'sources', |
| 486 | nanobench_srcs, 'skia') |
Mike Klein | 27eb22b | 2016-12-07 12:27:56 -0500 | [diff] [blame] | 487 | |
Mike Klein | f536c45 | 2018-05-01 10:36:42 -0400 | [diff] [blame] | 488 | # skcms is a little special, kind of a second-party library. |
Brian Osman | 35ea04d | 2019-05-01 11:03:36 -0400 | [diff] [blame] | 489 | local_includes.add("include/third_party/skcms") |
| 490 | dm_includes .add("include/third_party/skcms") |
Mike Klein | f536c45 | 2018-05-01 10:36:42 -0400 | [diff] [blame] | 491 | |
Mike Klein | d505b19 | 2018-09-05 15:55:25 -0400 | [diff] [blame] | 492 | # Android's build will choke if we list headers. |
| 493 | def strip_headers(sources): |
| 494 | return {s for s in sources if not s.endswith('.h')} |
| 495 | |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 496 | gn_to_bp_utils.GrabDependentValues(js, '//:skia', 'sources', android_srcs, None) |
| 497 | android_srcs = strip_headers(android_srcs) |
| 498 | |
| 499 | js_linux = gn_to_bp_utils.GenerateJSONFromGN(gn_args_linux) |
| 500 | linux_srcs = strip_slashes(js_linux['targets']['//:skia']['sources']) |
| 501 | gn_to_bp_utils.GrabDependentValues(js_linux, '//:skia', 'sources', linux_srcs, |
| 502 | None) |
| 503 | linux_srcs = strip_headers(linux_srcs) |
| 504 | |
Leon Scroggins III | 85e22fc | 2018-11-28 08:58:47 -0500 | [diff] [blame] | 505 | js_mac = gn_to_bp_utils.GenerateJSONFromGN(gn_args_mac) |
| 506 | mac_srcs = strip_slashes(js_mac['targets']['//:skia']['sources']) |
| 507 | gn_to_bp_utils.GrabDependentValues(js_mac, '//:skia', 'sources', mac_srcs, |
| 508 | None) |
| 509 | mac_srcs = strip_headers(mac_srcs) |
| 510 | |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 511 | js_win = gn_to_bp_utils.GenerateJSONFromGN(gn_args_win) |
| 512 | win_srcs = strip_slashes(js_win['targets']['//:skia']['sources']) |
| 513 | gn_to_bp_utils.GrabDependentValues(js_win, '//:skia', 'sources', win_srcs, |
| 514 | None) |
| 515 | win_srcs = strip_headers(win_srcs) |
| 516 | |
Leon Scroggins III | 85e22fc | 2018-11-28 08:58:47 -0500 | [diff] [blame] | 517 | srcs = android_srcs.intersection(linux_srcs).intersection(mac_srcs) |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 518 | srcs = srcs.intersection(win_srcs) |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 519 | android_srcs = android_srcs.difference(srcs) |
| 520 | linux_srcs = linux_srcs.difference(srcs) |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 521 | mac_srcs = mac_srcs.difference(srcs) |
| 522 | win_srcs = win_srcs.difference(srcs) |
Leon Scroggins III | 6c41bf5 | 2021-01-29 15:33:00 -0500 | [diff] [blame] | 523 | |
| 524 | js_renderengine = gn_to_bp_utils.GenerateJSONFromGN(gn_args_renderengine) |
| 525 | renderengine_srcs = strip_slashes( |
| 526 | js_renderengine['targets']['//:skia']['sources']) |
| 527 | gn_to_bp_utils.GrabDependentValues(js_renderengine, '//:skia', 'sources', |
| 528 | renderengine_srcs, None) |
| 529 | renderengine_srcs = strip_headers(renderengine_srcs) |
| 530 | |
Mike Klein | d505b19 | 2018-09-05 15:55:25 -0400 | [diff] [blame] | 531 | dm_srcs = strip_headers(dm_srcs) |
| 532 | nanobench_srcs = strip_headers(nanobench_srcs) |
Mike Klein | 27eb22b | 2016-12-07 12:27:56 -0500 | [diff] [blame] | 533 | |
Derek Sollenberger | 5d3f770 | 2018-02-01 09:22:53 -0500 | [diff] [blame] | 534 | cflags = gn_to_bp_utils.CleanupCFlags(cflags) |
| 535 | cflags_cc = gn_to_bp_utils.CleanupCCFlags(cflags_cc) |
Leon Scroggins III | 981a31e | 2017-10-06 11:53:53 -0400 | [diff] [blame] | 536 | |
Leon Scroggins III | 4f8a467 | 2016-12-19 09:32:21 -0500 | [diff] [blame] | 537 | here = os.path.dirname(__file__) |
Derek Sollenberger | 5d3f770 | 2018-02-01 09:22:53 -0500 | [diff] [blame] | 538 | defs = gn_to_bp_utils.GetArchSources(os.path.join(here, 'opts.gni')) |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 539 | |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 540 | def get_defines(json): |
| 541 | return {str(d) for d in json['targets']['//:skia']['defines']} |
Leon Scroggins III | 6c41bf5 | 2021-01-29 15:33:00 -0500 | [diff] [blame] | 542 | android_defines = get_defines(js) |
| 543 | linux_defines = get_defines(js_linux) |
| 544 | mac_defines = get_defines(js_mac) |
| 545 | win_defines = get_defines(js_win) |
| 546 | renderengine_defines = get_defines(js_renderengine) |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 547 | |
| 548 | def mkdir_if_not_exists(path): |
| 549 | if not os.path.exists(path): |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 550 | os.makedirs(path) |
| 551 | mkdir_if_not_exists('android/include/config/') |
| 552 | mkdir_if_not_exists('linux/include/config/') |
| 553 | mkdir_if_not_exists('mac/include/config/') |
| 554 | mkdir_if_not_exists('win/include/config/') |
Leon Scroggins III | 6c41bf5 | 2021-01-29 15:33:00 -0500 | [diff] [blame] | 555 | mkdir_if_not_exists('renderengine/include/config/') |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 556 | |
| 557 | platforms = { 'IOS', 'MAC', 'WIN', 'ANDROID', 'UNIX' } |
| 558 | |
| 559 | def disallow_platforms(config, desired): |
| 560 | with open(config, 'a') as f: |
| 561 | p = sorted(platforms.difference({ desired })) |
| 562 | s = '#if ' |
| 563 | for i in range(len(p)): |
| 564 | s = s + 'defined(SK_BUILD_FOR_%s)' % p[i] |
| 565 | if i < len(p) - 1: |
| 566 | s += ' || ' |
| 567 | if i % 2 == 1: |
| 568 | s += '\\\n ' |
Martin Vejdarski | beaaf47 | 2020-03-03 13:53:20 +0700 | [diff] [blame] | 569 | print(s, file=f) |
| 570 | print(' #error "Only SK_BUILD_FOR_%s should be defined!"' % desired, file=f) |
| 571 | print('#endif', file=f) |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 572 | |
| 573 | def append_to_file(config, s): |
| 574 | with open(config, 'a') as f: |
Martin Vejdarski | beaaf47 | 2020-03-03 13:53:20 +0700 | [diff] [blame] | 575 | print(s, file=f) |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 576 | |
Leon Scroggins III | 6c41bf5 | 2021-01-29 15:33:00 -0500 | [diff] [blame] | 577 | def write_android_config(config_path, defines): |
| 578 | gn_to_bp_utils.WriteUserConfig(config_path, defines) |
| 579 | append_to_file(config_path, ''' |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 580 | #ifndef SK_BUILD_FOR_ANDROID |
| 581 | #error "SK_BUILD_FOR_ANDROID must be defined!" |
| 582 | #endif''') |
Leon Scroggins III | 6c41bf5 | 2021-01-29 15:33:00 -0500 | [diff] [blame] | 583 | disallow_platforms(config_path, 'ANDROID') |
| 584 | |
| 585 | write_android_config('android/include/config/SkUserConfig.h', android_defines) |
| 586 | write_android_config('renderengine/include/config/SkUserConfig.h', renderengine_defines) |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 587 | |
Leon Scroggins III | 85e22fc | 2018-11-28 08:58:47 -0500 | [diff] [blame] | 588 | def write_config(config_path, defines, platform): |
| 589 | gn_to_bp_utils.WriteUserConfig(config_path, defines) |
| 590 | append_to_file(config_path, ''' |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 591 | // Correct SK_BUILD_FOR flags that may have been set by |
Mike Klein | 81d35a7 | 2020-02-05 10:17:57 -0600 | [diff] [blame] | 592 | // SkTypes.h/Android.bp |
Leon Scroggins III | 85e22fc | 2018-11-28 08:58:47 -0500 | [diff] [blame] | 593 | #ifndef SK_BUILD_FOR_%s |
| 594 | #define SK_BUILD_FOR_%s |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 595 | #endif |
| 596 | #ifdef SK_BUILD_FOR_ANDROID |
| 597 | #undef SK_BUILD_FOR_ANDROID |
Leon Scroggins III | 85e22fc | 2018-11-28 08:58:47 -0500 | [diff] [blame] | 598 | #endif''' % (platform, platform)) |
| 599 | disallow_platforms(config_path, platform) |
| 600 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 601 | write_config('linux/include/config/SkUserConfig.h', linux_defines, 'UNIX') |
| 602 | write_config('mac/include/config/SkUserConfig.h', mac_defines, 'MAC') |
| 603 | write_config('win/include/config/SkUserConfig.h', win_defines, 'WIN') |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 604 | |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 605 | # Turn a list of strings into the style bpfmt outputs. |
Leon Scroggins III | 6ccd2ca | 2017-01-26 17:21:27 -0500 | [diff] [blame] | 606 | def bpfmt(indent, lst, sort=True): |
| 607 | if sort: |
| 608 | lst = sorted(lst) |
| 609 | return ('\n' + ' '*indent).join('"%s",' % v for v in lst) |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 610 | |
| 611 | # OK! We have everything to fill in Android.bp... |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 612 | with open('Android.bp', 'w') as Android_bp: |
Martin Vejdarski | beaaf47 | 2020-03-03 13:53:20 +0700 | [diff] [blame] | 613 | print(bp.substitute({ |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 614 | 'export_includes': bpfmt(8, export_includes), |
| 615 | 'local_includes': bpfmt(8, local_includes), |
| 616 | 'srcs': bpfmt(8, srcs), |
Leon Scroggins III | 981a31e | 2017-10-06 11:53:53 -0400 | [diff] [blame] | 617 | 'cflags': bpfmt(8, cflags, False), |
| 618 | 'cflags_cc': bpfmt(8, cflags_cc), |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 619 | |
Mike Klein | d505b19 | 2018-09-05 15:55:25 -0400 | [diff] [blame] | 620 | 'arm_srcs': bpfmt(16, strip_headers(defs['armv7'])), |
| 621 | 'arm_neon_srcs': bpfmt(20, strip_headers(defs['neon'])), |
| 622 | 'arm64_srcs': bpfmt(16, strip_headers(defs['arm64'] + |
| 623 | defs['crc32'])), |
Mike Klein | d505b19 | 2018-09-05 15:55:25 -0400 | [diff] [blame] | 624 | 'x86_srcs': bpfmt(16, strip_headers(defs['sse2'] + |
| 625 | defs['ssse3'] + |
| 626 | defs['sse41'] + |
| 627 | defs['sse42'] + |
| 628 | defs['avx' ] + |
Mike Klein | ad56c4c | 2020-06-05 06:57:30 -0500 | [diff] [blame] | 629 | defs['hsw' ] + |
| 630 | defs['skx' ])), |
Leon Scroggins III | 6ccd2ca | 2017-01-26 17:21:27 -0500 | [diff] [blame] | 631 | |
Leon Scroggins III | 6ccd2ca | 2017-01-26 17:21:27 -0500 | [diff] [blame] | 632 | 'dm_includes' : bpfmt(8, dm_includes), |
| 633 | 'dm_srcs' : bpfmt(8, dm_srcs), |
| 634 | |
| 635 | 'nanobench_includes' : bpfmt(8, nanobench_includes), |
| 636 | 'nanobench_srcs' : bpfmt(8, nanobench_srcs), |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 637 | |
| 638 | 'android_srcs': bpfmt(10, android_srcs), |
| 639 | 'linux_srcs': bpfmt(10, linux_srcs), |
Leon Scroggins III | 85e22fc | 2018-11-28 08:58:47 -0500 | [diff] [blame] | 640 | 'mac_srcs': bpfmt(10, mac_srcs), |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 641 | 'win_srcs': bpfmt(10, win_srcs), |
Leon Scroggins III | 6c41bf5 | 2021-01-29 15:33:00 -0500 | [diff] [blame] | 642 | |
| 643 | 'renderengine_srcs': bpfmt(8, renderengine_srcs), |
Martin Vejdarski | beaaf47 | 2020-03-03 13:53:20 +0700 | [diff] [blame] | 644 | }), file=Android_bp) |