Chromium Code Reviews| Index: tools/grit/grit_rule.gni |
| diff --git a/tools/grit/grit_rule.gni b/tools/grit/grit_rule.gni |
| index b77a24d5e6fb3f2f429bb47c8f71fcea2941774e..1749c088a7bc4b25403ae6206fef5fe486670a82 100644 |
| --- a/tools/grit/grit_rule.gni |
| +++ b/tools/grit/grit_rule.gni |
| @@ -82,6 +82,8 @@ import("//build/config/chrome_build.gni") |
| import("//build/config/crypto.gni") |
| import("//build/config/features.gni") |
| import("//build/config/ui.gni") |
| +import("//build/util/java_action.gni") |
| +import("//third_party/closure_compiler/compile_js2.gni") |
| declare_args() { |
| # Enables used resource whitelist generation. |
| @@ -89,6 +91,7 @@ declare_args() { |
| } |
| grit_defines = [] |
| +grit_environment = [] |
| # Mac and iOS want Title Case strings. |
| use_titlecase_in_grd_files = is_mac || is_ios |
| @@ -103,6 +106,8 @@ if (is_chrome_branded) { |
| grit_defines += [ |
| "-D", |
| "_google_chrome", |
| + ] |
| + grit_environment += [ |
| "-E", |
| "CHROMIUM_BUILD=google_chrome", |
| ] |
| @@ -110,6 +115,8 @@ if (is_chrome_branded) { |
| grit_defines += [ |
| "-D", |
| "_chromium", |
| + ] |
| + grit_environment += [ |
| "-E", |
| "CHROMIUM_BUILD=chromium", |
| ] |
| @@ -174,7 +181,7 @@ if (enable_image_loader_extension) { |
| } |
| if (is_android) { |
| - grit_defines += [ |
| + grit_environment += [ |
| "-E", |
| "ANDROID_JAVA_TAGGED_ONLY=true", |
| ] |
| @@ -427,7 +434,7 @@ template("grit") { |
| rebase_path(depfile, root_build_dir), |
| "--write-only-new=1", |
| "--depend-on-stamp", |
| - ] + grit_defines |
| + ] + grit_defines + grit_environment |
| # Add extra defines with -D flags. |
| if (defined(invoker.defines)) { |
| @@ -439,6 +446,11 @@ template("grit") { |
| } |
| } |
| + if (defined(invoker.moved_file_list)) { |
| + response_file_contents = invoker.moved_file_list |
| + args += [ "--moved-input-file-list={{response_file_name}}" ] |
| + } |
| + |
| args += grit_flags + assert_files_flags |
| if (defined(invoker.visibility)) { |
| @@ -493,3 +505,92 @@ template("grit") { |
| output_name = grit_output_name |
| } |
| } |
| + |
| +flatten_resource_path = "//tools/grit/flatten_resource.py" |
| +closure_compiler_path = "//third_party/closure_compiler/compiler/compiler.jar" |
| + |
| +template("strip_js") { |
| + assert(defined(invoker.sources), |
| + "Need sources in $target_name listing the js files.") |
| + |
| + _target_name = target_name |
| + |
| + action_foreach("${_target_name}_flatten") { |
| + script = flatten_resource_path |
| + sources = invoker.sources |
| + output = "{{source_gen_dir}}/flattened_${target_name}/{{source_file_part}}" |
| + outputs = [ |
| + output, |
| + ] |
| + args = grit_defines |
| + args += [ |
| + rebase_path("{{source}}"), |
| + rebase_path("$root_out_dir/$output"), |
| + ] |
| + } |
| + |
| + compile_js2_foreach(_target_name) { |
| + sources = get_target_outputs(":${_target_name}_flatten") |
| + deps = [ |
| + ":${_target_name}_flatten", |
| + ] |
| + strip_whitespace = true |
| + } |
| +} |
| + |
| +template("strip_and_grit") { |
| + _target_name = target_name |
| + |
| + if (strip_resource_files) { |
| + strip_js("${_target_name}_stripped") { |
| + sources = invoker.js_resource_files |
| + } |
| + grit(_target_name) { |
| + forward_variables_from(invoker, |
| + [ |
| + "source", |
| + "outputs", |
| + "outputs_dir", |
| + "defines", |
| + "grit_flags", |
| + "output_dir", |
| + ]) |
| + moved_file_list = [] |
| + |
| + foreach(js_resource_file, invoker.js_resource_files) { |
| + name = get_path_info(js_resource_file, "file") |
| + |
| + # Generating the actual paths is messy, because, to avoid name clashes both the |
|
Dan Beam
2016/07/14 17:47:59
80 col wrap
|
| + # actions in strip_js use {{source_gen_dir}}, hence adding $root_gen_dir to |
| + # the front of the path twice. |
| + gen_dir = get_path_info(js_resource_file, "gen_dir") |
| + gen_dir_rebased = rebase_path(gen_dir, "//") |
| + stripped_target_name = "${_target_name}_stripped" |
| + actual = "${root_gen_dir}/${gen_dir_rebased}/flattened_${stripped_target_name}_flatten/closure_${stripped_target_name}/${name}" |
| + abs_orig = rebase_path(js_resource_file) |
| + abs_actual = rebase_path(actual) |
| + moved_file_list += [ "$abs_orig:$abs_actual" ] |
| + } |
| + |
| + deps = invoker.deps |
| + deps += [ ":${_target_name}_stripped" ] |
| + } |
| + } else { |
| + # If we can't run the closure compiler simply run grit. |
| + grit(_target_name) { |
| + forward_variables_from(invoker, |
| + [ |
| + "source", |
| + "outputs", |
| + "outputs_dir", |
| + "defines", |
| + "grit_flags", |
| + "output_dir", |
| + ]) |
| + |
| + inputs = invoker.js_resource_files |
| + |
| + deps = invoker.deps |
| + } |
| + } |
| +} |