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