OLD | NEW |
---|---|
1 # Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import("//third_party/closure_compiler/closure_args.gni") | 5 import("//third_party/closure_compiler/closure_args.gni") |
6 | 6 |
7 script_path = "//third_party/closure_compiler" | 7 script_path = "//third_party/closure_compiler" |
8 compiler_path = "$script_path/compiler/compiler.jar" | 8 compiler_path = "$script_path/compiler/compiler.jar" |
9 | 9 |
10 # Defines a target that creates an ordering for .js files to be used by | 10 # Defines a target that creates an ordering for .js files to be used by |
11 # js_binary to compile. | 11 # js_binary to compile. |
12 # | 12 # |
13 # Variables: | 13 # Variables: |
14 # sources: | 14 # sources: |
15 # List of Javascript files to include in the library | 15 # List of Javascript files to include in the library |
16 # | 16 # |
17 # deps: | 17 # deps: |
Sami
2017/05/24 09:16:22
I think renaming this to js_deps instead would mak
alex clarke (OOO till 29th)
2017/05/24 11:38:19
+dbeam@ WDYT?
| |
18 # List of js_library targets to depend on | 18 # List of js_library targets to depend on |
19 # | 19 # |
20 # extra_deps: | |
21 # List of any other rules to depend on. E.g. a rule that generates js source | |
22 # files | |
23 # | |
20 # Example: | 24 # Example: |
21 # js_library("apple_tree") { | 25 # js_library("apple_tree") { |
22 # sources = ["tree_main.js"] | 26 # sources = ["tree_main.js"] |
23 # deps = [ | 27 # deps = [ |
24 # ":branch", | 28 # ":branch", |
25 # ":trunk", | 29 # ":trunk", |
26 # ":root", | 30 # ":root", |
27 # ] | 31 # ] |
28 # } | 32 # } |
29 | 33 |
30 template("js_library") { | 34 template("js_library") { |
31 assert(defined(invoker.sources) || defined(invoker.deps), | 35 assert(defined(invoker.sources) || defined(invoker.deps), |
32 "Need sources or deps in $target_name for js_library") | 36 "Need sources or deps in $target_name for js_library") |
33 action(target_name) { | 37 action(target_name) { |
34 script = "$script_path/js_library.py" | 38 script = "$script_path/js_library.py" |
35 forward_variables_from(invoker, | 39 forward_variables_from(invoker, |
36 [ | 40 [ |
37 "sources", | 41 "sources", |
38 "deps", | 42 "deps", |
43 "extra_deps", | |
39 ]) | 44 ]) |
40 output_file = "$target_gen_dir/$target_name.js_library" | 45 output_file = "$target_gen_dir/$target_name.js_library" |
41 outputs = [ | 46 outputs = [ |
42 output_file, | 47 output_file, |
43 ] | 48 ] |
44 args = [ "--output" ] + [ rebase_path(output_file, root_build_dir) ] | 49 args = [ "--output" ] + [ rebase_path(output_file, root_build_dir) ] |
45 if (defined(sources)) { | 50 if (defined(sources)) { |
46 args += [ "--sources" ] + rebase_path(sources, root_build_dir) | 51 args += [ "--sources" ] + rebase_path(sources, root_build_dir) |
47 } | 52 } |
48 if (defined(deps)) { | 53 if (defined(deps)) { |
49 args += [ "--deps" ] | 54 args += [ "--deps" ] |
50 foreach(dep, deps) { | 55 foreach(dep, deps) { |
51 # Get the output path for each dep | 56 # Get the output path for each dep |
52 dep_gen_dir = get_label_info(dep, "target_gen_dir") | 57 dep_gen_dir = get_label_info(dep, "target_gen_dir") |
53 dep_name = get_label_info(dep, "name") | 58 dep_name = get_label_info(dep, "name") |
54 dep_output_path = "$dep_gen_dir/$dep_name.js_library" | 59 dep_output_path = "$dep_gen_dir/$dep_name.js_library" |
55 args += [ rebase_path(dep_output_path, root_build_dir) ] | 60 args += [ rebase_path(dep_output_path, root_build_dir) ] |
56 } | 61 } |
57 } | 62 } |
63 if (defined(extra_deps)) { | |
64 if (!defined(deps)) { | |
65 deps = [] | |
66 } | |
67 deps += extra_deps | |
68 } | |
58 } | 69 } |
59 } | 70 } |
60 | 71 |
61 # Defines a target that compiles javascript files using the Closure compiler. | 72 # Defines a target that compiles javascript files using the Closure compiler. |
62 # This will produce a minified javascript output file. Additional checks and | 73 # This will produce a minified javascript output file. Additional checks and |
63 # optimizations can be configured using the closure_flags attribute. | 74 # optimizations can be configured using the closure_flags attribute. |
64 # | 75 # |
65 # Variables: | 76 # Variables: |
66 # sources: | 77 # sources: |
67 # List of .js files to compile | 78 # List of .js files to compile |
68 # | 79 # |
69 # deps: | 80 # deps: |
70 # List of js_library rules to depend on | 81 # List of js_library rules to depend on |
71 # | 82 # |
83 # extra_deps: | |
84 # List of any other rules to depend on. E.g. a rule that generates js source | |
85 # files | |
86 # | |
72 # outputs: | 87 # outputs: |
73 # A file to write the compiled .js to. | 88 # A file to write the compiled .js to. |
74 # Only takes in a single file, but must be placed in a list | 89 # Only takes in a single file, but must be placed in a list |
75 # | 90 # |
76 # bootstrap_file: | 91 # bootstrap_file: |
77 # A .js files to include before all others | 92 # A .js files to include before all others |
78 # | 93 # |
79 # config_files: | 94 # config_files: |
80 # A list of .js files to include after the bootstrap_file but before all | 95 # A list of .js files to include after the bootstrap_file but before all |
81 # others | 96 # others |
(...skipping 28 matching lines...) Expand all Loading... | |
110 script = "$script_path/js_binary.py" | 125 script = "$script_path/js_binary.py" |
111 forward_variables_from(invoker, | 126 forward_variables_from(invoker, |
112 [ | 127 [ |
113 "sources", | 128 "sources", |
114 "deps", | 129 "deps", |
115 "outputs", | 130 "outputs", |
116 "bootstrap_file", | 131 "bootstrap_file", |
117 "config_files", | 132 "config_files", |
118 "closure_flags", | 133 "closure_flags", |
119 "externs_list", | 134 "externs_list", |
135 "extra_deps", | |
120 ]) | 136 ]) |
121 args = [ | 137 args = [ |
122 "--compiler", | 138 "--compiler", |
123 rebase_path(compiler_path, root_build_dir), | 139 rebase_path(compiler_path, root_build_dir), |
124 ] | 140 ] |
125 args += [ "--output" ] + rebase_path(outputs, root_build_dir) | 141 args += [ "--output" ] + rebase_path(outputs, root_build_dir) |
126 if (defined(sources)) { | 142 if (defined(sources)) { |
127 args += [ "--sources" ] + rebase_path(sources, root_build_dir) | 143 args += [ "--sources" ] + rebase_path(sources, root_build_dir) |
128 } else { | 144 } else { |
129 sources = [] | 145 sources = [] |
130 } | 146 } |
131 if (defined(deps)) { | 147 if (defined(deps)) { |
132 args += [ "--deps" ] | 148 args += [ "--deps" ] |
133 foreach(dep, deps) { | 149 foreach(dep, deps) { |
134 # Get the output path for each dep | 150 # Get the output path for each dep |
135 dep_gen_dir = get_label_info(dep, "target_gen_dir") | 151 dep_gen_dir = get_label_info(dep, "target_gen_dir") |
136 dep_name = get_label_info(dep, "name") | 152 dep_name = get_label_info(dep, "name") |
137 dep_output_path = "$dep_gen_dir/$dep_name.js_library" | 153 dep_output_path = "$dep_gen_dir/$dep_name.js_library" |
138 args += [ rebase_path(dep_output_path, root_build_dir) ] | 154 args += [ rebase_path(dep_output_path, root_build_dir) ] |
139 } | 155 } |
140 } | 156 } |
157 if (defined(extra_deps)) { | |
158 if (!defined(deps)) { | |
159 deps = [] | |
160 } | |
161 deps += extra_deps | |
162 } | |
141 if (defined(bootstrap_file)) { | 163 if (defined(bootstrap_file)) { |
142 args += [ | 164 args += [ |
143 "--bootstrap", | 165 "--bootstrap", |
144 rebase_path(bootstrap_file, root_build_dir), | 166 rebase_path(bootstrap_file, root_build_dir), |
145 ] | 167 ] |
146 sources += [ bootstrap_file ] | 168 sources += [ bootstrap_file ] |
147 } | 169 } |
148 if (defined(config_files)) { | 170 if (defined(config_files)) { |
149 args += [ "--config" ] + rebase_path(config_files, root_build_dir) | 171 args += [ "--config" ] + rebase_path(config_files, root_build_dir) |
150 sources += config_files | 172 sources += config_files |
151 } | 173 } |
152 | 174 |
153 # |minifying_closure_args| from | 175 # |minifying_closure_args| from |
154 # //third_party/closure_compiler/closure_args.gni | 176 # //third_party/closure_compiler/closure_args.gni |
155 args += [ "--flags" ] + minifying_closure_args | 177 args += [ "--flags" ] + minifying_closure_args |
156 if (defined(closure_flags)) { | 178 if (defined(closure_flags)) { |
157 args += closure_flags | 179 args += closure_flags |
158 } | 180 } |
159 if (defined(externs_list)) { | 181 if (defined(externs_list)) { |
160 args += [ "--externs" ] | 182 args += [ "--externs" ] |
161 args += rebase_path(externs_list, root_build_dir) | 183 args += rebase_path(externs_list, root_build_dir) |
162 sources += externs_list | 184 sources += externs_list |
163 } | 185 } |
164 } | 186 } |
165 } | 187 } |
OLD | NEW |