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

Unified Diff: third_party/closure_compiler/compile_js.gni

Issue 2800833004: Create js_library and js_binary templates for closure compiling. (Closed)
Patch Set: update comments Created 3 years, 8 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
« no previous file with comments | « third_party/closure_compiler/compile2.py ('k') | third_party/closure_compiler/js_binary.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/closure_compiler/compile_js.gni
diff --git a/third_party/closure_compiler/compile_js.gni b/third_party/closure_compiler/compile_js.gni
new file mode 100644
index 0000000000000000000000000000000000000000..958ac1bc9b7c897d2d3af141bd79b371203cb2f2
--- /dev/null
+++ b/third_party/closure_compiler/compile_js.gni
@@ -0,0 +1,165 @@
+# Copyright 2017 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("//third_party/closure_compiler/closure_args.gni")
+
+script_path = "//third_party/closure_compiler"
+compiler_path = "$script_path/compiler/compiler.jar"
+
+# Defines a target that creates an ordering for .js files to be used by
+# js_binary to compile.
+#
+# Variables:
+# sources:
+# List of Javascript files to include in the library
+#
+# deps:
+# List of js_library targets to depend on
+#
+# Example:
+# js_library("apple_tree") {
+# sources = ["tree_main.js"]
+# deps = [
+# ":branch",
+# ":trunk",
+# ":root",
+# ]
+# }
+
+template("js_library") {
+ assert(defined(invoker.sources) || defined(invoker.deps),
+ "Need sources or deps in $target_name for js_library")
+ action(target_name) {
+ script = "$script_path/js_library.py"
+ forward_variables_from(invoker,
+ [
+ "sources",
+ "deps",
+ ])
+ output_file = "$target_gen_dir/$target_name.js_library"
+ outputs = [
+ output_file,
+ ]
+ args = [ "--output" ] + [ rebase_path(output_file, root_build_dir) ]
+ if (defined(sources)) {
+ args += [ "--sources" ] + rebase_path(sources, root_build_dir)
+ }
+ if (defined(deps)) {
+ args += [ "--deps" ]
+ foreach(dep, deps) {
+ # Get the output path for each dep
+ dep_gen_dir = get_label_info(dep, "target_gen_dir")
+ dep_name = get_label_info(dep, "name")
+ dep_output_path = "$dep_gen_dir/$dep_name.js_library"
+ args += [ rebase_path(dep_output_path, root_build_dir) ]
+ }
+ }
+ }
+}
+
+# Defines a target that compiles javascript files using the Closure compiler.
+# This will produce a minified javascript output file. Additional checks and
+# optimizations can be configured using the closure_flags attribute.
+#
+# Variables:
+# sources:
+# List of .js files to compile
+#
+# deps:
+# List of js_library rules to depend on
+#
+# outputs:
+# A file to write the compiled .js to.
+# Only takes in a single file, but must be placed in a list
+#
+# bootstrap_file:
+# A .js files to include before all others
+#
+# config_files:
+# A list of .js files to include after the bootstrap_file but before all
+# others
+#
+# closure_flags:
+# A list of custom flags to pass to the Closure compiler. Do not include
+# the leading dashes
+#
+# externs_list:
+# A list of .js files to pass to the compiler as externs
+#
+# Example:
+# js_binary("tree") {
+# sources = ["tree_main.js"]
+# deps = [":apple_tree"]
+# outputs = [ "$target_gen_dir/tree.js" ]
+# bootstrap_file = "bootstrap.js"
+# config_files = [
+# "config1.js",
+# "config2.js",
+# ]
+# closure_flags = ["jscomp_error=undefinedVars"]
+# externs_list = [ "externs.js" ]
+# }
+
+template("js_binary") {
+ assert(defined(invoker.sources) || defined(invoker.deps),
+ "Need sources or deps in $target_name for js_binary")
+ assert(defined(invoker.outputs), "Need outputs in $target_name for js_binary")
+
+ action(target_name) {
+ script = "$script_path/js_binary.py"
+ forward_variables_from(invoker,
+ [
+ "sources",
+ "deps",
+ "outputs",
+ "bootstrap_file",
+ "config_files",
+ "closure_flags",
+ "externs_list",
+ ])
+ args = [
+ "--compiler",
+ rebase_path(compiler_path, root_build_dir),
+ ]
+ args += [ "--output" ] + rebase_path(outputs, root_build_dir)
+ if (defined(sources)) {
+ args += [ "--sources" ] + rebase_path(sources, root_build_dir)
+ } else {
+ sources = []
+ }
+ if (defined(deps)) {
+ args += [ "--deps" ]
+ foreach(dep, deps) {
+ # Get the output path for each dep
+ dep_gen_dir = get_label_info(dep, "target_gen_dir")
+ dep_name = get_label_info(dep, "name")
+ dep_output_path = "$dep_gen_dir/$dep_name.js_library"
+ args += [ rebase_path(dep_output_path, root_build_dir) ]
+ }
+ }
+ if (defined(bootstrap_file)) {
+ args += [
+ "--bootstrap",
+ rebase_path(bootstrap_file, root_build_dir),
+ ]
+ sources += [ bootstrap_file ]
+ }
+ if (defined(config_files)) {
+ args += [ "--config" ] + rebase_path(config_files, root_build_dir)
+ sources += config_files
+ }
+
+ # |minifying_closure_args| from
+ # //third_party/closure_compiler/closure_args.gni
+ args += [ "--flags" ] + minifying_closure_args
+ if (defined(closure_flags)) {
+ args += closure_flags
+ }
+ if (defined(externs_list)) {
+ args += [ "--externs" ]
+ args += rebase_path(externs_list, root_build_dir)
+ sources += externs_list
+ }
+ }
+}
« no previous file with comments | « third_party/closure_compiler/compile2.py ('k') | third_party/closure_compiler/js_binary.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698