• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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            "libmediandk", // Needed to link libcrabbyavif_ffi in some configurations.
280        ],
281        whole_static_libs: [
282            "libcrabbyavif_ffi",
283        ],
284      },
285      darwin: {
286        host_ldlibs: [
287            "-framework AppKit",
288        ],
289      },
290      windows: {
291        host_ldlibs: [
292            "-lgdi32",
293            "-loleaut32",
294            "-lole32",
295            "-lopengl32",
296            "-luuid",
297            "-lwindowscodecs",
298        ],
299      },
300    },
301}
302
303cc_defaults {
304    name: "skia_tool_deps",
305    defaults: [
306        "skia_deps",
307    ],
308    shared_libs: [
309        "libicu",
310        "libharfbuzz_ng",
311    ],
312    static_libs: [
313        "libskia",
314    ],
315    cflags: [
316        "-DSK_SHAPER_HARFBUZZ_AVAILABLE",
317        "-DSK_SHAPER_UNICODE_AVAILABLE",
318        "-DSK_UNICODE_AVAILABLE",
319        "-DSK_UNICODE_ICU_IMPLEMENTATION",
320        "-Wno-implicit-fallthrough",
321        "-Wno-unused-parameter",
322        "-Wno-unused-variable",
323    ],
324    target: {
325      windows: {
326        enabled: true,
327      },
328    },
329
330    data: [
331        "resources/**/*",
332    ],
333}
334
335cc_defaults {
336    name: "skia_gm_srcs",
337    local_include_dirs: [
338        $gm_includes
339    ],
340
341    srcs: [
342        $gm_srcs
343    ],
344}
345
346cc_defaults {
347    name: "skia_test_minus_gm_srcs",
348    local_include_dirs: [
349        $test_minus_gm_includes
350    ],
351
352    srcs: [
353        $test_minus_gm_srcs
354    ],
355}
356
357cc_defaults {
358    name: "skqp_jni_defaults",
359    sdk_version: "$skqp_sdk_version",
360    stl: "libc++_static",
361    compile_multilib: "both",
362
363    defaults: [
364        "skia_arch_defaults",
365    ],
366
367    cflags: [
368        $skqp_cflags
369        "-Wno-unused-parameter",
370        "-Wno-unused-variable",
371    ],
372
373    cppflags:[
374        $skqp_cflags_cc
375    ],
376
377    local_include_dirs: [
378        "skqp",
379        $skqp_includes
380    ],
381
382    export_include_dirs: [
383        "skqp",
384    ],
385
386    srcs: [
387        $skqp_srcs
388    ],
389
390    header_libs: ["jni_headers"],
391
392    shared_libs: [
393          "libandroid",
394          "libEGL",
395          "libGLESv2",
396          "liblog",
397          "libvulkan",
398          "libz",
399    ],
400    static_libs: [
401          "libexpat",
402          "libjpeg_static_ndk",
403          "libpng_ndk",
404          "libwebp-decode",
405          "libwebp-encode",
406          "libwuffs_mirror_release_c",
407    ]
408}
409''')
410
411# This template is separate from the general bp template so that multiple SkQP
412# variants can be generated.
413# Note: override_android_test doesn't support the fields we would need to
414# override, so we have to live with some duplication between multiple instances
415# of android_test.
416skqp_instance_bp = string.Template('''cc_library_shared {
417    // Note: this must be included in the list of libraries that SkQP attempts
418    // to load in
419    // platform_tools/android/apps/skqp/src/main/java/org/skia/skqp/SkQP.java
420    name: "$skqp_jni_lib_name",
421    defaults: ["skqp_jni_defaults"],
422    // Appended to the list of cflags set in skqp_jni_defaults
423    cflags: [
424        $skqp_extra_cflags
425    ],
426}
427
428android_test {
429    // Module (and APK) name
430    name: "$skqp_name",
431    team: "trendy_team_android_core_graphics_stack",
432    defaults: ["cts_defaults"],
433    test_suites: [
434        $skqp_test_suites
435    ],
436
437    // These both override the package names set in AndroidManifest.xml (which
438    // remain there to allow building/running SkQP outside of Android framework)
439    package_name: "$skqp_package_name",
440    instrumentation_target_package: "$skqp_package_name",
441
442    libs: ["android.test.runner.stubs"],
443    jni_libs: ["$skqp_jni_lib_name"],
444    compile_multilib: "both",
445
446    static_libs: [
447        "android-support-design",
448        "ctstestrunner-axt",
449    ],
450    manifest: "platform_tools/android/apps/skqp/src/main/AndroidManifest.xml",
451    test_config_template: "platform_tools/android/apps/skqp/src/main/AndroidTestTemplate.xml",
452
453    asset_dirs: ["platform_tools/android/apps/skqp/src/main/assets", "resources"],
454    resource_dirs: ["platform_tools/android/apps/skqp/src/main/res"],
455    srcs: ["platform_tools/android/apps/skqp/src/main/java/**/*.java"],
456
457    sdk_version: "test_current",
458}
459''')
460
461# We'll run GN to get the main source lists and include directories for Skia.
462def generate_args(target_os, enable_gpu, renderengine = False):
463  d = {
464    'is_official_build':                    'true',
465
466    # gn_to_bp_utils' GetArchSources will take care of architecture-specific
467    # files.
468    'target_cpu':                           '"none"',
469
470    # Use the custom FontMgr, as the framework will handle fonts.
471    'skia_enable_fontmgr_custom_directory': 'false',
472    'skia_enable_fontmgr_custom_embedded':  'false',
473    'skia_enable_fontmgr_android':          'false',
474    'skia_enable_fontmgr_win':              'false',
475    'skia_enable_fontmgr_win_gdi':          'false',
476    'skia_use_fonthost_mac':                'false',
477
478    'skia_use_system_harfbuzz':             'false',
479    'skia_pdf_subset_harfbuzz':             'true',
480
481    # enable features used in skia_nanobench
482    'skia_tools_require_resources':         'true',
483
484    'skia_use_fontconfig':                  'false',
485    'skia_include_multiframe_procs':        'true',
486
487    # Tracing-related flags:
488    'skia_disable_tracing':                 'false',
489    # The two Perfetto integrations are currently mutually exclusive due to
490    # complexity.
491    'skia_use_perfetto':                    'false',
492  }
493  d['target_os'] = target_os
494  if target_os == '"android"':
495    d['skia_enable_tools'] = 'true'
496    # Only enable for actual Android framework builds targeting Android devices.
497    # (E.g. disabled for host builds and SkQP)
498    d['skia_android_framework_use_perfetto'] = 'true'
499
500  if enable_gpu:
501    d['skia_use_vulkan']    = 'true'
502    d['skia_enable_ganesh'] = 'true'
503    if renderengine:
504      d['skia_enable_graphite'] = 'true'
505  else:
506    d['skia_use_vulkan']      = 'false'
507    d['skia_enable_ganesh']   = 'false'
508    d['skia_enable_graphite'] = 'false'
509
510  if target_os == '"win"':
511    # The Android Windows build system does not provide FontSub.h
512    d['skia_use_xps'] = 'false'
513
514    # BUILDCONFIG.gn expects these to be set when building for Windows, but
515    # we're just creating Android.bp, so we don't need them. Populate with
516    # some placeholder values.
517    d['win_vc'] = '"placeholder_version"'
518    d['win_sdk_version'] = '"placeholder_version"'
519    d['win_toolchain_version'] = '"placeholder_version"'
520
521  if target_os == '"android"' and not renderengine:
522    d['skia_use_libheif']  = 'true'
523    d['skia_use_crabbyavif'] = 'true'
524    d['skia_use_jpeg_gainmaps'] = 'true'
525  else:
526    d['skia_use_libheif']  = 'false'
527    d['skia_use_crabbyavif'] = 'false'
528
529  if renderengine:
530    d['skia_use_libpng_decode'] = 'false'
531    d['skia_use_libjpeg_turbo_decode'] = 'false'
532    d['skia_use_libjpeg_turbo_encode'] = 'false'
533    d['skia_use_libwebp_decode'] = 'false'
534    d['skia_use_libwebp_encode'] = 'false'
535    d['skia_use_wuffs'] = 'false'
536    d['skia_enable_pdf'] = 'false'
537    d['skia_use_freetype'] = 'false'
538    d['skia_use_fixed_gamma_text'] = 'false'
539    d['skia_use_expat'] = 'false'
540    d['skia_enable_fontmgr_custom_empty'] = 'false'
541  else:
542    d['skia_enable_android_utils'] = 'true'
543    d['skia_use_freetype'] = 'true'
544    d['skia_use_fixed_gamma_text'] = 'true'
545    d['skia_enable_fontmgr_custom_empty'] = 'true'
546    d['skia_use_wuffs'] = 'true'
547
548  return d
549
550gn_args       = generate_args('"android"', True)
551gn_args_linux = generate_args('"linux"',   False)
552gn_args_mac   = generate_args('"mac"',     False)
553gn_args_win   = generate_args('"win"',     False)
554gn_args_renderengine  = generate_args('"android"', True, True)
555
556js = gn_to_bp_utils.GenerateJSONFromGN(gn_args)
557
558def strip_slashes(lst):
559  return {str(p.lstrip('/')) for p in lst}
560
561android_srcs    = strip_slashes(js['targets']['//:skia']['sources'])
562cflags          = strip_slashes(js['targets']['//:skia']['cflags'])
563cflags_cc       = strip_slashes(js['targets']['//:skia']['cflags_cc'])
564local_includes  = strip_slashes(js['targets']['//:skia']['include_dirs'])
565export_includes = strip_slashes(js['targets']['//:public']['include_dirs'])
566
567gm_srcs         = strip_slashes(js['targets']['//:gm']['sources'])
568gm_includes     = strip_slashes(js['targets']['//:gm']['include_dirs'])
569
570test_srcs         = strip_slashes(js['targets']['//:tests']['sources'])
571test_includes     = strip_slashes(js['targets']['//:tests']['include_dirs'])
572
573dm_srcs         = strip_slashes(js['targets']['//:dm']['sources'])
574dm_includes     = strip_slashes(js['targets']['//:dm']['include_dirs'])
575
576nanobench_target = js['targets']['//:nanobench']
577nanobench_srcs     = strip_slashes(nanobench_target['sources'])
578nanobench_includes = strip_slashes(nanobench_target['include_dirs'])
579
580
581gn_to_bp_utils.GrabDependentValues(js, '//:gm', 'sources', gm_srcs, '//:skia')
582gn_to_bp_utils.GrabDependentValues(js, '//:tests', 'sources', test_srcs, '//:skia')
583gn_to_bp_utils.GrabDependentValues(js, '//:dm', 'sources',
584                                   dm_srcs, ['//:skia', '//:gm', '//:tests'])
585gn_to_bp_utils.GrabDependentValues(js, '//:nanobench', 'sources',
586                                   nanobench_srcs, ['//:skia', '//:gm'])
587
588# skcms is a little special, kind of a second-party library.
589local_includes.add("modules/skcms")
590gm_includes   .add("modules/skcms")
591
592# Android's build (soong) will break if we list anything other than these file
593# types in `srcs` (e.g. all header extensions must be excluded).
594def strip_non_srcs(sources):
595  src_extensions = ['.s', '.S', '.c', '.cpp', '.cc', '.cxx', '.mm']
596  return {s for s in sources if os.path.splitext(s)[1] in src_extensions}
597
598VMA_DEP = "//src/gpu/vk/vulkanmemoryallocator:vulkanmemoryallocator"
599
600gn_to_bp_utils.GrabDependentValues(js, '//:skia', 'sources', android_srcs, VMA_DEP)
601android_srcs    = strip_non_srcs(android_srcs)
602
603js_linux        = gn_to_bp_utils.GenerateJSONFromGN(gn_args_linux)
604linux_srcs      = strip_slashes(js_linux['targets']['//:skia']['sources'])
605gn_to_bp_utils.GrabDependentValues(js_linux, '//:skia', 'sources', linux_srcs,
606                                   None)
607linux_srcs      = strip_non_srcs(linux_srcs)
608
609js_mac          = gn_to_bp_utils.GenerateJSONFromGN(gn_args_mac)
610mac_srcs        = strip_slashes(js_mac['targets']['//:skia']['sources'])
611gn_to_bp_utils.GrabDependentValues(js_mac, '//:skia', 'sources', mac_srcs,
612                                   None)
613mac_srcs        = strip_non_srcs(mac_srcs)
614
615js_win          = gn_to_bp_utils.GenerateJSONFromGN(gn_args_win)
616win_srcs        = strip_slashes(js_win['targets']['//:skia']['sources'])
617gn_to_bp_utils.GrabDependentValues(js_win, '//:skia', 'sources', win_srcs,
618                                   None)
619win_srcs        = strip_non_srcs(win_srcs)
620
621srcs = android_srcs.intersection(linux_srcs).intersection(mac_srcs)
622srcs = srcs.intersection(win_srcs)
623
624android_srcs    = android_srcs.difference(srcs)
625linux_srcs      =   linux_srcs.difference(srcs)
626mac_srcs        =     mac_srcs.difference(srcs)
627win_srcs        =     win_srcs.difference(srcs)
628
629gm_srcs         = strip_non_srcs(gm_srcs)
630test_srcs       = strip_non_srcs(test_srcs)
631dm_srcs         = strip_non_srcs(dm_srcs).difference(gm_srcs).difference(test_srcs)
632nanobench_srcs  = strip_non_srcs(nanobench_srcs).difference(gm_srcs)
633
634test_minus_gm_includes = test_includes.difference(gm_includes)
635test_minus_gm_srcs = test_srcs.difference(gm_srcs)
636
637cflags = gn_to_bp_utils.CleanupCFlags(cflags)
638cflags_cc = gn_to_bp_utils.CleanupCCFlags(cflags_cc)
639
640# Execute GN for specialized RenderEngine target
641js_renderengine   = gn_to_bp_utils.GenerateJSONFromGN(gn_args_renderengine)
642renderengine_srcs = strip_slashes(
643    js_renderengine['targets']['//:skia']['sources'])
644gn_to_bp_utils.GrabDependentValues(js_renderengine, '//:skia', 'sources',
645                                   renderengine_srcs, VMA_DEP)
646renderengine_srcs = strip_non_srcs(renderengine_srcs)
647
648# Execute GN for specialized SkQP target
649skqp_sdk_version = 26
650js_skqp = gn_to_bp_utils.GenerateJSONFromGN(skqp_gn_args.GetGNArgs(api_level=skqp_sdk_version,
651                                                                   debug=False,
652                                                                   is_android_bp=True))
653skqp_srcs      = strip_slashes(js_skqp['targets']['//:libskqp_jni']['sources'])
654skqp_includes  = strip_slashes(js_skqp['targets']['//:libskqp_jni']['include_dirs'])
655skqp_cflags    = strip_slashes(js_skqp['targets']['//:libskqp_jni']['cflags'])
656skqp_cflags_cc = strip_slashes(js_skqp['targets']['//:libskqp_jni']['cflags_cc'])
657skqp_defines   = strip_slashes(js_skqp['targets']['//:libskqp_jni']['defines'])
658
659skqp_includes.update(strip_slashes(js_skqp['targets']['//:public']['include_dirs']))
660
661gn_to_bp_utils.GrabDependentValues(js_skqp, '//:libskqp_jni', 'sources',
662                                   skqp_srcs, VMA_DEP)
663# We are exlcuding gpu here to get rid of the includes that are being added from
664# vulkanmemoryallocator. This does not seem to remove any other incldues from gpu so things
665# should work out fine for now
666gn_to_bp_utils.GrabDependentValues(js_skqp, '//:libskqp_jni', 'include_dirs',
667                                   skqp_includes, ['//:gif', '//:gpu'])
668gn_to_bp_utils.GrabDependentValues(js_skqp, '//:libskqp_jni', 'cflags',
669                                   skqp_cflags, None)
670gn_to_bp_utils.GrabDependentValues(js_skqp, '//:libskqp_jni', 'cflags_cc',
671                                   skqp_cflags_cc, None)
672gn_to_bp_utils.GrabDependentValues(js_skqp, '//:libskqp_jni', 'defines',
673                                   skqp_defines, None)
674
675skqp_defines.add("GPU_TEST_UTILS=1")
676skqp_defines.add("SK_ALLOW_STATIC_GLOBAL_INITIALIZERS=1")
677skqp_defines.add("SK_BUILD_FOR_SKQP")
678skqp_defines.add("SK_ENABLE_DUMP_GPU")
679skqp_defines.remove("SK_USE_INTERNAL_VULKAN_HEADERS")
680skqp_defines.remove("SK_USE_PERFETTO")
681
682skqp_srcs = strip_non_srcs(skqp_srcs)
683skqp_cflags = gn_to_bp_utils.CleanupCFlags(skqp_cflags)
684skqp_cflags_cc = gn_to_bp_utils.CleanupCCFlags(skqp_cflags_cc)
685
686here = os.path.dirname(__file__)
687defs = gn_to_bp_utils.GetArchSources(os.path.join(here, 'opts.gni'))
688
689def get_defines(json):
690  return {str(d) for d in json['targets']['//:skia']['defines']}
691android_defines      = get_defines(js)
692linux_defines        = get_defines(js_linux)
693mac_defines          = get_defines(js_mac)
694win_defines          = get_defines(js_win)
695renderengine_defines = get_defines(js_renderengine)
696renderengine_defines.add('SK_IN_RENDERENGINE')
697
698def mkdir_if_not_exists(path):
699  if not os.path.exists(path):
700    os.makedirs(path)
701mkdir_if_not_exists('android/include/config/')
702mkdir_if_not_exists('linux/include/config/')
703mkdir_if_not_exists('mac/include/config/')
704mkdir_if_not_exists('win/include/config/')
705mkdir_if_not_exists('renderengine/include/config/')
706mkdir_if_not_exists('skqp/include/config/')
707mkdir_if_not_exists('vma_android/include')
708
709shutil.copy('third_party/externals/vulkanmemoryallocator/include/vk_mem_alloc.h',
710            'vma_android/include')
711shutil.copy('third_party/externals/vulkanmemoryallocator/LICENSE.txt', 'vma_android/')
712
713platforms = { 'IOS', 'MAC', 'WIN', 'ANDROID', 'UNIX' }
714
715def disallow_platforms(config, desired):
716  with open(config, 'a') as f:
717    p = sorted(platforms.difference({ desired }))
718    s = '#if '
719    for i in range(len(p)):
720      s = s + 'defined(SK_BUILD_FOR_%s)' % p[i]
721      if i < len(p) - 1:
722        s += ' || '
723        if i % 2 == 1:
724          s += '\\\n    '
725    print(s, file=f)
726    print('    #error "Only SK_BUILD_FOR_%s should be defined!"' % desired, file=f)
727    print('#endif', file=f)
728
729def append_to_file(config, s):
730  with open(config, 'a') as f:
731    print(s, file=f)
732
733def write_android_config(config_path, defines, isNDKConfig = False):
734  gn_to_bp_utils.WriteUserConfig(config_path, defines)
735  append_to_file(config_path, '''
736#ifndef SK_BUILD_FOR_ANDROID
737    #error "SK_BUILD_FOR_ANDROID must be defined!"
738#endif''')
739  disallow_platforms(config_path, 'ANDROID')
740
741  if isNDKConfig:
742    append_to_file(config_path, '''
743#undef SK_BUILD_FOR_ANDROID_FRAMEWORK''')
744
745write_android_config('android/include/config/SkUserConfig.h', android_defines)
746write_android_config('renderengine/include/config/SkUserConfig.h', renderengine_defines)
747write_android_config('skqp/include/config/SkUserConfig.h', skqp_defines, True)
748
749def write_config(config_path, defines, platform):
750  gn_to_bp_utils.WriteUserConfig(config_path, defines)
751  append_to_file(config_path, '''
752// Correct SK_BUILD_FOR flags that may have been set by
753// SkTypes.h/Android.bp
754#ifndef SK_BUILD_FOR_%s
755    #define SK_BUILD_FOR_%s
756#endif
757#ifdef SK_BUILD_FOR_ANDROID
758    #undef SK_BUILD_FOR_ANDROID
759#endif''' % (platform, platform))
760  disallow_platforms(config_path, platform)
761
762write_config('linux/include/config/SkUserConfig.h', linux_defines, 'UNIX')
763write_config('mac/include/config/SkUserConfig.h',   mac_defines, 'MAC')
764write_config('win/include/config/SkUserConfig.h',   win_defines, 'WIN')
765
766# Turn a list of strings into the style bpfmt outputs.
767def bpfmt(indent, lst, sort=True):
768  if sort:
769    lst = sorted(lst)
770  return ('\n' + ' '*indent).join('"%s",' % v for v in lst)
771
772# OK!  We have everything to fill in Android.bp...
773with open('Android.bp', 'w') as Android_bp:
774  print(bp.substitute({
775    'export_includes': bpfmt(8, export_includes),
776    'local_includes':  bpfmt(8, local_includes),
777    'srcs':            bpfmt(8, srcs),
778    'cflags':          bpfmt(8, cflags, False),
779    'cflags_cc':       bpfmt(8, cflags_cc),
780
781    'x86_srcs':      bpfmt(16, strip_non_srcs(defs['hsw'] +
782                                             defs['skx'])),
783
784    'gm_includes'       : bpfmt(8, gm_includes),
785    'gm_srcs'           : bpfmt(8, gm_srcs),
786
787    'test_minus_gm_includes' : bpfmt(8, test_minus_gm_includes),
788    'test_minus_gm_srcs'     : bpfmt(8, test_minus_gm_srcs),
789
790    'dm_includes'       : bpfmt(8, dm_includes),
791    'dm_srcs'           : bpfmt(8, dm_srcs),
792
793    'nanobench_includes'    : bpfmt(8, nanobench_includes),
794    'nanobench_srcs'        : bpfmt(8, nanobench_srcs),
795
796    'skqp_sdk_version': skqp_sdk_version,
797    'skqp_includes':    bpfmt(8, skqp_includes),
798    'skqp_srcs':        bpfmt(8, skqp_srcs),
799    'skqp_cflags':      bpfmt(8, skqp_cflags, False),
800    'skqp_cflags_cc':   bpfmt(8, skqp_cflags_cc),
801
802    'android_srcs':  bpfmt(10, android_srcs),
803    'linux_srcs':    bpfmt(10, linux_srcs),
804    'mac_srcs':      bpfmt(10, mac_srcs),
805    'win_srcs':      bpfmt(10, win_srcs),
806
807    'renderengine_srcs': bpfmt(8, renderengine_srcs),
808  }), file=Android_bp)
809
810  print(skqp_instance_bp.substitute({
811    'skqp_name':         'CtsSkQPTestCases',
812    'skqp_package_name': 'org.skia.skqp',
813    'skqp_jni_lib_name': 'libskqp_jni',
814    'skqp_test_suites':  bpfmt(8, ['general-tests', 'cts'], False),
815    'skqp_extra_cflags': '',
816  }), file=Android_bp)
817
818  # This duplicated SkQP test module runs all tests that are included in SkQP,
819  # regardless of the device's actual vendor API level (excluding those marked
820  # with kNever). This is used for ensuring coverage, and isn't enforced in CTS.
821  #
822  # This build is currently only maintained for soong / blueprint builds of SkQP
823  # in the Android framework itself due to staffing constraints.
824  print(skqp_instance_bp.substitute({
825    'skqp_name':         'AllSkQPTestCases',
826    'skqp_package_name': 'org.skia.skqp_alltests',
827    'skqp_jni_lib_name': 'libskqp_jni_alltests',
828    'skqp_test_suites':  bpfmt(8, ['general-tests'], False),
829    'skqp_extra_cflags': bpfmt(8, ['-DSKQP_ENFORCE_ALL_INCLUDED_TESTS'], False),
830  }), file=Android_bp)
831