Index: build/secondary/tools/grit/grit_rule.gni |
diff --git a/build/secondary/tools/grit/grit_rule.gni b/build/secondary/tools/grit/grit_rule.gni |
index 86a155a7fb12e00bc2a473952dbf431b63f1e4ed..ef3e3d454bf16e43eff00256bc95ebc8b832f964 100644 |
--- a/build/secondary/tools/grit/grit_rule.gni |
+++ b/build/secondary/tools/grit/grit_rule.gni |
@@ -10,6 +10,23 @@ |
# source |
# Path to .grd file. |
# |
+# outputs (optional) |
+# List of outputs from grit, relative to the target_gen_dir. If supplied, |
+# a call to Grit to compute the outputs can be skipped which will make |
+# GN run faster. Grit will verify at build time that this list is correct |
+# and will fail if there is a mismatch between the outputs specified by |
+# the .grd file and the outputs list here. |
+# |
+# To get this list, you can look in the .grd file for |
+# <output filename="..." and put those filename here. The base directory |
+# of the list in Grit and the output list specified in the GN grit target |
+# are the same (the target_gen_dir) so you can generally copy the names |
+# exactly. |
+# |
+# To get the list of outputs programatically, run: |
+# python tools/grit/grit_info.py --outputs . path/to/your.grd |
+# And strip the leading "./" from the output files. |
+# |
# grit_flags (optional) |
# List of strings containing extra command-line flags to pass to Grit. |
# |
@@ -165,9 +182,6 @@ 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 |
@@ -195,25 +209,37 @@ template("grit") { |
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") |
+ grit_inputs = [ invoker.source ] |
+ |
+ assert_files_flags = [] |
+ if (defined(invoker.outputs)) { |
+ # If the declaration specified outputs, we want to make sure that they |
+ # actually match what Grit is writing. We write the list to a file (some |
+ # of the output lists are long enough to not fit on a Windows command line) |
+ # and ask Grit to verify those are the actual outputs at runtime. |
+ asserted_list_file = "$target_out_dir/${target_name}_expected_outputs.txt" |
+ write_file(asserted_list_file, |
+ rebase_path(invoker.outputs, root_build_dir, target_gen_dir)) |
+ assert_files_flags += [ |
+ "--assert-file-list=" + rebase_path(asserted_list_file, root_build_dir), |
+ ] |
+ grit_outputs = get_path_info( |
+ rebase_path(invoker.outputs, ".", target_gen_dir), |
+ "abspath") |
+ } else { |
+ # Ask Grit for the output list. |
+ 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 |
@@ -235,17 +261,21 @@ template("grit") { |
script = "//tools/grit/grit.py" |
inputs = grit_inputs |
outputs = grit_outputs |
+ depfile = "$target_out_dir/${target_name}.d" |
args = [ |
"-i", source_path, "build", |
"-f", resource_ids, |
"-o", rebased_output_dir, |
- ] + grit_defines + grit_flags |
+ "--depdir", ".", |
+ "--depfile", rebase_path(depfile, root_build_dir), |
+ ] + grit_defines + grit_flags + assert_files_flags |
visibility = target_visibility |
+ deps = [ "//tools/grit:grit_sources" ] |
if (defined(invoker.deps)) { |
- deps = invoker.deps |
+ deps += invoker.deps |
} |
} |