OLD | NEW |
---|---|
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 # Generate C++ and JavaScript source files from mojom files. The output files | 5 # Generate C++ and JavaScript source files from mojom files. The output files |
6 # will go under the generated file directory tree with the same path as each | 6 # will go under the generated file directory tree with the same path as each |
7 # input file. | 7 # input file. |
8 # | 8 # |
9 # Parameters: | 9 # Parameters: |
10 # | 10 # |
11 # sources (required) | 11 # sources (required) |
12 # List of source .mojom files to compile. | 12 # List of source .mojom files to compile. |
13 # | 13 # |
14 # deps (optional) | 14 # deps (optional) |
15 # Note: this can contain only other mojom targets. | 15 # Note: this can contain only other mojom targets. |
16 # | 16 # |
17 # public_deps (optional) | 17 # public_deps (optional) |
18 # Note: this can contain only other mojom targets. | 18 # Note: this can contain only other mojom targets. |
19 # | 19 # |
20 # testonly (optional) | 20 # testonly (optional) |
21 # | 21 # |
22 # visibility (optional) | 22 # visibility (optional) |
23 # | |
24 # generators (optional) | |
viettrungluu
2014/10/08 16:21:56
Possibly you should separate out the gn and gyp ch
Elliot Glaysher
2014/10/08 18:20:51
Done: https://codereview.chromium.org/641743002/
| |
25 # List of languages to generate object files for. | |
23 template("mojom") { | 26 template("mojom") { |
24 assert(defined(invoker.sources), | 27 assert(defined(invoker.sources), |
25 "\"sources\" must be defined for the $target_name template.") | 28 "\"sources\" must be defined for the $target_name template.") |
26 | 29 |
27 generator_root = "//mojo/public/tools/bindings" | 30 generator_root = "//mojo/public/tools/bindings" |
28 generator_script = "$generator_root/mojom_bindings_generator.py" | 31 generator_script = "$generator_root/mojom_bindings_generator.py" |
29 generator_sources = [ | 32 generator_sources = [ |
30 generator_script, | 33 generator_script, |
31 "$generator_root/generators/cpp_templates/enum_declaration.tmpl", | 34 "$generator_root/generators/cpp_templates/enum_declaration.tmpl", |
32 "$generator_root/generators/cpp_templates/interface_declaration.tmpl", | 35 "$generator_root/generators/cpp_templates/interface_declaration.tmpl", |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 "{{source_gen_dir}}/{{source_name_part}}_mojom.py", | 99 "{{source_gen_dir}}/{{source_name_part}}_mojom.py", |
97 ] | 100 ] |
98 | 101 |
99 if (defined(invoker.visibility)) { | 102 if (defined(invoker.visibility)) { |
100 # Need to save this because the the target_name is overwritten inside the | 103 # Need to save this because the the target_name is overwritten inside the |
101 # action to be that of the action itself. Only define this in the case the | 104 # action to be that of the action itself. Only define this in the case the |
102 # var is used to avoid unused var error. | 105 # var is used to avoid unused var error. |
103 target_visibility = [ ":$target_name" ] | 106 target_visibility = [ ":$target_name" ] |
104 } | 107 } |
105 | 108 |
109 # Work around gn requiring all outputs to be used; there are some branches | |
110 # through the if branches below where these variables may otherwise be unused. | |
111 assert(generator_cpp_outputs != []) | |
112 assert(generator_java_outputs != []) | |
113 assert(generator_js_outputs != []) | |
114 assert(generator_python_outputs != []) | |
115 | |
106 generator_target_name = target_name + "__generator" | 116 generator_target_name = target_name + "__generator" |
107 action_foreach(generator_target_name) { | 117 action_foreach(generator_target_name) { |
108 if (defined(invoker.visibility)) { | 118 if (defined(invoker.visibility)) { |
109 visibility = target_visibility + invoker.visibility | 119 visibility = target_visibility + invoker.visibility |
110 } | 120 } |
111 script = generator_script | 121 script = generator_script |
112 inputs = generator_sources | 122 inputs = generator_sources |
113 sources = invoker.sources | 123 sources = invoker.sources |
114 outputs = generator_cpp_outputs + | 124 outputs = [] |
115 generator_java_outputs + | 125 generator_string = "" |
116 generator_js_outputs + | 126 if (defined(invoker.generators)) { |
117 generator_python_outputs | 127 generator_string = "--generators=" |
128 first_item = true | |
129 foreach (item, invoker.generators) { | |
130 if (first_item) { | |
131 first_item = false | |
132 } else { | |
133 generator_string += "," | |
134 } | |
135 | |
136 generator_string += item | |
137 if (item == "c++") { | |
138 outputs += generator_cpp_outputs | |
139 } else if (item == "java") { | |
140 outputs += generator_java_outputs | |
141 } else if (item == "javascript") { | |
142 outputs += generator_js_outputs | |
143 } else if (item == "python") { | |
144 outputs += generator_python_outputs | |
145 } | |
146 } | |
147 } else { | |
148 outputs = generator_cpp_outputs + | |
149 generator_java_outputs + | |
150 generator_js_outputs + | |
151 generator_python_outputs | |
152 } | |
153 | |
118 args = [ | 154 args = [ |
119 "{{source}}", | 155 "{{source}}", |
156 ] | |
157 | |
158 if (generator_string != "") { | |
159 args += [ generator_string ] | |
160 } | |
161 | |
162 args += [ | |
120 "--use_chromium_bundled_pylibs", | 163 "--use_chromium_bundled_pylibs", |
121 "-d", rebase_path("//", root_build_dir), | 164 "-d", rebase_path("//", root_build_dir), |
122 "-I", rebase_path("//", root_build_dir), | 165 "-I", rebase_path("//", root_build_dir), |
123 "-o", "{{source_gen_dir}}", | 166 "-o", "{{source_gen_dir}}", |
124 ] | 167 ] |
125 } | 168 } |
126 | 169 |
127 source_set(target_name) { | 170 source_set(target_name) { |
128 if (defined(invoker.visibility)) { | 171 if (defined(invoker.visibility)) { |
129 visibility = invoker.visibility | 172 visibility = invoker.visibility |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
182 # //mojo/something:something and we can append "_java" to get the java | 225 # //mojo/something:something and we can append "_java" to get the java |
183 # dependency name. | 226 # dependency name. |
184 full_name = get_label_info(d, "label_no_toolchain") | 227 full_name = get_label_info(d, "label_no_toolchain") |
185 deps += [ "${full_name}_java" ] | 228 deps += [ "${full_name}_java" ] |
186 } | 229 } |
187 | 230 |
188 srcjars = process_file_template(invoker.sources, generator_java_outputs) | 231 srcjars = process_file_template(invoker.sources, generator_java_outputs) |
189 } | 232 } |
190 } | 233 } |
191 } | 234 } |
OLD | NEW |