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") | |
|
Dirk Pranke
2017/04/14 02:01:44
or, not and?
damargulis
2017/04/14 17:46:33
I think it should be or. It definitely needs to b
Dirk Pranke
2017/04/15 00:46:44
ok, just checking.
| |
| 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 # peform error, syntax, and type checking. Additional checks and options | |
| 64 # can be configured using the defs 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 # defs: | |
| 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 # defs = ["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, "*") | |
|
Dirk Pranke
2017/04/14 02:01:44
Is the forward_variables_from() really necessary?
damargulis
2017/04/14 17:46:33
The action needs to be explicitly told what its so
| |
| 113 args = [ | |
| 114 "--compiler", | |
| 115 rebase_path(compiler_path, root_build_dir), | |
| 116 ] | |
| 117 args += [ "--output" ] + rebase_path(outputs, root_build_dir) | |
| 118 if (defined(sources)) { | |
| 119 args += [ "--sources" ] + rebase_path(sources, root_build_dir) | |
| 120 } | |
| 121 if (defined(deps)) { | |
| 122 args += [ "--deps" ] | |
| 123 foreach(dep, deps) { | |
| 124 # Get the output path for each dep | |
| 125 dep_gen_dir = get_label_info(dep, "target_gen_dir") | |
| 126 dep_name = get_label_info(dep, "name") | |
| 127 dep_output_path = "$dep_gen_dir/$dep_name.js_library" | |
| 128 args += [ rebase_path(dep_output_path, root_build_dir) ] | |
| 129 } | |
| 130 } | |
| 131 if (defined(bootstrap_file)) { | |
| 132 args += [ | |
| 133 "--bootstrap", | |
| 134 rebase_path(bootstrap_file, root_build_dir), | |
| 135 ] | |
| 136 } | |
| 137 if (defined(config_files)) { | |
| 138 args += [ "--config" ] + rebase_path(config_files, root_build_dir) | |
| 139 } | |
| 140 | |
| 141 # |default_closure_args| from //third_party/closure_compiler/closure_args.gn i | |
| 142 args += [ "--defs" ] + default_closure_args - [ "checks_only" ] | |
| 143 if (defined(defs)) { | |
| 144 args += defs | |
| 145 } | |
| 146 args += | |
| 147 [ "--externs" ] + | |
| 148 [ rebase_path("$script_path/externs/polymer-1.0.js", root_build_dir) ] | |
| 149 if (defined(externs_list)) { | |
| 150 args += rebase_path(externs_list, root_build_dir) | |
| 151 } | |
| 152 } | |
| 153 } | |
| OLD | NEW |