Chromium Code Reviews| 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..e8223a73e9d4dab706cdb0530684d820d36b82d9 |
| --- /dev/null |
| +++ b/third_party/closure_compiler/compile_js.gni |
| @@ -0,0 +1,156 @@ |
| +# 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. Based off of the js_library rule in Blaze. |
| +# Usage is similar but adapted to fit the .gn syntax. |
|
mbjorge
2017/04/07 19:23:18
I don't think the references to the corresponding
damargulis
2017/04/07 23:02:18
Done.
|
| +# |
| +# Variables: |
| +# sources: |
| +# List of Javascript files to include in the library |
| +# |
| +# deps: |
| +# List of js_library targets to depend on |
|
mbjorge
2017/04/07 19:23:18
Do you know what would happen if an non-js_library
damargulis
2017/04/07 23:02:18
Right now, the python script will error out. It w
|
| +# |
| +# Example: |
| +# in Blaze: |
|
mbjorge
2017/04/07 19:23:18
remove Blaze example
damargulis
2017/04/07 23:02:18
Done.
|
| +# js_library( |
| +# name = "apple_tree", |
| +# srcs = ["tree_main.js"], |
| +# deps = [ |
| +# ":branch", |
| +# ":trunk", |
| +# ":root", |
| +# ], |
| +# ) |
| +# |
| +# in .gn |
| +# 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", |
| + ]) |
| + outputs = [ |
|
slan
2017/04/07 23:08:39
super-nit: This needs to be an array, but your pyt
damargulis
2017/04/08 00:19:49
Done.
|
| + "$target_gen_dir/$target_name.txt", |
| + ] |
| + args = [ "--output" ] + rebase_path(outputs, root_build_dir) |
| + if (defined(sources)) { |
| + args += [ "--sources" ] + rebase_path(sources, root_build_dir) |
| + } |
| + if (defined(deps)) { |
| + args += [ "--deps" ] |
| + foreach(dep, deps) { |
| + target_path = get_label_info(dep, "target_gen_dir") + "/" + |
|
mbjorge
2017/04/07 19:23:18
I think if you mirror the format of the outputs ta
damargulis
2017/04/07 23:02:18
Done.
|
| + get_label_info(dep, "name") + ".txt" |
| + args += [ rebase_path(target_path, root_build_dir) ] |
| + } |
| + } |
| + } |
| +} |
| + |
| +# Defines a target that compiles javascript files using the closure compiler |
|
mbjorge
2017/04/07 19:23:18
Would be good to add a sentence that tells someone
damargulis
2017/04/07 23:02:18
Done.
|
| +# Based off of the js_binary rule in Blaze. Usage is similar but adapted |
|
mbjorge
2017/04/07 19:23:17
-Blaze refenenes
damargulis
2017/04/07 23:02:18
Done.
|
| +# to use the .gn syntax. |
| +# |
| +# Variables: |
| +# sources: |
| +# List of .js files to compile |
| +# |
| +# deps: |
| +# List of js_library rules to depend on |
| +# |
| +# 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 |
| +# |
| +# defs: |
| +# 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: |
| +# in Blaze: |
|
mbjorge
2017/04/07 19:23:18
remove blaze example
damargulis
2017/04/07 23:02:18
Done.
|
| +# js_binary( |
| +# name = "tree", |
| +# srcs = ["tree_main.js"], |
| +# compile = 1, |
| +# deps = [":apple_tree"], |
| +# defs = ["--jscomp_error=undefinedVars"], |
| +# ) |
| +# |
| +# in .gn |
| +# js_binary("tree") { |
|
slan
2017/04/07 23:08:39
nit: put bootstrap and config files in the example
damargulis
2017/04/08 00:19:49
Done.
|
| +# sources = ["tree_main.js"] |
| +# deps = [":apple_tree"] |
| +# defs = ["jscomp_error=undefinedVars"] |
| +# } |
| + |
| +template("js_binary") { |
| + assert(defined(invoker.sources) || defined(invoker.deps), |
| + "Need sources or deps in $target_name for js_binary") |
| + |
| + action(target_name) { |
| + script = "$script_path/js_binary.py" |
| + forward_variables_from(invoker, "*") |
| + outputs = [ |
|
mbjorge
2017/04/07 19:23:17
if the generated .js file is actually useful, then
damargulis
2017/04/07 23:02:18
Done.
|
| + "$target_gen_dir/$target_name.js", |
| + ] |
| + 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) |
| + } |
| + if (defined(deps)) { |
| + args += [ "--deps" ] |
| + foreach(dep, deps) { |
| + target_path = get_label_info(dep, "target_gen_dir") + "/" + |
| + get_label_info(dep, "name") + ".txt" |
| + args += [ rebase_path(target_path, root_build_dir) ] |
| + } |
| + } |
| + if (defined(bootstrap_file)) { |
| + args += [ |
| + "--bootstrap", |
| + rebase_path(bootstrap_file, root_build_dir), |
| + ] |
| + } |
| + if (defined(config_files)) { |
| + args += [ "--config" ] + rebase_path(config_files, root_build_dir) |
| + } |
| + args += [ "--defs" ] + common_closure_args |
| + if (defined(defs)) { |
| + args += defs |
| + } |
| + if (defined(externs_list)) { |
| + args += [ "--externs" ] + rebase_path(externs_list, root_build_dir) |
| + } |
| + } |
| +} |