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
|
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Instantiate grit. This will produce a script target to run grit, and a
# static library that compiles the .cc files.
#
# Parameters
#
# source
# Path to .grd file.
#
# grit_flags (optional)
# List of strings containing extra command-line flags to pass to Grit.
#
# resource_ids (optional)
# Path to a grit "firstidsfile". Default is
# //tools/gritsettings/resource_ids. Set to "" to use the value specified in
# the <grit> nodes of the processed files.
#
# output_dir (optional)
# Directory for generated files.
#
# deps (optional)
# visibility (optional)
# Normal meaning.
#
# Example
#
# grit("my_resources") {
# source = "myfile.grd" # source is required.
# grit_flags = [ "-E", "foo=bar" ] # Optional extra flags.
# # You can also put deps here if the grit source depends on generated
# # files.
# }
import ("//build/config/crypto.gni")
import ("//build/config/features.gni")
import ("//build/config/ui.gni")
grit_defines = []
# Mac and iOS want Title Case strings.
use_titlecase_in_grd_files = is_mac || is_ios
if (use_titlecase_in_grd_files) {
grit_defines += [ "-D", "use_titlecase" ]
}
if (is_chrome_branded) {
grit_defines += [
"-D", "_google_chrome",
"-E", "CHROMIUM_BUILD=google_chrome",
]
} else {
grit_defines += [
"-D", "_chromium",
"-E", "CHROMIUM_BUILD=chromium",
]
}
if (is_chromeos) {
grit_defines += [
"-D", "chromeos",
"-D", "scale_factors=2x"
]
}
if (is_desktop_linux) {
grit_defines += [ "-D", "desktop_linux" ]
}
if (toolkit_views) {
grit_defines += [ "-D", "toolkit_views" ]
}
if (use_aura) {
grit_defines += [ "-D", "use_aura" ]
}
if (use_ash) {
grit_defines += [ "-D", "use_ash" ]
}
if (use_nss_certs) {
grit_defines += [ "-D", "use_nss" ]
}
if (use_ozone) {
grit_defines += [ "-D", "use_ozone" ]
}
if (enable_image_loader_extension) {
grit_defines += [ "-D", "image_loader_extension" ]
}
if (enable_remoting) {
grit_defines += [ "-D", "remoting" ]
}
if (is_android) {
grit_defines += [
"-t", "android",
"-E", "ANDROID_JAVA_TAGGED_ONLY=true",
]
}
if (is_mac || is_ios) {
grit_defines += [ "-D", "scale_factors=2x" ]
}
if (is_ios) {
grit_defines += [
"-t", "ios",
# iOS uses a whitelist to filter resources.
"-w", rebase_path("//build/ios/grit_whitelist.txt", root_build_dir),
]
}
if (enable_extensions) {
grit_defines += [ "-D", "enable_extensions" ]
}
if (enable_plugins) {
grit_defines += [ "-D", "enable_plugins" ]
}
if (enable_printing != 0) {
grit_defines += [ "-D", "enable_printing" ]
if (enable_printing == 1) {
grit_defines += [ "-D", "enable_full_printing" ]
}
}
if (enable_themes) {
grit_defines += [ "-D", "enable_themes" ]
}
if (enable_app_list) {
grit_defines += [ "-D", "enable_app_list" ]
}
if (enable_settings_app) {
grit_defines += [ "-D", "enable_settings_app" ]
}
if (enable_google_now) {
grit_defines += [ "-D", "enable_google_now" ]
}
# Note: use_concatenated_impulse_responses is omitted. It is never used and
# should probably be removed from GYP build.
if (enable_webrtc) {
grit_defines += [ "-D", "enable_webrtc" ]
}
# Note: enable_hangout_services_extension is omitted. It is never set in the
# GYP build. Need to figure out what it's for.
if (enable_task_manager) {
grit_defines += [ "-D", "enable_task_manager" ]
}
if (enable_notifications) {
grit_defines += [ "-D", "enable_notifications" ]
}
if (enable_wifi_bootstrapping) {
grit_defines += [ "-D", "enable_wifi_bootstrapping" ]
}
if (enable_service_discovery) {
grit_defines += [ "-D", "enable_service_discovery" ]
}
grit_resource_id_file = "//tools/gritsettings/resource_ids"
grit_info_script = "//tools/grit/grit_info.py"
template("grit") {
assert(defined(invoker.source),
"\"source\" must be defined for the grit template $target_name")
assert(!defined(invoker.sources) && !defined(invoker.outputs),
"Neither \"sources\" nor \"outputs\" can be defined for the grit " +
"template $target_name")
if (defined(invoker.resource_ids)) {
resource_ids = invoker.resource_ids
} else {
resource_ids = grit_resource_id_file
}
if (defined(invoker.output_dir)) {
output_dir = invoker.output_dir
} else {
output_dir = target_gen_dir
}
# These are all passed as arguments to the script so have to be relative to
# the build directory.
if (resource_ids != "") {
resource_ids = rebase_path(resource_ids, root_build_dir)
}
rebased_output_dir = rebase_path(output_dir, root_build_dir)
source_path = rebase_path(invoker.source, root_build_dir)
if (defined(invoker.grit_flags)) {
grit_flags = invoker.grit_flags
} else {
grit_flags = [] # These are optional so default to empty list.
}
grit_inputs_build_rel = exec_script(grit_info_script,
[ "--inputs", source_path, "-f", resource_ids] + grit_flags, "list lines")
# The inputs are relative to the current (build) directory, rebase to
# the current one.
grit_inputs = rebase_path(grit_inputs_build_rel, ".", root_build_dir) + [
grit_resource_id_file,
]
grit_outputs_build_rel = exec_script(grit_info_script,
[ "--outputs", "$rebased_output_dir", source_path, "-f", resource_ids ] +
grit_flags,
"list lines")
# The names returned by grit are relative to the current (build) directory,
# but references to files in this template are expected to be relative to the
# invoking BUILD.gn file's directory. Make it absolute so there's no
# ambiguity.
grit_outputs = get_path_info(
rebase_path(grit_outputs_build_rel, ".", root_build_dir), "abspath")
# The config and the action below get this visibility son only the generated
# source set can depend on them. The variable "target_name" will get
# overwritten inside the innter classes so we need to compute it here.
target_visibility = ":$target_name"
# The current grit setup makes an file in $output_dir/grit/foo.h that
# the source code expects to include via "grit/foo.h". It would be nice to
# change this to including absolute paths relative to the root gen directory
# (like "mycomponent/foo.h"). This config sets up the include path.
grit_config = target_name + "_grit_config"
config(grit_config) {
include_dirs = [ output_dir ]
visibility = target_visibility
}
grit_custom_target = target_name + "_grit"
action(grit_custom_target) {
script = "//tools/grit/grit.py"
inputs = grit_inputs
outputs = grit_outputs
args = [
"-i", source_path, "build",
"-f", resource_ids,
"-o", rebased_output_dir,
] + grit_defines + grit_flags
visibility = target_visibility
if (defined(invoker.deps)) {
deps = invoker.deps
}
}
# This is the thing that people actually link with, it must be named the
# same as the argument the template was invoked with.
source_set(target_name) {
# Since we generate a file, we need to be run before the targets that
# depend on us.
sources = grit_outputs
# Deps set on the template invocation will go on the grit script running
# target rather than this library.
deps = [ ":$grit_custom_target" ]
direct_dependent_configs = [ ":$grit_config" ]
if (defined(invoker.visibility)) {
visibility = invoker.visibility
}
if (defined(invoker.output_name)) {
output_name = invoker.output_name
}
}
}
|