Hal Canary | 3388c1a | 2019-09-16 12:53:17 -0400 | [diff] [blame] | 1 | # Copyright 2019 Google LLC. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | import("skia.gni") |
| 6 | |
| 7 | if (is_ios) { |
| 8 | # Template to compile .xib and .storyboard files. |
| 9 | # |
| 10 | # Arguments |
| 11 | # |
| 12 | # sources: |
| 13 | # list of string, sources to compile |
| 14 | # |
| 15 | # ibtool_flags: |
| 16 | # (optional) list of string, additional flags to pass to the ibtool |
| 17 | template("compile_ib_files") { |
| 18 | action_foreach(target_name) { |
| 19 | forward_variables_from(invoker, |
| 20 | [ |
| 21 | "testonly", |
| 22 | "visibility", |
| 23 | ]) |
| 24 | assert(defined(invoker.sources), |
| 25 | "sources must be specified for $target_name") |
| 26 | assert(defined(invoker.output_extension), |
| 27 | "output_extension must be specified for $target_name") |
| 28 | |
| 29 | ibtool_flags = [] |
| 30 | if (defined(invoker.ibtool_flags)) { |
| 31 | ibtool_flags = invoker.ibtool_flags |
| 32 | } |
| 33 | |
| 34 | _output_extension = invoker.output_extension |
| 35 | |
| 36 | script = "//gn/compile_ib_files.py" |
| 37 | sources = invoker.sources |
| 38 | outputs = [ |
| 39 | "$target_gen_dir/$target_name/{{source_name_part}}.$_output_extension", |
| 40 | ] |
| 41 | args = [ |
| 42 | "--input", |
| 43 | "{{source}}", |
| 44 | "--output", |
| 45 | rebase_path( |
| 46 | "$target_gen_dir/$target_name/{{source_name_part}}.$_output_extension", |
| 47 | root_build_dir), |
| 48 | ] |
| 49 | |
| 50 | # if (!use_system_xcode) { |
| 51 | # args += [ |
| 52 | # "--developer_dir", |
| 53 | # hermetic_xcode_path, |
| 54 | # ] |
| 55 | # } |
| 56 | args += ibtool_flags |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | template("bundle_data_ib_file") { |
| 61 | assert(defined(invoker.source), |
| 62 | "source needs to be defined for $target_name") |
| 63 | |
| 64 | _source_extension = get_path_info(invoker.source, "extension") |
| 65 | assert(_source_extension == "xib" || _source_extension == "storyboard", |
| 66 | "source must be a .xib or .storyboard for $target_name") |
| 67 | |
| 68 | _target_name = target_name |
| 69 | if (_source_extension == "xib") { |
| 70 | _compile_ib_file = target_name + "_compile_xib" |
| 71 | _output_extension = "nib" |
| 72 | } else { |
| 73 | _compile_ib_file = target_name + "_compile_storyboard" |
| 74 | _output_extension = "storyboardc" |
| 75 | } |
| 76 | |
| 77 | compile_ib_files(_compile_ib_file) { |
Mike Klein | 96f6401 | 2020-04-03 10:59:37 -0500 | [diff] [blame] | 78 | sources = [ invoker.source ] |
Hal Canary | 3388c1a | 2019-09-16 12:53:17 -0400 | [diff] [blame] | 79 | output_extension = _output_extension |
| 80 | visibility = [ ":$_target_name" ] |
| 81 | ibtool_flags = [ |
| 82 | # "--minimum-deployment-target", |
| 83 | # ios_deployment_target, |
| 84 | "--auto-activate-custom-fonts", |
| 85 | "--target-device", |
| 86 | "iphone", |
| 87 | "--target-device", |
| 88 | "ipad", |
| 89 | ] |
| 90 | } |
| 91 | |
| 92 | bundle_data(_target_name) { |
| 93 | forward_variables_from(invoker, "*", [ "source" ]) |
| 94 | |
| 95 | if (!defined(public_deps)) { |
| 96 | public_deps = [] |
| 97 | } |
| 98 | public_deps += [ ":$_compile_ib_file" ] |
| 99 | |
| 100 | sources = get_target_outputs(":$_compile_ib_file") |
| 101 | |
Mike Klein | 96f6401 | 2020-04-03 10:59:37 -0500 | [diff] [blame] | 102 | outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ] |
Hal Canary | 3388c1a | 2019-09-16 12:53:17 -0400 | [diff] [blame] | 103 | } |
| 104 | } |
| 105 | |
| 106 | template("ios_app_bundle") { |
| 107 | app_name = target_name |
| 108 | gen_path = target_gen_dir |
Jim Van Verth | b50e5cf | 2020-11-16 10:24:30 -0500 | [diff] [blame] | 109 | bundle_prefix = "com.google" |
Hal Canary | 3388c1a | 2019-09-16 12:53:17 -0400 | [diff] [blame] | 110 | |
| 111 | action("${app_name}_generate_info_plist") { |
| 112 | script = "//gn/gen_plist_ios.py" |
Mike Klein | 96f6401 | 2020-04-03 10:59:37 -0500 | [diff] [blame] | 113 | outputs = [ "$gen_path/${app_name}_Info.plist" ] |
Jim Van Verth | b50e5cf | 2020-11-16 10:24:30 -0500 | [diff] [blame] | 114 | args = [ |
| 115 | rebase_path("$gen_path/$app_name", root_build_dir), |
| 116 | "$bundle_prefix", |
| 117 | ] |
Hal Canary | 3388c1a | 2019-09-16 12:53:17 -0400 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | bundle_data("${app_name}_bundle_info_plist") { |
Mike Klein | 96f6401 | 2020-04-03 10:59:37 -0500 | [diff] [blame] | 121 | public_deps = [ ":${app_name}_generate_info_plist" ] |
| 122 | sources = [ "$gen_path/${app_name}_Info.plist" ] |
| 123 | outputs = [ "{{bundle_resources_dir}}/Info.plist" ] |
Hal Canary | 3388c1a | 2019-09-16 12:53:17 -0400 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | if (defined(invoker.data_sources)) { |
| 127 | bundle_data("${app_name}_bundle_resources_and_skps") { |
| 128 | sources = invoker.data_sources |
| 129 | |
| 130 | # iOS reserves the folders 'Resources' and 'resources' so store one level deeper |
Mike Klein | 96f6401 | 2020-04-03 10:59:37 -0500 | [diff] [blame] | 131 | outputs = [ "{{bundle_resources_dir}}/data/{{source_file_part}}" ] |
Hal Canary | 3388c1a | 2019-09-16 12:53:17 -0400 | [diff] [blame] | 132 | } |
| 133 | } |
| 134 | |
| 135 | if (defined(invoker.launchscreen)) { |
| 136 | bundle_data_ib_file("${app_name}_bundle_launchscreen") { |
| 137 | source = invoker.launchscreen |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | executable("${app_name}_generate_executable") { |
Greg Daniel | 6f66302 | 2021-06-18 14:15:01 -0400 | [diff] [blame] | 142 | if (!defined(configs)) { |
| 143 | configs = [] |
| 144 | } |
Hal Canary | 3388c1a | 2019-09-16 12:53:17 -0400 | [diff] [blame] | 145 | forward_variables_from(invoker, |
| 146 | "*", |
| 147 | [ |
| 148 | "output_name", |
| 149 | "visibility", |
| 150 | "is_shared_library", |
| 151 | "data_sources", |
| 152 | "extra_configs", |
Greg Daniel | 6f66302 | 2021-06-18 14:15:01 -0400 | [diff] [blame] | 153 | "configs", |
Hal Canary | 3388c1a | 2019-09-16 12:53:17 -0400 | [diff] [blame] | 154 | ]) |
Greg Daniel | 6f66302 | 2021-06-18 14:15:01 -0400 | [diff] [blame] | 155 | if (defined(invoker.configs)) { |
| 156 | configs += invoker.configs |
| 157 | } |
Jim Van Verth | 421ee3a | 2020-11-18 15:27:13 -0500 | [diff] [blame] | 158 | if (defined(invoker.extra_configs)) { |
Hal Canary | 3388c1a | 2019-09-16 12:53:17 -0400 | [diff] [blame] | 159 | configs += invoker.extra_configs |
| 160 | } |
| 161 | output_name = rebase_path("$gen_path/$app_name", root_build_dir) |
| 162 | } |
| 163 | |
| 164 | action("${app_name}_dsymutil") { |
Mike Klein | 96f6401 | 2020-04-03 10:59:37 -0500 | [diff] [blame] | 165 | public_deps = [ ":${app_name}_generate_executable" ] |
| 166 | sources = [ "$gen_path/$app_name" ] |
Hal Canary | 3388c1a | 2019-09-16 12:53:17 -0400 | [diff] [blame] | 167 | script = "//gn/call.py" |
| 168 | args = [ |
| 169 | "dsymutil", |
| 170 | rebase_path("$gen_path/$app_name"), |
| 171 | ] |
Mike Klein | 96f6401 | 2020-04-03 10:59:37 -0500 | [diff] [blame] | 172 | outputs = [ "$gen_path/${app_name}.dSYM" ] |
Hal Canary | 3388c1a | 2019-09-16 12:53:17 -0400 | [diff] [blame] | 173 | testonly = defined(invoker.testonly) && invoker.testonly |
| 174 | pool = "//gn/toolchain:dsymutil_pool($default_toolchain)" |
| 175 | } |
| 176 | |
| 177 | bundle_data("${app_name}_bundle_executable_and_symbols") { |
| 178 | public_deps = [ |
| 179 | ":${app_name}_dsymutil", |
| 180 | ":${app_name}_generate_executable", |
| 181 | ] |
| 182 | sources = [ |
| 183 | "$gen_path/${app_name}", |
| 184 | "$gen_path/${app_name}.dSYM", |
| 185 | ] |
Mike Klein | 96f6401 | 2020-04-03 10:59:37 -0500 | [diff] [blame] | 186 | outputs = [ "{{bundle_executable_dir}}/{{source_file_part}}" ] |
Hal Canary | 3388c1a | 2019-09-16 12:53:17 -0400 | [diff] [blame] | 187 | testonly = defined(invoker.testonly) && invoker.testonly |
| 188 | } |
| 189 | |
| 190 | create_bundle("$app_name") { |
| 191 | product_type = "com.apple.product-type.application" |
| 192 | testonly = defined(invoker.testonly) && invoker.testonly |
| 193 | |
| 194 | bundle_root_dir = "${root_build_dir}/${target_name}.app" |
| 195 | bundle_resources_dir = bundle_root_dir |
| 196 | bundle_executable_dir = bundle_root_dir |
| 197 | |
Jim Van Verth | b50e5cf | 2020-11-16 10:24:30 -0500 | [diff] [blame] | 198 | xcode_extra_attributes = { |
| 199 | PRODUCT_BUNDLE_IDENTIFIER = "${bundle_prefix}.${app_name}" |
Jim Van Verth | 2d36627 | 2020-11-18 15:44:04 -0500 | [diff] [blame] | 200 | if (ios_min_target != "") { |
| 201 | IPHONEOS_DEPLOYMENT_TARGET = ios_min_target |
| 202 | } |
Jim Van Verth | b50e5cf | 2020-11-16 10:24:30 -0500 | [diff] [blame] | 203 | } |
| 204 | |
Hal Canary | 3388c1a | 2019-09-16 12:53:17 -0400 | [diff] [blame] | 205 | deps = [ |
| 206 | ":${app_name}_bundle_executable_and_symbols", |
| 207 | ":${app_name}_bundle_info_plist", |
| 208 | ] |
| 209 | if (defined(invoker.launchscreen)) { |
| 210 | deps += [ ":${app_name}_bundle_launchscreen" ] |
| 211 | } |
| 212 | if (defined(invoker.data_sources)) { |
| 213 | deps += [ ":${app_name}_bundle_resources_and_skps" ] |
| 214 | } |
| 215 | |
| 216 | # should only code sign when running on a device, not the simulator |
| 217 | if (target_cpu != "x64") { |
| 218 | code_signing_script = "//gn/codesign_ios.py" |
| 219 | code_signing_sources = [ "$target_gen_dir/$app_name" ] |
| 220 | code_signing_outputs = [ |
| 221 | "$bundle_root_dir/_CodeSignature/CodeResources", |
| 222 | "$bundle_root_dir/embedded.mobileprovision", |
| 223 | ] |
| 224 | code_signing_args = [ |
| 225 | rebase_path("$bundle_root_dir", root_build_dir), |
| 226 | skia_ios_identity, |
| 227 | skia_ios_profile, |
| 228 | ] |
| 229 | } |
| 230 | } |
| 231 | } |
| 232 | } |