Derek Sollenberger | 5d3f770 | 2018-02-01 09:22:53 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # |
| 3 | # Copyright 2016 Google Inc. |
| 4 | # |
| 5 | # Use of this source code is governed by a BSD-style license that can be |
| 6 | # found in the LICENSE file. |
| 7 | |
| 8 | # Generate Android.bp for Skia from GN configuration. |
| 9 | |
| 10 | import argparse |
| 11 | import json |
| 12 | import os |
| 13 | import pprint |
| 14 | import string |
| 15 | import subprocess |
| 16 | import sys |
| 17 | import tempfile |
| 18 | |
| 19 | root_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), |
| 20 | os.pardir, os.pardir) |
| 21 | skia_gn_dir = os.path.join(root_dir, 'gn') |
| 22 | sys.path.insert(0, skia_gn_dir) |
| 23 | |
| 24 | import gn_to_bp_utils |
| 25 | |
| 26 | # First we start off with a template for Android.bp, |
| 27 | # with holes for source lists and include directories. |
| 28 | bp = string.Template('''// This file is autogenerated by tools/skqp/gn_to_bp.py. |
| 29 | |
| 30 | cc_library_shared { |
| 31 | name: "libskqp_app", |
| 32 | sdk_version: "26", |
| 33 | stl: "libc++_static", |
Derek Sollenberger | d396222 | 2018-04-02 12:17:37 -0400 | [diff] [blame] | 34 | compile_multilib: "both", |
Derek Sollenberger | 5d3f770 | 2018-02-01 09:22:53 -0500 | [diff] [blame] | 35 | |
| 36 | cflags: [ |
| 37 | $cflags |
| 38 | "-Wno-unused-parameter", |
| 39 | "-Wno-unused-variable", |
| 40 | ], |
| 41 | |
| 42 | cppflags:[ |
| 43 | $cflags_cc |
| 44 | ], |
| 45 | |
| 46 | local_include_dirs: [ |
| 47 | $local_includes |
| 48 | ], |
| 49 | |
| 50 | srcs: [ |
Hal Canary | 6512fa3 | 2019-02-07 14:12:21 -0500 | [diff] [blame] | 51 | "third_party/vulkanmemoryallocator/GrVulkanMemoryAllocator.cpp", |
Derek Sollenberger | 5d3f770 | 2018-02-01 09:22:53 -0500 | [diff] [blame] | 52 | $srcs |
| 53 | ], |
| 54 | |
| 55 | arch: { |
| 56 | arm: { |
| 57 | srcs: [ |
| 58 | $arm_srcs |
| 59 | ], |
| 60 | |
| 61 | neon: { |
| 62 | srcs: [ |
| 63 | $arm_neon_srcs |
| 64 | ], |
| 65 | }, |
| 66 | }, |
| 67 | |
| 68 | arm64: { |
| 69 | srcs: [ |
| 70 | $arm64_srcs |
| 71 | ], |
| 72 | }, |
| 73 | |
| 74 | mips: { |
| 75 | srcs: [ |
| 76 | $none_srcs |
| 77 | ], |
| 78 | }, |
| 79 | |
| 80 | mips64: { |
| 81 | srcs: [ |
| 82 | $none_srcs |
| 83 | ], |
| 84 | }, |
| 85 | |
| 86 | x86: { |
| 87 | srcs: [ |
| 88 | $x86_srcs |
| 89 | ], |
Derek Sollenberger | 5d3f770 | 2018-02-01 09:22:53 -0500 | [diff] [blame] | 90 | }, |
| 91 | |
| 92 | x86_64: { |
| 93 | srcs: [ |
| 94 | $x86_srcs |
| 95 | ], |
| 96 | }, |
| 97 | }, |
| 98 | |
| 99 | shared_libs: [ |
| 100 | "libandroid", |
| 101 | "libEGL", |
| 102 | "libGLESv2", |
| 103 | "liblog", |
| 104 | "libvulkan", |
| 105 | "libz", |
| 106 | ], |
| 107 | static_libs: [ |
| 108 | "libjpeg_static_ndk", |
Derek Sollenberger | 5d3f770 | 2018-02-01 09:22:53 -0500 | [diff] [blame] | 109 | "libpng_ndk", |
| 110 | "libwebp-decode", |
| 111 | "libwebp-encode", |
| 112 | ] |
| 113 | }''') |
| 114 | |
| 115 | # We'll run GN to get the main source lists and include directories for Skia. |
| 116 | gn_args = { |
Derek Sollenberger | 5d3f770 | 2018-02-01 09:22:53 -0500 | [diff] [blame] | 117 | 'target_cpu': '"none"', |
| 118 | 'target_os': '"android"', |
Derek Sollenberger | 82831b1 | 2018-02-05 11:51:29 -0500 | [diff] [blame] | 119 | |
| 120 | # setup skqp |
| 121 | 'is_debug': 'false', |
Derek Sollenberger | 5d3f770 | 2018-02-01 09:22:53 -0500 | [diff] [blame] | 122 | 'ndk_api': '26', |
Hal Canary | ac7f23c | 2018-11-26 14:07:41 -0500 | [diff] [blame] | 123 | 'skia_skqp_global_error_tolerance': '8', |
Hal Canary | 6512fa3 | 2019-02-07 14:12:21 -0500 | [diff] [blame] | 124 | 'skia_tools_require_resources': 'true', |
Derek Sollenberger | 5d3f770 | 2018-02-01 09:22:53 -0500 | [diff] [blame] | 125 | |
| 126 | # setup vulkan |
| 127 | 'skia_use_vulkan': 'true', |
Derek Sollenberger | 5d3f770 | 2018-02-01 09:22:53 -0500 | [diff] [blame] | 128 | |
| 129 | # enable/disable skia subsystems |
| 130 | 'skia_enable_fontmgr_empty': 'true', |
| 131 | 'skia_enable_pdf': 'false', |
Florin Malita | 87ccf33 | 2018-05-04 12:23:24 -0400 | [diff] [blame] | 132 | 'skia_enable_skottie': 'false', |
Derek Sollenberger | 5d3f770 | 2018-02-01 09:22:53 -0500 | [diff] [blame] | 133 | 'skia_use_expat': 'false', |
| 134 | 'skia_use_dng_sdk': 'false', |
| 135 | 'skia_use_icu': 'false', |
| 136 | 'skia_use_lua': 'false', |
| 137 | 'skia_use_piex': 'false', |
Derek Sollenberger | 5d3f770 | 2018-02-01 09:22:53 -0500 | [diff] [blame] | 138 | |
| 139 | # specify that the Android.bp will supply the necessary components |
| 140 | 'skia_use_system_expat': 'true', # removed this when gn is fixed |
| 141 | 'skia_use_system_libpng': 'true', |
Derek Sollenberger | 5d3f770 | 2018-02-01 09:22:53 -0500 | [diff] [blame] | 142 | 'skia_use_system_libwebp': 'true', |
| 143 | 'skia_use_system_libjpeg_turbo': 'true', |
| 144 | 'skia_use_system_zlib': 'true', |
| 145 | } |
| 146 | |
| 147 | js = gn_to_bp_utils.GenerateJSONFromGN(gn_args) |
| 148 | |
| 149 | def strip_slashes(lst): |
| 150 | return {str(p.lstrip('/')) for p in lst} |
| 151 | |
| 152 | srcs = strip_slashes(js['targets']['//:libskqp_app']['sources']) |
| 153 | cflags = strip_slashes(js['targets']['//:libskqp_app']['cflags']) |
| 154 | cflags_cc = strip_slashes(js['targets']['//:libskqp_app']['cflags_cc']) |
| 155 | local_includes = strip_slashes(js['targets']['//:libskqp_app']['include_dirs']) |
| 156 | defines = {str(d) for d in js['targets']['//:libskqp_app']['defines']} |
| 157 | |
Hal Canary | 6512fa3 | 2019-02-07 14:12:21 -0500 | [diff] [blame] | 158 | defines.update(["SK_ENABLE_DUMP_GPU", "SK_BUILD_FOR_SKQP"]) |
| 159 | cflags_cc.update(['-Wno-extra-semi-stmt']) |
| 160 | |
Derek Sollenberger | 5d3f770 | 2018-02-01 09:22:53 -0500 | [diff] [blame] | 161 | gn_to_bp_utils.GrabDependentValues(js, '//:libskqp_app', 'sources', srcs, None) |
| 162 | gn_to_bp_utils.GrabDependentValues(js, '//:libskqp_app', 'include_dirs', |
| 163 | local_includes, 'freetype') |
| 164 | gn_to_bp_utils.GrabDependentValues(js, '//:libskqp_app', 'defines', |
| 165 | defines, None) |
| 166 | |
| 167 | # No need to list headers or other extra flags. |
| 168 | srcs = {s for s in srcs if not s.endswith('.h')} |
| 169 | cflags = gn_to_bp_utils.CleanupCFlags(cflags) |
| 170 | cflags_cc = gn_to_bp_utils.CleanupCCFlags(cflags_cc) |
| 171 | |
| 172 | # We need to add the include path to the vulkan defines and header file set in |
| 173 | # then skia_vulkan_header gn arg that is used for framework builds. |
| 174 | local_includes.add("platform_tools/android/vulkan") |
| 175 | |
| 176 | # Get architecture specific source files |
| 177 | defs = gn_to_bp_utils.GetArchSources(os.path.join(skia_gn_dir, 'opts.gni')) |
| 178 | |
| 179 | # Add source file until fix lands in |
| 180 | # https://skia-review.googlesource.com/c/skia/+/101820 |
| 181 | srcs.add("src/ports/SkFontMgr_empty_factory.cpp") |
| 182 | |
| 183 | # Turn a list of strings into the style bpfmt outputs. |
| 184 | def bpfmt(indent, lst, sort=True): |
| 185 | if sort: |
| 186 | lst = sorted(lst) |
| 187 | return ('\n' + ' '*indent).join('"%s",' % v for v in lst) |
| 188 | |
| 189 | # Most defines go into SkUserConfig.h, where they're seen by Skia and its users. |
| 190 | gn_to_bp_utils.WriteUserConfig('include/config/SkUserConfig.h', defines) |
| 191 | |
| 192 | # OK! We have everything to fill in Android.bp... |
| 193 | with open('Android.bp', 'w') as f: |
| 194 | print >>f, bp.substitute({ |
| 195 | 'local_includes': bpfmt(8, local_includes), |
| 196 | 'srcs': bpfmt(8, srcs), |
| 197 | 'cflags': bpfmt(8, cflags, False), |
| 198 | 'cflags_cc': bpfmt(8, cflags_cc), |
| 199 | |
| 200 | 'arm_srcs': bpfmt(16, defs['armv7']), |
| 201 | 'arm_neon_srcs': bpfmt(20, defs['neon']), |
| 202 | 'arm64_srcs': bpfmt(16, defs['arm64'] + |
| 203 | defs['crc32']), |
| 204 | 'none_srcs': bpfmt(16, defs['none']), |
| 205 | 'x86_srcs': bpfmt(16, defs['sse2'] + |
| 206 | defs['ssse3'] + |
| 207 | defs['sse41'] + |
| 208 | defs['sse42'] + |
Hal Canary | 6512fa3 | 2019-02-07 14:12:21 -0500 | [diff] [blame] | 209 | defs['avx'] + |
| 210 | defs['hsw']), |
Derek Sollenberger | 5d3f770 | 2018-02-01 09:22:53 -0500 | [diff] [blame] | 211 | }) |
| 212 | |