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

Side by Side Diff: third_party/closure_compiler/compile_js.gni

Issue 2800833004: Create js_library and js_binary templates for closure compiling. (Closed)
Patch Set: fixes 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 unified diff | Download patch
OLDNEW
(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 outputs = [
41 "$target_gen_dir/$target_name.txt",
42 ]
43 args = [ "--output" ] + rebase_path(outputs, root_build_dir)
44 if (defined(sources)) {
45 args += [ "--sources" ] + rebase_path(sources, root_build_dir)
46 }
47 if (defined(deps)) {
48 args += [ "--deps" ]
49 foreach(dep, deps) {
50 # Get the output path for each dep
51 dep_gen_dir = get_label_info(dep, "target_gen_dir")
52 dep_name = get_label_info(dep, "name")
53 dep_output_path = "$dep_gen_dir/$dep_name.txt"
54 args += [ rebase_path(dep_output_path, root_build_dir) ]
55 }
56 }
57 }
58 }
59
60 # Defines a target that compiles javascript files using the closure compiler.
61 # This will produce a minified and optimized javascript output file, and will
62 # peform error, syntax, and type checking. Additional checks and options
63 # can be configured using the defs attribute.
64 #
65 # Variables:
66 # sources:
67 # List of .js files to compile
68 #
69 # deps:
70 # List of js_library rules to depend on
71 #
72 # outputs:
73 # A file to write the compiled .js to.
74 # Only takes in a single file, but should be placed in a list
75 #
76 # bootstrap_file:
77 # A .js files to include before all others
78 #
79 # config_files:
80 # A list of .js files to include after the bootstrap_file but before all
81 # others
82 #
83 # defs:
84 # A list of custom flags to pass to the closure compiler. Do not include
85 # the leading dashes
86 #
87 # externs_list:
88 # A list of .js files to pass to the compiler as externs
89 #
90 # Example:
91 # js_binary("tree") {
92 # sources = ["tree_main.js"]
93 # deps = [":apple_tree"]
94 # outputs = [ "$target_gen_dir/tree.js" ]
95 # defs = ["jscomp_error=undefinedVars"]
96 # }
97
98 template("js_binary") {
99 assert(defined(invoker.sources) || defined(invoker.deps),
100 "Need sources or deps in $target_name for js_binary")
101 assert(defined(invoker.outputs), "Need outputs in $target_name for js_binary")
102
103 action(target_name) {
104 script = "$script_path/js_binary.py"
105 forward_variables_from(invoker, "*")
106 args = [
107 "--compiler",
108 rebase_path(compiler_path, root_build_dir),
109 ]
110 args += [ "--output" ] + rebase_path(outputs, root_build_dir)
111 if (defined(sources)) {
112 args += [ "--sources" ] + rebase_path(sources, root_build_dir)
113 }
114 if (defined(deps)) {
115 args += [ "--deps" ]
116 foreach(dep, deps) {
117 target_path = get_label_info(dep, "target_gen_dir") + "/" +
mbjorge 2017/04/07 23:30:19 copy from above; makes it clear it's doing the sam
damargulis 2017/04/08 00:19:49 Done.
118 get_label_info(dep, "name") + ".txt"
119 args += [ rebase_path(target_path, root_build_dir) ]
120 }
121 }
122 if (defined(bootstrap_file)) {
123 args += [
124 "--bootstrap",
125 rebase_path(bootstrap_file, root_build_dir),
126 ]
127 }
128 if (defined(config_files)) {
129 args += [ "--config" ] + rebase_path(config_files, root_build_dir)
130 }
131 args += [ "--defs" ] + default_closure_args
mbjorge 2017/04/07 23:30:19 Add a comment above here: # |default_closure_args
damargulis 2017/04/08 00:19:49 Done.
132 if (defined(defs)) {
133 args += defs
134 }
135 args +=
136 [ "--externs" ] +
137 [ rebase_path("$script_path/externs/polymer-1.0.js", root_build_dir) ]
138 if (defined(externs_list)) {
139 args += rebase_path(externs_list, root_build_dir)
140 }
141 }
142 }
OLDNEW
« no previous file with comments | « no previous file | third_party/closure_compiler/js_binary.py » ('j') | third_party/closure_compiler/js_binary.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698