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