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) { |
| 78 | sources = [ |
| 79 | invoker.source, |
| 80 | ] |
| 81 | output_extension = _output_extension |
| 82 | visibility = [ ":$_target_name" ] |
| 83 | ibtool_flags = [ |
| 84 | # "--minimum-deployment-target", |
| 85 | # ios_deployment_target, |
| 86 | "--auto-activate-custom-fonts", |
| 87 | "--target-device", |
| 88 | "iphone", |
| 89 | "--target-device", |
| 90 | "ipad", |
| 91 | ] |
| 92 | } |
| 93 | |
| 94 | bundle_data(_target_name) { |
| 95 | forward_variables_from(invoker, "*", [ "source" ]) |
| 96 | |
| 97 | if (!defined(public_deps)) { |
| 98 | public_deps = [] |
| 99 | } |
| 100 | public_deps += [ ":$_compile_ib_file" ] |
| 101 | |
| 102 | sources = get_target_outputs(":$_compile_ib_file") |
| 103 | |
| 104 | outputs = [ |
| 105 | "{{bundle_resources_dir}}/{{source_file_part}}", |
| 106 | ] |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | template("ios_app_bundle") { |
| 111 | app_name = target_name |
| 112 | gen_path = target_gen_dir |
| 113 | |
| 114 | action("${app_name}_generate_info_plist") { |
| 115 | script = "//gn/gen_plist_ios.py" |
| 116 | outputs = [ |
| 117 | "$gen_path/${app_name}_Info.plist", |
| 118 | ] |
| 119 | args = [ rebase_path("$gen_path/$app_name", root_build_dir) ] |
| 120 | } |
| 121 | |
| 122 | bundle_data("${app_name}_bundle_info_plist") { |
| 123 | public_deps = [ |
| 124 | ":${app_name}_generate_info_plist", |
| 125 | ] |
| 126 | sources = [ |
| 127 | "$gen_path/${app_name}_Info.plist", |
| 128 | ] |
| 129 | outputs = [ |
| 130 | "{{bundle_root_dir}}/Info.plist", |
| 131 | ] |
| 132 | } |
| 133 | |
| 134 | if (defined(invoker.data_sources)) { |
| 135 | bundle_data("${app_name}_bundle_resources_and_skps") { |
| 136 | sources = invoker.data_sources |
| 137 | |
| 138 | # iOS reserves the folders 'Resources' and 'resources' so store one level deeper |
| 139 | outputs = [ |
| 140 | "{{bundle_resources_dir}}/data/{{source_file_part}}", |
| 141 | ] |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | if (defined(invoker.launchscreen)) { |
| 146 | bundle_data_ib_file("${app_name}_bundle_launchscreen") { |
| 147 | source = invoker.launchscreen |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | executable("${app_name}_generate_executable") { |
| 152 | forward_variables_from(invoker, |
| 153 | "*", |
| 154 | [ |
| 155 | "output_name", |
| 156 | "visibility", |
| 157 | "is_shared_library", |
| 158 | "data_sources", |
| 159 | "extra_configs", |
| 160 | ]) |
| 161 | if (defined(invoker.extra_configsa)) { |
| 162 | configs += invoker.extra_configs |
| 163 | } |
| 164 | output_name = rebase_path("$gen_path/$app_name", root_build_dir) |
| 165 | } |
| 166 | |
| 167 | action("${app_name}_dsymutil") { |
| 168 | public_deps = [ |
| 169 | ":${app_name}_generate_executable", |
| 170 | ] |
| 171 | sources = [ |
| 172 | "$gen_path/$app_name", |
| 173 | ] |
| 174 | script = "//gn/call.py" |
| 175 | args = [ |
| 176 | "dsymutil", |
| 177 | rebase_path("$gen_path/$app_name"), |
| 178 | ] |
| 179 | outputs = [ |
| 180 | "$gen_path/${app_name}.dSYM", |
| 181 | ] |
| 182 | testonly = defined(invoker.testonly) && invoker.testonly |
| 183 | pool = "//gn/toolchain:dsymutil_pool($default_toolchain)" |
| 184 | } |
| 185 | |
| 186 | bundle_data("${app_name}_bundle_executable_and_symbols") { |
| 187 | public_deps = [ |
| 188 | ":${app_name}_dsymutil", |
| 189 | ":${app_name}_generate_executable", |
| 190 | ] |
| 191 | sources = [ |
| 192 | "$gen_path/${app_name}", |
| 193 | "$gen_path/${app_name}.dSYM", |
| 194 | ] |
| 195 | outputs = [ |
| 196 | "{{bundle_executable_dir}}/{{source_file_part}}", |
| 197 | ] |
| 198 | testonly = defined(invoker.testonly) && invoker.testonly |
| 199 | } |
| 200 | |
| 201 | create_bundle("$app_name") { |
| 202 | product_type = "com.apple.product-type.application" |
| 203 | testonly = defined(invoker.testonly) && invoker.testonly |
| 204 | |
| 205 | bundle_root_dir = "${root_build_dir}/${target_name}.app" |
| 206 | bundle_resources_dir = bundle_root_dir |
| 207 | bundle_executable_dir = bundle_root_dir |
| 208 | |
| 209 | deps = [ |
| 210 | ":${app_name}_bundle_executable_and_symbols", |
| 211 | ":${app_name}_bundle_info_plist", |
| 212 | ] |
| 213 | if (defined(invoker.launchscreen)) { |
| 214 | deps += [ ":${app_name}_bundle_launchscreen" ] |
| 215 | } |
| 216 | if (defined(invoker.data_sources)) { |
| 217 | deps += [ ":${app_name}_bundle_resources_and_skps" ] |
| 218 | } |
| 219 | |
| 220 | # should only code sign when running on a device, not the simulator |
| 221 | if (target_cpu != "x64") { |
| 222 | code_signing_script = "//gn/codesign_ios.py" |
| 223 | code_signing_sources = [ "$target_gen_dir/$app_name" ] |
| 224 | code_signing_outputs = [ |
| 225 | "$bundle_root_dir/_CodeSignature/CodeResources", |
| 226 | "$bundle_root_dir/embedded.mobileprovision", |
| 227 | ] |
| 228 | code_signing_args = [ |
| 229 | rebase_path("$bundle_root_dir", root_build_dir), |
| 230 | skia_ios_identity, |
| 231 | skia_ios_profile, |
| 232 | ] |
| 233 | } |
| 234 | } |
| 235 | } |
| 236 | } |