Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 import("//third_party/closure_compiler/closure_args.gni") | |
| 6 | |
| 7 script_path = "//third_party/closure_compiler" | |
| 8 compiler_path = "$script_path/compiler/compiler.jar" | |
| 9 | |
| 10 # Defines a target that creates an ordering for .js files to be used by | |
| 11 # js_binary to compile. | |
| 12 # | |
| 13 # Variables: | |
| 14 # sources: | |
| 15 # List of Javascript files to include in the library | |
| 16 # | |
| 17 # deps: | |
| 18 # List of js_library targets to depend on | |
| 19 # | |
| 20 # Example: | |
| 21 # js_library("apple_tree") { | |
| 22 # sources = ["tree_main.js"] | |
| 23 # deps = [ | |
| 24 # ":branch", | |
| 25 # ":trunk", | |
| 26 # ":root", | |
| 27 # ] | |
| 28 # } | |
| 29 | |
| 30 template("js_library") { | |
| 31 assert(defined(invoker.sources) || defined(invoker.deps), | |
| 32 "Need sources or deps in $target_name for js_library") | |
| 33 action(target_name) { | |
| 34 script = "$script_path/js_library.py" | |
| 35 forward_variables_from(invoker, | |
| 36 [ | |
| 37 "sources", | |
| 38 "deps", | |
| 39 ]) | |
| 40 output_file = "$target_gen_dir/$target_name.js_library" | |
| 41 outputs = [ | |
| 42 output_file, | |
| 43 ] | |
| 44 args = [ "--output" ] + [ rebase_path(output_file, root_build_dir) ] | |
| 45 if (defined(sources)) { | |
| 46 args += [ "--sources" ] + rebase_path(sources, root_build_dir) | |
| 47 } | |
| 48 if (defined(deps)) { | |
| 49 args += [ "--deps" ] | |
| 50 foreach(dep, deps) { | |
| 51 # Get the output path for each dep | |
| 52 dep_gen_dir = get_label_info(dep, "target_gen_dir") | |
| 53 dep_name = get_label_info(dep, "name") | |
| 54 dep_output_path = "$dep_gen_dir/$dep_name.js_library" | |
| 55 args += [ rebase_path(dep_output_path, root_build_dir) ] | |
| 56 } | |
| 57 } | |
| 58 } | |
| 59 } | |
| 60 | |
| 61 # Defines a target that compiles javascript files using the Closure compiler. | |
| 62 # This will produce a minified and optimized javascript output file, and will | |
| 63 # perform error, syntax, and type checking. Additional checks and options | |
| 64 # can be configured using the closure_flags attribute. | |
| 65 # | |
| 66 # Variables: | |
| 67 # sources: | |
| 68 # List of .js files to compile | |
| 69 # | |
| 70 # deps: | |
| 71 # List of js_library rules to depend on | |
| 72 # | |
| 73 # outputs: | |
| 74 # A file to write the compiled .js to. | |
| 75 # Only takes in a single file, but must be placed in a list | |
| 76 # | |
| 77 # bootstrap_file: | |
| 78 # A .js files to include before all others | |
| 79 # | |
| 80 # config_files: | |
| 81 # A list of .js files to include after the bootstrap_file but before all | |
| 82 # others | |
| 83 # | |
| 84 # closure_flags: | |
| 85 # A list of custom flags to pass to the Closure compiler. Do not include | |
| 86 # the leading dashes | |
| 87 # | |
| 88 # externs_list: | |
| 89 # A list of .js files to pass to the compiler as externs | |
| 90 # | |
| 91 # Example: | |
| 92 # js_binary("tree") { | |
| 93 # sources = ["tree_main.js"] | |
| 94 # deps = [":apple_tree"] | |
| 95 # outputs = [ "$target_gen_dir/tree.js" ] | |
| 96 # bootstrap_file = "bootstrap.js" | |
| 97 # config_files = [ | |
| 98 # "config1.js", | |
| 99 # "config2.js", | |
| 100 # ] | |
| 101 # closure_flags = ["jscomp_error=undefinedVars"] | |
| 102 # externs_list = [ "externs.js" ] | |
| 103 # } | |
| 104 | |
| 105 template("js_binary") { | |
| 106 assert(defined(invoker.sources) || defined(invoker.deps), | |
| 107 "Need sources or deps in $target_name for js_binary") | |
| 108 assert(defined(invoker.outputs), "Need outputs in $target_name for js_binary") | |
| 109 | |
| 110 action(target_name) { | |
| 111 script = "$script_path/js_binary.py" | |
| 112 forward_variables_from(invoker, | |
| 113 [ | |
| 114 "sources", | |
| 115 "deps", | |
| 116 "outputs", | |
| 117 "bootstrap_file", | |
| 118 "config_files", | |
| 119 "closure_flags", | |
| 120 "externs_list", | |
| 121 ]) | |
| 122 args = [ | |
| 123 "--compiler", | |
| 124 rebase_path(compiler_path, root_build_dir), | |
| 125 ] | |
| 126 args += [ "--output" ] + rebase_path(outputs, root_build_dir) | |
| 127 if (defined(sources)) { | |
| 128 args += [ "--sources" ] + rebase_path(sources, root_build_dir) | |
| 129 } else { | |
| 130 sources = [] | |
| 131 } | |
| 132 if (defined(deps)) { | |
| 133 args += [ "--deps" ] | |
| 134 foreach(dep, deps) { | |
| 135 # Get the output path for each dep | |
| 136 dep_gen_dir = get_label_info(dep, "target_gen_dir") | |
| 137 dep_name = get_label_info(dep, "name") | |
| 138 dep_output_path = "$dep_gen_dir/$dep_name.js_library" | |
| 139 args += [ rebase_path(dep_output_path, root_build_dir) ] | |
| 140 } | |
| 141 } | |
| 142 if (defined(bootstrap_file)) { | |
| 143 args += [ | |
| 144 "--bootstrap", | |
| 145 rebase_path(bootstrap_file, root_build_dir), | |
| 146 ] | |
| 147 sources += [ bootstrap_file ] | |
| 148 } | |
| 149 if (defined(config_files)) { | |
| 150 args += [ "--config" ] + rebase_path(config_files, root_build_dir) | |
| 151 sources += config_files | |
| 152 } | |
| 153 | |
| 154 # |default_closure_args| from //third_party/closure_compiler/closure_args.gn i | |
| 155 args += [ "--flags" ] + default_closure_args - [ "checks_only" ] | |
|
Dan Beam
2017/04/21 00:33:40
you should be using minifying_closure_args instead
| |
| 156 if (defined(closure_flags)) { | |
| 157 args += closure_flags | |
| 158 } | |
| 159 args += | |
| 160 [ "--externs" ] + | |
| 161 [ rebase_path("$script_path/externs/polymer-1.0.js", root_build_dir) ] | |
| 162 if (defined(externs_list)) { | |
| 163 args += rebase_path(externs_list, root_build_dir) | |
| 164 sources += externs_list | |
| 165 } | |
| 166 } | |
| 167 } | |
| OLD | NEW |