1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
build / config / apple / mobile_bundle_data.gni [blame]
# Copyright 2024 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/config/zip.gni")
if (is_ios) {
import("//build/config/ios/ios_sdk_overrides.gni")
}
# Compile a xib or storyboard file and add it to a bundle_data so that it is
# available at runtime in the bundle.
#
# Arguments
#
# source:
# string, path of the xib or storyboard to compile.
#
# extension:
# string, extension of the generated file or bundle.
#
# bundle_files:
# list of string, name of the files in the generated bundle;
# if empty, the output is expected to be a single file.
#
# Forwards all variables to the bundle_data target.
template("bundle_data_ib_file") {
assert(defined(invoker.source), "source needs to be defined for $target_name")
assert(defined(invoker.extension),
"extension needs to be defined for $target_name")
assert(defined(invoker.bundle_files),
"bundle_files needs to be defined for $target_name")
_target_name = target_name
_compile_target =
target_name + "_compile_" + get_path_info(invoker.source, "extension")
_output_path = "$target_gen_dir/$_target_name/"
_output_name = get_path_info(invoker.source, "name") + ".${invoker.extension}"
if (is_ios) {
_deployment_target = ios_deployment_target
_target_devices = [
"iphone",
"ipad",
]
} else {
assert(false, "Unsupported platform: " + current_os)
}
action(_compile_target) {
forward_variables_from(invoker,
"*",
[
"source",
"bundle_files",
])
script = "//build/config/apple/compile_ib_files.py"
args = [
"--input",
rebase_path(invoker.source, root_build_dir),
"--output",
rebase_path("$_output_path/$_output_name", root_build_dir),
"--minimum-deployment-target",
_deployment_target,
"--auto-activate-custom-fonts",
]
foreach(target_device, _target_devices) {
args += [
"--target-device",
target_device,
]
}
sources = [ invoker.source ]
if (invoker.bundle_files == []) {
outputs = [ "$_output_path/$_output_name" ]
} else {
outputs = []
foreach(_bundle_file, invoker.bundle_files) {
outputs += [ "$_output_path/$_output_name/$_bundle_file" ]
}
}
}
bundle_data(_target_name) {
forward_variables_from(invoker, "*", [ "source" ])
if (!defined(public_deps)) {
public_deps = []
}
public_deps += [ ":$_compile_target" ]
sources = get_target_outputs(":$_compile_target")
if (invoker.bundle_files == []) {
outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
} else {
outputs =
[ "{{bundle_resources_dir}}/$_output_name/{{source_file_part}}" ]
}
}
}
# Compile a xib file and add it to a bundle_data so that it is available at
# runtime in the bundle.
#
# Arguments
#
# source:
# string, path of the xib or storyboard to compile.
#
# Forwards all variables to the bundle_data target.
template("bundle_data_xib_file") {
assert(defined(invoker.source), "source needs to be defined for $target_name")
_extension = get_path_info(invoker.source, "extension")
assert(_extension == "xib",
"source must have the .xib extension for $target_name")
bundle_data_ib_file(target_name) {
forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
forward_variables_from(invoker, TESTONLY_AND_VISIBILITY)
extension = "nib"
bundle_files = []
}
}
# Compile a storyboard file and add it to a bundle_data so that it is available
# at runtime in the bundle.
#
# Arguments
#
# source:
# string, path of the xib or storyboard to compile.
#
# bundle_files
# list of strings, name of the individual files in the generated bundle
#
# Forwards all variables to the bundle_data target.
template("bundle_data_storyboard_file") {
assert(defined(invoker.source), "source needs to be defined for $target_name")
assert(defined(invoker.bundle_files) && invoker.bundle_files != [],
"bundle_files needs to be defined for $target_name")
_extension = get_path_info(invoker.source, "extension")
assert(_extension == "storyboard",
"source must have the .storyboard extension for $target_name")
bundle_data_ib_file(target_name) {
forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
forward_variables_from(invoker, TESTONLY_AND_VISIBILITY)
extension = "storyboardc"
}
}
# Compile a strings file and add it to a bundle_data so that it is available
# at runtime in the bundle.
#
# Arguments
#
# source:
# string, path of the strings file to compile.
#
# output:
# string, path of the compiled file in the final bundle.
#
# Forwards all variables to the bundle_data target.
template("bundle_data_strings") {
assert(defined(invoker.source), "source needs to be defined for $target_name")
assert(defined(invoker.output), "output needs to be defined for $target_name")
_source_extension = get_path_info(invoker.source, "extension")
assert(_source_extension == "strings",
"source must be a .strings for $target_name")
_target_name = target_name
_convert_target = target_name + "_compile_strings"
convert_plist(_convert_target) {
visibility = [ ":$_target_name" ]
source = invoker.source
output =
"$target_gen_dir/$_target_name/" + get_path_info(invoker.source, "file")
format = "binary1"
}
bundle_data(_target_name) {
forward_variables_from(invoker,
"*",
[
"source",
"output",
])
if (!defined(public_deps)) {
public_deps = []
}
public_deps += [ ":$_convert_target" ]
sources = get_target_outputs(":$_convert_target")
outputs = [ invoker.output ]
}
}
# This template declares a bundle_data target that reference an assets
# catalog so that is is compiled to the asset catalog of the generated
# bundle.
#
# The target will ensure that only the files explicitly listed will be
# compiled into the final application (i.e. it allow listing some of
# the assets catalog content conditionally).
#
# The target requires that the files are located in a .xcassets bundle
# in the repository (or generated via a script). This ensures that the
# assets catalog is correctly visible in Xcode (though as usual, using
# Xcode to make change to the .xcassets bundle will not be reflected in
# the final build unless the target is updated in the gn configuration).
#
# Arguments
#
# sources:
# required, list of strings, path to the files contained in the
# .xcassets bundle; this may contains a sub-set of the files on
# disk if some assets are only compiled conditionally
#
# catalog:
# required, string, path to the .xcassets bundle; all path in
# sources must be relative to this path or the compilation will
# fail
#
# Example
#
# bundle_data_xcassets("assets") {
# catalog = "Assets.xcassets"
# sources = [
# "Assets.xcassets/Color.colorset/Contents.json",
# "Assets.xcassets/Contents.json",
# ]
# if (includes_images) {
# sources += [
# "Assets.xcassets/Image.imageset/Contents.json",
# "Assets.xcassets/Image.imageset/Image.svg",
# ]
# }
# }
template("bundle_data_xcassets") {
assert(defined(invoker.sources), "sources must be defined for $target_name")
assert(defined(invoker.catalog), "catalog must be defined for $target_name")
_target_name = target_name
_target_zip = target_name + "_zip"
zip(_target_zip) {
_catalog_name = get_path_info(invoker.catalog, "file")
_catalog_path = get_path_info(invoker.catalog, "dir")
inputs = invoker.sources
output = "$target_out_dir/$target_name/$_catalog_name"
base_dir = _catalog_path
}
bundle_data(_target_name) {
forward_variables_from(invoker,
"*",
[
"sources",
"deps",
"public_deps",
])
public_deps = [ ":$_target_zip" ]
sources = get_target_outputs(":$_target_zip")
outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
}
}