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: { |
| 180 | cflags: [ |
| 181 | "-mssse3", |
| 182 | ], |
| 183 | srcs: [ |
| 184 | $linux_srcs |
| 185 | ], |
| 186 | local_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 | export_include_dirs: [ |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 190 | "linux", |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 191 | ], |
| 192 | }, |
Leon Scroggins III | 85e22fc | 2018-11-28 08:58:47 -0500 | [diff] [blame] | 193 | darwin: { |
| 194 | cflags: [ |
| 195 | "-mssse3", |
| 196 | ], |
| 197 | srcs: [ |
| 198 | $mac_srcs |
| 199 | ], |
| 200 | local_include_dirs: [ |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 201 | "mac", |
Leon Scroggins III | 85e22fc | 2018-11-28 08:58:47 -0500 | [diff] [blame] | 202 | ], |
| 203 | export_include_dirs: [ |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 204 | "mac", |
Leon Scroggins III | 85e22fc | 2018-11-28 08:58:47 -0500 | [diff] [blame] | 205 | ], |
| 206 | }, |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 207 | windows: { |
Martin Stjernholm | b4382ce | 2020-11-10 22:53:19 +0000 | [diff] [blame] | 208 | enabled: true, |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 209 | cflags: [ |
| 210 | "-mssse3", |
| 211 | "-Wno-unknown-pragmas", |
| 212 | ], |
| 213 | srcs: [ |
| 214 | $win_srcs |
| 215 | ], |
| 216 | local_include_dirs: [ |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 217 | "win", |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 218 | ], |
| 219 | export_include_dirs: [ |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 220 | "win", |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 221 | ], |
| 222 | }, |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 223 | }, |
| 224 | |
Zhizhou Yang | e18b779 | 2017-12-11 10:37:44 -0800 | [diff] [blame] | 225 | defaults: ["skia_deps", |
| 226 | "skia_pgo", |
Leon Scroggins III | 6c41bf5 | 2021-01-29 15:33:00 -0500 | [diff] [blame] | 227 | "skia_defaults", |
Zhizhou Yang | e18b779 | 2017-12-11 10:37:44 -0800 | [diff] [blame] | 228 | ], |
| 229 | } |
| 230 | |
| 231 | // Build libskia with PGO by default. |
| 232 | // Location of PGO profile data is defined in build/soong/cc/pgo.go |
| 233 | // and is separate from skia. |
| 234 | // To turn it off, set ANDROID_PGO_NO_PROFILE_USE environment variable |
| 235 | // or set enable_profile_use property to false. |
| 236 | cc_defaults { |
| 237 | name: "skia_pgo", |
| 238 | pgo: { |
| 239 | instrumentation: true, |
Pirama Arumuga Nainar | 068ccaa | 2018-03-05 10:20:38 -0800 | [diff] [blame] | 240 | profile_file: "hwui/hwui.profdata", |
Zhizhou Yang | e18b779 | 2017-12-11 10:37:44 -0800 | [diff] [blame] | 241 | benchmarks: ["hwui", "skia"], |
Pirama Arumuga Nainar | 068ccaa | 2018-03-05 10:20:38 -0800 | [diff] [blame] | 242 | enable_profile_use: true, |
Zhizhou Yang | e18b779 | 2017-12-11 10:37:44 -0800 | [diff] [blame] | 243 | }, |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 244 | } |
| 245 | |
Pirama Arumuga Nainar | de2b95e | 2017-12-13 11:07:39 -0800 | [diff] [blame] | 246 | // "defaults" property to disable profile use for Skia tools and benchmarks. |
| 247 | cc_defaults { |
| 248 | name: "skia_pgo_no_profile_use", |
| 249 | defaults: [ |
| 250 | "skia_pgo", |
| 251 | ], |
| 252 | pgo: { |
| 253 | enable_profile_use: false, |
| 254 | }, |
| 255 | } |
| 256 | |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 257 | cc_defaults { |
Leon Scroggins III | 6c41bf5 | 2021-01-29 15:33:00 -0500 | [diff] [blame] | 258 | // Subset of the larger "skia_deps", which includes only the dependencies |
| 259 | // needed for libskia_renderengine. Note that it includes libpng and libz |
| 260 | // for the purposes of MSKP captures, but we could instead leave it up to |
| 261 | // RenderEngine to provide its own SkSerializerProcs if another client |
| 262 | // wants an even smaller version of libskia. |
| 263 | name: "skia_renderengine_deps", |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 264 | shared_libs: [ |
Jerome Gaillard | e80251a | 2020-10-27 13:35:00 +0000 | [diff] [blame] | 265 | "libcutils", |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 266 | "liblog", |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 267 | "libpng", |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 268 | "libz", |
| 269 | ], |
| 270 | static_libs: [ |
Matt Sarett | a309109 | 2017-02-20 12:50:52 -0500 | [diff] [blame] | 271 | "libarect", |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 272 | ], |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 273 | group_static_libs: true, |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 274 | target: { |
| 275 | android: { |
| 276 | shared_libs: [ |
| 277 | "libEGL", |
| 278 | "libGLESv2", |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 279 | "libvulkan", |
| 280 | "libnativewindow", |
| 281 | ], |
Stan Iliev | 12b8916 | 2019-03-11 13:33:02 -0400 | [diff] [blame] | 282 | export_shared_lib_headers: [ |
| 283 | "libvulkan", |
| 284 | ], |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 285 | }, |
Leon Scroggins III | 6c41bf5 | 2021-01-29 15:33:00 -0500 | [diff] [blame] | 286 | }, |
| 287 | } |
| 288 | |
| 289 | cc_defaults { |
| 290 | name: "skia_deps", |
| 291 | defaults: ["skia_renderengine_deps"], |
| 292 | shared_libs: [ |
| 293 | "libdng_sdk", |
| 294 | "libjpeg", |
| 295 | "libpiex", |
| 296 | "libexpat", |
| 297 | "libft2", |
| 298 | ], |
| 299 | static_libs: [ |
| 300 | "libwebp-decode", |
| 301 | "libwebp-encode", |
| 302 | "libsfntly", |
| 303 | ], |
| 304 | target: { |
| 305 | android: { |
| 306 | shared_libs: [ |
| 307 | "libheif", |
| 308 | ], |
| 309 | }, |
Leon Scroggins III | 85e22fc | 2018-11-28 08:58:47 -0500 | [diff] [blame] | 310 | darwin: { |
| 311 | host_ldlibs: [ |
| 312 | "-framework AppKit", |
| 313 | ], |
| 314 | }, |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 315 | windows: { |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 316 | host_ldlibs: [ |
| 317 | "-lgdi32", |
| 318 | "-loleaut32", |
| 319 | "-lole32", |
| 320 | "-lopengl32", |
| 321 | "-luuid", |
| 322 | "-lwindowscodecs", |
| 323 | ], |
| 324 | }, |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 325 | }, |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | cc_defaults { |
| 329 | name: "skia_tool_deps", |
| 330 | defaults: [ |
Pirama Arumuga Nainar | de2b95e | 2017-12-13 11:07:39 -0800 | [diff] [blame] | 331 | "skia_deps", |
| 332 | "skia_pgo_no_profile_use" |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 333 | ], |
Mike Reed | 579c295 | 2020-05-27 16:49:23 -0400 | [diff] [blame] | 334 | shared_libs: [ |
Victor Chang | 6bd4d1c | 2020-11-23 19:26:59 +0000 | [diff] [blame] | 335 | "libicu", |
Mike Reed | 579c295 | 2020-05-27 16:49:23 -0400 | [diff] [blame] | 336 | "libharfbuzz_ng", |
| 337 | ], |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 338 | static_libs: [ |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 339 | "libskia", |
| 340 | ], |
| 341 | cflags: [ |
Mike Reed | 579c295 | 2020-05-27 16:49:23 -0400 | [diff] [blame] | 342 | "-DSK_SHAPER_HARFBUZZ_AVAILABLE", |
Julia Lavrova | 1798f4f | 2020-08-26 14:22:48 +0000 | [diff] [blame] | 343 | "-DSK_UNICODE_AVAILABLE", |
Derek Sollenberger | 1821a5b | 2018-09-11 14:48:36 -0400 | [diff] [blame] | 344 | "-Wno-implicit-fallthrough", |
Derek Sollenberger | 9a72ae1 | 2017-12-14 13:01:30 -0500 | [diff] [blame] | 345 | "-Wno-unused-parameter", |
| 346 | "-Wno-unused-variable", |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 347 | ], |
Martin Stjernholm | b4382ce | 2020-11-10 22:53:19 +0000 | [diff] [blame] | 348 | target: { |
| 349 | windows: { |
| 350 | enabled: true, |
| 351 | }, |
| 352 | }, |
Leon Scroggins III | 6ccd2ca | 2017-01-26 17:21:27 -0500 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | cc_test { |
| 356 | name: "skia_dm", |
| 357 | |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 358 | defaults: [ |
| 359 | "skia_tool_deps" |
Leon Scroggins III | 6ccd2ca | 2017-01-26 17:21:27 -0500 | [diff] [blame] | 360 | ], |
| 361 | |
| 362 | local_include_dirs: [ |
| 363 | $dm_includes |
| 364 | ], |
| 365 | |
| 366 | srcs: [ |
| 367 | $dm_srcs |
| 368 | ], |
Dongwon Kang | 0c7861f | 2018-02-16 10:55:21 -0800 | [diff] [blame] | 369 | |
| 370 | shared_libs: [ |
| 371 | "libbinder", |
| 372 | "libutils", |
| 373 | ], |
Leon Scroggins III | 6ccd2ca | 2017-01-26 17:21:27 -0500 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | cc_test { |
| 377 | name: "skia_nanobench", |
| 378 | |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 379 | defaults: [ |
| 380 | "skia_tool_deps" |
Leon Scroggins III | 6ccd2ca | 2017-01-26 17:21:27 -0500 | [diff] [blame] | 381 | ], |
| 382 | |
| 383 | local_include_dirs: [ |
| 384 | $nanobench_includes |
| 385 | ], |
| 386 | |
| 387 | srcs: [ |
| 388 | $nanobench_srcs |
| 389 | ], |
Pirama Arumuga Nainar | 68c3fac | 2018-01-09 21:05:55 -0800 | [diff] [blame] | 390 | |
| 391 | data: [ |
Pirama Arumuga Nainar | 5be3c13 | 2019-09-30 17:18:02 -0700 | [diff] [blame] | 392 | "resources/**/*", |
Pirama Arumuga Nainar | 68c3fac | 2018-01-09 21:05:55 -0800 | [diff] [blame] | 393 | ], |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 394 | }''') |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 395 | |
| 396 | # 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] | 397 | def generate_args(target_os, enable_gpu, renderengine = False): |
Leon Scroggins III | a55445e | 2018-11-28 16:09:35 -0500 | [diff] [blame] | 398 | d = { |
Ben Wagner | 75626e4 | 2020-06-03 13:20:37 -0400 | [diff] [blame] | 399 | 'is_official_build': 'true', |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 400 | |
Leon Scroggins III | a55445e | 2018-11-28 16:09:35 -0500 | [diff] [blame] | 401 | # gn_to_bp_utils' GetArchSources will take care of architecture-specific |
| 402 | # files. |
Ben Wagner | 75626e4 | 2020-06-03 13:20:37 -0400 | [diff] [blame] | 403 | 'target_cpu': '"none"', |
Hal Canary | 23564b9 | 2018-09-07 14:33:14 -0400 | [diff] [blame] | 404 | |
Leon Scroggins III | a55445e | 2018-11-28 16:09:35 -0500 | [diff] [blame] | 405 | # Use the custom FontMgr, as the framework will handle fonts. |
Ben Wagner | 75626e4 | 2020-06-03 13:20:37 -0400 | [diff] [blame] | 406 | 'skia_enable_fontmgr_custom_directory': 'false', |
| 407 | 'skia_enable_fontmgr_custom_embedded': 'false', |
Ben Wagner | 75626e4 | 2020-06-03 13:20:37 -0400 | [diff] [blame] | 408 | 'skia_enable_fontmgr_android': 'false', |
| 409 | 'skia_enable_fontmgr_win': 'false', |
| 410 | 'skia_enable_fontmgr_win_gdi': 'false', |
| 411 | 'skia_use_fonthost_mac': 'false', |
Leon Scroggins III | a55445e | 2018-11-28 16:09:35 -0500 | [diff] [blame] | 412 | |
Nathaniel Nifong | 60c37e7 | 2019-10-16 11:21:47 -0400 | [diff] [blame] | 413 | # enable features used in skia_nanobench |
Ben Wagner | 75626e4 | 2020-06-03 13:20:37 -0400 | [diff] [blame] | 414 | 'skia_tools_require_resources': 'true', |
Nathaniel Nifong | 60c37e7 | 2019-10-16 11:21:47 -0400 | [diff] [blame] | 415 | |
Ben Wagner | 75626e4 | 2020-06-03 13:20:37 -0400 | [diff] [blame] | 416 | 'skia_use_fontconfig': 'false', |
Ben Wagner | 75626e4 | 2020-06-03 13:20:37 -0400 | [diff] [blame] | 417 | 'skia_include_multiframe_procs': 'false', |
| 418 | 'skia_libgifcodec_path': '"third_party/libgifcodec"', |
Leon Scroggins III | a55445e | 2018-11-28 16:09:35 -0500 | [diff] [blame] | 419 | } |
| 420 | d['target_os'] = target_os |
| 421 | if target_os == '"android"': |
| 422 | d['skia_enable_tools'] = 'true' |
Nathaniel Nifong | 0c4fbf1 | 2019-06-25 15:48:47 -0400 | [diff] [blame] | 423 | d['skia_include_multiframe_procs'] = 'true' |
Leon Scroggins III | a55445e | 2018-11-28 16:09:35 -0500 | [diff] [blame] | 424 | |
| 425 | if enable_gpu: |
| 426 | d['skia_use_vulkan'] = 'true' |
| 427 | else: |
| 428 | d['skia_use_vulkan'] = 'false' |
| 429 | d['skia_enable_gpu'] = 'false' |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 430 | |
| 431 | if target_os == '"win"': |
| 432 | # The Android Windows build system does not provide FontSub.h |
| 433 | d['skia_use_xps'] = 'false' |
| 434 | |
| 435 | # BUILDCONFIG.gn expects these to be set when building for Windows, but |
| 436 | # 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] | 437 | # some placeholder values. |
| 438 | d['win_vc'] = '"placeholder_version"' |
| 439 | d['win_sdk_version'] = '"placeholder_version"' |
| 440 | d['win_toolchain_version'] = '"placeholder_version"' |
Leon Scroggins III | 6c41bf5 | 2021-01-29 15:33:00 -0500 | [diff] [blame] | 441 | |
| 442 | if target_os == '"android"' and not renderengine: |
| 443 | d['skia_use_libheif'] = 'true' |
| 444 | else: |
| 445 | d['skia_use_libheif'] = 'false' |
| 446 | |
| 447 | if renderengine: |
| 448 | d['skia_use_libpng_decode'] = 'false' |
| 449 | d['skia_use_libjpeg_turbo_decode'] = 'false' |
| 450 | d['skia_use_libjpeg_turbo_encode'] = 'false' |
| 451 | d['skia_use_libwebp_decode'] = 'false' |
| 452 | d['skia_use_libwebp_encode'] = 'false' |
| 453 | d['skia_use_libgifcodec'] = 'false' |
| 454 | d['skia_enable_pdf'] = 'false' |
| 455 | d['skia_use_freetype'] = 'false' |
| 456 | d['skia_use_fixed_gamma_text'] = 'false' |
| 457 | d['skia_use_expat'] = 'false' |
| 458 | d['skia_enable_fontmgr_custom_empty'] = 'false' |
| 459 | else: |
| 460 | d['skia_enable_android_utils'] = 'true' |
| 461 | d['skia_use_freetype'] = 'true' |
| 462 | d['skia_use_fixed_gamma_text'] = 'true' |
| 463 | d['skia_enable_fontmgr_custom_empty'] = 'true' |
| 464 | |
Leon Scroggins III | a55445e | 2018-11-28 16:09:35 -0500 | [diff] [blame] | 465 | return d |
| 466 | |
| 467 | gn_args = generate_args('"android"', True) |
| 468 | gn_args_linux = generate_args('"linux"', False) |
| 469 | gn_args_mac = generate_args('"mac"', False) |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 470 | gn_args_win = generate_args('"win"', False) |
Leon Scroggins III | 6c41bf5 | 2021-01-29 15:33:00 -0500 | [diff] [blame] | 471 | gn_args_renderengine = generate_args('"android"', True, True) |
Leon Scroggins III | 85e22fc | 2018-11-28 08:58:47 -0500 | [diff] [blame] | 472 | |
Derek Sollenberger | 5d3f770 | 2018-02-01 09:22:53 -0500 | [diff] [blame] | 473 | js = gn_to_bp_utils.GenerateJSONFromGN(gn_args) |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 474 | |
| 475 | def strip_slashes(lst): |
Ben Wagner | e127523 | 2017-02-23 18:00:06 -0500 | [diff] [blame] | 476 | return {str(p.lstrip('/')) for p in lst} |
Mike Klein | 27eb22b | 2016-12-07 12:27:56 -0500 | [diff] [blame] | 477 | |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 478 | android_srcs = strip_slashes(js['targets']['//:skia']['sources']) |
Leon Scroggins III | 981a31e | 2017-10-06 11:53:53 -0400 | [diff] [blame] | 479 | cflags = strip_slashes(js['targets']['//:skia']['cflags']) |
| 480 | cflags_cc = strip_slashes(js['targets']['//:skia']['cflags_cc']) |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 481 | local_includes = strip_slashes(js['targets']['//:skia']['include_dirs']) |
| 482 | export_includes = strip_slashes(js['targets']['//:public']['include_dirs']) |
| 483 | |
Leon Scroggins III | 6ccd2ca | 2017-01-26 17:21:27 -0500 | [diff] [blame] | 484 | dm_srcs = strip_slashes(js['targets']['//:dm']['sources']) |
| 485 | dm_includes = strip_slashes(js['targets']['//:dm']['include_dirs']) |
| 486 | |
| 487 | nanobench_target = js['targets']['//:nanobench'] |
| 488 | nanobench_srcs = strip_slashes(nanobench_target['sources']) |
| 489 | nanobench_includes = strip_slashes(nanobench_target['include_dirs']) |
| 490 | |
Derek Sollenberger | 5d3f770 | 2018-02-01 09:22:53 -0500 | [diff] [blame] | 491 | gn_to_bp_utils.GrabDependentValues(js, '//:dm', 'sources', dm_srcs, 'skia') |
| 492 | gn_to_bp_utils.GrabDependentValues(js, '//:nanobench', 'sources', |
| 493 | nanobench_srcs, 'skia') |
Mike Klein | 27eb22b | 2016-12-07 12:27:56 -0500 | [diff] [blame] | 494 | |
Mike Klein | f536c45 | 2018-05-01 10:36:42 -0400 | [diff] [blame] | 495 | # skcms is a little special, kind of a second-party library. |
Brian Osman | 35ea04d | 2019-05-01 11:03:36 -0400 | [diff] [blame] | 496 | local_includes.add("include/third_party/skcms") |
| 497 | dm_includes .add("include/third_party/skcms") |
Mike Klein | f536c45 | 2018-05-01 10:36:42 -0400 | [diff] [blame] | 498 | |
Mike Klein | d505b19 | 2018-09-05 15:55:25 -0400 | [diff] [blame] | 499 | # Android's build will choke if we list headers. |
| 500 | def strip_headers(sources): |
| 501 | return {s for s in sources if not s.endswith('.h')} |
| 502 | |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 503 | gn_to_bp_utils.GrabDependentValues(js, '//:skia', 'sources', android_srcs, None) |
| 504 | android_srcs = strip_headers(android_srcs) |
| 505 | |
| 506 | js_linux = gn_to_bp_utils.GenerateJSONFromGN(gn_args_linux) |
| 507 | linux_srcs = strip_slashes(js_linux['targets']['//:skia']['sources']) |
| 508 | gn_to_bp_utils.GrabDependentValues(js_linux, '//:skia', 'sources', linux_srcs, |
| 509 | None) |
| 510 | linux_srcs = strip_headers(linux_srcs) |
| 511 | |
Leon Scroggins III | 85e22fc | 2018-11-28 08:58:47 -0500 | [diff] [blame] | 512 | js_mac = gn_to_bp_utils.GenerateJSONFromGN(gn_args_mac) |
| 513 | mac_srcs = strip_slashes(js_mac['targets']['//:skia']['sources']) |
| 514 | gn_to_bp_utils.GrabDependentValues(js_mac, '//:skia', 'sources', mac_srcs, |
| 515 | None) |
| 516 | mac_srcs = strip_headers(mac_srcs) |
| 517 | |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 518 | js_win = gn_to_bp_utils.GenerateJSONFromGN(gn_args_win) |
| 519 | win_srcs = strip_slashes(js_win['targets']['//:skia']['sources']) |
| 520 | gn_to_bp_utils.GrabDependentValues(js_win, '//:skia', 'sources', win_srcs, |
| 521 | None) |
| 522 | win_srcs = strip_headers(win_srcs) |
| 523 | |
Leon Scroggins III | 85e22fc | 2018-11-28 08:58:47 -0500 | [diff] [blame] | 524 | srcs = android_srcs.intersection(linux_srcs).intersection(mac_srcs) |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 525 | srcs = srcs.intersection(win_srcs) |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 526 | android_srcs = android_srcs.difference(srcs) |
| 527 | linux_srcs = linux_srcs.difference(srcs) |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 528 | mac_srcs = mac_srcs.difference(srcs) |
| 529 | win_srcs = win_srcs.difference(srcs) |
Leon Scroggins III | 6c41bf5 | 2021-01-29 15:33:00 -0500 | [diff] [blame] | 530 | |
| 531 | js_renderengine = gn_to_bp_utils.GenerateJSONFromGN(gn_args_renderengine) |
| 532 | renderengine_srcs = strip_slashes( |
| 533 | js_renderengine['targets']['//:skia']['sources']) |
| 534 | gn_to_bp_utils.GrabDependentValues(js_renderengine, '//:skia', 'sources', |
| 535 | renderengine_srcs, None) |
| 536 | renderengine_srcs = strip_headers(renderengine_srcs) |
| 537 | |
Mike Klein | d505b19 | 2018-09-05 15:55:25 -0400 | [diff] [blame] | 538 | dm_srcs = strip_headers(dm_srcs) |
| 539 | nanobench_srcs = strip_headers(nanobench_srcs) |
Mike Klein | 27eb22b | 2016-12-07 12:27:56 -0500 | [diff] [blame] | 540 | |
Derek Sollenberger | 5d3f770 | 2018-02-01 09:22:53 -0500 | [diff] [blame] | 541 | cflags = gn_to_bp_utils.CleanupCFlags(cflags) |
| 542 | cflags_cc = gn_to_bp_utils.CleanupCCFlags(cflags_cc) |
Leon Scroggins III | 981a31e | 2017-10-06 11:53:53 -0400 | [diff] [blame] | 543 | |
Leon Scroggins III | 4f8a467 | 2016-12-19 09:32:21 -0500 | [diff] [blame] | 544 | here = os.path.dirname(__file__) |
Derek Sollenberger | 5d3f770 | 2018-02-01 09:22:53 -0500 | [diff] [blame] | 545 | defs = gn_to_bp_utils.GetArchSources(os.path.join(here, 'opts.gni')) |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 546 | |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 547 | def get_defines(json): |
| 548 | return {str(d) for d in json['targets']['//:skia']['defines']} |
Leon Scroggins III | 6c41bf5 | 2021-01-29 15:33:00 -0500 | [diff] [blame] | 549 | android_defines = get_defines(js) |
| 550 | linux_defines = get_defines(js_linux) |
| 551 | mac_defines = get_defines(js_mac) |
| 552 | win_defines = get_defines(js_win) |
| 553 | renderengine_defines = get_defines(js_renderengine) |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 554 | |
| 555 | def mkdir_if_not_exists(path): |
| 556 | if not os.path.exists(path): |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 557 | os.makedirs(path) |
| 558 | mkdir_if_not_exists('android/include/config/') |
| 559 | mkdir_if_not_exists('linux/include/config/') |
| 560 | mkdir_if_not_exists('mac/include/config/') |
| 561 | mkdir_if_not_exists('win/include/config/') |
Leon Scroggins III | 6c41bf5 | 2021-01-29 15:33:00 -0500 | [diff] [blame] | 562 | mkdir_if_not_exists('renderengine/include/config/') |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 563 | |
| 564 | platforms = { 'IOS', 'MAC', 'WIN', 'ANDROID', 'UNIX' } |
| 565 | |
| 566 | def disallow_platforms(config, desired): |
| 567 | with open(config, 'a') as f: |
| 568 | p = sorted(platforms.difference({ desired })) |
| 569 | s = '#if ' |
| 570 | for i in range(len(p)): |
| 571 | s = s + 'defined(SK_BUILD_FOR_%s)' % p[i] |
| 572 | if i < len(p) - 1: |
| 573 | s += ' || ' |
| 574 | if i % 2 == 1: |
| 575 | s += '\\\n ' |
Martin Vejdarski | beaaf47 | 2020-03-03 13:53:20 +0700 | [diff] [blame] | 576 | print(s, file=f) |
| 577 | print(' #error "Only SK_BUILD_FOR_%s should be defined!"' % desired, file=f) |
| 578 | print('#endif', file=f) |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 579 | |
| 580 | def append_to_file(config, s): |
| 581 | with open(config, 'a') as f: |
Martin Vejdarski | beaaf47 | 2020-03-03 13:53:20 +0700 | [diff] [blame] | 582 | print(s, file=f) |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 583 | |
Leon Scroggins III | 6c41bf5 | 2021-01-29 15:33:00 -0500 | [diff] [blame] | 584 | def write_android_config(config_path, defines): |
| 585 | gn_to_bp_utils.WriteUserConfig(config_path, defines) |
| 586 | append_to_file(config_path, ''' |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 587 | #ifndef SK_BUILD_FOR_ANDROID |
| 588 | #error "SK_BUILD_FOR_ANDROID must be defined!" |
| 589 | #endif''') |
Leon Scroggins III | 6c41bf5 | 2021-01-29 15:33:00 -0500 | [diff] [blame] | 590 | disallow_platforms(config_path, 'ANDROID') |
| 591 | |
| 592 | write_android_config('android/include/config/SkUserConfig.h', android_defines) |
| 593 | write_android_config('renderengine/include/config/SkUserConfig.h', renderengine_defines) |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 594 | |
Leon Scroggins III | 85e22fc | 2018-11-28 08:58:47 -0500 | [diff] [blame] | 595 | def write_config(config_path, defines, platform): |
| 596 | gn_to_bp_utils.WriteUserConfig(config_path, defines) |
| 597 | append_to_file(config_path, ''' |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 598 | // Correct SK_BUILD_FOR flags that may have been set by |
Mike Klein | 81d35a7 | 2020-02-05 10:17:57 -0600 | [diff] [blame] | 599 | // SkTypes.h/Android.bp |
Leon Scroggins III | 85e22fc | 2018-11-28 08:58:47 -0500 | [diff] [blame] | 600 | #ifndef SK_BUILD_FOR_%s |
| 601 | #define SK_BUILD_FOR_%s |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 602 | #endif |
| 603 | #ifdef SK_BUILD_FOR_ANDROID |
| 604 | #undef SK_BUILD_FOR_ANDROID |
Leon Scroggins III | 85e22fc | 2018-11-28 08:58:47 -0500 | [diff] [blame] | 605 | #endif''' % (platform, platform)) |
| 606 | disallow_platforms(config_path, platform) |
| 607 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 608 | write_config('linux/include/config/SkUserConfig.h', linux_defines, 'UNIX') |
| 609 | write_config('mac/include/config/SkUserConfig.h', mac_defines, 'MAC') |
| 610 | write_config('win/include/config/SkUserConfig.h', win_defines, 'WIN') |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 611 | |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 612 | # Turn a list of strings into the style bpfmt outputs. |
Leon Scroggins III | 6ccd2ca | 2017-01-26 17:21:27 -0500 | [diff] [blame] | 613 | def bpfmt(indent, lst, sort=True): |
| 614 | if sort: |
| 615 | lst = sorted(lst) |
| 616 | return ('\n' + ' '*indent).join('"%s",' % v for v in lst) |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 617 | |
| 618 | # OK! We have everything to fill in Android.bp... |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 619 | with open('Android.bp', 'w') as Android_bp: |
Martin Vejdarski | beaaf47 | 2020-03-03 13:53:20 +0700 | [diff] [blame] | 620 | print(bp.substitute({ |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 621 | 'export_includes': bpfmt(8, export_includes), |
| 622 | 'local_includes': bpfmt(8, local_includes), |
| 623 | 'srcs': bpfmt(8, srcs), |
Leon Scroggins III | 981a31e | 2017-10-06 11:53:53 -0400 | [diff] [blame] | 624 | 'cflags': bpfmt(8, cflags, False), |
| 625 | 'cflags_cc': bpfmt(8, cflags_cc), |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 626 | |
Mike Klein | d505b19 | 2018-09-05 15:55:25 -0400 | [diff] [blame] | 627 | 'arm_srcs': bpfmt(16, strip_headers(defs['armv7'])), |
| 628 | 'arm_neon_srcs': bpfmt(20, strip_headers(defs['neon'])), |
| 629 | 'arm64_srcs': bpfmt(16, strip_headers(defs['arm64'] + |
| 630 | defs['crc32'])), |
Mike Klein | d505b19 | 2018-09-05 15:55:25 -0400 | [diff] [blame] | 631 | 'x86_srcs': bpfmt(16, strip_headers(defs['sse2'] + |
| 632 | defs['ssse3'] + |
| 633 | defs['sse41'] + |
| 634 | defs['sse42'] + |
| 635 | defs['avx' ] + |
Mike Klein | ad56c4c | 2020-06-05 06:57:30 -0500 | [diff] [blame] | 636 | defs['hsw' ] + |
| 637 | defs['skx' ])), |
Leon Scroggins III | 6ccd2ca | 2017-01-26 17:21:27 -0500 | [diff] [blame] | 638 | |
Leon Scroggins III | 6ccd2ca | 2017-01-26 17:21:27 -0500 | [diff] [blame] | 639 | 'dm_includes' : bpfmt(8, dm_includes), |
| 640 | 'dm_srcs' : bpfmt(8, dm_srcs), |
| 641 | |
| 642 | 'nanobench_includes' : bpfmt(8, nanobench_includes), |
| 643 | 'nanobench_srcs' : bpfmt(8, nanobench_srcs), |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 644 | |
| 645 | 'android_srcs': bpfmt(10, android_srcs), |
| 646 | 'linux_srcs': bpfmt(10, linux_srcs), |
Leon Scroggins III | 85e22fc | 2018-11-28 08:58:47 -0500 | [diff] [blame] | 647 | 'mac_srcs': bpfmt(10, mac_srcs), |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 648 | 'win_srcs': bpfmt(10, win_srcs), |
Leon Scroggins III | 6c41bf5 | 2021-01-29 15:33:00 -0500 | [diff] [blame] | 649 | |
| 650 | 'renderengine_srcs': bpfmt(8, renderengine_srcs), |
Martin Vejdarski | beaaf47 | 2020-03-03 13:53:20 +0700 | [diff] [blame] | 651 | }), file=Android_bp) |