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: [ |
Derek Sollenberger | 3de7684 | 2019-01-08 13:36:38 -0500 | [diff] [blame] | 172 | "libandroidicu", |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 173 | "libdng_sdk", |
| 174 | "libexpat", |
| 175 | "libft2", |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 176 | "libjpeg", |
| 177 | "liblog", |
| 178 | "libpiex", |
| 179 | "libpng", |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 180 | "libz", |
| 181 | ], |
| 182 | static_libs: [ |
Matt Sarett | a309109 | 2017-02-20 12:50:52 -0500 | [diff] [blame] | 183 | "libarect", |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 184 | "libsfntly", |
| 185 | "libwebp-decode", |
| 186 | "libwebp-encode", |
| 187 | ], |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 188 | group_static_libs: true, |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 189 | target: { |
| 190 | android: { |
| 191 | shared_libs: [ |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 192 | "libcutils", |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 193 | "libEGL", |
| 194 | "libGLESv2", |
| 195 | "libheif", |
| 196 | "libvulkan", |
| 197 | "libnativewindow", |
| 198 | ], |
Stan Iliev | 12b8916 | 2019-03-11 13:33:02 -0400 | [diff] [blame] | 199 | export_shared_lib_headers: [ |
| 200 | "libvulkan", |
| 201 | ], |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 202 | }, |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 203 | host: { |
| 204 | static_libs: [ |
| 205 | "libcutils", |
| 206 | ], |
| 207 | }, |
Leon Scroggins III | 85e22fc | 2018-11-28 08:58:47 -0500 | [diff] [blame] | 208 | darwin: { |
| 209 | host_ldlibs: [ |
| 210 | "-framework AppKit", |
| 211 | ], |
| 212 | }, |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 213 | windows: { |
Leon Scroggins III | a09d232 | 2020-02-14 16:07:56 -0500 | [diff] [blame] | 214 | enabled: true, |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 215 | host_ldlibs: [ |
| 216 | "-lgdi32", |
| 217 | "-loleaut32", |
| 218 | "-lole32", |
| 219 | "-lopengl32", |
| 220 | "-luuid", |
| 221 | "-lwindowscodecs", |
| 222 | ], |
| 223 | }, |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 224 | }, |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | cc_defaults { |
| 228 | name: "skia_tool_deps", |
| 229 | defaults: [ |
Pirama Arumuga Nainar | de2b95e | 2017-12-13 11:07:39 -0800 | [diff] [blame] | 230 | "skia_deps", |
| 231 | "skia_pgo_no_profile_use" |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 232 | ], |
| 233 | static_libs: [ |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 234 | "libskia", |
| 235 | ], |
| 236 | cflags: [ |
Derek Sollenberger | 1821a5b | 2018-09-11 14:48:36 -0400 | [diff] [blame] | 237 | "-Wno-implicit-fallthrough", |
Derek Sollenberger | 9a72ae1 | 2017-12-14 13:01:30 -0500 | [diff] [blame] | 238 | "-Wno-unused-parameter", |
| 239 | "-Wno-unused-variable", |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 240 | ], |
Leon Scroggins III | 6ccd2ca | 2017-01-26 17:21:27 -0500 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | cc_test { |
| 244 | name: "skia_dm", |
| 245 | |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 246 | defaults: [ |
| 247 | "skia_tool_deps" |
Leon Scroggins III | 6ccd2ca | 2017-01-26 17:21:27 -0500 | [diff] [blame] | 248 | ], |
| 249 | |
| 250 | local_include_dirs: [ |
| 251 | $dm_includes |
| 252 | ], |
| 253 | |
| 254 | srcs: [ |
| 255 | $dm_srcs |
| 256 | ], |
Dongwon Kang | 0c7861f | 2018-02-16 10:55:21 -0800 | [diff] [blame] | 257 | |
| 258 | shared_libs: [ |
| 259 | "libbinder", |
| 260 | "libutils", |
| 261 | ], |
Leon Scroggins III | 6ccd2ca | 2017-01-26 17:21:27 -0500 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | cc_test { |
| 265 | name: "skia_nanobench", |
| 266 | |
Derek Sollenberger | 5a93216 | 2017-09-21 14:25:14 -0400 | [diff] [blame] | 267 | defaults: [ |
| 268 | "skia_tool_deps" |
Leon Scroggins III | 6ccd2ca | 2017-01-26 17:21:27 -0500 | [diff] [blame] | 269 | ], |
| 270 | |
| 271 | local_include_dirs: [ |
| 272 | $nanobench_includes |
| 273 | ], |
| 274 | |
| 275 | srcs: [ |
| 276 | $nanobench_srcs |
| 277 | ], |
Pirama Arumuga Nainar | 68c3fac | 2018-01-09 21:05:55 -0800 | [diff] [blame] | 278 | |
| 279 | data: [ |
Pirama Arumuga Nainar | 5be3c13 | 2019-09-30 17:18:02 -0700 | [diff] [blame] | 280 | "resources/**/*", |
Pirama Arumuga Nainar | 68c3fac | 2018-01-09 21:05:55 -0800 | [diff] [blame] | 281 | ], |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 282 | }''') |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 283 | |
| 284 | # 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] | 285 | def generate_args(target_os, enable_gpu): |
| 286 | d = { |
| 287 | 'is_official_build': 'true', |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 288 | |
Leon Scroggins III | a55445e | 2018-11-28 16:09:35 -0500 | [diff] [blame] | 289 | # gn_to_bp_utils' GetArchSources will take care of architecture-specific |
| 290 | # files. |
| 291 | 'target_cpu': '"none"', |
Hal Canary | 23564b9 | 2018-09-07 14:33:14 -0400 | [diff] [blame] | 292 | |
Leon Scroggins III | 63cfb36 | 2020-04-24 13:00:48 -0400 | [diff] [blame] | 293 | 'skia_enable_android_utils': 'true', |
Leon Scroggins III | a55445e | 2018-11-28 16:09:35 -0500 | [diff] [blame] | 294 | # Use the custom FontMgr, as the framework will handle fonts. |
| 295 | 'skia_enable_fontmgr_custom': 'false', |
| 296 | 'skia_enable_fontmgr_custom_empty': 'true', |
| 297 | 'skia_enable_fontmgr_android': 'false', |
Leon Scroggins III | 631dbc8 | 2019-03-04 13:54:02 -0500 | [diff] [blame] | 298 | 'skia_enable_fontmgr_win': 'false', |
| 299 | 'skia_enable_fontmgr_win_gdi': 'false', |
Leon Scroggins III | a55445e | 2018-11-28 16:09:35 -0500 | [diff] [blame] | 300 | 'skia_use_fonthost_mac': 'false', |
| 301 | |
Nathaniel Nifong | 60c37e7 | 2019-10-16 11:21:47 -0400 | [diff] [blame] | 302 | # enable features used in skia_nanobench |
| 303 | 'skia_enable_sksl_interpreter': 'true', |
| 304 | 'skia_tools_require_resources': 'true', |
| 305 | |
Leon Scroggins III | a55445e | 2018-11-28 16:09:35 -0500 | [diff] [blame] | 306 | 'skia_use_freetype': 'true', |
| 307 | 'skia_use_fontconfig': 'false', |
| 308 | 'skia_use_fixed_gamma_text': 'true', |
Nathaniel Nifong | 0c4fbf1 | 2019-06-25 15:48:47 -0400 | [diff] [blame] | 309 | 'skia_include_multiframe_procs': 'false', |
Hal Canary | 2dad990 | 2019-11-20 16:01:31 -0500 | [diff] [blame] | 310 | 'skia_libgifcodec_path': '"third_party/libgifcodec"', |
Leon Scroggins III | a55445e | 2018-11-28 16:09:35 -0500 | [diff] [blame] | 311 | } |
| 312 | d['target_os'] = target_os |
| 313 | if target_os == '"android"': |
| 314 | d['skia_enable_tools'] = 'true' |
| 315 | d['skia_use_libheif'] = 'true' |
Nathaniel Nifong | 0c4fbf1 | 2019-06-25 15:48:47 -0400 | [diff] [blame] | 316 | d['skia_include_multiframe_procs'] = 'true' |
Leon Scroggins III | a55445e | 2018-11-28 16:09:35 -0500 | [diff] [blame] | 317 | else: |
| 318 | d['skia_use_libheif'] = 'false' |
| 319 | |
| 320 | if enable_gpu: |
| 321 | d['skia_use_vulkan'] = 'true' |
| 322 | else: |
| 323 | d['skia_use_vulkan'] = 'false' |
| 324 | d['skia_enable_gpu'] = 'false' |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 325 | |
| 326 | if target_os == '"win"': |
| 327 | # The Android Windows build system does not provide FontSub.h |
| 328 | d['skia_use_xps'] = 'false' |
| 329 | |
| 330 | # BUILDCONFIG.gn expects these to be set when building for Windows, but |
| 331 | # we're just creating Android.bp, so we don't need them. Populate with |
| 332 | # some dummy values. |
| 333 | d['win_vc'] = '"dummy_version"' |
| 334 | d['win_sdk_version'] = '"dummy_version"' |
Hal Canary | f72728e | 2019-07-10 11:24:52 -0400 | [diff] [blame] | 335 | d['win_toolchain_version'] = '"dummy_version"' |
Leon Scroggins III | a55445e | 2018-11-28 16:09:35 -0500 | [diff] [blame] | 336 | return d |
| 337 | |
| 338 | gn_args = generate_args('"android"', True) |
| 339 | gn_args_linux = generate_args('"linux"', False) |
| 340 | gn_args_mac = generate_args('"mac"', False) |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 341 | gn_args_win = generate_args('"win"', False) |
Leon Scroggins III | 85e22fc | 2018-11-28 08:58:47 -0500 | [diff] [blame] | 342 | |
Derek Sollenberger | 5d3f770 | 2018-02-01 09:22:53 -0500 | [diff] [blame] | 343 | js = gn_to_bp_utils.GenerateJSONFromGN(gn_args) |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 344 | |
| 345 | def strip_slashes(lst): |
Ben Wagner | e127523 | 2017-02-23 18:00:06 -0500 | [diff] [blame] | 346 | return {str(p.lstrip('/')) for p in lst} |
Mike Klein | 27eb22b | 2016-12-07 12:27:56 -0500 | [diff] [blame] | 347 | |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 348 | android_srcs = strip_slashes(js['targets']['//:skia']['sources']) |
Leon Scroggins III | 981a31e | 2017-10-06 11:53:53 -0400 | [diff] [blame] | 349 | cflags = strip_slashes(js['targets']['//:skia']['cflags']) |
| 350 | cflags_cc = strip_slashes(js['targets']['//:skia']['cflags_cc']) |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 351 | local_includes = strip_slashes(js['targets']['//:skia']['include_dirs']) |
| 352 | export_includes = strip_slashes(js['targets']['//:public']['include_dirs']) |
| 353 | |
Leon Scroggins III | 6ccd2ca | 2017-01-26 17:21:27 -0500 | [diff] [blame] | 354 | dm_srcs = strip_slashes(js['targets']['//:dm']['sources']) |
| 355 | dm_includes = strip_slashes(js['targets']['//:dm']['include_dirs']) |
| 356 | |
| 357 | nanobench_target = js['targets']['//:nanobench'] |
| 358 | nanobench_srcs = strip_slashes(nanobench_target['sources']) |
| 359 | nanobench_includes = strip_slashes(nanobench_target['include_dirs']) |
| 360 | |
Derek Sollenberger | 5d3f770 | 2018-02-01 09:22:53 -0500 | [diff] [blame] | 361 | gn_to_bp_utils.GrabDependentValues(js, '//:dm', 'sources', dm_srcs, 'skia') |
| 362 | gn_to_bp_utils.GrabDependentValues(js, '//:nanobench', 'sources', |
| 363 | nanobench_srcs, 'skia') |
Mike Klein | 27eb22b | 2016-12-07 12:27:56 -0500 | [diff] [blame] | 364 | |
Mike Klein | f536c45 | 2018-05-01 10:36:42 -0400 | [diff] [blame] | 365 | # skcms is a little special, kind of a second-party library. |
Brian Osman | 35ea04d | 2019-05-01 11:03:36 -0400 | [diff] [blame] | 366 | local_includes.add("include/third_party/skcms") |
| 367 | dm_includes .add("include/third_party/skcms") |
Mike Klein | f536c45 | 2018-05-01 10:36:42 -0400 | [diff] [blame] | 368 | |
Mike Klein | d505b19 | 2018-09-05 15:55:25 -0400 | [diff] [blame] | 369 | # Android's build will choke if we list headers. |
| 370 | def strip_headers(sources): |
| 371 | return {s for s in sources if not s.endswith('.h')} |
| 372 | |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 373 | gn_to_bp_utils.GrabDependentValues(js, '//:skia', 'sources', android_srcs, None) |
| 374 | android_srcs = strip_headers(android_srcs) |
| 375 | |
| 376 | js_linux = gn_to_bp_utils.GenerateJSONFromGN(gn_args_linux) |
| 377 | linux_srcs = strip_slashes(js_linux['targets']['//:skia']['sources']) |
| 378 | gn_to_bp_utils.GrabDependentValues(js_linux, '//:skia', 'sources', linux_srcs, |
| 379 | None) |
| 380 | linux_srcs = strip_headers(linux_srcs) |
| 381 | |
Leon Scroggins III | 85e22fc | 2018-11-28 08:58:47 -0500 | [diff] [blame] | 382 | js_mac = gn_to_bp_utils.GenerateJSONFromGN(gn_args_mac) |
| 383 | mac_srcs = strip_slashes(js_mac['targets']['//:skia']['sources']) |
| 384 | gn_to_bp_utils.GrabDependentValues(js_mac, '//:skia', 'sources', mac_srcs, |
| 385 | None) |
| 386 | mac_srcs = strip_headers(mac_srcs) |
| 387 | |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 388 | js_win = gn_to_bp_utils.GenerateJSONFromGN(gn_args_win) |
| 389 | win_srcs = strip_slashes(js_win['targets']['//:skia']['sources']) |
| 390 | gn_to_bp_utils.GrabDependentValues(js_win, '//:skia', 'sources', win_srcs, |
| 391 | None) |
| 392 | win_srcs = strip_headers(win_srcs) |
| 393 | |
Leon Scroggins III | 85e22fc | 2018-11-28 08:58:47 -0500 | [diff] [blame] | 394 | srcs = android_srcs.intersection(linux_srcs).intersection(mac_srcs) |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 395 | srcs = srcs.intersection(win_srcs) |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 396 | android_srcs = android_srcs.difference(srcs) |
| 397 | linux_srcs = linux_srcs.difference(srcs) |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 398 | mac_srcs = mac_srcs.difference(srcs) |
| 399 | win_srcs = win_srcs.difference(srcs) |
Mike Klein | d505b19 | 2018-09-05 15:55:25 -0400 | [diff] [blame] | 400 | dm_srcs = strip_headers(dm_srcs) |
| 401 | nanobench_srcs = strip_headers(nanobench_srcs) |
Mike Klein | 27eb22b | 2016-12-07 12:27:56 -0500 | [diff] [blame] | 402 | |
Derek Sollenberger | 5d3f770 | 2018-02-01 09:22:53 -0500 | [diff] [blame] | 403 | cflags = gn_to_bp_utils.CleanupCFlags(cflags) |
| 404 | cflags_cc = gn_to_bp_utils.CleanupCCFlags(cflags_cc) |
Leon Scroggins III | 981a31e | 2017-10-06 11:53:53 -0400 | [diff] [blame] | 405 | |
Leon Scroggins III | 4f8a467 | 2016-12-19 09:32:21 -0500 | [diff] [blame] | 406 | here = os.path.dirname(__file__) |
Derek Sollenberger | 5d3f770 | 2018-02-01 09:22:53 -0500 | [diff] [blame] | 407 | defs = gn_to_bp_utils.GetArchSources(os.path.join(here, 'opts.gni')) |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 408 | |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 409 | def get_defines(json): |
| 410 | return {str(d) for d in json['targets']['//:skia']['defines']} |
| 411 | android_defines = get_defines(js) |
| 412 | linux_defines = get_defines(js_linux) |
Leon Scroggins III | 85e22fc | 2018-11-28 08:58:47 -0500 | [diff] [blame] | 413 | mac_defines = get_defines(js_mac) |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 414 | win_defines = get_defines(js_win) |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 415 | |
| 416 | def mkdir_if_not_exists(path): |
| 417 | if not os.path.exists(path): |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 418 | os.makedirs(path) |
| 419 | mkdir_if_not_exists('android/include/config/') |
| 420 | mkdir_if_not_exists('linux/include/config/') |
| 421 | mkdir_if_not_exists('mac/include/config/') |
| 422 | mkdir_if_not_exists('win/include/config/') |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 423 | |
| 424 | platforms = { 'IOS', 'MAC', 'WIN', 'ANDROID', 'UNIX' } |
| 425 | |
| 426 | def disallow_platforms(config, desired): |
| 427 | with open(config, 'a') as f: |
| 428 | p = sorted(platforms.difference({ desired })) |
| 429 | s = '#if ' |
| 430 | for i in range(len(p)): |
| 431 | s = s + 'defined(SK_BUILD_FOR_%s)' % p[i] |
| 432 | if i < len(p) - 1: |
| 433 | s += ' || ' |
| 434 | if i % 2 == 1: |
| 435 | s += '\\\n ' |
Martin Vejdarski | beaaf47 | 2020-03-03 13:53:20 +0700 | [diff] [blame] | 436 | print(s, file=f) |
| 437 | print(' #error "Only SK_BUILD_FOR_%s should be defined!"' % desired, file=f) |
| 438 | print('#endif', file=f) |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 439 | |
| 440 | def append_to_file(config, s): |
| 441 | with open(config, 'a') as f: |
Martin Vejdarski | beaaf47 | 2020-03-03 13:53:20 +0700 | [diff] [blame] | 442 | print(s, file=f) |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 443 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 444 | android_config = 'android/include/config/SkUserConfig.h' |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 445 | gn_to_bp_utils.WriteUserConfig(android_config, android_defines) |
| 446 | append_to_file(android_config, ''' |
| 447 | #ifndef SK_BUILD_FOR_ANDROID |
| 448 | #error "SK_BUILD_FOR_ANDROID must be defined!" |
| 449 | #endif''') |
| 450 | disallow_platforms(android_config, 'ANDROID') |
| 451 | |
Leon Scroggins III | 85e22fc | 2018-11-28 08:58:47 -0500 | [diff] [blame] | 452 | def write_config(config_path, defines, platform): |
| 453 | gn_to_bp_utils.WriteUserConfig(config_path, defines) |
| 454 | append_to_file(config_path, ''' |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 455 | // Correct SK_BUILD_FOR flags that may have been set by |
Mike Klein | 81d35a7 | 2020-02-05 10:17:57 -0600 | [diff] [blame] | 456 | // SkTypes.h/Android.bp |
Leon Scroggins III | 85e22fc | 2018-11-28 08:58:47 -0500 | [diff] [blame] | 457 | #ifndef SK_BUILD_FOR_%s |
| 458 | #define SK_BUILD_FOR_%s |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 459 | #endif |
| 460 | #ifdef SK_BUILD_FOR_ANDROID |
| 461 | #undef SK_BUILD_FOR_ANDROID |
Leon Scroggins III | 85e22fc | 2018-11-28 08:58:47 -0500 | [diff] [blame] | 462 | #endif''' % (platform, platform)) |
| 463 | disallow_platforms(config_path, platform) |
| 464 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 465 | write_config('linux/include/config/SkUserConfig.h', linux_defines, 'UNIX') |
| 466 | write_config('mac/include/config/SkUserConfig.h', mac_defines, 'MAC') |
| 467 | write_config('win/include/config/SkUserConfig.h', win_defines, 'WIN') |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 468 | |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 469 | # Turn a list of strings into the style bpfmt outputs. |
Leon Scroggins III | 6ccd2ca | 2017-01-26 17:21:27 -0500 | [diff] [blame] | 470 | def bpfmt(indent, lst, sort=True): |
| 471 | if sort: |
| 472 | lst = sorted(lst) |
| 473 | return ('\n' + ' '*indent).join('"%s",' % v for v in lst) |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 474 | |
| 475 | # OK! We have everything to fill in Android.bp... |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 476 | with open('Android.bp', 'w') as Android_bp: |
Martin Vejdarski | beaaf47 | 2020-03-03 13:53:20 +0700 | [diff] [blame] | 477 | print(bp.substitute({ |
Mike Klein | ee43f6f | 2016-12-12 14:09:38 -0500 | [diff] [blame] | 478 | 'export_includes': bpfmt(8, export_includes), |
| 479 | 'local_includes': bpfmt(8, local_includes), |
| 480 | 'srcs': bpfmt(8, srcs), |
Leon Scroggins III | 981a31e | 2017-10-06 11:53:53 -0400 | [diff] [blame] | 481 | 'cflags': bpfmt(8, cflags, False), |
| 482 | 'cflags_cc': bpfmt(8, cflags_cc), |
Mike Klein | 308b5ac | 2016-12-06 16:03:52 -0500 | [diff] [blame] | 483 | |
Mike Klein | d505b19 | 2018-09-05 15:55:25 -0400 | [diff] [blame] | 484 | 'arm_srcs': bpfmt(16, strip_headers(defs['armv7'])), |
| 485 | 'arm_neon_srcs': bpfmt(20, strip_headers(defs['neon'])), |
| 486 | 'arm64_srcs': bpfmt(16, strip_headers(defs['arm64'] + |
| 487 | defs['crc32'])), |
Mike Klein | d505b19 | 2018-09-05 15:55:25 -0400 | [diff] [blame] | 488 | 'x86_srcs': bpfmt(16, strip_headers(defs['sse2'] + |
| 489 | defs['ssse3'] + |
| 490 | defs['sse41'] + |
| 491 | defs['sse42'] + |
| 492 | defs['avx' ] + |
| 493 | defs['hsw' ])), |
Leon Scroggins III | 6ccd2ca | 2017-01-26 17:21:27 -0500 | [diff] [blame] | 494 | |
Leon Scroggins III | 6ccd2ca | 2017-01-26 17:21:27 -0500 | [diff] [blame] | 495 | 'dm_includes' : bpfmt(8, dm_includes), |
| 496 | 'dm_srcs' : bpfmt(8, dm_srcs), |
| 497 | |
| 498 | 'nanobench_includes' : bpfmt(8, nanobench_includes), |
| 499 | 'nanobench_srcs' : bpfmt(8, nanobench_srcs), |
Leon Scroggins III | c41a5f5 | 2018-11-15 15:54:59 -0500 | [diff] [blame] | 500 | |
| 501 | 'android_srcs': bpfmt(10, android_srcs), |
| 502 | 'linux_srcs': bpfmt(10, linux_srcs), |
Leon Scroggins III | 85e22fc | 2018-11-28 08:58:47 -0500 | [diff] [blame] | 503 | 'mac_srcs': bpfmt(10, mac_srcs), |
Leon Scroggins III | ee0e5d0 | 2019-02-27 10:59:11 -0500 | [diff] [blame] | 504 | 'win_srcs': bpfmt(10, win_srcs), |
Martin Vejdarski | beaaf47 | 2020-03-03 13:53:20 +0700 | [diff] [blame] | 505 | }), file=Android_bp) |