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 | |
Martin Vejdarski | beaaf47 | 2020-03-03 13:53:20 +0700 | [diff] [blame] | 10 | from __future__ import print_function |
| 11 | |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 12 | import os |
| 13 | import pprint |
| 14 | import string |
| 15 | import subprocess |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 16 | import tempfile |
| 17 | |
Derek Sollenberger | 5d3f770 | 2018-02-01 09:22:53 -0500 | [diff] [blame] | 18 | import gn_to_bp_utils |
| 19 | |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 20 | # First we start off with a template for Android.bp, |
| 21 | # with holes for source lists and include directories. |
| 22 | bp = string.Template('''// This file is autogenerated by gn_to_bp.py. |
| 23 | |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 24 | cc_library_static { |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 25 | name: "libskia", |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 26 | host_supported: true, |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 27 | cflags: [ |
Leon Scroggins III | 981a31e | 2017-10-06 11:53:53 -0400 | [diff] [blame] | 28 | $cflags |
| 29 | ], |
| 30 | |
| 31 | cppflags:[ |
| 32 | $cflags_cc |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 33 | ], |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 34 | |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 35 | export_include_dirs: [ |
| 36 | $export_includes |
| 37 | ], |
Mike Klein | 27eb22b | 2016-12-07 12:27:56 -0500 | [diff] [blame] | 38 | |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 39 | local_include_dirs: [ |
| 40 | $local_includes |
| 41 | ], |
Mike Klein | 27eb22b | 2016-12-07 12:27:56 -0500 | [diff] [blame] | 42 | |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 43 | srcs: [ |
| 44 | $srcs |
| 45 | ], |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 46 | |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 47 | arch: { |
| 48 | arm: { |
| 49 | srcs: [ |
| 50 | $arm_srcs |
| 51 | ], |
Mike Klein | 27eb22b | 2016-12-07 12:27:56 -0500 | [diff] [blame] | 52 | |
Leon Scroggins III | f7332d3 | 2017-08-10 09:09:54 -0400 | [diff] [blame] | 53 | neon: { |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 54 | srcs: [ |
| 55 | $arm_neon_srcs |
| 56 | ], |
| 57 | }, |
| 58 | }, |
| 59 | |
| 60 | arm64: { |
| 61 | srcs: [ |
| 62 | $arm64_srcs |
| 63 | ], |
| 64 | }, |
| 65 | |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 66 | x86: { |
| 67 | srcs: [ |
| 68 | $x86_srcs |
| 69 | ], |
| 70 | }, |
| 71 | |
| 72 | x86_64: { |
| 73 | srcs: [ |
| 74 | $x86_srcs |
| 75 | ], |
| 76 | }, |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 77 | }, |
Mike Klein | 27eb22b | 2016-12-07 12:27:56 -0500 | [diff] [blame] | 78 | |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 79 | target: { |
| 80 | android: { |
| 81 | srcs: [ |
| 82 | $android_srcs |
| 83 | "third_party/vulkanmemoryallocator/GrVulkanMemoryAllocator.cpp", |
| 84 | ], |
| 85 | local_include_dirs: [ |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 86 | "android", |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 87 | "third_party/vulkanmemoryallocator/", |
| 88 | ], |
| 89 | export_include_dirs: [ |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 90 | "android", |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 91 | ], |
| 92 | }, |
| 93 | linux_glibc: { |
| 94 | cflags: [ |
| 95 | "-mssse3", |
| 96 | ], |
| 97 | srcs: [ |
| 98 | $linux_srcs |
| 99 | ], |
| 100 | local_include_dirs: [ |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 101 | "linux", |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 102 | ], |
| 103 | export_include_dirs: [ |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 104 | "linux", |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 105 | ], |
| 106 | }, |
Leon Scroggins III | 85e22fc | 2018-11-28 08:58:47 -0500 | [diff] [blame] | 107 | darwin: { |
| 108 | cflags: [ |
| 109 | "-mssse3", |
| 110 | ], |
| 111 | srcs: [ |
| 112 | $mac_srcs |
| 113 | ], |
| 114 | local_include_dirs: [ |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 115 | "mac", |
Leon Scroggins III | 85e22fc | 2018-11-28 08:58:47 -0500 | [diff] [blame] | 116 | ], |
| 117 | export_include_dirs: [ |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 118 | "mac", |
Leon Scroggins III | 85e22fc | 2018-11-28 08:58:47 -0500 | [diff] [blame] | 119 | ], |
| 120 | }, |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 121 | windows: { |
| 122 | cflags: [ |
| 123 | "-mssse3", |
| 124 | "-Wno-unknown-pragmas", |
| 125 | ], |
| 126 | srcs: [ |
| 127 | $win_srcs |
| 128 | ], |
| 129 | local_include_dirs: [ |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 130 | "win", |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 131 | ], |
| 132 | export_include_dirs: [ |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 133 | "win", |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 134 | ], |
| 135 | }, |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 136 | }, |
| 137 | |
Zhizhou Yang | e18b779 | 2017-12-11 10:37:44 -0800 | [diff] [blame] | 138 | defaults: ["skia_deps", |
| 139 | "skia_pgo", |
| 140 | ], |
| 141 | } |
| 142 | |
| 143 | // Build libskia with PGO by default. |
| 144 | // Location of PGO profile data is defined in build/soong/cc/pgo.go |
| 145 | // and is separate from skia. |
| 146 | // To turn it off, set ANDROID_PGO_NO_PROFILE_USE environment variable |
| 147 | // or set enable_profile_use property to false. |
| 148 | cc_defaults { |
| 149 | name: "skia_pgo", |
| 150 | pgo: { |
| 151 | instrumentation: true, |
Pirama Arumuga Nainar | 068ccaa | 2018-03-05 10:20:38 -0800 | [diff] [blame] | 152 | profile_file: "hwui/hwui.profdata", |
Zhizhou Yang | e18b779 | 2017-12-11 10:37:44 -0800 | [diff] [blame] | 153 | benchmarks: ["hwui", "skia"], |
Pirama Arumuga Nainar | 068ccaa | 2018-03-05 10:20:38 -0800 | [diff] [blame] | 154 | enable_profile_use: true, |
Zhizhou Yang | e18b779 | 2017-12-11 10:37:44 -0800 | [diff] [blame] | 155 | }, |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 156 | } |
| 157 | |
Pirama Arumuga Nainar | de2b95e | 2017-12-13 11:07:39 -0800 | [diff] [blame] | 158 | // "defaults" property to disable profile use for Skia tools and benchmarks. |
| 159 | cc_defaults { |
| 160 | name: "skia_pgo_no_profile_use", |
| 161 | defaults: [ |
| 162 | "skia_pgo", |
| 163 | ], |
| 164 | pgo: { |
| 165 | enable_profile_use: false, |
| 166 | }, |
| 167 | } |
| 168 | |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 169 | cc_defaults { |
| 170 | name: "skia_deps", |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 171 | shared_libs: [ |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 172 | "libdng_sdk", |
| 173 | "libexpat", |
| 174 | "libft2", |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 175 | "libjpeg", |
| 176 | "liblog", |
| 177 | "libpiex", |
| 178 | "libpng", |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 179 | "libz", |
| 180 | ], |
| 181 | static_libs: [ |
Matt Sarett | a309109 | 2017-02-20 12:50:52 -0500 | [diff] [blame] | 182 | "libarect", |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 183 | "libsfntly", |
| 184 | "libwebp-decode", |
| 185 | "libwebp-encode", |
| 186 | ], |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 187 | group_static_libs: true, |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 188 | target: { |
| 189 | android: { |
| 190 | shared_libs: [ |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 191 | "libcutils", |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 192 | "libEGL", |
| 193 | "libGLESv2", |
| 194 | "libheif", |
| 195 | "libvulkan", |
| 196 | "libnativewindow", |
| 197 | ], |
Stan Iliev | 12b8916 | 2019-03-11 13:33:02 -0400 | [diff] [blame] | 198 | export_shared_lib_headers: [ |
| 199 | "libvulkan", |
| 200 | ], |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 201 | }, |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 202 | host: { |
| 203 | static_libs: [ |
| 204 | "libcutils", |
| 205 | ], |
| 206 | }, |
Leon Scroggins III | 85e22fc | 2018-11-28 08:58:47 -0500 | [diff] [blame] | 207 | darwin: { |
| 208 | host_ldlibs: [ |
| 209 | "-framework AppKit", |
| 210 | ], |
| 211 | }, |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 212 | windows: { |
Leon Scroggins III | a09d232 | 2020-02-14 16:07:56 -0500 | [diff] [blame] | 213 | enabled: true, |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 214 | host_ldlibs: [ |
| 215 | "-lgdi32", |
| 216 | "-loleaut32", |
| 217 | "-lole32", |
| 218 | "-lopengl32", |
| 219 | "-luuid", |
| 220 | "-lwindowscodecs", |
| 221 | ], |
| 222 | }, |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 223 | }, |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | cc_defaults { |
| 227 | name: "skia_tool_deps", |
| 228 | defaults: [ |
Pirama Arumuga Nainar | de2b95e | 2017-12-13 11:07:39 -0800 | [diff] [blame] | 229 | "skia_deps", |
| 230 | "skia_pgo_no_profile_use" |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 231 | ], |
Mike Reed | 579c295 | 2020-05-27 16:49:23 -0400 | [diff] [blame] | 232 | shared_libs: [ |
| 233 | "libandroidicu", |
| 234 | "libharfbuzz_ng", |
| 235 | ], |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 236 | static_libs: [ |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 237 | "libskia", |
| 238 | ], |
| 239 | cflags: [ |
Mike Reed | 579c295 | 2020-05-27 16:49:23 -0400 | [diff] [blame] | 240 | "-DSK_SHAPER_HARFBUZZ_AVAILABLE", |
Derek Sollenberger | 1821a5b | 2018-09-11 14:48:36 -0400 | [diff] [blame] | 241 | "-Wno-implicit-fallthrough", |
Derek Sollenberger | 9a72ae1 | 2017-12-14 13:01:30 -0500 | [diff] [blame] | 242 | "-Wno-unused-parameter", |
| 243 | "-Wno-unused-variable", |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 244 | ], |
Leon Scroggins III | 6ccd2ca | 2017-01-26 17:21:27 -0500 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | cc_test { |
| 248 | name: "skia_dm", |
| 249 | |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 250 | defaults: [ |
| 251 | "skia_tool_deps" |
Leon Scroggins III | 6ccd2ca | 2017-01-26 17:21:27 -0500 | [diff] [blame] | 252 | ], |
| 253 | |
| 254 | local_include_dirs: [ |
| 255 | $dm_includes |
| 256 | ], |
| 257 | |
| 258 | srcs: [ |
| 259 | $dm_srcs |
| 260 | ], |
Dongwon Kang | 0c7861f | 2018-02-16 10:55:21 -0800 | [diff] [blame] | 261 | |
| 262 | shared_libs: [ |
| 263 | "libbinder", |
| 264 | "libutils", |
| 265 | ], |
Leon Scroggins III | 6ccd2ca | 2017-01-26 17:21:27 -0500 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | cc_test { |
| 269 | name: "skia_nanobench", |
| 270 | |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 271 | defaults: [ |
| 272 | "skia_tool_deps" |
Leon Scroggins III | 6ccd2ca | 2017-01-26 17:21:27 -0500 | [diff] [blame] | 273 | ], |
| 274 | |
| 275 | local_include_dirs: [ |
| 276 | $nanobench_includes |
| 277 | ], |
| 278 | |
| 279 | srcs: [ |
| 280 | $nanobench_srcs |
| 281 | ], |
Pirama Arumuga Nainar | 68c3fac | 2018-01-09 21:05:55 -0800 | [diff] [blame] | 282 | |
| 283 | data: [ |
Pirama Arumuga Nainar | 5be3c13 | 2019-09-30 17:18:02 -0700 | [diff] [blame] | 284 | "resources/**/*", |
Pirama Arumuga Nainar | 68c3fac | 2018-01-09 21:05:55 -0800 | [diff] [blame] | 285 | ], |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 286 | }''') |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 287 | |
| 288 | # We'll run GN to get the main source lists and include directories for Skia. |
Leon Scroggins III | a55445e | 2018-11-28 16:09:35 -0500 | [diff] [blame] | 289 | def generate_args(target_os, enable_gpu): |
| 290 | d = { |
Ben Wagner | 75626e4 | 2020-06-03 13:20:37 -0400 | [diff] [blame] | 291 | 'is_official_build': 'true', |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 292 | |
Leon Scroggins III | a55445e | 2018-11-28 16:09:35 -0500 | [diff] [blame] | 293 | # gn_to_bp_utils' GetArchSources will take care of architecture-specific |
| 294 | # files. |
Ben Wagner | 75626e4 | 2020-06-03 13:20:37 -0400 | [diff] [blame] | 295 | 'target_cpu': '"none"', |
Hal Canary | 23564b9 | 2018-09-07 14:33:14 -0400 | [diff] [blame] | 296 | |
Ben Wagner | 75626e4 | 2020-06-03 13:20:37 -0400 | [diff] [blame] | 297 | 'skia_enable_android_utils': 'true', |
Leon Scroggins III | a55445e | 2018-11-28 16:09:35 -0500 | [diff] [blame] | 298 | # Use the custom FontMgr, as the framework will handle fonts. |
Ben Wagner | 75626e4 | 2020-06-03 13:20:37 -0400 | [diff] [blame] | 299 | 'skia_enable_fontmgr_custom_directory': 'false', |
| 300 | 'skia_enable_fontmgr_custom_embedded': 'false', |
| 301 | 'skia_enable_fontmgr_custom_empty': 'true', |
| 302 | 'skia_enable_fontmgr_android': 'false', |
| 303 | 'skia_enable_fontmgr_win': 'false', |
| 304 | 'skia_enable_fontmgr_win_gdi': 'false', |
| 305 | 'skia_use_fonthost_mac': 'false', |
Leon Scroggins III | a55445e | 2018-11-28 16:09:35 -0500 | [diff] [blame] | 306 | |
Nathaniel Nifong | 60c37e7 | 2019-10-16 11:21:47 -0400 | [diff] [blame] | 307 | # enable features used in skia_nanobench |
Ben Wagner | 75626e4 | 2020-06-03 13:20:37 -0400 | [diff] [blame] | 308 | 'skia_enable_sksl_interpreter': 'true', |
| 309 | 'skia_tools_require_resources': 'true', |
Nathaniel Nifong | 60c37e7 | 2019-10-16 11:21:47 -0400 | [diff] [blame] | 310 | |
Ben Wagner | 75626e4 | 2020-06-03 13:20:37 -0400 | [diff] [blame] | 311 | 'skia_use_freetype': 'true', |
| 312 | 'skia_use_fontconfig': 'false', |
| 313 | 'skia_use_fixed_gamma_text': 'true', |
| 314 | 'skia_include_multiframe_procs': 'false', |
| 315 | 'skia_libgifcodec_path': '"third_party/libgifcodec"', |
Leon Scroggins III | a55445e | 2018-11-28 16:09:35 -0500 | [diff] [blame] | 316 | } |
| 317 | d['target_os'] = target_os |
| 318 | if target_os == '"android"': |
| 319 | d['skia_enable_tools'] = 'true' |
| 320 | d['skia_use_libheif'] = 'true' |
Nathaniel Nifong | 0c4fbf1 | 2019-06-25 15:48:47 -0400 | [diff] [blame] | 321 | d['skia_include_multiframe_procs'] = 'true' |
Leon Scroggins III | a55445e | 2018-11-28 16:09:35 -0500 | [diff] [blame] | 322 | else: |
| 323 | d['skia_use_libheif'] = 'false' |
| 324 | |
| 325 | if enable_gpu: |
| 326 | d['skia_use_vulkan'] = 'true' |
| 327 | else: |
| 328 | d['skia_use_vulkan'] = 'false' |
| 329 | d['skia_enable_gpu'] = 'false' |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 330 | |
| 331 | if target_os == '"win"': |
| 332 | # The Android Windows build system does not provide FontSub.h |
| 333 | d['skia_use_xps'] = 'false' |
| 334 | |
| 335 | # BUILDCONFIG.gn expects these to be set when building for Windows, but |
| 336 | # we're just creating Android.bp, so we don't need them. Populate with |
| 337 | # some dummy values. |
| 338 | d['win_vc'] = '"dummy_version"' |
| 339 | d['win_sdk_version'] = '"dummy_version"' |
Hal Canary | f72728e | 2019-07-10 11:24:52 -0400 | [diff] [blame] | 340 | d['win_toolchain_version'] = '"dummy_version"' |
Leon Scroggins III | a55445e | 2018-11-28 16:09:35 -0500 | [diff] [blame] | 341 | return d |
| 342 | |
| 343 | gn_args = generate_args('"android"', True) |
| 344 | gn_args_linux = generate_args('"linux"', False) |
| 345 | gn_args_mac = generate_args('"mac"', False) |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 346 | gn_args_win = generate_args('"win"', False) |
Leon Scroggins III | 85e22fc | 2018-11-28 08:58:47 -0500 | [diff] [blame] | 347 | |
Derek Sollenberger | 5d3f770 | 2018-02-01 09:22:53 -0500 | [diff] [blame] | 348 | js = gn_to_bp_utils.GenerateJSONFromGN(gn_args) |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 349 | |
| 350 | def strip_slashes(lst): |
Ben Wagner | e127523 | 2017-02-23 18:00:06 -0500 | [diff] [blame] | 351 | return {str(p.lstrip('/')) for p in lst} |
Mike Klein | 27eb22b | 2016-12-07 12:27:56 -0500 | [diff] [blame] | 352 | |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 353 | android_srcs = strip_slashes(js['targets']['//:skia']['sources']) |
Leon Scroggins III | 981a31e | 2017-10-06 11:53:53 -0400 | [diff] [blame] | 354 | cflags = strip_slashes(js['targets']['//:skia']['cflags']) |
| 355 | cflags_cc = strip_slashes(js['targets']['//:skia']['cflags_cc']) |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 356 | local_includes = strip_slashes(js['targets']['//:skia']['include_dirs']) |
| 357 | export_includes = strip_slashes(js['targets']['//:public']['include_dirs']) |
| 358 | |
Leon Scroggins III | 6ccd2ca | 2017-01-26 17:21:27 -0500 | [diff] [blame] | 359 | dm_srcs = strip_slashes(js['targets']['//:dm']['sources']) |
| 360 | dm_includes = strip_slashes(js['targets']['//:dm']['include_dirs']) |
| 361 | |
| 362 | nanobench_target = js['targets']['//:nanobench'] |
| 363 | nanobench_srcs = strip_slashes(nanobench_target['sources']) |
| 364 | nanobench_includes = strip_slashes(nanobench_target['include_dirs']) |
| 365 | |
Derek Sollenberger | 5d3f770 | 2018-02-01 09:22:53 -0500 | [diff] [blame] | 366 | gn_to_bp_utils.GrabDependentValues(js, '//:dm', 'sources', dm_srcs, 'skia') |
| 367 | gn_to_bp_utils.GrabDependentValues(js, '//:nanobench', 'sources', |
| 368 | nanobench_srcs, 'skia') |
Mike Klein | 27eb22b | 2016-12-07 12:27:56 -0500 | [diff] [blame] | 369 | |
Mike Klein | f536c45 | 2018-05-01 10:36:42 -0400 | [diff] [blame] | 370 | # skcms is a little special, kind of a second-party library. |
Brian Osman | 35ea04d | 2019-05-01 11:03:36 -0400 | [diff] [blame] | 371 | local_includes.add("include/third_party/skcms") |
| 372 | dm_includes .add("include/third_party/skcms") |
Mike Klein | f536c45 | 2018-05-01 10:36:42 -0400 | [diff] [blame] | 373 | |
Mike Klein | d505b19 | 2018-09-05 15:55:25 -0400 | [diff] [blame] | 374 | # Android's build will choke if we list headers. |
| 375 | def strip_headers(sources): |
| 376 | return {s for s in sources if not s.endswith('.h')} |
| 377 | |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 378 | gn_to_bp_utils.GrabDependentValues(js, '//:skia', 'sources', android_srcs, None) |
| 379 | android_srcs = strip_headers(android_srcs) |
| 380 | |
| 381 | js_linux = gn_to_bp_utils.GenerateJSONFromGN(gn_args_linux) |
| 382 | linux_srcs = strip_slashes(js_linux['targets']['//:skia']['sources']) |
| 383 | gn_to_bp_utils.GrabDependentValues(js_linux, '//:skia', 'sources', linux_srcs, |
| 384 | None) |
| 385 | linux_srcs = strip_headers(linux_srcs) |
| 386 | |
Leon Scroggins III | 85e22fc | 2018-11-28 08:58:47 -0500 | [diff] [blame] | 387 | js_mac = gn_to_bp_utils.GenerateJSONFromGN(gn_args_mac) |
| 388 | mac_srcs = strip_slashes(js_mac['targets']['//:skia']['sources']) |
| 389 | gn_to_bp_utils.GrabDependentValues(js_mac, '//:skia', 'sources', mac_srcs, |
| 390 | None) |
| 391 | mac_srcs = strip_headers(mac_srcs) |
| 392 | |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 393 | js_win = gn_to_bp_utils.GenerateJSONFromGN(gn_args_win) |
| 394 | win_srcs = strip_slashes(js_win['targets']['//:skia']['sources']) |
| 395 | gn_to_bp_utils.GrabDependentValues(js_win, '//:skia', 'sources', win_srcs, |
| 396 | None) |
| 397 | win_srcs = strip_headers(win_srcs) |
| 398 | |
Leon Scroggins III | 85e22fc | 2018-11-28 08:58:47 -0500 | [diff] [blame] | 399 | srcs = android_srcs.intersection(linux_srcs).intersection(mac_srcs) |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 400 | srcs = srcs.intersection(win_srcs) |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 401 | android_srcs = android_srcs.difference(srcs) |
| 402 | linux_srcs = linux_srcs.difference(srcs) |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 403 | mac_srcs = mac_srcs.difference(srcs) |
| 404 | win_srcs = win_srcs.difference(srcs) |
Mike Klein | d505b19 | 2018-09-05 15:55:25 -0400 | [diff] [blame] | 405 | dm_srcs = strip_headers(dm_srcs) |
| 406 | nanobench_srcs = strip_headers(nanobench_srcs) |
Mike Klein | 27eb22b | 2016-12-07 12:27:56 -0500 | [diff] [blame] | 407 | |
Derek Sollenberger | 5d3f770 | 2018-02-01 09:22:53 -0500 | [diff] [blame] | 408 | cflags = gn_to_bp_utils.CleanupCFlags(cflags) |
| 409 | cflags_cc = gn_to_bp_utils.CleanupCCFlags(cflags_cc) |
Leon Scroggins III | 981a31e | 2017-10-06 11:53:53 -0400 | [diff] [blame] | 410 | |
Leon Scroggins III | 4f8a467 | 2016-12-19 09:32:21 -0500 | [diff] [blame] | 411 | here = os.path.dirname(__file__) |
Derek Sollenberger | 5d3f770 | 2018-02-01 09:22:53 -0500 | [diff] [blame] | 412 | defs = gn_to_bp_utils.GetArchSources(os.path.join(here, 'opts.gni')) |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 413 | |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 414 | def get_defines(json): |
| 415 | return {str(d) for d in json['targets']['//:skia']['defines']} |
| 416 | android_defines = get_defines(js) |
| 417 | linux_defines = get_defines(js_linux) |
Leon Scroggins III | 85e22fc | 2018-11-28 08:58:47 -0500 | [diff] [blame] | 418 | mac_defines = get_defines(js_mac) |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 419 | win_defines = get_defines(js_win) |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 420 | |
| 421 | def mkdir_if_not_exists(path): |
| 422 | if not os.path.exists(path): |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 423 | os.makedirs(path) |
| 424 | mkdir_if_not_exists('android/include/config/') |
| 425 | mkdir_if_not_exists('linux/include/config/') |
| 426 | mkdir_if_not_exists('mac/include/config/') |
| 427 | mkdir_if_not_exists('win/include/config/') |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 428 | |
| 429 | platforms = { 'IOS', 'MAC', 'WIN', 'ANDROID', 'UNIX' } |
| 430 | |
| 431 | def disallow_platforms(config, desired): |
| 432 | with open(config, 'a') as f: |
| 433 | p = sorted(platforms.difference({ desired })) |
| 434 | s = '#if ' |
| 435 | for i in range(len(p)): |
| 436 | s = s + 'defined(SK_BUILD_FOR_%s)' % p[i] |
| 437 | if i < len(p) - 1: |
| 438 | s += ' || ' |
| 439 | if i % 2 == 1: |
| 440 | s += '\\\n ' |
Martin Vejdarski | beaaf47 | 2020-03-03 13:53:20 +0700 | [diff] [blame] | 441 | print(s, file=f) |
| 442 | print(' #error "Only SK_BUILD_FOR_%s should be defined!"' % desired, file=f) |
| 443 | print('#endif', file=f) |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 444 | |
| 445 | def append_to_file(config, s): |
| 446 | with open(config, 'a') as f: |
Martin Vejdarski | beaaf47 | 2020-03-03 13:53:20 +0700 | [diff] [blame] | 447 | print(s, file=f) |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 448 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 449 | android_config = 'android/include/config/SkUserConfig.h' |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 450 | gn_to_bp_utils.WriteUserConfig(android_config, android_defines) |
| 451 | append_to_file(android_config, ''' |
| 452 | #ifndef SK_BUILD_FOR_ANDROID |
| 453 | #error "SK_BUILD_FOR_ANDROID must be defined!" |
| 454 | #endif''') |
| 455 | disallow_platforms(android_config, 'ANDROID') |
| 456 | |
Leon Scroggins III | 85e22fc | 2018-11-28 08:58:47 -0500 | [diff] [blame] | 457 | def write_config(config_path, defines, platform): |
| 458 | gn_to_bp_utils.WriteUserConfig(config_path, defines) |
| 459 | append_to_file(config_path, ''' |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 460 | // Correct SK_BUILD_FOR flags that may have been set by |
Mike Klein | 81d35a7 | 2020-02-05 10:17:57 -0600 | [diff] [blame] | 461 | // SkTypes.h/Android.bp |
Leon Scroggins III | 85e22fc | 2018-11-28 08:58:47 -0500 | [diff] [blame] | 462 | #ifndef SK_BUILD_FOR_%s |
| 463 | #define SK_BUILD_FOR_%s |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 464 | #endif |
| 465 | #ifdef SK_BUILD_FOR_ANDROID |
| 466 | #undef SK_BUILD_FOR_ANDROID |
Leon Scroggins III | 85e22fc | 2018-11-28 08:58:47 -0500 | [diff] [blame] | 467 | #endif''' % (platform, platform)) |
| 468 | disallow_platforms(config_path, platform) |
| 469 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 470 | write_config('linux/include/config/SkUserConfig.h', linux_defines, 'UNIX') |
| 471 | write_config('mac/include/config/SkUserConfig.h', mac_defines, 'MAC') |
| 472 | write_config('win/include/config/SkUserConfig.h', win_defines, 'WIN') |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 473 | |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 474 | # Turn a list of strings into the style bpfmt outputs. |
Leon Scroggins III | 6ccd2ca | 2017-01-26 17:21:27 -0500 | [diff] [blame] | 475 | def bpfmt(indent, lst, sort=True): |
| 476 | if sort: |
| 477 | lst = sorted(lst) |
| 478 | return ('\n' + ' '*indent).join('"%s",' % v for v in lst) |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 479 | |
| 480 | # OK! We have everything to fill in Android.bp... |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 481 | with open('Android.bp', 'w') as Android_bp: |
Martin Vejdarski | beaaf47 | 2020-03-03 13:53:20 +0700 | [diff] [blame] | 482 | print(bp.substitute({ |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 483 | 'export_includes': bpfmt(8, export_includes), |
| 484 | 'local_includes': bpfmt(8, local_includes), |
| 485 | 'srcs': bpfmt(8, srcs), |
Leon Scroggins III | 981a31e | 2017-10-06 11:53:53 -0400 | [diff] [blame] | 486 | 'cflags': bpfmt(8, cflags, False), |
| 487 | 'cflags_cc': bpfmt(8, cflags_cc), |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 488 | |
Mike Klein | d505b19 | 2018-09-05 15:55:25 -0400 | [diff] [blame] | 489 | 'arm_srcs': bpfmt(16, strip_headers(defs['armv7'])), |
| 490 | 'arm_neon_srcs': bpfmt(20, strip_headers(defs['neon'])), |
| 491 | 'arm64_srcs': bpfmt(16, strip_headers(defs['arm64'] + |
| 492 | defs['crc32'])), |
Mike Klein | d505b19 | 2018-09-05 15:55:25 -0400 | [diff] [blame] | 493 | 'x86_srcs': bpfmt(16, strip_headers(defs['sse2'] + |
| 494 | defs['ssse3'] + |
| 495 | defs['sse41'] + |
| 496 | defs['sse42'] + |
| 497 | defs['avx' ] + |
Mike Klein | ad56c4c | 2020-06-05 06:57:30 -0500 | [diff] [blame] | 498 | defs['hsw' ] + |
| 499 | defs['skx' ])), |
Leon Scroggins III | 6ccd2ca | 2017-01-26 17:21:27 -0500 | [diff] [blame] | 500 | |
Leon Scroggins III | 6ccd2ca | 2017-01-26 17:21:27 -0500 | [diff] [blame] | 501 | 'dm_includes' : bpfmt(8, dm_includes), |
| 502 | 'dm_srcs' : bpfmt(8, dm_srcs), |
| 503 | |
| 504 | 'nanobench_includes' : bpfmt(8, nanobench_includes), |
| 505 | 'nanobench_srcs' : bpfmt(8, nanobench_srcs), |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 506 | |
| 507 | 'android_srcs': bpfmt(10, android_srcs), |
| 508 | 'linux_srcs': bpfmt(10, linux_srcs), |
Leon Scroggins III | 85e22fc | 2018-11-28 08:58:47 -0500 | [diff] [blame] | 509 | 'mac_srcs': bpfmt(10, mac_srcs), |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 510 | 'win_srcs': bpfmt(10, win_srcs), |
Martin Vejdarski | beaaf47 | 2020-03-03 13:53:20 +0700 | [diff] [blame] | 511 | }), file=Android_bp) |