| 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 (required) |
| 11 # Path to .grd file. | 11 # Path to .grd file. |
| 12 # | 12 # |
| 13 # outputs (optional) | 13 # outputs (required) |
| 14 # List of outputs from grit, relative to the target_gen_dir. If supplied, | 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 | 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 | 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 | 17 # and will fail if there is a mismatch between the outputs specified by |
| 18 # the .grd file and the outputs list here. | 18 # the .grd file and the outputs list here. |
| 19 # | 19 # |
| 20 # To get this list, you can look in the .grd file for | 20 # To get this list, you can look in the .grd file for |
| 21 # <output filename="..." and put those filename here. The base directory | 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 | 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 | 23 # are the same (the target_gen_dir) so you can generally copy the names |
| (...skipping 14 matching lines...) Expand all Loading... |
| 38 # output_dir (optional) | 38 # output_dir (optional) |
| 39 # Directory for generated files. | 39 # Directory for generated files. |
| 40 # | 40 # |
| 41 # deps (optional) | 41 # deps (optional) |
| 42 # visibility (optional) | 42 # visibility (optional) |
| 43 # Normal meaning. | 43 # Normal meaning. |
| 44 # | 44 # |
| 45 # Example | 45 # Example |
| 46 # | 46 # |
| 47 # grit("my_resources") { | 47 # grit("my_resources") { |
| 48 # source = "myfile.grd" # source is required. | 48 # # Source and outputs are required. |
| 49 # source = "myfile.grd" |
| 50 # outputs = [ |
| 51 # "foo_strings.h", |
| 52 # "foo_strings.pak", |
| 53 # ] |
| 54 # |
| 49 # grit_flags = [ "-E", "foo=bar" ] # Optional extra flags. | 55 # grit_flags = [ "-E", "foo=bar" ] # Optional extra flags. |
| 50 # # You can also put deps here if the grit source depends on generated | 56 # # You can also put deps here if the grit source depends on generated |
| 51 # # files. | 57 # # files. |
| 52 # } | 58 # } |
| 53 import ("//build/config/crypto.gni") | 59 import ("//build/config/crypto.gni") |
| 54 import ("//build/config/features.gni") | 60 import ("//build/config/features.gni") |
| 55 import ("//build/config/ui.gni") | 61 import ("//build/config/ui.gni") |
| 56 | 62 |
| 57 grit_defines = [] | 63 grit_defines = [] |
| 58 | 64 |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 | 211 |
| 206 if (defined(invoker.grit_flags)) { | 212 if (defined(invoker.grit_flags)) { |
| 207 grit_flags = invoker.grit_flags | 213 grit_flags = invoker.grit_flags |
| 208 } else { | 214 } else { |
| 209 grit_flags = [] # These are optional so default to empty list. | 215 grit_flags = [] # These are optional so default to empty list. |
| 210 } | 216 } |
| 211 | 217 |
| 212 grit_inputs = [ invoker.source ] | 218 grit_inputs = [ invoker.source ] |
| 213 | 219 |
| 214 assert_files_flags = [] | 220 assert_files_flags = [] |
| 215 if (defined(invoker.outputs)) { | |
| 216 # If the declaration specified outputs, we want to make sure that they | |
| 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") | |
| 235 | 221 |
| 236 # The names returned by grit are relative to the current (build) directory, | 222 # We want to make sure the declared outputs actually match what Grit is |
| 237 # but references to files in this template are expected to be relative to | 223 # writing. We write the list to a file (some of the output lists are long |
| 238 # the invoking BUILD.gn file's directory. Make it absolute so there's no | 224 # enough to not fit on a Windows command line) and ask Grit to verify those |
| 239 # ambiguity. | 225 # are the actual outputs at runtime. |
| 240 grit_outputs = get_path_info( | 226 asserted_list_file = "$target_out_dir/${target_name}_expected_outputs.txt" |
| 241 rebase_path(grit_outputs_build_rel, ".", root_build_dir), "abspath") | 227 write_file(asserted_list_file, |
| 242 } | 228 rebase_path(invoker.outputs, root_build_dir, target_gen_dir)) |
| 229 assert_files_flags += [ |
| 230 "--assert-file-list=" + rebase_path(asserted_list_file, root_build_dir), |
| 231 ] |
| 232 grit_outputs = get_path_info( |
| 233 rebase_path(invoker.outputs, ".", target_gen_dir), |
| 234 "abspath") |
| 243 | 235 |
| 244 # The config and the action below get this visibility son only the generated | 236 # The config and the action below get this visibility son only the generated |
| 245 # source set can depend on them. The variable "target_name" will get | 237 # source set can depend on them. The variable "target_name" will get |
| 246 # overwritten inside the innter classes so we need to compute it here. | 238 # overwritten inside the innter classes so we need to compute it here. |
| 247 target_visibility = ":$target_name" | 239 target_visibility = ":$target_name" |
| 248 | 240 |
| 249 # The current grit setup makes an file in $output_dir/grit/foo.h that | 241 # The current grit setup makes an file in $output_dir/grit/foo.h that |
| 250 # the source code expects to include via "grit/foo.h". It would be nice to | 242 # the source code expects to include via "grit/foo.h". It would be nice to |
| 251 # change this to including absolute paths relative to the root gen directory | 243 # change this to including absolute paths relative to the root gen directory |
| 252 # (like "mycomponent/foo.h"). This config sets up the include path. | 244 # (like "mycomponent/foo.h"). This config sets up the include path. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 direct_dependent_configs = [ ":$grit_config" ] | 284 direct_dependent_configs = [ ":$grit_config" ] |
| 293 | 285 |
| 294 if (defined(invoker.visibility)) { | 286 if (defined(invoker.visibility)) { |
| 295 visibility = invoker.visibility | 287 visibility = invoker.visibility |
| 296 } | 288 } |
| 297 if (defined(invoker.output_name)) { | 289 if (defined(invoker.output_name)) { |
| 298 output_name = invoker.output_name | 290 output_name = invoker.output_name |
| 299 } | 291 } |
| 300 } | 292 } |
| 301 } | 293 } |
| OLD | NEW |