blob: 501ebcd56b2e0c3b7fdec1dcb8a3ed4ff357b31b [file] [log] [blame]
Hal Canary3388c1a2019-09-16 12:53:17 -04001# 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
5import("skia.gni")
6
7if (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 Klein96f64012020-04-03 10:59:37 -050078 sources = [ invoker.source ]
Hal Canary3388c1a2019-09-16 12:53:17 -040079 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 Klein96f64012020-04-03 10:59:37 -0500102 outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
Hal Canary3388c1a2019-09-16 12:53:17 -0400103 }
104 }
105
106 template("ios_app_bundle") {
107 app_name = target_name
108 gen_path = target_gen_dir
109
110 action("${app_name}_generate_info_plist") {
111 script = "//gn/gen_plist_ios.py"
Mike Klein96f64012020-04-03 10:59:37 -0500112 outputs = [ "$gen_path/${app_name}_Info.plist" ]
Hal Canary3388c1a2019-09-16 12:53:17 -0400113 args = [ rebase_path("$gen_path/$app_name", root_build_dir) ]
114 }
115
116 bundle_data("${app_name}_bundle_info_plist") {
Mike Klein96f64012020-04-03 10:59:37 -0500117 public_deps = [ ":${app_name}_generate_info_plist" ]
118 sources = [ "$gen_path/${app_name}_Info.plist" ]
119 outputs = [ "{{bundle_resources_dir}}/Info.plist" ]
Hal Canary3388c1a2019-09-16 12:53:17 -0400120 }
121
122 if (defined(invoker.data_sources)) {
123 bundle_data("${app_name}_bundle_resources_and_skps") {
124 sources = invoker.data_sources
125
126 # iOS reserves the folders 'Resources' and 'resources' so store one level deeper
Mike Klein96f64012020-04-03 10:59:37 -0500127 outputs = [ "{{bundle_resources_dir}}/data/{{source_file_part}}" ]
Hal Canary3388c1a2019-09-16 12:53:17 -0400128 }
129 }
130
131 if (defined(invoker.launchscreen)) {
132 bundle_data_ib_file("${app_name}_bundle_launchscreen") {
133 source = invoker.launchscreen
134 }
135 }
136
137 executable("${app_name}_generate_executable") {
138 forward_variables_from(invoker,
139 "*",
140 [
141 "output_name",
142 "visibility",
143 "is_shared_library",
144 "data_sources",
145 "extra_configs",
146 ])
147 if (defined(invoker.extra_configsa)) {
148 configs += invoker.extra_configs
149 }
150 output_name = rebase_path("$gen_path/$app_name", root_build_dir)
151 }
152
153 action("${app_name}_dsymutil") {
Mike Klein96f64012020-04-03 10:59:37 -0500154 public_deps = [ ":${app_name}_generate_executable" ]
155 sources = [ "$gen_path/$app_name" ]
Hal Canary3388c1a2019-09-16 12:53:17 -0400156 script = "//gn/call.py"
157 args = [
158 "dsymutil",
159 rebase_path("$gen_path/$app_name"),
160 ]
Mike Klein96f64012020-04-03 10:59:37 -0500161 outputs = [ "$gen_path/${app_name}.dSYM" ]
Hal Canary3388c1a2019-09-16 12:53:17 -0400162 testonly = defined(invoker.testonly) && invoker.testonly
163 pool = "//gn/toolchain:dsymutil_pool($default_toolchain)"
164 }
165
166 bundle_data("${app_name}_bundle_executable_and_symbols") {
167 public_deps = [
168 ":${app_name}_dsymutil",
169 ":${app_name}_generate_executable",
170 ]
171 sources = [
172 "$gen_path/${app_name}",
173 "$gen_path/${app_name}.dSYM",
174 ]
Mike Klein96f64012020-04-03 10:59:37 -0500175 outputs = [ "{{bundle_executable_dir}}/{{source_file_part}}" ]
Hal Canary3388c1a2019-09-16 12:53:17 -0400176 testonly = defined(invoker.testonly) && invoker.testonly
177 }
178
179 create_bundle("$app_name") {
180 product_type = "com.apple.product-type.application"
181 testonly = defined(invoker.testonly) && invoker.testonly
182
183 bundle_root_dir = "${root_build_dir}/${target_name}.app"
184 bundle_resources_dir = bundle_root_dir
185 bundle_executable_dir = bundle_root_dir
186
187 deps = [
188 ":${app_name}_bundle_executable_and_symbols",
189 ":${app_name}_bundle_info_plist",
190 ]
191 if (defined(invoker.launchscreen)) {
192 deps += [ ":${app_name}_bundle_launchscreen" ]
193 }
194 if (defined(invoker.data_sources)) {
195 deps += [ ":${app_name}_bundle_resources_and_skps" ]
196 }
197
198 # should only code sign when running on a device, not the simulator
199 if (target_cpu != "x64") {
200 code_signing_script = "//gn/codesign_ios.py"
201 code_signing_sources = [ "$target_gen_dir/$app_name" ]
202 code_signing_outputs = [
203 "$bundle_root_dir/_CodeSignature/CodeResources",
204 "$bundle_root_dir/embedded.mobileprovision",
205 ]
206 code_signing_args = [
207 rebase_path("$bundle_root_dir", root_build_dir),
208 skia_ios_identity,
209 skia_ios_profile,
210 ]
211 }
212 }
213 }
214}