| 1 |
#!/usr/bin/env python3 |
| 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 and various SkUserConfig.h for Android Framework |
| 9 |
# using Skia's GN configuration. |
| 10 |
# |
| 11 |
# To test this locally, run python3 gn/gn_to_bp.py --out /tmp/somewhere |
| 12 |
# |
| 13 |
# To test this on the CQ, use Canary-Android |
| 14 |
|
| 15 |
import argparse |
| 16 |
import os |
| 17 |
import shutil |
| 18 |
import string |
| 19 |
|
| 20 |
import skqp_gn_args |
| 21 |
import gn_to_bp_utils |
| 22 |
|
| 23 |
parser = argparse.ArgumentParser(description='Generate Android.bp for Skia.', |
| 24 |
formatter_class=argparse.RawDescriptionHelpFormatter, |
| 25 |
epilog=''' |
| 26 |
Example usage: |
| 27 |
python3 gn/gn_to_bp.py --out /tmp/skia_android_bp |
| 28 |
''') |
| 29 |
parser.add_argument('--gn', default='gn', help='Path to gn executable.') |
| 30 |
parser.add_argument('--out', default='.', help='Output directory.') |
| 31 |
args = parser.parse_args() |
| 32 |
|
| 33 |
def out_path(p): |
| 34 |
return os.path.join(args.out, p) |
| 35 |
|
| 36 |
# First we start off with a template for Android.bp, |
| 37 |
# with holes for source lists and include directories. |
| 38 |
bp = string.Template('''// This file is autogenerated by gn_to_bp.py. |
| 39 |
// To make changes to this file, follow the instructions on skia.org for |
| 40 |
// downloading Skia and submitting changes. Modify gn_to_bp.py (or the build |
| 41 |
// files it uses) and submit to skia-review.googlesource.com, NOT to AOSP or |
| 42 |
// Android Internal. The autoroller will then create the updated Android.bp |
| 43 |
// and submit it to Android Internal, which will eventually merge to AOSP. |
| 44 |
// You can also ask a Skia engineer for help. |
| 45 |
|
| 46 |
package { |
| 47 |
default_applicable_licenses: ["external_skia_license"], |
| 48 |
} |
| 49 |
|
| 50 |
// Added automatically by a large-scale-change that took the approach of |
| 51 |
// 'apply every license found to every target'. While this makes sure we respect |
| 52 |
// every license restriction, it may not be entirely correct. |
| 53 |
// |
| 54 |
// e.g. GPL in an MIT project might only apply to the contrib/ directory. |
| 55 |
// |
| 56 |
// Please consider splitting the single license below into multiple licenses, |
| 57 |
// taking care not to lose any license_kind information, and overriding the |
| 58 |
// default license using the 'licenses: [...]' property on targets as needed. |
| 59 |
// |
| 60 |
// For unused files, consider creating a 'fileGroup' with "//visibility:private" |
| 61 |
// to attach the license to, and including a comment whether the files may be |
| 62 |
// used in the current project. |
| 63 |
// |
| 64 |
// large-scale-change included anything that looked like it might be a license |
| 65 |
// text as a license_text. e.g. LICENSE, NOTICE, COPYING etc. |
| 66 |
// |
| 67 |
// Please consider removing redundant or irrelevant files from 'license_text:'. |
| 68 |
// |
| 69 |
// large-scale-change filtered out the below license kinds as false-positives: |
| 70 |
// SPDX-license-identifier-CC-BY-NC |
| 71 |
// SPDX-license-identifier-GPL-2.0 |
| 72 |
// SPDX-license-identifier-LGPL-2.1 |
| 73 |
// SPDX-license-identifier-OFL:by_exception_only |
| 74 |
// See: http://go/android-license-faq |
| 75 |
license { |
| 76 |
name: "external_skia_license", |
| 77 |
visibility: [":__subpackages__"], |
| 78 |
license_kinds: [ |
| 79 |
"SPDX-license-identifier-Apache-2.0", |
| 80 |
"SPDX-license-identifier-BSD", |
| 81 |
"SPDX-license-identifier-CC0-1.0", |
| 82 |
"SPDX-license-identifier-FTL", |
| 83 |
"SPDX-license-identifier-MIT", |
| 84 |
"legacy_unencumbered", |
| 85 |
], |
| 86 |
license_text: [ |
| 87 |
"LICENSE", |
| 88 |
"NOTICE", |
| 89 |
], |
| 90 |
} |
| 91 |
|
| 92 |
cc_defaults { |
| 93 |
name: "skia_arch_defaults", |
| 94 |
arch: { |
| 95 |
arm: { |
| 96 |
srcs: [], |
| 97 |
}, |
| 98 |
|
| 99 |
arm64: { |
| 100 |
srcs: [], |
| 101 |
}, |
| 102 |
|
| 103 |
x86: { |
| 104 |
srcs: [ |
| 105 |
$x86_srcs |
| 106 |
], |
| 107 |
}, |
| 108 |
|
| 109 |
x86_64: { |
| 110 |
srcs: [ |
| 111 |
$x86_srcs |
| 112 |
], |
| 113 |
}, |
| 114 |
}, |
| 115 |
|
| 116 |
target: { |
| 117 |
android: { |
| 118 |
srcs: [ |
| 119 |
"src/gpu/vk/vulkanmemoryallocator/VulkanMemoryAllocatorWrapper.cpp", |
| 120 |
], |
| 121 |
local_include_dirs: [ |
| 122 |
"src/gpu/vk/vulkanmemoryallocator", |
| 123 |
"vma_android/include", |
| 124 |
], |
| 125 |
}, |
| 126 |
}, |
| 127 |
} |
| 128 |
|
| 129 |
cc_defaults { |
| 130 |
name: "skia_defaults", |
| 131 |
defaults: ["skia_arch_defaults"], |
| 132 |
cflags: [ |
| 133 |
$cflags |
| 134 |
], |
| 135 |
|
| 136 |
cppflags:[ |
| 137 |
$cflags_cc |
| 138 |
], |
| 139 |
|
| 140 |
export_include_dirs: [ |
| 141 |
$export_includes |
| 142 |
], |
| 143 |
|
| 144 |
local_include_dirs: [ |
| 145 |
$local_includes |
| 146 |
], |
| 147 |
|
| 148 |
sanitize: { |
| 149 |
blocklist: "libskia_blocklist.txt", |
| 150 |
}, |
| 151 |
} |
| 152 |
|
| 153 |
cc_library_static { |
| 154 |
// Smaller version of Skia, without e.g. codecs, intended for use by RenderEngine. |
| 155 |
name: "libskia_renderengine", |
| 156 |
defaults: ["skia_defaults", |
| 157 |
"skia_renderengine_deps"], |
| 158 |
srcs: [ |
| 159 |
$renderengine_srcs |
| 160 |
], |
| 161 |
local_include_dirs: [ |
| 162 |
"renderengine", |
| 163 |
], |
| 164 |
export_include_dirs: [ |
| 165 |
"renderengine", |
| 166 |
], |
| 167 |
} |
| 168 |
|
| 169 |
// Skia's ffi.rs pulls in a number of additional rust sources. |
| 170 |
// There isn't anywhere to explicitly mention them here, but the dependency |
| 171 |
// should be tracked by the Soong build. If not, it will be necessary to find |
| 172 |
// some means of adding them as dependencies here. |
| 173 |
rust_ffi_static { |
| 174 |
name: "libskia_rust_ffi", |
| 175 |
host_supported: true, |
| 176 |
crate_name: "skia", |
| 177 |
srcs: ["src/ports/fontations/src/ffi.rs"], |
| 178 |
include_dirs: ["src/ports/fontations/src"], |
| 179 |
rustlibs: [ |
| 180 |
"libcxx", |
| 181 |
"libskrifa", |
| 182 |
"libread_fonts", |
| 183 |
"libfont_types", |
| 184 |
], |
| 185 |
features: [ "cxx" ], |
| 186 |
target: { |
| 187 |
windows: { |
| 188 |
enabled: true, |
| 189 |
}, |
| 190 |
}, |
| 191 |
} |
| 192 |
|
| 193 |
gensrcs { |
| 194 |
name: "libskia_cxx_bridge_code", |
| 195 |
tools: ["cxxbridge"], |
| 196 |
cmd: "$$(location cxxbridge) $$(in) >> $$(out)", |
| 197 |
srcs: ["src/ports/fontations/src/ffi.rs"], |
| 198 |
output_extension: "cpp", |
| 199 |
} |
| 200 |
|
| 201 |
gensrcs { |
| 202 |
name: "libskia_cxx_bridge_header", |
| 203 |
tools: ["cxxbridge"], |
| 204 |
cmd: "$$(location cxxbridge) $$(in) --header >> $$(out)", |
| 205 |
srcs: ["src/ports/fontations/src/ffi.rs"], |
| 206 |
output_extension: "rs.h", |
| 207 |
export_include_dirs: ["."] |
| 208 |
} |
| 209 |
|
| 210 |
cc_library_static { |
| 211 |
name: "libskia_skcms", |
| 212 |
host_supported: true, |
| 213 |
sdk_version: "current", |
| 214 |
srcs: [ |
| 215 |
$skcms_srcs |
| 216 |
], |
| 217 |
export_include_dirs: [ |
| 218 |
"modules/skcms", |
| 219 |
], |
| 220 |
} |
| 221 |
|
| 222 |
cc_library_static { |
| 223 |
name: "libskia", |
| 224 |
host_supported: true, |
| 225 |
cppflags:[ |
| 226 |
// Exceptions are necessary for SkRawCodec. |
| 227 |
// FIXME: Should we split SkRawCodec into a separate target so the rest |
| 228 |
// of Skia need not be compiled with exceptions? |
| 229 |
"-fexceptions", |
| 230 |
], |
| 231 |
|
| 232 |
srcs: [ |
| 233 |
$srcs |
| 234 |
], |
| 235 |
generated_headers: [ |
| 236 |
"libskia_cxx_bridge_header", |
| 237 |
], |
| 238 |
generated_sources: [ |
| 239 |
"libskia_cxx_bridge_code", |
| 240 |
], |
| 241 |
|
| 242 |
target: { |
| 243 |
android: { |
| 244 |
srcs: [ |
| 245 |
$android_srcs |
| 246 |
], |
| 247 |
local_include_dirs: [ |
| 248 |
"android", |
| 249 |
], |
| 250 |
export_include_dirs: [ |
| 251 |
"android", |
| 252 |
], |
| 253 |
}, |
| 254 |
host_linux: { |
| 255 |
srcs: [ |
| 256 |
$linux_srcs |
| 257 |
], |
| 258 |
local_include_dirs: [ |
| 259 |
"linux", |
| 260 |
], |
| 261 |
export_include_dirs: [ |
| 262 |
"linux", |
| 263 |
], |
| 264 |
}, |
| 265 |
darwin: { |
| 266 |
srcs: [ |
| 267 |
$mac_srcs |
| 268 |
], |
| 269 |
local_include_dirs: [ |
| 270 |
"mac", |
| 271 |
], |
| 272 |
export_include_dirs: [ |
| 273 |
"mac", |
| 274 |
], |
| 275 |
}, |
| 276 |
windows: { |
| 277 |
enabled: true, |
| 278 |
cflags: [ |
| 279 |
"-Wno-unknown-pragmas", |
| 280 |
], |
| 281 |
srcs: [ |
| 282 |
$win_srcs |
| 283 |
], |
| 284 |
local_include_dirs: [ |
| 285 |
"win", |
| 286 |
], |
| 287 |
export_include_dirs: [ |
| 288 |
"win", |
| 289 |
], |
| 290 |
}, |
| 291 |
}, |
| 292 |
|
| 293 |
defaults: ["skia_deps", |
| 294 |
"skia_defaults", |
| 295 |
], |
| 296 |
} |
| 297 |
|
| 298 |
cc_defaults { |
| 299 |
// Subset of the larger "skia_deps", which includes only the dependencies |
| 300 |
// needed for libskia_renderengine. Note that it includes libpng and libz |
| 301 |
// for the purposes of MSKP captures, but we could instead leave it up to |
| 302 |
// RenderEngine to provide its own SkSerializerProcs if another client |
| 303 |
// wants an even smaller version of libskia. |
| 304 |
name: "skia_renderengine_deps", |
| 305 |
shared_libs: [ |
| 306 |
"libcutils", |
| 307 |
"liblog", |
| 308 |
"libpng", |
| 309 |
"libz", |
| 310 |
], |
| 311 |
static_libs: [ |
| 312 |
"libarect", |
| 313 |
], |
| 314 |
target: { |
| 315 |
android: { |
| 316 |
shared_libs: [ |
| 317 |
"libEGL", |
| 318 |
"libGLESv2", |
| 319 |
"libvulkan", |
| 320 |
"libnativewindow", |
| 321 |
], |
| 322 |
static_libs: [ |
| 323 |
"libperfetto_client_experimental", |
| 324 |
], |
| 325 |
export_shared_lib_headers: [ |
| 326 |
"libvulkan", |
| 327 |
], |
| 328 |
}, |
| 329 |
}, |
| 330 |
} |
| 331 |
|
| 332 |
cc_defaults { |
| 333 |
name: "skia_deps", |
| 334 |
defaults: ["skia_renderengine_deps"], |
| 335 |
shared_libs: [ |
| 336 |
"libjpeg", |
| 337 |
"libpiex", |
| 338 |
"libexpat", |
| 339 |
"libft2", |
| 340 |
"libharfbuzz_subset", |
| 341 |
], |
| 342 |
static_libs: [ |
| 343 |
"libwebp-decode", |
| 344 |
"libwebp-encode", |
| 345 |
"libwuffs_mirror_release_c", |
| 346 |
], |
| 347 |
cflags: [ |
| 348 |
"-DSK_PDF_USE_HARFBUZZ_SUBSET", |
| 349 |
], |
| 350 |
whole_static_libs: [ |
| 351 |
"libskia_rust_ffi", |
| 352 |
"libskrifa", |
| 353 |
], |
| 354 |
target: { |
| 355 |
android: { |
| 356 |
shared_libs: [ |
| 357 |
"libmediandk", // Needed to link libcrabbyavif_ffi in some configurations. |
| 358 |
"libdng_sdk", |
| 359 |
], |
| 360 |
whole_static_libs: [ |
| 361 |
"libcrabbyavif_ffi", |
| 362 |
], |
| 363 |
}, |
| 364 |
host_linux: { |
| 365 |
static_libs: [ |
| 366 |
"libdng_sdk", |
| 367 |
], |
| 368 |
}, |
| 369 |
darwin: { |
| 370 |
host_ldlibs: [ |
| 371 |
"-framework AppKit", |
| 372 |
], |
| 373 |
static_libs: [ |
| 374 |
"libdng_sdk", |
| 375 |
], |
| 376 |
}, |
| 377 |
windows: { |
| 378 |
host_ldlibs: [ |
| 379 |
"-lgdi32", |
| 380 |
"-loleaut32", |
| 381 |
"-lole32", |
| 382 |
"-lopengl32", |
| 383 |
"-luuid", |
| 384 |
"-lwindowscodecs", |
| 385 |
], |
| 386 |
}, |
| 387 |
}, |
| 388 |
} |
| 389 |
|
| 390 |
cc_defaults { |
| 391 |
name: "skia_tool_deps", |
| 392 |
defaults: [ |
| 393 |
"skia_deps", |
| 394 |
], |
| 395 |
shared_libs: [ |
| 396 |
"libicu", |
| 397 |
"libharfbuzz_ng", |
| 398 |
], |
| 399 |
static_libs: [ |
| 400 |
"libskia", |
| 401 |
], |
| 402 |
cflags: [ |
| 403 |
"-DSK_SHAPER_HARFBUZZ_AVAILABLE", |
| 404 |
"-DSK_SHAPER_UNICODE_AVAILABLE", |
| 405 |
"-DSK_UNICODE_AVAILABLE", |
| 406 |
"-DSK_UNICODE_ICU_IMPLEMENTATION", |
| 407 |
"-Wno-implicit-fallthrough", |
| 408 |
"-Wno-unused-parameter", |
| 409 |
"-Wno-unused-variable", |
| 410 |
], |
| 411 |
target: { |
| 412 |
windows: { |
| 413 |
enabled: true, |
| 414 |
}, |
| 415 |
}, |
| 416 |
|
| 417 |
data: [ |
| 418 |
"resources/**/*", |
| 419 |
], |
| 420 |
} |
| 421 |
|
| 422 |
cc_defaults { |
| 423 |
name: "skia_gm_srcs", |
| 424 |
local_include_dirs: [ |
| 425 |
$gm_includes |
| 426 |
], |
| 427 |
|
| 428 |
srcs: [ |
| 429 |
$gm_srcs |
| 430 |
], |
| 431 |
} |
| 432 |
|
| 433 |
cc_defaults { |
| 434 |
name: "skia_test_minus_gm_srcs", |
| 435 |
local_include_dirs: [ |
| 436 |
$test_minus_gm_includes |
| 437 |
], |
| 438 |
|
| 439 |
srcs: [ |
| 440 |
$test_minus_gm_srcs |
| 441 |
], |
| 442 |
} |
| 443 |
|
| 444 |
cc_defaults { |
| 445 |
name: "skqp_jni_defaults", |
| 446 |
sdk_version: "$skqp_sdk_version", |
| 447 |
stl: "libc++_static", |
| 448 |
compile_multilib: "both", |
| 449 |
|
| 450 |
defaults: [ |
| 451 |
"skia_arch_defaults", |
| 452 |
], |
| 453 |
|
| 454 |
cflags: [ |
| 455 |
$skqp_cflags |
| 456 |
"-Wno-unused-parameter", |
| 457 |
"-Wno-unused-variable", |
| 458 |
], |
| 459 |
|
| 460 |
cppflags:[ |
| 461 |
$skqp_cflags_cc |
| 462 |
], |
| 463 |
|
| 464 |
local_include_dirs: [ |
| 465 |
"skqp", |
| 466 |
$skqp_includes |
| 467 |
], |
| 468 |
|
| 469 |
export_include_dirs: [ |
| 470 |
"skqp", |
| 471 |
], |
| 472 |
|
| 473 |
srcs: [ |
| 474 |
$skqp_srcs |
| 475 |
], |
| 476 |
|
| 477 |
header_libs: ["jni_headers"], |
| 478 |
|
| 479 |
shared_libs: [ |
| 480 |
"libandroid", |
| 481 |
"libEGL", |
| 482 |
"libGLESv2", |
| 483 |
"liblog", |
| 484 |
"libvulkan", |
| 485 |
"libz", |
| 486 |
], |
| 487 |
static_libs: [ |
| 488 |
"libexpat", |
| 489 |
"libjpeg_static_ndk", |
| 490 |
"libpng_ndk", |
| 491 |
"libwebp-decode", |
| 492 |
"libwebp-encode", |
| 493 |
"libwuffs_mirror_release_c", |
| 494 |
] |
| 495 |
} |
| 496 |
''') |
| 497 |
|
| 498 |
# This template is separate from the general bp template so that multiple SkQP |
| 499 |
# variants can be generated. |
| 500 |
# Note: override_android_test doesn't support the fields we would need to |
| 501 |
# override, so we have to live with some duplication between multiple instances |
| 502 |
# of android_test. |
| 503 |
skqp_instance_bp = string.Template('''cc_library_shared { |
| 504 |
// Note: this must be included in the list of libraries that SkQP attempts |
| 505 |
// to load in |
| 506 |
// platform_tools/android/apps/skqp/src/main/java/org/skia/skqp/SkQP.java |
| 507 |
name: "$skqp_jni_lib_name", |
| 508 |
defaults: ["skqp_jni_defaults"], |
| 509 |
// Appended to the list of cflags set in skqp_jni_defaults |
| 510 |
cflags: [ |
| 511 |
$skqp_extra_cflags |
| 512 |
], |
| 513 |
} |
| 514 |
|
| 515 |
android_test { |
| 516 |
// Module (and APK) name |
| 517 |
name: "$skqp_name", |
| 518 |
team: "trendy_team_android_core_graphics_stack", |
| 519 |
defaults: ["cts_defaults"], |
| 520 |
test_suites: [ |
| 521 |
$skqp_test_suites |
| 522 |
], |
| 523 |
|
| 524 |
// These both override the package names set in AndroidManifest.xml (which |
| 525 |
// remain there to allow building/running SkQP outside of Android framework) |
| 526 |
package_name: "$skqp_package_name", |
| 527 |
instrumentation_target_package: "$skqp_package_name", |
| 528 |
|
| 529 |
libs: ["android.test.runner.stubs"], |
| 530 |
jni_libs: ["$skqp_jni_lib_name"], |
| 531 |
compile_multilib: "both", |
| 532 |
|
| 533 |
static_libs: [ |
| 534 |
"android-support-design", |
| 535 |
"ctstestrunner-axt", |
| 536 |
], |
| 537 |
manifest: "platform_tools/android/apps/skqp/src/main/AndroidManifest.xml", |
| 538 |
test_config_template: "platform_tools/android/apps/skqp/src/main/AndroidTestTemplate.xml", |
| 539 |
|
| 540 |
asset_dirs: ["platform_tools/android/apps/skqp/src/main/assets", "resources"], |
| 541 |
resource_dirs: ["platform_tools/android/apps/skqp/src/main/res"], |
| 542 |
srcs: ["platform_tools/android/apps/skqp/src/main/java/**/*.java"], |
| 543 |
|
| 544 |
sdk_version: "test_current", |
| 545 |
} |
| 546 |
''') |
| 547 |
|
| 548 |
# We'll run GN to get the main source lists and include directories for Skia. |
| 549 |
def generate_args(target_os, enable_gpu, renderengine = False): |
| 550 |
d = { |
| 551 |
'is_official_build': 'true', |
| 552 |
|
| 553 |
# gn_to_bp_utils' GetArchSources will take care of architecture-specific |
| 554 |
# files. |
| 555 |
'target_cpu': '"none"', |
| 556 |
|
| 557 |
# Use the custom FontMgr, as the framework will handle fonts. |
| 558 |
'skia_enable_fontmgr_custom_directory': 'false', |
| 559 |
'skia_enable_fontmgr_custom_embedded': 'false', |
| 560 |
'skia_enable_fontmgr_android': 'false', |
| 561 |
'skia_enable_fontmgr_android_ndk': 'false', |
| 562 |
'skia_enable_fontmgr_win': 'false', |
| 563 |
'skia_enable_fontmgr_win_gdi': 'false', |
| 564 |
'skia_use_fonthost_mac': 'false', |
| 565 |
|
| 566 |
'skia_use_system_harfbuzz': 'false', |
| 567 |
'skia_pdf_subset_harfbuzz': 'true', |
| 568 |
|
| 569 |
# enable features used in skia_nanobench |
| 570 |
'skia_tools_require_resources': 'true', |
| 571 |
|
| 572 |
'skia_use_fontconfig': 'false', |
| 573 |
'skia_include_multiframe_procs': 'true', |
| 574 |
|
| 575 |
# Tracing-related flags: |
| 576 |
'skia_disable_tracing': 'false', |
| 577 |
# The two Perfetto integrations are currently mutually exclusive due to |
| 578 |
# complexity. |
| 579 |
'skia_use_perfetto': 'false', |
| 580 |
} |
| 581 |
d['target_os'] = target_os |
| 582 |
if target_os == '"android"': |
| 583 |
d['skia_enable_tools'] = 'true' |
| 584 |
# Only enable for actual Android framework builds targeting Android devices. |
| 585 |
# (E.g. disabled for host builds and SkQP) |
| 586 |
d['skia_android_framework_use_perfetto'] = 'true' |
| 587 |
|
| 588 |
if enable_gpu: |
| 589 |
d['skia_use_vulkan'] = 'true' |
| 590 |
d['skia_enable_ganesh'] = 'true' |
| 591 |
if renderengine: |
| 592 |
d['skia_enable_graphite'] = 'true' |
| 593 |
else: |
| 594 |
d['skia_use_vulkan'] = 'false' |
| 595 |
d['skia_enable_ganesh'] = 'false' |
| 596 |
d['skia_enable_graphite'] = 'false' |
| 597 |
|
| 598 |
if target_os == '"win"': |
| 599 |
# The Android Windows build system does not provide FontSub.h |
| 600 |
d['skia_use_xps'] = 'false' |
| 601 |
|
| 602 |
# BUILDCONFIG.gn expects these to be set when building for Windows, but |
| 603 |
# we're just creating Android.bp, so we don't need them. Populate with |
| 604 |
# some placeholder values. |
| 605 |
d['win_vc'] = '"placeholder_version"' |
| 606 |
d['win_sdk_version'] = '"placeholder_version"' |
| 607 |
d['win_toolchain_version'] = '"placeholder_version"' |
| 608 |
|
| 609 |
if target_os == '"android"' and not renderengine: |
| 610 |
d['skia_use_crabbyavif'] = 'true' |
| 611 |
d['skia_use_jpeg_gainmaps'] = 'true' |
| 612 |
else: |
| 613 |
d['skia_use_crabbyavif'] = 'false' |
| 614 |
|
| 615 |
if renderengine: |
| 616 |
d['skia_use_libpng_decode'] = 'false' |
| 617 |
d['skia_use_libjpeg_turbo_decode'] = 'false' |
| 618 |
d['skia_use_libjpeg_turbo_encode'] = 'false' |
| 619 |
d['skia_use_libwebp_decode'] = 'false' |
| 620 |
d['skia_use_libwebp_encode'] = 'false' |
| 621 |
d['skia_use_wuffs'] = 'false' |
| 622 |
d['skia_enable_pdf'] = 'false' |
| 623 |
d['skia_use_freetype'] = 'false' |
| 624 |
d['skia_use_fixed_gamma_text'] = 'false' |
| 625 |
d['skia_use_expat'] = 'false' |
| 626 |
d['skia_enable_fontmgr_custom_empty'] = 'false' |
| 627 |
else: |
| 628 |
d['skia_enable_android_utils'] = 'true' |
| 629 |
d['skia_use_freetype'] = 'true' |
| 630 |
d['skia_use_fontations'] = 'true' |
| 631 |
d['skia_use_fixed_gamma_text'] = 'true' |
| 632 |
d['skia_enable_fontmgr_custom_empty'] = 'true' |
| 633 |
d['skia_use_wuffs'] = 'true' |
| 634 |
|
| 635 |
return d |
| 636 |
|
| 637 |
# Android's build (soong) will break if we list anything other than these file |
| 638 |
# types in `srcs` (e.g. all header extensions must be excluded). |
| 639 |
# All libcxx generated *.rs.* must also be excluded. |
| 640 |
def is_src(s): |
| 641 |
src_extensions = ['.s', '.S', '.c', '.cpp', '.cc', '.cxx', '.mm'] |
| 642 |
(base, ext) = os.path.splitext(s) |
| 643 |
(_, baseExt) = os.path.splitext(base) |
| 644 |
return ext in src_extensions and baseExt != ".rs" |
| 645 |
|
| 646 |
def strip_non_srcs(sources): |
| 647 |
return {s for s in sources if is_src(s) } |
| 648 |
|
| 649 |
def get_defines(json): |
| 650 |
defines = {d for d in json['targets']['//:skia']['defines']} |
| 651 |
return defines |
| 652 |
|
| 653 |
def disallow_platforms(config, desired): |
| 654 |
PLATFORMS = { 'IOS', 'MAC', 'WIN', 'ANDROID', 'UNIX' } |
| 655 |
with open(config, 'a') as f: |
| 656 |
p = sorted(PLATFORMS.difference({ desired })) |
| 657 |
s = '#if ' |
| 658 |
for i in range(len(p)): |
| 659 |
s = s + 'defined(SK_BUILD_FOR_%s)' % p[i] |
| 660 |
if i < len(p) - 1: |
| 661 |
s += ' || ' |
| 662 |
if i % 2 == 1: |
| 663 |
s += '\\\n ' |
| 664 |
print(s, file=f) |
| 665 |
print(' #error "Only SK_BUILD_FOR_%s should be defined!"' % desired, file=f) |
| 666 |
print('#endif', file=f) |
| 667 |
|
| 668 |
def append_to_file(config, s): |
| 669 |
with open(config, 'a') as f: |
| 670 |
print(s, file=f) |
| 671 |
|
| 672 |
def write_android_config(config_path, defines, isNDKConfig = False): |
| 673 |
gn_to_bp_utils.WriteUserConfig(config_path, defines) |
| 674 |
append_to_file(config_path, ''' |
| 675 |
#ifndef SK_BUILD_FOR_ANDROID |
| 676 |
#error "SK_BUILD_FOR_ANDROID must be defined!" |
| 677 |
#endif''') |
| 678 |
disallow_platforms(config_path, 'ANDROID') |
| 679 |
|
| 680 |
if isNDKConfig: |
| 681 |
append_to_file(config_path, ''' |
| 682 |
#undef SK_BUILD_FOR_ANDROID_FRAMEWORK''') |
| 683 |
|
| 684 |
def write_config(config_path, defines, platform): |
| 685 |
gn_to_bp_utils.WriteUserConfig(config_path, defines) |
| 686 |
append_to_file(config_path, ''' |
| 687 |
// Correct SK_BUILD_FOR flags that may have been set by |
| 688 |
// SkTypes.h/Android.bp |
| 689 |
#ifndef SK_BUILD_FOR_%s |
| 690 |
#define SK_BUILD_FOR_%s |
| 691 |
#endif |
| 692 |
#ifdef SK_BUILD_FOR_ANDROID |
| 693 |
#undef SK_BUILD_FOR_ANDROID |
| 694 |
#endif''' % (platform, platform)) |
| 695 |
disallow_platforms(config_path, platform) |
| 696 |
|
| 697 |
# Turn a list of strings into the style bpfmt outputs. |
| 698 |
def bpfmt(indent, lst, sort=True): |
| 699 |
if sort: |
| 700 |
lst = sorted(lst) |
| 701 |
return ('\n' + ' '*indent).join('"%s",' % v for v in lst) |
| 702 |
|
| 703 |
def main(): |
| 704 |
gn_args = generate_args('"android"', True) |
| 705 |
gn_args_linux = generate_args('"linux"', False) |
| 706 |
gn_args_mac = generate_args('"mac"', False) |
| 707 |
gn_args_win = generate_args('"win"', False) |
| 708 |
gn_args_renderengine = generate_args('"android"', True, True) |
| 709 |
|
| 710 |
js = gn_to_bp_utils.GenerateJSONFromGN(args.gn, gn_args) |
| 711 |
build_dir = js['build_settings']['build_dir'] |
| 712 |
|
| 713 |
def strip_slashes(lst): |
| 714 |
return {p.lstrip('/') for p in lst if not p.startswith(build_dir)} |
| 715 |
|
| 716 |
# Also remove generated files and directories. |
| 717 |
android_srcs = strip_slashes(js['targets']['//:skia']['sources']) |
| 718 |
cflags = strip_slashes(js['targets']['//:skia']['cflags']) |
| 719 |
cflags_cc = strip_slashes(js['targets']['//:skia']['cflags_cc']) |
| 720 |
local_includes = strip_slashes(js['targets']['//:skia']['include_dirs']) |
| 721 |
export_includes = strip_slashes(js['targets']['//:public']['include_dirs']) |
| 722 |
|
| 723 |
gm_srcs = strip_slashes(js['targets']['//:gm']['sources']) |
| 724 |
gm_includes = strip_slashes(js['targets']['//:gm']['include_dirs']) |
| 725 |
|
| 726 |
test_srcs = strip_slashes(js['targets']['//:tests']['sources']) |
| 727 |
test_includes = strip_slashes(js['targets']['//:tests']['include_dirs']) |
| 728 |
|
| 729 |
dm_srcs = strip_slashes(js['targets']['//:dm']['sources']) |
| 730 |
dm_includes = strip_slashes(js['targets']['//:dm']['include_dirs']) |
| 731 |
|
| 732 |
nanobench_target = js['targets']['//:nanobench'] |
| 733 |
nanobench_srcs = strip_slashes(nanobench_target['sources']) |
| 734 |
nanobench_includes = strip_slashes(nanobench_target['include_dirs']) |
| 735 |
|
| 736 |
skcms_srcs = strip_slashes(js['targets']['//modules/skcms:skcms']['sources']) |
| 737 |
|
| 738 |
|
| 739 |
gn_to_bp_utils.GrabDependentValues(js, '//:gm', 'sources', gm_srcs, ['//:skia', '//:pathops']) |
| 740 |
gn_to_bp_utils.GrabDependentValues(js, '//:tests', 'sources', test_srcs, ['//:skia', '//:pathops']) |
| 741 |
gn_to_bp_utils.GrabDependentValues(js, '//:dm', 'sources', |
| 742 |
dm_srcs, ['//:skia', '//:gm', '//:tests', '//:pathops']) |
| 743 |
gn_to_bp_utils.GrabDependentValues(js, '//:nanobench', 'sources', |
| 744 |
nanobench_srcs, ['//:skia', '//:gm', '//:pathops']) |
| 745 |
|
| 746 |
# skcms is a little special, kind of a second-party library. |
| 747 |
local_includes.add("modules/skcms") |
| 748 |
gm_includes .add("modules/skcms") |
| 749 |
|
| 750 |
VMA_DEP = "//src/gpu/vk/vulkanmemoryallocator:vulkanmemoryallocator" |
| 751 |
|
| 752 |
gn_to_bp_utils.GrabDependentValues(js, '//:skia', 'sources', android_srcs, VMA_DEP) |
| 753 |
android_srcs = strip_non_srcs(android_srcs) |
| 754 |
|
| 755 |
js_linux = gn_to_bp_utils.GenerateJSONFromGN(args.gn, gn_args_linux) |
| 756 |
linux_srcs = strip_slashes(js_linux['targets']['//:skia']['sources']) |
| 757 |
gn_to_bp_utils.GrabDependentValues(js_linux, '//:skia', 'sources', linux_srcs, |
| 758 |
None) |
| 759 |
linux_srcs = strip_non_srcs(linux_srcs) |
| 760 |
|
| 761 |
js_mac = gn_to_bp_utils.GenerateJSONFromGN(args.gn, gn_args_mac) |
| 762 |
mac_srcs = strip_slashes(js_mac['targets']['//:skia']['sources']) |
| 763 |
gn_to_bp_utils.GrabDependentValues(js_mac, '//:skia', 'sources', mac_srcs, |
| 764 |
None) |
| 765 |
mac_srcs = strip_non_srcs(mac_srcs) |
| 766 |
|
| 767 |
js_win = gn_to_bp_utils.GenerateJSONFromGN(args.gn, gn_args_win) |
| 768 |
win_srcs = strip_slashes(js_win['targets']['//:skia']['sources']) |
| 769 |
gn_to_bp_utils.GrabDependentValues(js_win, '//:skia', 'sources', win_srcs, |
| 770 |
None) |
| 771 |
win_srcs = strip_non_srcs(win_srcs) |
| 772 |
|
| 773 |
srcs = android_srcs.intersection(linux_srcs).intersection(mac_srcs) |
| 774 |
srcs = srcs.intersection(win_srcs) |
| 775 |
|
| 776 |
android_srcs = android_srcs.difference(srcs) |
| 777 |
linux_srcs = linux_srcs.difference(srcs) |
| 778 |
mac_srcs = mac_srcs.difference(srcs) |
| 779 |
win_srcs = win_srcs.difference(srcs) |
| 780 |
|
| 781 |
gm_srcs = strip_non_srcs(gm_srcs) |
| 782 |
test_srcs = strip_non_srcs(test_srcs) |
| 783 |
dm_srcs = strip_non_srcs(dm_srcs).difference(gm_srcs).difference(test_srcs) |
| 784 |
nanobench_srcs = strip_non_srcs(nanobench_srcs).difference(gm_srcs) |
| 785 |
skcms_srcs = strip_non_srcs(skcms_srcs) |
| 786 |
|
| 787 |
test_minus_gm_includes = test_includes.difference(gm_includes) |
| 788 |
test_minus_gm_srcs = test_srcs.difference(gm_srcs) |
| 789 |
|
| 790 |
cflags = gn_to_bp_utils.CleanupCFlags(cflags) |
| 791 |
cflags_cc = gn_to_bp_utils.CleanupCCFlags(cflags_cc) |
| 792 |
|
| 793 |
# Execute GN for specialized RenderEngine target |
| 794 |
js_renderengine = gn_to_bp_utils.GenerateJSONFromGN(args.gn, gn_args_renderengine) |
| 795 |
renderengine_srcs = strip_slashes( |
| 796 |
js_renderengine['targets']['//:skia']['sources']) |
| 797 |
gn_to_bp_utils.GrabDependentValues(js_renderengine, '//:skia', 'sources', |
| 798 |
renderengine_srcs, VMA_DEP) |
| 799 |
renderengine_srcs = strip_non_srcs(renderengine_srcs) |
| 800 |
|
| 801 |
# Execute GN for specialized SkQP target |
| 802 |
skqp_sdk_version = 26 |
| 803 |
js_skqp = gn_to_bp_utils.GenerateJSONFromGN(args.gn, skqp_gn_args.GetGNArgs(api_level=skqp_sdk_version, |
| 804 |
debug=False, |
| 805 |
is_android_bp=True)) |
| 806 |
skqp_srcs = strip_slashes(js_skqp['targets']['//:libskqp_jni']['sources']) |
| 807 |
skqp_includes = strip_slashes(js_skqp['targets']['//:libskqp_jni']['include_dirs']) |
| 808 |
skqp_cflags = strip_slashes(js_skqp['targets']['//:libskqp_jni']['cflags']) |
| 809 |
skqp_cflags_cc = strip_slashes(js_skqp['targets']['//:libskqp_jni']['cflags_cc']) |
| 810 |
skqp_defines = strip_slashes(js_skqp['targets']['//:libskqp_jni']['defines']) |
| 811 |
|
| 812 |
skqp_includes.update(strip_slashes(js_skqp['targets']['//:public']['include_dirs'])) |
| 813 |
|
| 814 |
gn_to_bp_utils.GrabDependentValues(js_skqp, '//:libskqp_jni', 'sources', |
| 815 |
skqp_srcs, VMA_DEP) |
| 816 |
# We are exlcuding gpu here to get rid of the includes that are being added from |
| 817 |
# vulkanmemoryallocator. This does not seem to remove any other incldues from gpu so things |
| 818 |
# should work out fine for now |
| 819 |
gn_to_bp_utils.GrabDependentValues(js_skqp, '//:libskqp_jni', 'include_dirs', |
| 820 |
skqp_includes, ['//:gif', '//:gpu']) |
| 821 |
gn_to_bp_utils.GrabDependentValues(js_skqp, '//:libskqp_jni', 'cflags', |
| 822 |
skqp_cflags, None) |
| 823 |
gn_to_bp_utils.GrabDependentValues(js_skqp, '//:libskqp_jni', 'cflags_cc', |
| 824 |
skqp_cflags_cc, None) |
| 825 |
gn_to_bp_utils.GrabDependentValues(js_skqp, '//:libskqp_jni', 'defines', |
| 826 |
skqp_defines, None) |
| 827 |
|
| 828 |
skqp_defines.add("GPU_TEST_UTILS=1") |
| 829 |
skqp_defines.add("SK_ALLOW_STATIC_GLOBAL_INITIALIZERS=1") |
| 830 |
skqp_defines.add("SK_BUILD_FOR_SKQP") |
| 831 |
skqp_defines.add("SK_ENABLE_DUMP_GPU") |
| 832 |
skqp_defines.remove("SK_USE_INTERNAL_VULKAN_HEADERS") |
| 833 |
skqp_defines.remove("SK_USE_PERFETTO") |
| 834 |
|
| 835 |
skqp_srcs = strip_non_srcs(skqp_srcs) |
| 836 |
skqp_cflags = gn_to_bp_utils.CleanupCFlags(skqp_cflags) |
| 837 |
skqp_cflags_cc = gn_to_bp_utils.CleanupCCFlags(skqp_cflags_cc) |
| 838 |
|
| 839 |
here = os.path.dirname(__file__) |
| 840 |
defs = gn_to_bp_utils.GetArchSources(os.path.join(here, 'opts.gni')) |
| 841 |
|
| 842 |
android_defines = get_defines(js) |
| 843 |
linux_defines = get_defines(js_linux) |
| 844 |
mac_defines = get_defines(js_mac) |
| 845 |
win_defines = get_defines(js_win) |
| 846 |
renderengine_defines = get_defines(js_renderengine) |
| 847 |
renderengine_defines.add('SK_IN_RENDERENGINE') |
| 848 |
|
| 849 |
os.makedirs(out_path('android/include/config/'), exist_ok=True) |
| 850 |
os.makedirs(out_path('linux/include/config/'), exist_ok=True) |
| 851 |
os.makedirs(out_path('mac/include/config/'), exist_ok=True) |
| 852 |
os.makedirs(out_path('win/include/config/'), exist_ok=True) |
| 853 |
os.makedirs(out_path('renderengine/include/config/'), exist_ok=True) |
| 854 |
os.makedirs(out_path('skqp/include/config/'), exist_ok=True) |
| 855 |
os.makedirs(out_path('vma_android/include'), exist_ok=True) |
| 856 |
|
| 857 |
shutil.copy('third_party/externals/vulkanmemoryallocator/include/vk_mem_alloc.h', |
| 858 |
out_path('vma_android/include')) |
| 859 |
shutil.copy('third_party/externals/vulkanmemoryallocator/LICENSE.txt', out_path('vma_android/')) |
| 860 |
|
| 861 |
write_android_config(out_path('android/include/config/SkUserConfig.h'), android_defines) |
| 862 |
write_android_config(out_path('renderengine/include/config/SkUserConfig.h'), renderengine_defines) |
| 863 |
write_android_config(out_path('skqp/include/config/SkUserConfig.h'), skqp_defines, True) |
| 864 |
|
| 865 |
write_config(out_path('linux/include/config/SkUserConfig.h'), linux_defines, 'UNIX') |
| 866 |
write_config(out_path('mac/include/config/SkUserConfig.h'), mac_defines, 'MAC') |
| 867 |
write_config(out_path('win/include/config/SkUserConfig.h'), win_defines, 'WIN') |
| 868 |
|
| 869 |
# OK! We have everything to fill in Android.bp... |
| 870 |
with open(out_path('Android.bp'), 'w') as Android_bp: |
| 871 |
print(bp.substitute({ |
| 872 |
'export_includes': bpfmt(8, export_includes), |
| 873 |
'local_includes': bpfmt(8, local_includes), |
| 874 |
'srcs': bpfmt(8, srcs), |
| 875 |
'cflags': bpfmt(8, cflags, False), |
| 876 |
'cflags_cc': bpfmt(8, cflags_cc), |
| 877 |
|
| 878 |
'x86_srcs': bpfmt(16, strip_non_srcs(defs['hsw'] + |
| 879 |
defs['skx'])), |
| 880 |
|
| 881 |
'gm_includes' : bpfmt(8, gm_includes), |
| 882 |
'gm_srcs' : bpfmt(8, gm_srcs), |
| 883 |
|
| 884 |
'test_minus_gm_includes' : bpfmt(8, test_minus_gm_includes), |
| 885 |
'test_minus_gm_srcs' : bpfmt(8, test_minus_gm_srcs), |
| 886 |
|
| 887 |
'dm_includes' : bpfmt(8, dm_includes), |
| 888 |
'dm_srcs' : bpfmt(8, dm_srcs), |
| 889 |
|
| 890 |
'nanobench_includes' : bpfmt(8, nanobench_includes), |
| 891 |
'nanobench_srcs' : bpfmt(8, nanobench_srcs), |
| 892 |
|
| 893 |
'skcms_srcs': bpfmt(8, skcms_srcs), |
| 894 |
|
| 895 |
'skqp_sdk_version': skqp_sdk_version, |
| 896 |
'skqp_includes': bpfmt(8, skqp_includes), |
| 897 |
'skqp_srcs': bpfmt(8, skqp_srcs), |
| 898 |
'skqp_cflags': bpfmt(8, skqp_cflags, False), |
| 899 |
'skqp_cflags_cc': bpfmt(8, skqp_cflags_cc), |
| 900 |
|
| 901 |
'android_srcs': bpfmt(10, android_srcs), |
| 902 |
'linux_srcs': bpfmt(10, linux_srcs), |
| 903 |
'mac_srcs': bpfmt(10, mac_srcs), |
| 904 |
'win_srcs': bpfmt(10, win_srcs), |
| 905 |
|
| 906 |
'renderengine_srcs': bpfmt(8, renderengine_srcs), |
| 907 |
}), file=Android_bp) |
| 908 |
|
| 909 |
print(skqp_instance_bp.substitute({ |
| 910 |
'skqp_name': 'CtsSkQPTestCases', |
| 911 |
'skqp_package_name': 'org.skia.skqp', |
| 912 |
'skqp_jni_lib_name': 'libskqp_jni', |
| 913 |
'skqp_test_suites': bpfmt(8, ['general-tests', 'cts'], False), |
| 914 |
'skqp_extra_cflags': '', |
| 915 |
}), file=Android_bp) |
| 916 |
|
| 917 |
# This duplicated SkQP test module runs all tests that are included in SkQP, |
| 918 |
# regardless of the device's actual vendor API level (excluding those marked |
| 919 |
# with kNever). This is used for ensuring coverage, and isn't enforced in CTS. |
| 920 |
# |
| 921 |
# This build is currently only maintained for soong / blueprint builds of SkQP |
| 922 |
# in the Android framework itself due to staffing constraints. |
| 923 |
print(skqp_instance_bp.substitute({ |
| 924 |
'skqp_name': 'AllSkQPTestCases', |
| 925 |
'skqp_package_name': 'org.skia.skqp_alltests', |
| 926 |
'skqp_jni_lib_name': 'libskqp_jni_alltests', |
| 927 |
'skqp_test_suites': bpfmt(8, ['general-tests'], False), |
| 928 |
'skqp_extra_cflags': bpfmt(8, ['-DSKQP_ENFORCE_ALL_INCLUDED_TESTS'], False), |
| 929 |
}), file=Android_bp) |
| 930 |
|
| 931 |
if __name__ == '__main__': |
| 932 |
main() |