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

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: use get_label_info 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. Based off of the js_library rule in Blaze.
12 # 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.
13 #
14 # Variables:
15 # sources:
16 # List of Javascript files to include in the library
17 #
18 # deps:
19 # 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
20 #
21 # Example:
22 # in Blaze:
mbjorge 2017/04/07 19:23:18 remove Blaze example
damargulis 2017/04/07 23:02:18 Done.
23 # js_library(
24 # name = "apple_tree",
25 # srcs = ["tree_main.js"],
26 # deps = [
27 # ":branch",
28 # ":trunk",
29 # ":root",
30 # ],
31 # )
32 #
33 # in .gn
34 # js_library("apple_tree") {
35 # sources = ["tree_main.js"]
36 # deps = [
37 # ":branch",
38 # ":trunk",
39 # ":root",
40 # ]
41 # }
42
43 template("js_library") {
44 assert(defined(invoker.sources) || defined(invoker.deps),
45 "Need sources or deps in $target_name for js_library")
46 action(target_name) {
47 script = "$script_path/js_library.py"
48 forward_variables_from(invoker,
49 [
50 "sources",
51 "deps",
52 ])
53 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.
54 "$target_gen_dir/$target_name.txt",
55 ]
56 args = [ "--output" ] + rebase_path(outputs, root_build_dir)
57 if (defined(sources)) {
58 args += [ "--sources" ] + rebase_path(sources, root_build_dir)
59 }
60 if (defined(deps)) {
61 args += [ "--deps" ]
62 foreach(dep, deps) {
63 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.
64 get_label_info(dep, "name") + ".txt"
65 args += [ rebase_path(target_path, root_build_dir) ]
66 }
67 }
68 }
69 }
70
71 # 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.
72 # 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.
73 # to use the .gn syntax.
74 #
75 # Variables:
76 # sources:
77 # List of .js files to compile
78 #
79 # deps:
80 # List of js_library rules to depend on
81 #
82 # bootstrap_file:
83 # A .js files to include before all others
84 #
85 # config_files:
86 # A list of .js files to include after the bootstrap_file but before all
87 # others
88 #
89 # defs:
90 # A list of custom flags to pass to the closure compiler. Do not include
91 # the leading dashes
92 #
93 # externs_list:
94 # A list of .js files to pass to the compiler as externs
95 #
96 # Example:
97 # in Blaze:
mbjorge 2017/04/07 19:23:18 remove blaze example
damargulis 2017/04/07 23:02:18 Done.
98 # js_binary(
99 # name = "tree",
100 # srcs = ["tree_main.js"],
101 # compile = 1,
102 # deps = [":apple_tree"],
103 # defs = ["--jscomp_error=undefinedVars"],
104 # )
105 #
106 # in .gn
107 # 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.
108 # sources = ["tree_main.js"]
109 # deps = [":apple_tree"]
110 # defs = ["jscomp_error=undefinedVars"]
111 # }
112
113 template("js_binary") {
114 assert(defined(invoker.sources) || defined(invoker.deps),
115 "Need sources or deps in $target_name for js_binary")
116
117 action(target_name) {
118 script = "$script_path/js_binary.py"
119 forward_variables_from(invoker, "*")
120 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.
121 "$target_gen_dir/$target_name.js",
122 ]
123 args = [
124 "--compiler",
125 rebase_path(compiler_path, root_build_dir),
126 ]
127 args += [ "--output" ] + rebase_path(outputs, root_build_dir)
128 if (defined(sources)) {
129 args += [ "--sources" ] + rebase_path(sources, root_build_dir)
130 }
131 if (defined(deps)) {
132 args += [ "--deps" ]
133 foreach(dep, deps) {
134 target_path = get_label_info(dep, "target_gen_dir") + "/" +
135 get_label_info(dep, "name") + ".txt"
136 args += [ rebase_path(target_path, root_build_dir) ]
137 }
138 }
139 if (defined(bootstrap_file)) {
140 args += [
141 "--bootstrap",
142 rebase_path(bootstrap_file, root_build_dir),
143 ]
144 }
145 if (defined(config_files)) {
146 args += [ "--config" ] + rebase_path(config_files, root_build_dir)
147 }
148 args += [ "--defs" ] + common_closure_args
149 if (defined(defs)) {
150 args += defs
151 }
152 if (defined(externs_list)) {
153 args += [ "--externs" ] + rebase_path(externs_list, root_build_dir)
154 }
155 }
156 }
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