| Index: tools/grit/grit_rule.gni
|
| diff --git a/tools/grit/grit_rule.gni b/tools/grit/grit_rule.gni
|
| index 2f9e2129671f1021a8c11d26f8d6e049556bf0b5..1452be8f47ef30712540fdb217e6be38126c9020 100644
|
| --- a/tools/grit/grit_rule.gni
|
| +++ b/tools/grit/grit_rule.gni
|
| @@ -10,6 +10,16 @@
|
| # source (required)
|
| # Path to .grd file.
|
| #
|
| +# source_is_generated (optional, defaults to false)
|
| +# Declares that the input is generated so that grit_info is not run
|
| +# on the file when compute_grit_inputs_for_analyze is set (because the
|
| +# file will not exist at analyze time). For "analyze" to be correct in
|
| +# this case, the inputs to the grit file must either be listed in the
|
| +# inputs variable or are listed as inputs to dependencies of this target.
|
| +#
|
| +# inputs (optional)
|
| +# List of additional files, required for grit to process source file.
|
| +#
|
| # outputs (required)
|
| # List of outputs from grit, relative to the target_gen_dir. Grit will
|
| # verify at build time that this list is correct and will fail if there
|
| @@ -59,8 +69,6 @@
|
| # configs (optional)
|
| # List of additional configs to be applied to the generated target.
|
| # deps (optional)
|
| -# inputs (optional)
|
| -# List of additional files, required for grit to process source file.
|
| # visibility (optional)
|
| # Normal meaning.
|
| #
|
| @@ -88,6 +96,18 @@ import("//third_party/closure_compiler/closure_args.gni")
|
| assert(!enable_resource_whitelist_generation || is_android,
|
| "resource whitelist generation only works on android")
|
|
|
| +declare_args() {
|
| + # When set, this will fork out to grit at GN-time to get all inputs
|
| + # referenced by the .grd file.
|
| + #
|
| + # Normal builds don't need this since proper incremental builds are handled
|
| + # by grit writing out the inputs in .d files at build-time. But for analyze
|
| + # to work on the bots, it needs to know about all input files at GN-time so
|
| + # it knows which tests to trigger when something changes. This option will
|
| + # slow down the GN run.
|
| + compute_grit_inputs_for_analyze = false
|
| +}
|
| +
|
| grit_defines = []
|
|
|
| # Mac and iOS want Title Case strings.
|
| @@ -312,18 +332,11 @@ template("grit") {
|
| assert(defined(invoker.source),
|
| "\"source\" must be defined for the grit template $target_name")
|
|
|
| - grit_inputs = [ invoker.source ]
|
| -
|
| if (defined(invoker.resource_ids)) {
|
| resource_ids = invoker.resource_ids
|
| } else {
|
| resource_ids = grit_resource_id_file
|
| }
|
| - if (resource_ids != "") {
|
| - # The script depends on the ID file. Only add this dependency if the ID
|
| - # file is specified.
|
| - grit_inputs += [ resource_ids ]
|
| - }
|
|
|
| if (defined(invoker.output_dir)) {
|
| output_dir = invoker.output_dir
|
| @@ -345,12 +358,10 @@ template("grit") {
|
|
|
| # 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)
|
|
|
| + # Compute flags.
|
| grit_flags = []
|
| if (enable_resource_whitelist_generation) {
|
| grit_flags += [ "-h" ]
|
| @@ -363,6 +374,18 @@ template("grit") {
|
| if (defined(invoker.grit_flags)) {
|
| grit_flags += invoker.grit_flags
|
| }
|
| + if (resource_ids != "") {
|
| + grit_flags += [
|
| + "-f",
|
| + rebase_path(resource_ids, root_build_dir),
|
| + ]
|
| + }
|
| +
|
| + if (defined(invoker.source_is_generated)) {
|
| + source_is_generated = invoker.source_is_generated
|
| + } else {
|
| + source_is_generated = false
|
| + }
|
|
|
| assert_files_flags = []
|
|
|
| @@ -407,44 +430,45 @@ template("grit") {
|
| grit_custom_target = target_name + "_grit"
|
| action(grit_custom_target) {
|
| script = "//tools/grit/grit.py"
|
| - inputs = grit_inputs
|
| +
|
| + inputs = [
|
| + invoker.source,
|
| + ]
|
| + if (resource_ids != "") {
|
| + # The script depends on the ID file. Only add this dependency if the ID
|
| + # file is specified.
|
| + inputs += [ resource_ids ]
|
| + }
|
|
|
| depfile = "$depfile_dir/${grit_output_name}_stamp.d"
|
| outputs = [ "${depfile}.stamp" ] + grit_outputs
|
|
|
| args = [
|
| - "-i",
|
| - source_path,
|
| - "build",
|
| - ]
|
| - if (resource_ids != "") {
|
| - args += [
|
| - "-f",
|
| - resource_ids,
|
| - ]
|
| - }
|
| - args += [
|
| - "-o",
|
| - rebased_output_dir,
|
| - "--depdir",
|
| - ".",
|
| - "--depfile",
|
| - rebase_path(depfile, root_build_dir),
|
| - "--write-only-new=1",
|
| - "--depend-on-stamp",
|
| - ] + grit_defines
|
| + "-i",
|
| + source_path,
|
| + "build",
|
| + "-o",
|
| + rebased_output_dir,
|
| + "--depdir",
|
| + ".",
|
| + "--depfile",
|
| + rebase_path(depfile, root_build_dir),
|
| + "--write-only-new=1",
|
| + "--depend-on-stamp",
|
| + ] + grit_defines
|
|
|
| # Add extra defines with -D flags.
|
| + define_args = []
|
| if (defined(invoker.defines)) {
|
| foreach(i, invoker.defines) {
|
| - args += [
|
| + define_args += [
|
| "-D",
|
| i,
|
| ]
|
| }
|
| }
|
|
|
| - args += grit_flags + assert_files_flags
|
| + args += define_args + grit_flags + assert_files_flags
|
|
|
| if (_strip_resource_files) {
|
| js_minifier_command = rebase_path(_js_minifier)
|
| @@ -461,6 +485,27 @@ template("grit") {
|
| inputs += [ _js_minifier ]
|
| }
|
|
|
| + # Must be after the args are computed since they are re-used.
|
| + # See the comments for the two variables used in this condition for
|
| + # why this works this way.
|
| + if (compute_grit_inputs_for_analyze && !source_is_generated) {
|
| + grit_info_script = "//tools/grit/grit_info.py"
|
| + grit_info_args = [
|
| + "--inputs",
|
| + source_path,
|
| + ] + grit_flags + grit_defines
|
| +
|
| + # Only call exec_script when the user has explicitly opted into greater
|
| + # precision at the expense of performance.
|
| + rel_inputs = exec_script(grit_info_script,
|
| + grit_info_args,
|
| + "list lines",
|
| + [ grit_info_script ])
|
| + inputs += rebase_path(rel_inputs, ".", root_build_dir)
|
| + } else {
|
| + assert(source_is_generated || !source_is_generated) # Prevent error.
|
| + }
|
| +
|
| if (defined(invoker.visibility)) {
|
| # This needs to include both what the invoker specified (since they
|
| # probably include generated headers from this target), as well as the
|
|
|