| 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 # grit_flags (optional) | 13 # grit_flags (optional) |
| 14 # List of strings containing extra command-line flags to pass to Grit. | 14 # List of strings containing extra command-line flags to pass to Grit. |
| 15 # | 15 # |
| 16 # resource_ids (optional) |
| 17 # Path to a grit "firstidsfile". Default is |
| 18 # //tools/gritsettings/resource_ids. Set to "" to use the value specified in |
| 19 # the <grit> nodes of the processed files. |
| 20 # |
| 21 # output_dir (optional) |
| 22 # Directory for generated files. |
| 23 # |
| 16 # deps (optional) | 24 # deps (optional) |
| 17 # visibility (optional) | 25 # visibility (optional) |
| 18 # Normal meaning. | 26 # Normal meaning. |
| 19 # | 27 # |
| 20 # Example | 28 # Example |
| 21 # | 29 # |
| 22 # grit("my_resources") { | 30 # grit("my_resources") { |
| 23 # source = "myfile.grd" # source is required. | 31 # source = "myfile.grd" # source is required. |
| 24 # grit_flags = [ "-E", "foo=bar" ] # Optional extra flags. | 32 # grit_flags = [ "-E", "foo=bar" ] # Optional extra flags. |
| 25 # # You can also put deps here if the grit source depends on generated | 33 # # You can also put deps here if the grit source depends on generated |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 grit_resource_id_file = "//tools/gritsettings/resource_ids" | 162 grit_resource_id_file = "//tools/gritsettings/resource_ids" |
| 155 grit_info_script = "//tools/grit/grit_info.py" | 163 grit_info_script = "//tools/grit/grit_info.py" |
| 156 | 164 |
| 157 template("grit") { | 165 template("grit") { |
| 158 assert(defined(invoker.source), | 166 assert(defined(invoker.source), |
| 159 "\"source\" must be defined for the grit template $target_name") | 167 "\"source\" must be defined for the grit template $target_name") |
| 160 assert(!defined(invoker.sources) && !defined(invoker.outputs), | 168 assert(!defined(invoker.sources) && !defined(invoker.outputs), |
| 161 "Neither \"sources\" nor \"outputs\" can be defined for the grit " + | 169 "Neither \"sources\" nor \"outputs\" can be defined for the grit " + |
| 162 "template $target_name") | 170 "template $target_name") |
| 163 | 171 |
| 172 if (defined(invoker.resource_ids)) { |
| 173 resource_ids = invoker.resource_ids |
| 174 } else { |
| 175 resource_ids = grit_resource_id_file |
| 176 } |
| 177 |
| 178 if (defined(invoker.output_dir)) { |
| 179 output_dir = invoker.output_dir |
| 180 } else { |
| 181 output_dir = target_gen_dir |
| 182 } |
| 183 |
| 164 # These are all passed as arguments to the script so have to be relative to | 184 # These are all passed as arguments to the script so have to be relative to |
| 165 # the build directory. | 185 # the build directory. |
| 166 resource_ids = | 186 if (resource_ids != "") { |
| 167 rebase_path(grit_resource_id_file, root_build_dir) | 187 resource_ids = rebase_path(resource_ids, root_build_dir) |
| 168 output_dir = rebase_path(target_gen_dir, root_build_dir) | 188 } |
| 189 rebased_output_dir = rebase_path(output_dir, root_build_dir) |
| 169 source_path = rebase_path(invoker.source, root_build_dir) | 190 source_path = rebase_path(invoker.source, root_build_dir) |
| 170 | 191 |
| 171 if (defined(invoker.grit_flags)) { | 192 if (defined(invoker.grit_flags)) { |
| 172 grit_flags = invoker.grit_flags | 193 grit_flags = invoker.grit_flags |
| 173 } else { | 194 } else { |
| 174 grit_flags = [] # These are optional so default to empty list. | 195 grit_flags = [] # These are optional so default to empty list. |
| 175 } | 196 } |
| 176 | 197 |
| 177 grit_inputs_build_rel = exec_script(grit_info_script, | 198 grit_inputs_build_rel = exec_script(grit_info_script, |
| 178 [ "--inputs", source_path, "-f", resource_ids] + grit_flags, "list lines") | 199 [ "--inputs", source_path, "-f", resource_ids] + grit_flags, "list lines") |
| 179 # The inputs are relative to the current (build) directory, rebase to | 200 # The inputs are relative to the current (build) directory, rebase to |
| 180 # the current one. | 201 # the current one. |
| 181 grit_inputs = rebase_path(grit_inputs_build_rel, ".", root_build_dir) + [ | 202 grit_inputs = rebase_path(grit_inputs_build_rel, ".", root_build_dir) + [ |
| 182 grit_resource_id_file, | 203 grit_resource_id_file, |
| 183 ] | 204 ] |
| 184 | 205 |
| 185 grit_outputs_build_rel = exec_script(grit_info_script, | 206 grit_outputs_build_rel = exec_script(grit_info_script, |
| 186 [ "--outputs", "$output_dir", source_path, "-f", resource_ids ] + | 207 [ "--outputs", "$rebased_output_dir", source_path, "-f", resource_ids ] + |
| 187 grit_flags, | 208 grit_flags, |
| 188 "list lines") | 209 "list lines") |
| 189 | 210 |
| 190 # The inputs are relative to the current (build) directory, rebase to | 211 # The inputs are relative to the current (build) directory, rebase to |
| 191 # the current one. | 212 # the current one. |
| 192 grit_outputs = rebase_path(grit_outputs_build_rel, ".", root_build_dir) | 213 grit_outputs = rebase_path(grit_outputs_build_rel, ".", root_build_dir) |
| 193 | 214 |
| 194 # The config and the action below get this visibility son only the generated | 215 # The config and the action below get this visibility son only the generated |
| 195 # source set can depend on them. The variable "target_name" will get | 216 # source set can depend on them. The variable "target_name" will get |
| 196 # overwritten inside the innter classes so we need to compute it here. | 217 # overwritten inside the innter classes so we need to compute it here. |
| 197 target_visibility = ":$target_name" | 218 target_visibility = ":$target_name" |
| 198 | 219 |
| 199 # The current grit setup makes an file in $target_gen_dir/grit/foo.h that | 220 # The current grit setup makes an file in $output_dir/grit/foo.h that |
| 200 # the source code expects to include via "grit/foo.h". It would be nice to | 221 # the source code expects to include via "grit/foo.h". It would be nice to |
| 201 # change this to including absolute paths relative to the root gen directory | 222 # change this to including absolute paths relative to the root gen directory |
| 202 # (like "mycomponent/foo.h"). This config sets up the include path. | 223 # (like "mycomponent/foo.h"). This config sets up the include path. |
| 203 grit_config = target_name + "_grit_config" | 224 grit_config = target_name + "_grit_config" |
| 204 config(grit_config) { | 225 config(grit_config) { |
| 205 include_dirs = [ target_gen_dir ] | 226 include_dirs = [ output_dir ] |
| 206 visibility = target_visibility | 227 visibility = target_visibility |
| 207 } | 228 } |
| 208 | 229 |
| 209 grit_custom_target = target_name + "_grit" | 230 grit_custom_target = target_name + "_grit" |
| 210 action(grit_custom_target) { | 231 action(grit_custom_target) { |
| 211 script = "//tools/grit/grit.py" | 232 script = "//tools/grit/grit.py" |
| 212 inputs = grit_inputs | 233 inputs = grit_inputs |
| 213 outputs = grit_outputs | 234 outputs = grit_outputs |
| 214 | 235 |
| 215 args = [ | 236 args = [ |
| 216 "-i", source_path, "build", | 237 "-i", source_path, "build", |
| 217 "-f", resource_ids, | 238 "-f", resource_ids, |
| 218 "-o", output_dir, | 239 "-o", rebased_output_dir, |
| 219 ] + grit_defines + grit_flags | 240 ] + grit_defines + grit_flags |
| 220 | 241 |
| 221 visibility = target_visibility | 242 visibility = target_visibility |
| 222 | 243 |
| 223 if (defined(invoker.deps)) { | 244 if (defined(invoker.deps)) { |
| 224 deps = invoker.deps | 245 deps = invoker.deps |
| 225 } | 246 } |
| 226 } | 247 } |
| 227 | 248 |
| 228 # This is the thing that people actually link with, it must be named the | 249 # This is the thing that people actually link with, it must be named the |
| 229 # same as the argument the template was invoked with. | 250 # same as the argument the template was invoked with. |
| 230 source_set(target_name) { | 251 source_set(target_name) { |
| 231 # Since we generate a file, we need to be run before the targets that | 252 # Since we generate a file, we need to be run before the targets that |
| 232 # depend on us. | 253 # depend on us. |
| 233 sources = grit_outputs | 254 sources = grit_outputs |
| 234 | 255 |
| 235 # Deps set on the template invocation will go on the grit script running | 256 # Deps set on the template invocation will go on the grit script running |
| 236 # target rather than this library. | 257 # target rather than this library. |
| 237 deps = [ ":$grit_custom_target" ] | 258 deps = [ ":$grit_custom_target" ] |
| 238 direct_dependent_configs = [ ":$grit_config" ] | 259 direct_dependent_configs = [ ":$grit_config" ] |
| 239 | 260 |
| 240 if (defined(invoker.visibility)) { | 261 if (defined(invoker.visibility)) { |
| 241 visibility = invoker.visibility | 262 visibility = invoker.visibility |
| 242 } | 263 } |
| 243 if (defined(invoker.output_name)) { | 264 if (defined(invoker.output_name)) { |
| 244 output_name = invoker.output_name | 265 output_name = invoker.output_name |
| 245 } | 266 } |
| 246 } | 267 } |
| 247 } | 268 } |
| OLD | NEW |