Mike Klein | 308b5ac | 2016-12-06 16:03:52 -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 json |
| 11 | import os |
| 12 | import pprint |
| 13 | import string |
| 14 | import subprocess |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 15 | import tempfile |
| 16 | |
Derek Sollenberger | 5d3f770 | 2018-02-01 09:22:53 -0500 | [diff] [blame] | 17 | import gn_to_bp_utils |
| 18 | |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 19 | # First we start off with a template for Android.bp, |
| 20 | # with holes for source lists and include directories. |
| 21 | bp = string.Template('''// This file is autogenerated by gn_to_bp.py. |
| 22 | |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 23 | cc_library_static { |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 24 | name: "libskia", |
| 25 | cflags: [ |
Leon Scroggins III | 981a31e | 2017-10-06 11:53:53 -0400 | [diff] [blame] | 26 | $cflags |
| 27 | ], |
| 28 | |
| 29 | cppflags:[ |
| 30 | $cflags_cc |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 31 | ], |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 32 | |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 33 | export_include_dirs: [ |
| 34 | $export_includes |
| 35 | ], |
Mike Klein | 27eb22b | 2016-12-07 12:27:56 -0500 | [diff] [blame] | 36 | |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 37 | local_include_dirs: [ |
| 38 | $local_includes |
| 39 | ], |
Mike Klein | 27eb22b | 2016-12-07 12:27:56 -0500 | [diff] [blame] | 40 | |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 41 | srcs: [ |
| 42 | $srcs |
| 43 | ], |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 44 | |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 45 | arch: { |
| 46 | arm: { |
| 47 | srcs: [ |
| 48 | $arm_srcs |
| 49 | ], |
Mike Klein | 27eb22b | 2016-12-07 12:27:56 -0500 | [diff] [blame] | 50 | |
Leon Scroggins III | f7332d3 | 2017-08-10 09:09:54 -0400 | [diff] [blame] | 51 | neon: { |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 52 | srcs: [ |
| 53 | $arm_neon_srcs |
| 54 | ], |
| 55 | }, |
| 56 | }, |
| 57 | |
| 58 | arm64: { |
| 59 | srcs: [ |
| 60 | $arm64_srcs |
| 61 | ], |
| 62 | }, |
| 63 | |
| 64 | mips: { |
| 65 | srcs: [ |
Mike Klein | 40a82bd | 2016-12-20 17:34:29 -0500 | [diff] [blame] | 66 | $none_srcs |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 67 | ], |
| 68 | }, |
| 69 | |
| 70 | mips64: { |
| 71 | srcs: [ |
Mike Klein | 40a82bd | 2016-12-20 17:34:29 -0500 | [diff] [blame] | 72 | $none_srcs |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 73 | ], |
| 74 | }, |
| 75 | |
| 76 | x86: { |
| 77 | srcs: [ |
| 78 | $x86_srcs |
| 79 | ], |
Leon Scroggins III | 74663e7 | 2017-11-30 14:42:58 -0500 | [diff] [blame] | 80 | cflags: [ |
Leon Scroggins III | 6d892f5 | 2017-12-01 09:48:10 -0500 | [diff] [blame] | 81 | // Clang seems to think new/malloc will only be 4-byte aligned |
| 82 | // on x86 Android. We're pretty sure it's actually 8-byte |
| 83 | // alignment. tests/OverAlignedTest.cpp has more information, |
| 84 | // and should fail if we're wrong. |
Leon Scroggins III | 74663e7 | 2017-11-30 14:42:58 -0500 | [diff] [blame] | 85 | "-Wno-over-aligned" |
| 86 | ], |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 87 | }, |
| 88 | |
| 89 | x86_64: { |
| 90 | srcs: [ |
| 91 | $x86_srcs |
| 92 | ], |
| 93 | }, |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 94 | }, |
Mike Klein | 27eb22b | 2016-12-07 12:27:56 -0500 | [diff] [blame] | 95 | |
Zhizhou Yang | e18b779 | 2017-12-11 10:37:44 -0800 | [diff] [blame] | 96 | defaults: ["skia_deps", |
| 97 | "skia_pgo", |
| 98 | ], |
| 99 | } |
| 100 | |
| 101 | // Build libskia with PGO by default. |
| 102 | // Location of PGO profile data is defined in build/soong/cc/pgo.go |
| 103 | // and is separate from skia. |
| 104 | // To turn it off, set ANDROID_PGO_NO_PROFILE_USE environment variable |
| 105 | // or set enable_profile_use property to false. |
| 106 | cc_defaults { |
| 107 | name: "skia_pgo", |
| 108 | pgo: { |
| 109 | instrumentation: true, |
Pirama Arumuga Nainar | 068ccaa | 2018-03-05 10:20:38 -0800 | [diff] [blame] | 110 | profile_file: "hwui/hwui.profdata", |
Zhizhou Yang | e18b779 | 2017-12-11 10:37:44 -0800 | [diff] [blame] | 111 | benchmarks: ["hwui", "skia"], |
Pirama Arumuga Nainar | 068ccaa | 2018-03-05 10:20:38 -0800 | [diff] [blame] | 112 | enable_profile_use: true, |
Zhizhou Yang | e18b779 | 2017-12-11 10:37:44 -0800 | [diff] [blame] | 113 | }, |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 114 | } |
| 115 | |
Pirama Arumuga Nainar | de2b95e | 2017-12-13 11:07:39 -0800 | [diff] [blame] | 116 | // "defaults" property to disable profile use for Skia tools and benchmarks. |
| 117 | cc_defaults { |
| 118 | name: "skia_pgo_no_profile_use", |
| 119 | defaults: [ |
| 120 | "skia_pgo", |
| 121 | ], |
| 122 | pgo: { |
| 123 | enable_profile_use: false, |
| 124 | }, |
| 125 | } |
| 126 | |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 127 | cc_defaults { |
| 128 | name: "skia_deps", |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 129 | shared_libs: [ |
| 130 | "libEGL", |
| 131 | "libGLESv2", |
| 132 | "libdng_sdk", |
| 133 | "libexpat", |
| 134 | "libft2", |
Leon Scroggins III | 04be2b5 | 2017-08-17 15:13:20 -0400 | [diff] [blame] | 135 | "libheif", |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 136 | "libicui18n", |
| 137 | "libicuuc", |
| 138 | "libjpeg", |
| 139 | "liblog", |
| 140 | "libpiex", |
| 141 | "libpng", |
| 142 | "libvulkan", |
| 143 | "libz", |
Derek Sollenberger | 488f0d6 | 2017-03-03 15:48:33 -0500 | [diff] [blame] | 144 | "libcutils", |
Stan Iliev | 7e910df | 2017-06-02 10:29:21 -0400 | [diff] [blame] | 145 | "libnativewindow", |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 146 | ], |
| 147 | static_libs: [ |
Matt Sarett | a309109 | 2017-02-20 12:50:52 -0500 | [diff] [blame] | 148 | "libarect", |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 149 | "libsfntly", |
| 150 | "libwebp-decode", |
| 151 | "libwebp-encode", |
| 152 | ], |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 153 | group_static_libs: true, |
| 154 | } |
| 155 | |
| 156 | cc_defaults { |
| 157 | name: "skia_tool_deps", |
| 158 | defaults: [ |
Pirama Arumuga Nainar | de2b95e | 2017-12-13 11:07:39 -0800 | [diff] [blame] | 159 | "skia_deps", |
| 160 | "skia_pgo_no_profile_use" |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 161 | ], |
| 162 | static_libs: [ |
| 163 | "libjsoncpp", |
| 164 | "libskia", |
| 165 | ], |
| 166 | cflags: [ |
Derek Sollenberger | 9a72ae1 | 2017-12-14 13:01:30 -0500 | [diff] [blame] | 167 | "-Wno-unused-parameter", |
| 168 | "-Wno-unused-variable", |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 169 | ], |
Leon Scroggins III | 6ccd2ca | 2017-01-26 17:21:27 -0500 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | cc_test { |
| 173 | name: "skia_dm", |
| 174 | |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 175 | defaults: [ |
| 176 | "skia_tool_deps" |
Leon Scroggins III | 6ccd2ca | 2017-01-26 17:21:27 -0500 | [diff] [blame] | 177 | ], |
| 178 | |
| 179 | local_include_dirs: [ |
| 180 | $dm_includes |
| 181 | ], |
| 182 | |
| 183 | srcs: [ |
| 184 | $dm_srcs |
| 185 | ], |
Dongwon Kang | 0c7861f | 2018-02-16 10:55:21 -0800 | [diff] [blame] | 186 | |
| 187 | shared_libs: [ |
| 188 | "libbinder", |
| 189 | "libutils", |
| 190 | ], |
Leon Scroggins III | 6ccd2ca | 2017-01-26 17:21:27 -0500 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | cc_test { |
| 194 | name: "skia_nanobench", |
| 195 | |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 196 | defaults: [ |
| 197 | "skia_tool_deps" |
Leon Scroggins III | 6ccd2ca | 2017-01-26 17:21:27 -0500 | [diff] [blame] | 198 | ], |
| 199 | |
| 200 | local_include_dirs: [ |
| 201 | $nanobench_includes |
| 202 | ], |
| 203 | |
| 204 | srcs: [ |
| 205 | $nanobench_srcs |
| 206 | ], |
Pirama Arumuga Nainar | 68c3fac | 2018-01-09 21:05:55 -0800 | [diff] [blame] | 207 | |
| 208 | data: [ |
| 209 | "resources/*", |
| 210 | ], |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 211 | }''') |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 212 | |
| 213 | # We'll run GN to get the main source lists and include directories for Skia. |
| 214 | gn_args = { |
Mike Klein | e459afd | 2017-03-03 09:21:30 -0500 | [diff] [blame] | 215 | 'is_official_build': 'true', |
Mike Klein | e459afd | 2017-03-03 09:21:30 -0500 | [diff] [blame] | 216 | 'skia_enable_tools': 'true', |
Leon Scroggins III | 04be2b5 | 2017-08-17 15:13:20 -0400 | [diff] [blame] | 217 | 'skia_use_libheif': 'true', |
Mike Klein | e459afd | 2017-03-03 09:21:30 -0500 | [diff] [blame] | 218 | 'skia_use_vulkan': 'true', |
| 219 | 'target_cpu': '"none"', |
| 220 | 'target_os': '"android"', |
Greg Daniel | afb7ec7 | 2017-12-07 12:48:30 -0500 | [diff] [blame] | 221 | 'skia_vulkan_header': '"Skia_Vulkan_Android.h"', |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 222 | } |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 223 | |
Derek Sollenberger | 5d3f770 | 2018-02-01 09:22:53 -0500 | [diff] [blame] | 224 | js = gn_to_bp_utils.GenerateJSONFromGN(gn_args) |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 225 | |
| 226 | def strip_slashes(lst): |
Ben Wagner | e127523 | 2017-02-23 18:00:06 -0500 | [diff] [blame] | 227 | return {str(p.lstrip('/')) for p in lst} |
Mike Klein | 27eb22b | 2016-12-07 12:27:56 -0500 | [diff] [blame] | 228 | |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 229 | srcs = strip_slashes(js['targets']['//:skia']['sources']) |
Leon Scroggins III | 981a31e | 2017-10-06 11:53:53 -0400 | [diff] [blame] | 230 | cflags = strip_slashes(js['targets']['//:skia']['cflags']) |
| 231 | cflags_cc = strip_slashes(js['targets']['//:skia']['cflags_cc']) |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 232 | local_includes = strip_slashes(js['targets']['//:skia']['include_dirs']) |
| 233 | export_includes = strip_slashes(js['targets']['//:public']['include_dirs']) |
Derek Sollenberger | 5d3f770 | 2018-02-01 09:22:53 -0500 | [diff] [blame] | 234 | defines = [str(d) for d in js['targets']['//:skia']['defines']] |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 235 | |
Brian Osman | 670a290 | 2018-04-23 13:31:56 -0400 | [diff] [blame] | 236 | # We need to add skcms.c, which lives in third_party |
| 237 | srcs.add("third_party/skcms/skcms.c") |
Brian Osman | ef7b80b | 2018-04-23 15:32:27 -0400 | [diff] [blame] | 238 | local_includes.add("third_party/skcms") |
Mike Klein | dabf06c | 2018-04-24 12:32:00 +0000 | [diff] [blame^] | 239 | # TODO: re-enable after relaxing CTS tests |
| 240 | defines.remove('SK_USE_SKCMS') |
Brian Osman | 670a290 | 2018-04-23 13:31:56 -0400 | [diff] [blame] | 241 | |
Leon Scroggins III | 6ccd2ca | 2017-01-26 17:21:27 -0500 | [diff] [blame] | 242 | dm_srcs = strip_slashes(js['targets']['//:dm']['sources']) |
| 243 | dm_includes = strip_slashes(js['targets']['//:dm']['include_dirs']) |
| 244 | |
| 245 | nanobench_target = js['targets']['//:nanobench'] |
| 246 | nanobench_srcs = strip_slashes(nanobench_target['sources']) |
| 247 | nanobench_includes = strip_slashes(nanobench_target['include_dirs']) |
| 248 | |
Derek Sollenberger | 5d3f770 | 2018-02-01 09:22:53 -0500 | [diff] [blame] | 249 | gn_to_bp_utils.GrabDependentValues(js, '//:skia', 'sources', srcs, None) |
| 250 | gn_to_bp_utils.GrabDependentValues(js, '//:dm', 'sources', dm_srcs, 'skia') |
| 251 | gn_to_bp_utils.GrabDependentValues(js, '//:nanobench', 'sources', |
| 252 | nanobench_srcs, 'skia') |
Mike Klein | 27eb22b | 2016-12-07 12:27:56 -0500 | [diff] [blame] | 253 | |
| 254 | # No need to list headers. |
Ben Wagner | e127523 | 2017-02-23 18:00:06 -0500 | [diff] [blame] | 255 | srcs = {s for s in srcs if not s.endswith('.h')} |
| 256 | dm_srcs = {s for s in dm_srcs if not s.endswith('.h')} |
| 257 | nanobench_srcs = {s for s in nanobench_srcs if not s.endswith('.h')} |
Mike Klein | 27eb22b | 2016-12-07 12:27:56 -0500 | [diff] [blame] | 258 | |
Derek Sollenberger | 5d3f770 | 2018-02-01 09:22:53 -0500 | [diff] [blame] | 259 | cflags = gn_to_bp_utils.CleanupCFlags(cflags) |
| 260 | cflags_cc = gn_to_bp_utils.CleanupCCFlags(cflags_cc) |
Leon Scroggins III | 981a31e | 2017-10-06 11:53:53 -0400 | [diff] [blame] | 261 | |
Greg Daniel | afb7ec7 | 2017-12-07 12:48:30 -0500 | [diff] [blame] | 262 | # We need to add the include path to the vulkan defines and header file set in |
| 263 | # then skia_vulkan_header gn arg that is used for framework builds. |
| 264 | local_includes.add("platform_tools/android/vulkan") |
| 265 | export_includes.add("platform_tools/android/vulkan") |
| 266 | |
Leon Scroggins III | 4f8a467 | 2016-12-19 09:32:21 -0500 | [diff] [blame] | 267 | here = os.path.dirname(__file__) |
Derek Sollenberger | 5d3f770 | 2018-02-01 09:22:53 -0500 | [diff] [blame] | 268 | defs = gn_to_bp_utils.GetArchSources(os.path.join(here, 'opts.gni')) |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 269 | |
Derek Sollenberger | 5d3f770 | 2018-02-01 09:22:53 -0500 | [diff] [blame] | 270 | gn_to_bp_utils.WriteUserConfig('include/config/SkUserConfig.h', defines) |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 271 | |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 272 | # Turn a list of strings into the style bpfmt outputs. |
Leon Scroggins III | 6ccd2ca | 2017-01-26 17:21:27 -0500 | [diff] [blame] | 273 | def bpfmt(indent, lst, sort=True): |
| 274 | if sort: |
| 275 | lst = sorted(lst) |
| 276 | return ('\n' + ' '*indent).join('"%s",' % v for v in lst) |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 277 | |
| 278 | # OK! We have everything to fill in Android.bp... |
| 279 | with open('Android.bp', 'w') as f: |
| 280 | print >>f, bp.substitute({ |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 281 | 'export_includes': bpfmt(8, export_includes), |
| 282 | 'local_includes': bpfmt(8, local_includes), |
| 283 | 'srcs': bpfmt(8, srcs), |
Leon Scroggins III | 981a31e | 2017-10-06 11:53:53 -0400 | [diff] [blame] | 284 | 'cflags': bpfmt(8, cflags, False), |
| 285 | 'cflags_cc': bpfmt(8, cflags_cc), |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 286 | |
Derek Sollenberger | 5d3f770 | 2018-02-01 09:22:53 -0500 | [diff] [blame] | 287 | 'arm_srcs': bpfmt(16, defs['armv7']), |
| 288 | 'arm_neon_srcs': bpfmt(20, defs['neon']), |
| 289 | 'arm64_srcs': bpfmt(16, defs['arm64'] + |
| 290 | defs['crc32']), |
| 291 | 'none_srcs': bpfmt(16, defs['none']), |
| 292 | 'x86_srcs': bpfmt(16, defs['sse2'] + |
| 293 | defs['ssse3'] + |
| 294 | defs['sse41'] + |
| 295 | defs['sse42'] + |
Mike Klein | 1b9b7d5 | 2018-02-27 10:37:40 -0500 | [diff] [blame] | 296 | defs['avx' ] + |
| 297 | defs['hsw' ]), |
Leon Scroggins III | 6ccd2ca | 2017-01-26 17:21:27 -0500 | [diff] [blame] | 298 | |
Leon Scroggins III | 6ccd2ca | 2017-01-26 17:21:27 -0500 | [diff] [blame] | 299 | 'dm_includes' : bpfmt(8, dm_includes), |
| 300 | 'dm_srcs' : bpfmt(8, dm_srcs), |
| 301 | |
| 302 | 'nanobench_includes' : bpfmt(8, nanobench_includes), |
| 303 | 'nanobench_srcs' : bpfmt(8, nanobench_srcs), |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 304 | }) |