Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(900)

Unified Diff: tools/grit/grit_rule.gni

Issue 2094193004: Strip comments and whitespace from Javascript resources (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Also strip Javascript browser resources Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« tools/grit/grit/tool/build.py ('K') | « tools/grit/grit/util.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/grit/grit_rule.gni
diff --git a/tools/grit/grit_rule.gni b/tools/grit/grit_rule.gni
index 107a4bc9a0d1193546370bc9ca8d4ece78b594e0..047772f9bd34b93748ac0e165289da4cc08a2a2c 100644
--- a/tools/grit/grit_rule.gni
+++ b/tools/grit/grit_rule.gni
@@ -82,6 +82,7 @@ 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")
declare_args() {
# Enables used resource whitelist generation.
@@ -89,6 +90,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 +105,8 @@ if (is_chrome_branded) {
grit_defines += [
"-D",
"_google_chrome",
+ ]
+ grit_environment += [
"-E",
"CHROMIUM_BUILD=google_chrome",
]
@@ -110,6 +114,8 @@ if (is_chrome_branded) {
grit_defines += [
"-D",
"_chromium",
+ ]
+ grit_environment += [
"-E",
"CHROMIUM_BUILD=chromium",
]
@@ -174,7 +180,7 @@ if (enable_image_loader_extension) {
}
if (is_android) {
- grit_defines += [
+ grit_environment += [
"-E",
"ANDROID_JAVA_TAGGED_ONLY=true",
]
@@ -433,7 +439,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)) {
@@ -445,6 +451,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)) {
@@ -499,3 +510,105 @@ 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
+ outputs = [
+ "{{source_gen_dir}}/{{source_name_part}}.${_target_name}_flattened_js",
+ ]
+ args = grit_defines
+ args += [
+ rebase_path("{{source}}"),
+ rebase_path(
+ "$root_out_dir/{{source_gen_dir}}/{{source_name_part}}.${_target_name}_flattened_js"),
+ ]
+ }
+
+ java_action_foreach(_target_name) {
Dan Beam 2016/06/29 22:20:57 does this run in an optimized way, i.e. https://c
aberent 2016/07/14 15:41:36 Now it does. See compile_js2.gni
+ script = closure_compiler_path
+ sources = get_target_outputs(":${_target_name}_flatten")
+ outputs = [
+ "{{source_gen_dir}}/{{source_name_part}}_${_target_name}.js",
+ ]
+
+ args = [
+ "--compilation_level",
+ "WHITESPACE_ONLY",
+ "--js_output_file",
+ rebase_path(
+ "$root_out_dir/{{source_gen_dir}}/{{source_name_part}}_${_target_name}.js"),
Dan Beam 2016/06/29 22:20:57 what about source maps? third_party/closure_compi
aberent 2016/07/14 15:41:36 Done.
+ "--js",
+ "{{source}}",
+ "--language_out=ES5",
Dan Beam 2016/06/29 22:20:57 don't you want a --language_in as well?
aberent 2016/07/14 15:41:36 Done. See compile_js2.gni
+ ]
+ deps = [
+ ":${_target_name}_flatten",
+ ]
+ }
+}
+
+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, "name")
+
+ # Generating the actual paths is messy, because, to avoid name clashes both the
+ # 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, "//")
+ actual = "${root_gen_dir}/${gen_dir_rebased}/${name}_${_target_name}_stripped.js"
+ 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
+ }
+ }
+}
« tools/grit/grit/tool/build.py ('K') | « tools/grit/grit/util.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698