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