OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 # Instantiate grit. This will produce a script target to run grit, and a | 5 # Instantiate grit. This will produce a script target to run grit, and a |
6 # static library that compiles the .cc files. | 6 # static library that compiles the .cc files. |
7 # | 7 # |
8 # Parameters | 8 # Parameters |
9 # | 9 # |
10 # source | 10 # source |
11 # Path to .grd file. | 11 # Path to .grd file. |
12 # | 12 # |
| 13 # outputs (optional) |
| 14 # List of outputs from grit, relative to the target_gen_dir. If supplied, |
| 15 # a call to Grit to compute the outputs can be skipped which will make |
| 16 # GN run faster. Grit will verify at build time that this list is correct |
| 17 # and will fail if there is a mismatch between the outputs specified by |
| 18 # the .grd file and the outputs list here. |
| 19 # |
| 20 # To get this list, you can look in the .grd file for |
| 21 # <output filename="..." and put those filename here. The base directory |
| 22 # of the list in Grit and the output list specified in the GN grit target |
| 23 # are the same (the target_gen_dir) so you can generally copy the names |
| 24 # exactly. |
| 25 # |
| 26 # To get the list of outputs programatically, run: |
| 27 # python tools/grit/grit_info.py --outputs . path/to/your.grd |
| 28 # And strip the leading "./" from the output files. |
| 29 # |
13 # grit_flags (optional) | 30 # grit_flags (optional) |
14 # List of strings containing extra command-line flags to pass to Grit. | 31 # List of strings containing extra command-line flags to pass to Grit. |
15 # | 32 # |
16 # resource_ids (optional) | 33 # resource_ids (optional) |
17 # Path to a grit "firstidsfile". Default is | 34 # Path to a grit "firstidsfile". Default is |
18 # //tools/gritsettings/resource_ids. Set to "" to use the value specified in | 35 # //tools/gritsettings/resource_ids. Set to "" to use the value specified in |
19 # the <grit> nodes of the processed files. | 36 # the <grit> nodes of the processed files. |
20 # | 37 # |
21 # output_dir (optional) | 38 # output_dir (optional) |
22 # Directory for generated files. | 39 # Directory for generated files. |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 if (enable_service_discovery) { | 175 if (enable_service_discovery) { |
159 grit_defines += [ "-D", "enable_service_discovery" ] | 176 grit_defines += [ "-D", "enable_service_discovery" ] |
160 } | 177 } |
161 | 178 |
162 grit_resource_id_file = "//tools/gritsettings/resource_ids" | 179 grit_resource_id_file = "//tools/gritsettings/resource_ids" |
163 grit_info_script = "//tools/grit/grit_info.py" | 180 grit_info_script = "//tools/grit/grit_info.py" |
164 | 181 |
165 template("grit") { | 182 template("grit") { |
166 assert(defined(invoker.source), | 183 assert(defined(invoker.source), |
167 "\"source\" must be defined for the grit template $target_name") | 184 "\"source\" must be defined for the grit template $target_name") |
168 assert(!defined(invoker.sources) && !defined(invoker.outputs), | |
169 "Neither \"sources\" nor \"outputs\" can be defined for the grit " + | |
170 "template $target_name") | |
171 | 185 |
172 if (defined(invoker.resource_ids)) { | 186 if (defined(invoker.resource_ids)) { |
173 resource_ids = invoker.resource_ids | 187 resource_ids = invoker.resource_ids |
174 } else { | 188 } else { |
175 resource_ids = grit_resource_id_file | 189 resource_ids = grit_resource_id_file |
176 } | 190 } |
177 | 191 |
178 if (defined(invoker.output_dir)) { | 192 if (defined(invoker.output_dir)) { |
179 output_dir = invoker.output_dir | 193 output_dir = invoker.output_dir |
180 } else { | 194 } else { |
181 output_dir = target_gen_dir | 195 output_dir = target_gen_dir |
182 } | 196 } |
183 | 197 |
184 # These are all passed as arguments to the script so have to be relative to | 198 # These are all passed as arguments to the script so have to be relative to |
185 # the build directory. | 199 # the build directory. |
186 if (resource_ids != "") { | 200 if (resource_ids != "") { |
187 resource_ids = rebase_path(resource_ids, root_build_dir) | 201 resource_ids = rebase_path(resource_ids, root_build_dir) |
188 } | 202 } |
189 rebased_output_dir = rebase_path(output_dir, root_build_dir) | 203 rebased_output_dir = rebase_path(output_dir, root_build_dir) |
190 source_path = rebase_path(invoker.source, root_build_dir) | 204 source_path = rebase_path(invoker.source, root_build_dir) |
191 | 205 |
192 if (defined(invoker.grit_flags)) { | 206 if (defined(invoker.grit_flags)) { |
193 grit_flags = invoker.grit_flags | 207 grit_flags = invoker.grit_flags |
194 } else { | 208 } else { |
195 grit_flags = [] # These are optional so default to empty list. | 209 grit_flags = [] # These are optional so default to empty list. |
196 } | 210 } |
197 | 211 |
198 grit_inputs_build_rel = exec_script(grit_info_script, | 212 grit_inputs = [ invoker.source ] |
199 [ "--inputs", source_path, "-f", resource_ids] + grit_flags, "list lines") | |
200 # The inputs are relative to the current (build) directory, rebase to | |
201 # the current one. | |
202 grit_inputs = rebase_path(grit_inputs_build_rel, ".", root_build_dir) + [ | |
203 grit_resource_id_file, | |
204 ] | |
205 | 213 |
206 grit_outputs_build_rel = exec_script(grit_info_script, | 214 assert_files_flags = [] |
207 [ "--outputs", "$rebased_output_dir", source_path, "-f", resource_ids ] + | 215 if (defined(invoker.outputs)) { |
208 grit_flags, | 216 # If the declaration specified outputs, we want to make sure that they |
209 "list lines") | 217 # actually match what Grit is writing. We write the list to a file (some |
| 218 # of the output lists are long enough to not fit on a Windows command line) |
| 219 # and ask Grit to verify those are the actual outputs at runtime. |
| 220 asserted_list_file = "$target_out_dir/${target_name}_expected_outputs.txt" |
| 221 write_file(asserted_list_file, |
| 222 rebase_path(invoker.outputs, root_build_dir, target_gen_dir)) |
| 223 assert_files_flags += [ |
| 224 "--assert-file-list=" + rebase_path(asserted_list_file, root_build_dir), |
| 225 ] |
| 226 grit_outputs = get_path_info( |
| 227 rebase_path(invoker.outputs, ".", target_gen_dir), |
| 228 "abspath") |
| 229 } else { |
| 230 # Ask Grit for the output list. |
| 231 grit_outputs_build_rel = exec_script(grit_info_script, |
| 232 [ "--outputs", "$rebased_output_dir", source_path, "-f", resource_ids ] + |
| 233 grit_flags, |
| 234 "list lines") |
210 | 235 |
211 # The names returned by grit are relative to the current (build) directory, | 236 # The names returned by grit are relative to the current (build) directory, |
212 # but references to files in this template are expected to be relative to the | 237 # but references to files in this template are expected to be relative to |
213 # invoking BUILD.gn file's directory. Make it absolute so there's no | 238 # the invoking BUILD.gn file's directory. Make it absolute so there's no |
214 # ambiguity. | 239 # ambiguity. |
215 grit_outputs = get_path_info( | 240 grit_outputs = get_path_info( |
216 rebase_path(grit_outputs_build_rel, ".", root_build_dir), "abspath") | 241 rebase_path(grit_outputs_build_rel, ".", root_build_dir), "abspath") |
| 242 } |
217 | 243 |
218 # The config and the action below get this visibility son only the generated | 244 # The config and the action below get this visibility son only the generated |
219 # source set can depend on them. The variable "target_name" will get | 245 # source set can depend on them. The variable "target_name" will get |
220 # overwritten inside the innter classes so we need to compute it here. | 246 # overwritten inside the innter classes so we need to compute it here. |
221 target_visibility = ":$target_name" | 247 target_visibility = ":$target_name" |
222 | 248 |
223 # The current grit setup makes an file in $output_dir/grit/foo.h that | 249 # The current grit setup makes an file in $output_dir/grit/foo.h that |
224 # the source code expects to include via "grit/foo.h". It would be nice to | 250 # the source code expects to include via "grit/foo.h". It would be nice to |
225 # change this to including absolute paths relative to the root gen directory | 251 # change this to including absolute paths relative to the root gen directory |
226 # (like "mycomponent/foo.h"). This config sets up the include path. | 252 # (like "mycomponent/foo.h"). This config sets up the include path. |
227 grit_config = target_name + "_grit_config" | 253 grit_config = target_name + "_grit_config" |
228 config(grit_config) { | 254 config(grit_config) { |
229 include_dirs = [ output_dir ] | 255 include_dirs = [ output_dir ] |
230 visibility = target_visibility | 256 visibility = target_visibility |
231 } | 257 } |
232 | 258 |
233 grit_custom_target = target_name + "_grit" | 259 grit_custom_target = target_name + "_grit" |
234 action(grit_custom_target) { | 260 action(grit_custom_target) { |
235 script = "//tools/grit/grit.py" | 261 script = "//tools/grit/grit.py" |
236 inputs = grit_inputs | 262 inputs = grit_inputs |
237 outputs = grit_outputs | 263 outputs = grit_outputs |
| 264 depfile = "$target_out_dir/${target_name}.d" |
238 | 265 |
239 args = [ | 266 args = [ |
240 "-i", source_path, "build", | 267 "-i", source_path, "build", |
241 "-f", resource_ids, | 268 "-f", resource_ids, |
242 "-o", rebased_output_dir, | 269 "-o", rebased_output_dir, |
243 ] + grit_defines + grit_flags | 270 "--depdir", ".", |
| 271 "--depfile", rebase_path(depfile, root_build_dir), |
| 272 ] + grit_defines + grit_flags + assert_files_flags |
244 | 273 |
245 visibility = target_visibility | 274 visibility = target_visibility |
246 | 275 |
| 276 deps = [ "//tools/grit:grit_sources" ] |
247 if (defined(invoker.deps)) { | 277 if (defined(invoker.deps)) { |
248 deps = invoker.deps | 278 deps += invoker.deps |
249 } | 279 } |
250 } | 280 } |
251 | 281 |
252 # This is the thing that people actually link with, it must be named the | 282 # This is the thing that people actually link with, it must be named the |
253 # same as the argument the template was invoked with. | 283 # same as the argument the template was invoked with. |
254 source_set(target_name) { | 284 source_set(target_name) { |
255 # Since we generate a file, we need to be run before the targets that | 285 # Since we generate a file, we need to be run before the targets that |
256 # depend on us. | 286 # depend on us. |
257 sources = grit_outputs | 287 sources = grit_outputs |
258 | 288 |
259 # Deps set on the template invocation will go on the grit script running | 289 # Deps set on the template invocation will go on the grit script running |
260 # target rather than this library. | 290 # target rather than this library. |
261 deps = [ ":$grit_custom_target" ] | 291 deps = [ ":$grit_custom_target" ] |
262 direct_dependent_configs = [ ":$grit_config" ] | 292 direct_dependent_configs = [ ":$grit_config" ] |
263 | 293 |
264 if (defined(invoker.visibility)) { | 294 if (defined(invoker.visibility)) { |
265 visibility = invoker.visibility | 295 visibility = invoker.visibility |
266 } | 296 } |
267 if (defined(invoker.output_name)) { | 297 if (defined(invoker.output_name)) { |
268 output_name = invoker.output_name | 298 output_name = invoker.output_name |
269 } | 299 } |
270 } | 300 } |
271 } | 301 } |
OLD | NEW |