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