| 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 # | 15 # |
| 16 # public_deps (optional) | 16 # public_deps (optional) |
| 17 # | 17 # |
| 18 # testonly (optional) | 18 # testonly (optional) |
| 19 # | 19 # |
| 20 # visibility (optional) | 20 # visibility (optional) |
| 21 # |
| 22 # generators (optional) |
| 23 # List of languages to generate object files for. |
| 21 template("mojom") { | 24 template("mojom") { |
| 22 assert(defined(invoker.sources), | 25 assert(defined(invoker.sources), |
| 23 "\"sources\" must be defined for the $target_name template.") | 26 "\"sources\" must be defined for the $target_name template.") |
| 24 | 27 |
| 25 generator_root = "//mojo/public/tools/bindings" | 28 generator_root = "//mojo/public/tools/bindings" |
| 26 generator_script = "$generator_root/mojom_bindings_generator.py" | 29 generator_script = "$generator_root/mojom_bindings_generator.py" |
| 27 generator_sources = [ | 30 generator_sources = [ |
| 28 generator_script, | 31 generator_script, |
| 29 "$generator_root/generators/cpp_templates/enum_declaration.tmpl", | 32 "$generator_root/generators/cpp_templates/enum_declaration.tmpl", |
| 30 "$generator_root/generators/cpp_templates/interface_declaration.tmpl", | 33 "$generator_root/generators/cpp_templates/interface_declaration.tmpl", |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 "{{source_gen_dir}}/{{source_name_part}}_mojom.py", | 83 "{{source_gen_dir}}/{{source_name_part}}_mojom.py", |
| 81 ] | 84 ] |
| 82 | 85 |
| 83 if (defined(invoker.visibility)) { | 86 if (defined(invoker.visibility)) { |
| 84 # Need to save this because the the target_name is overwritten inside the | 87 # Need to save this because the the target_name is overwritten inside the |
| 85 # action to be that of the action itself. Only define this in the case the | 88 # action to be that of the action itself. Only define this in the case the |
| 86 # var is used to avoid unused var error. | 89 # var is used to avoid unused var error. |
| 87 target_visibility = [ ":$target_name" ] | 90 target_visibility = [ ":$target_name" ] |
| 88 } | 91 } |
| 89 | 92 |
| 93 # Work around gn requiring all outputs to be used; there are some branches |
| 94 # through the if branches below where these variables may otherwise be unused. |
| 95 assert(generator_cpp_outputs != []) |
| 96 assert(generator_js_outputs != []) |
| 97 assert(generator_python_outputs != []) |
| 98 |
| 90 generator_target_name = target_name + "__generator" | 99 generator_target_name = target_name + "__generator" |
| 91 action_foreach(generator_target_name) { | 100 action_foreach(generator_target_name) { |
| 92 if (defined(invoker.visibility)) { | 101 if (defined(invoker.visibility)) { |
| 93 visibility = target_visibility + invoker.visibility | 102 visibility = target_visibility + invoker.visibility |
| 94 } | 103 } |
| 95 script = generator_script | 104 script = generator_script |
| 96 inputs = generator_sources | 105 inputs = generator_sources |
| 97 sources = invoker.sources | 106 sources = invoker.sources |
| 98 outputs = generator_cpp_outputs + | 107 outputs = [] |
| 99 generator_js_outputs + | 108 generator_string = "" |
| 100 generator_python_outputs | 109 if (defined(invoker.generators)) { |
| 110 generator_string = "--generators=" |
| 111 first_item = true |
| 112 foreach (item, invoker.generators) { |
| 113 if (first_item) { |
| 114 first_item = false |
| 115 } else { |
| 116 generator_string += "," |
| 117 } |
| 118 |
| 119 generator_string += item |
| 120 if (item == "c++") { |
| 121 outputs += generator_cpp_outputs |
| 122 } else if (item == "javascript") { |
| 123 outputs += generator_js_outputs |
| 124 } else if (item == "python") { |
| 125 outputs += generator_python_outputs |
| 126 } |
| 127 } |
| 128 } else { |
| 129 outputs = generator_cpp_outputs + |
| 130 generator_js_outputs + |
| 131 generator_python_outputs |
| 132 } |
| 133 |
| 101 args = [ | 134 args = [ |
| 102 "{{source}}", | 135 "{{source}}", |
| 136 ] |
| 137 |
| 138 if (generator_string != "") { |
| 139 args += [ generator_string ] |
| 140 } |
| 141 |
| 142 args += [ |
| 103 "--use_chromium_bundled_pylibs", | 143 "--use_chromium_bundled_pylibs", |
| 104 "-d", rebase_path("//", root_build_dir), | 144 "-d", rebase_path("//", root_build_dir), |
| 105 "-I", rebase_path("//", root_build_dir), | 145 "-I", rebase_path("//", root_build_dir), |
| 106 "-o", "{{source_gen_dir}}", | 146 "-o", "{{source_gen_dir}}", |
| 107 ] | 147 ] |
| 108 } | 148 } |
| 109 | 149 |
| 110 source_set(target_name) { | 150 source_set(target_name) { |
| 111 if (defined(invoker.visibility)) { | 151 if (defined(invoker.visibility)) { |
| 112 visibility = invoker.visibility | 152 visibility = invoker.visibility |
| 113 } | 153 } |
| 114 if (defined(invoker.testonly)) { | 154 if (defined(invoker.testonly)) { |
| 115 testonly = invoker.testonly | 155 testonly = invoker.testonly |
| 116 } | 156 } |
| 117 sources = process_file_template(invoker.sources, generator_cpp_outputs) | 157 sources = process_file_template(invoker.sources, generator_cpp_outputs) |
| 118 data = process_file_template(invoker.sources, generator_js_outputs) | 158 data = process_file_template(invoker.sources, generator_js_outputs) |
| 119 deps = [ | 159 deps = [ |
| 120 ":$generator_target_name", | 160 ":$generator_target_name", |
| 121 "//mojo/public/cpp/bindings", | 161 "//mojo/public/cpp/bindings", |
| 122 ] | 162 ] |
| 123 if (defined(invoker.deps)) { | 163 if (defined(invoker.deps)) { |
| 124 deps += invoker.deps | 164 deps += invoker.deps |
| 125 } | 165 } |
| 126 if (defined(invoker.public_deps)) { | 166 if (defined(invoker.public_deps)) { |
| 127 public_deps = invoker.public_deps | 167 public_deps = invoker.public_deps |
| 128 } | 168 } |
| 129 } | 169 } |
| 130 } | 170 } |
| OLD | NEW |