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++/JavaScript/Java source files from mojom files. The output files | 5 # Generate C++/JavaScript/Java 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 (optional if one of the deps sets listed below is present) | 11 # sources (optional if one of the deps sets listed below is present) |
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 # import_dirs (optional) | 20 # import_dirs (optional) |
21 # List of import directories that will get added when processing sources. | 21 # List of import directories that will get added when processing sources. |
22 # | 22 # |
23 # with_environment (optional) | 23 # with_environment (optional) |
24 # Set to |false| to omit an implicit bindings dependency on the Chromium | 24 # Set to |false| to omit an implicit bindings dependency on the Chromium |
25 # Mojo environment implementation. Defaults to |true| and in general | 25 # Mojo environment implementation. Defaults to |true| and in general |
26 # should only be overridden by mojom targets within the Mojo EDK. | 26 # should only be overridden by mojom targets within the Mojo EDK. |
27 # | 27 # |
| 28 # typemaps (optional) |
| 29 # A list of typemap files to apply during bindings generation. |
| 30 # |
| 31 # variant (optional) |
| 32 # A variant name to apply to generated bindings. Variant influences |
| 33 # generated source filenames as wells the symbols they define. |
| 34 # |
28 # testonly (optional) | 35 # testonly (optional) |
29 # | 36 # |
30 # visibility (optional) | 37 # visibility (optional) |
31 template("mojom") { | 38 template("mojom") { |
32 assert( | 39 assert( |
33 defined(invoker.sources) || defined(invoker.deps) || | 40 defined(invoker.sources) || defined(invoker.deps) || |
34 defined(invoker.public_deps), | 41 defined(invoker.public_deps), |
35 "\"sources\" or \"deps\" must be defined for the $target_name template.") | 42 "\"sources\" or \"deps\" must be defined for the $target_name template.") |
36 | 43 |
37 cpp_sources_suffix = "cpp_sources" | 44 cpp_sources_suffix = "cpp_sources" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 "$generator_root/pylib/mojom/generate/generator.py", | 102 "$generator_root/pylib/mojom/generate/generator.py", |
96 "$generator_root/pylib/mojom/generate/module.py", | 103 "$generator_root/pylib/mojom/generate/module.py", |
97 "$generator_root/pylib/mojom/generate/pack.py", | 104 "$generator_root/pylib/mojom/generate/pack.py", |
98 "$generator_root/pylib/mojom/generate/template_expander.py", | 105 "$generator_root/pylib/mojom/generate/template_expander.py", |
99 "$generator_root/pylib/mojom/parse/__init__.py", | 106 "$generator_root/pylib/mojom/parse/__init__.py", |
100 "$generator_root/pylib/mojom/parse/ast.py", | 107 "$generator_root/pylib/mojom/parse/ast.py", |
101 "$generator_root/pylib/mojom/parse/lexer.py", | 108 "$generator_root/pylib/mojom/parse/lexer.py", |
102 "$generator_root/pylib/mojom/parse/parser.py", | 109 "$generator_root/pylib/mojom/parse/parser.py", |
103 "$generator_root/pylib/mojom/parse/translate.py", | 110 "$generator_root/pylib/mojom/parse/translate.py", |
104 ] | 111 ] |
105 generator_cpp_outputs = [ | 112 if (defined(invoker.variant)) { |
106 "{{source_gen_dir}}/{{source_name_part}}.mojom.cc", | 113 variant = invoker.variant |
107 "{{source_gen_dir}}/{{source_name_part}}.mojom.h", | 114 generator_cpp_outputs = [ |
108 "{{source_gen_dir}}/{{source_name_part}}.mojom-internal.h", | 115 "{{source_gen_dir}}/{{source_name_part}}.mojom-${variant}.cc", |
109 ] | 116 "{{source_gen_dir}}/{{source_name_part}}.mojom-${variant}.h", |
110 generator_js_outputs = | 117 "{{source_gen_dir}}/{{source_name_part}}.mojom-${variant}-internal.h", |
111 [ "{{source_gen_dir}}/{{source_name_part}}.mojom.js" ] | 118 ] |
112 generator_java_outputs = | 119 generator_js_outputs = [] |
113 [ "{{source_gen_dir}}/{{source_name_part}}.mojom.srcjar" ] | 120 generator_java_outputs = [] |
| 121 } else { |
| 122 generator_cpp_outputs = [ |
| 123 "{{source_gen_dir}}/{{source_name_part}}.mojom.cc", |
| 124 "{{source_gen_dir}}/{{source_name_part}}.mojom.h", |
| 125 "{{source_gen_dir}}/{{source_name_part}}.mojom-internal.h", |
| 126 ] |
| 127 generator_js_outputs = |
| 128 [ "{{source_gen_dir}}/{{source_name_part}}.mojom.js" ] |
| 129 generator_java_outputs = |
| 130 [ "{{source_gen_dir}}/{{source_name_part}}.mojom.srcjar" ] |
| 131 } |
114 } | 132 } |
115 | 133 |
116 if (defined(invoker.sources)) { | 134 if (defined(invoker.sources)) { |
117 generator_target_name = target_name + "__generator" | 135 generator_target_name = target_name + "__generator" |
118 action_foreach(generator_target_name) { | 136 action_foreach(generator_target_name) { |
119 script = generator_script | 137 script = generator_script |
120 inputs = generator_sources | 138 inputs = generator_sources |
121 sources = invoker.sources | 139 sources = invoker.sources |
122 outputs = | 140 outputs = |
123 generator_cpp_outputs + generator_java_outputs + generator_js_outputs | 141 generator_cpp_outputs + generator_java_outputs + generator_js_outputs |
124 args = [ | 142 args = [ |
125 "{{source}}", | 143 "{{source}}", |
126 "--use_bundled_pylibs", | 144 "--use_bundled_pylibs", |
127 "-d", | 145 "-d", |
128 rebase_path("//", root_build_dir), | 146 rebase_path("//", root_build_dir), |
129 "-I", | 147 "-I", |
130 rebase_path("//", root_build_dir), | 148 rebase_path("//", root_build_dir), |
131 "-o", | 149 "-o", |
132 rebase_path(root_gen_dir), | 150 rebase_path(root_gen_dir), |
133 ] | 151 ] |
134 | 152 |
135 if (defined(invoker.import_dirs)) { | 153 if (defined(invoker.import_dirs)) { |
136 foreach(import_dir, invoker.import_dirs) { | 154 foreach(import_dir, invoker.import_dirs) { |
137 args += [ | 155 args += [ |
138 "-I", | 156 "-I", |
139 rebase_path(import_dir, root_build_dir), | 157 rebase_path(import_dir, root_build_dir), |
140 ] | 158 ] |
141 } | 159 } |
142 } | 160 } |
| 161 |
| 162 if (defined(invoker.variant)) { |
| 163 args += [ |
| 164 "--variant", |
| 165 invoker.variant, |
| 166 "-g", |
| 167 "c++", |
| 168 ] |
| 169 } else { |
| 170 args += [ |
| 171 "-g", |
| 172 "c++,javascript,java", |
| 173 ] |
| 174 } |
| 175 |
| 176 if (defined(invoker.typemaps)) { |
| 177 foreach(typemap, invoker.typemaps) { |
| 178 args += [ |
| 179 "--typemap", |
| 180 rebase_path(typemap, root_build_dir), |
| 181 ] |
| 182 } |
| 183 } |
143 } | 184 } |
144 } | 185 } |
145 | 186 |
146 source_set(target_name) { | 187 source_set(target_name) { |
147 if (defined(invoker.visibility)) { | 188 if (defined(invoker.visibility)) { |
148 visibility = invoker.visibility | 189 visibility = invoker.visibility |
149 } | 190 } |
150 if (defined(invoker.testonly)) { | 191 if (defined(invoker.testonly)) { |
151 testonly = invoker.testonly | 192 testonly = invoker.testonly |
152 } | 193 } |
153 if (defined(invoker.sources)) { | 194 if (defined(invoker.sources) && !defined(invoker.variant)) { |
154 data = process_file_template(invoker.sources, generator_js_outputs) | 195 data = process_file_template(invoker.sources, generator_js_outputs) |
155 } | 196 } |
156 | 197 |
157 public_deps = [ | 198 public_deps = [ |
158 "//mojo/public/cpp/bindings", | 199 "//mojo/public/cpp/bindings", |
159 ] | 200 ] |
160 if (defined(invoker.sources)) { | 201 if (defined(invoker.sources)) { |
161 public_deps += [ ":${cpp_sources_target_name}" ] | 202 public_deps += [ ":${cpp_sources_target_name}" ] |
162 } | 203 } |
163 if (defined(invoker.public_deps)) { | 204 if (defined(invoker.public_deps)) { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 # get the cpp dependency name. | 259 # get the cpp dependency name. |
219 full_name = get_label_info(d, "label_no_toolchain") | 260 full_name = get_label_info(d, "label_no_toolchain") |
220 deps += [ "${full_name}_${cpp_sources_suffix}" ] | 261 deps += [ "${full_name}_${cpp_sources_suffix}" ] |
221 } | 262 } |
222 if (!defined(invoker.with_environment) || invoker.with_environment) { | 263 if (!defined(invoker.with_environment) || invoker.with_environment) { |
223 deps += [ "//mojo/environment:chromium" ] | 264 deps += [ "//mojo/environment:chromium" ] |
224 } | 265 } |
225 } | 266 } |
226 } | 267 } |
227 | 268 |
228 if (is_android) { | 269 if (is_android && !defined(invoker.variant)) { |
229 import("//build/config/android/rules.gni") | 270 import("//build/config/android/rules.gni") |
230 | 271 |
231 java_srcjar_target_name = target_name + "_java_sources" | 272 java_srcjar_target_name = target_name + "_java_sources" |
232 action(java_srcjar_target_name) { | 273 action(java_srcjar_target_name) { |
233 script = "//mojo/public/tools/gn/zip.py" | 274 script = "//mojo/public/tools/gn/zip.py" |
234 inputs = process_file_template(invoker.sources, generator_java_outputs) | 275 inputs = process_file_template(invoker.sources, generator_java_outputs) |
235 output = "$target_gen_dir/$target_name.srcjar" | 276 output = "$target_gen_dir/$target_name.srcjar" |
236 outputs = [ | 277 outputs = [ |
237 output, | 278 output, |
238 ] | 279 ] |
(...skipping 21 matching lines...) Expand all Loading... |
260 # //mojo/something:something and we can append "_java" to get the java | 301 # //mojo/something:something and we can append "_java" to get the java |
261 # dependency name. | 302 # dependency name. |
262 full_name = get_label_info(d, "label_no_toolchain") | 303 full_name = get_label_info(d, "label_no_toolchain") |
263 deps += [ "${full_name}_java" ] | 304 deps += [ "${full_name}_java" ] |
264 } | 305 } |
265 | 306 |
266 srcjar_deps = [ ":$java_srcjar_target_name" ] | 307 srcjar_deps = [ ":$java_srcjar_target_name" ] |
267 } | 308 } |
268 } | 309 } |
269 } | 310 } |
OLD | NEW |