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 # Defines a static library corresponding to the output of schema compiler tools | 5 # Defines a static library corresponding to the output of schema compiler tools |
6 # over a set of extensions API schemas (IDL or JSON format.) The library target | 6 # over a set of extensions API schemas (IDL or JSON format.) The library target |
7 # has implicit hard dependencies on all schema files listed by the invoker and | 7 # has implicit hard dependencies on all schema files listed by the invoker and |
8 # is itself a hard dependency. | 8 # is itself a hard dependency. |
9 # | 9 # |
10 # Invocations of this template may use the following variables: | 10 # Invocations of this template may use the following variables: |
(...skipping 28 matching lines...) Expand all Loading... |
39 # | 39 # |
40 # uncompiled_sources [optional, only used when bundle = true or | 40 # uncompiled_sources [optional, only used when bundle = true or |
41 # bundle_registration = true] | 41 # bundle_registration = true] |
42 # A list of schema files which should not be compiled, but which should still | 42 # A list of schema files which should not be compiled, but which should still |
43 # be processed for API bundle generation. | 43 # be processed for API bundle generation. |
44 # | 44 # |
45 # deps [optional] | 45 # deps [optional] |
46 # If any deps are specified they will be inherited by the static library | 46 # If any deps are specified they will be inherited by the static library |
47 # target. | 47 # target. |
48 # | 48 # |
49 # The static library target also inherits the visibility and output_name | 49 # generate_static_library [optional, defaults to false] |
| 50 # Produces a static library instead of a source_set. |
| 51 # |
| 52 # The generated library target also inherits the visibility and output_name |
50 # of its invoker. | 53 # of its invoker. |
51 | 54 |
52 template("json_schema_api") { | 55 template("json_schema_api") { |
53 assert(defined(invoker.sources), | 56 assert(defined(invoker.sources), |
54 "\"sources\" must be defined for the $target_name template.") | 57 "\"sources\" must be defined for the $target_name template.") |
55 assert(defined(invoker.root_namespace), | 58 assert(defined(invoker.root_namespace), |
56 "\"root_namespace\" must be defined for the $target_name template.") | 59 "\"root_namespace\" must be defined for the $target_name template.") |
57 | 60 |
58 schemas = defined(invoker.schemas) && invoker.schemas | 61 schemas = defined(invoker.schemas) && invoker.schemas |
59 bundle = defined(invoker.bundle) && invoker.bundle | 62 bundle = defined(invoker.bundle) && invoker.bundle |
60 bundle_registration = | 63 bundle_registration = |
61 defined(invoker.bundle_registration) && invoker.bundle_registration | 64 defined(invoker.bundle_registration) && invoker.bundle_registration |
62 | 65 |
63 schema_include_rules = "" | 66 schema_include_rules = "" |
64 if (defined(invoker.schema_include_rules)) { | 67 if (defined(invoker.schema_include_rules)) { |
65 schema_include_rules = invoker.schema_include_rules | 68 schema_include_rules = invoker.schema_include_rules |
66 } | 69 } |
67 | 70 |
68 # Keep a copy of the target_name here since it will be trampled | 71 # Keep a copy of the target_name here since it will be trampled |
69 # in nested targets. | 72 # in nested targets. |
70 target_visibility = [ ":$target_name" ] | 73 target_visibility = [ ":$target_name" ] |
71 | 74 |
72 generated_config_name = target_name + "_generated_config" | 75 generated_config_name = target_name + "_generated_config" |
73 config(generated_config_name) { | 76 config(generated_config_name) { |
74 include_dirs = [ root_gen_dir ] | 77 include_dirs = [ root_gen_dir ] |
75 visibility = target_visibility | 78 visibility = target_visibility |
76 } | 79 } |
77 | 80 |
78 sources = invoker.sources | |
79 root_namespace = invoker.root_namespace | 81 root_namespace = invoker.root_namespace |
80 | 82 |
81 compiler_root = "//tools/json_schema_compiler" | 83 compiler_root = "//tools/json_schema_compiler" |
82 compiler_script = "$compiler_root/compiler.py" | 84 compiler_script = "$compiler_root/compiler.py" |
83 compiler_sources = [ | 85 compiler_sources = [ |
84 "$compiler_root/cc_generator.py", | 86 "$compiler_root/cc_generator.py", |
85 "$compiler_root/code.py", | 87 "$compiler_root/code.py", |
86 "$compiler_root/compiler.py", | 88 "$compiler_root/compiler.py", |
87 "$compiler_root/cpp_generator.py", | 89 "$compiler_root/cpp_generator.py", |
88 "$compiler_root/cpp_type_generator.py", | 90 "$compiler_root/cpp_type_generator.py", |
89 "$compiler_root/cpp_util.py", | 91 "$compiler_root/cpp_util.py", |
90 "$compiler_root/h_generator.py", | 92 "$compiler_root/h_generator.py", |
91 "$compiler_root/idl_schema.py", | 93 "$compiler_root/idl_schema.py", |
92 "$compiler_root/model.py", | 94 "$compiler_root/model.py", |
93 "$compiler_root/util_cc_helper.py", | 95 "$compiler_root/util_cc_helper.py", |
94 ] | 96 ] |
95 | 97 |
96 if (schemas) { | 98 if (schemas) { |
97 schema_generator_name = target_name + "_schema_generator" | 99 schema_generator_name = target_name + "_schema_generator" |
98 action_foreach(schema_generator_name) { | 100 action_foreach(schema_generator_name) { |
99 script = compiler_script | 101 script = compiler_script |
| 102 sources = invoker.sources |
100 inputs = compiler_sources | 103 inputs = compiler_sources |
101 outputs = [ | 104 outputs = [ |
102 "$target_gen_dir/{{source_name_part}}.cc", | 105 "$target_gen_dir/{{source_name_part}}.cc", |
103 "$target_gen_dir/{{source_name_part}}.h", | 106 "$target_gen_dir/{{source_name_part}}.h", |
104 ] | 107 ] |
105 args = [ | 108 args = [ |
106 "{{source}}", | 109 "{{source}}", |
107 "--root=" + rebase_path("//", root_build_dir), | 110 "--root=" + rebase_path("//", root_build_dir), |
108 "--destdir=" + rebase_path(root_gen_dir, root_build_dir), | 111 "--destdir=" + rebase_path(root_gen_dir, root_build_dir), |
109 "--namespace=$root_namespace", | 112 "--namespace=$root_namespace", |
(...skipping 10 matching lines...) Expand all Loading... |
120 | 123 |
121 if (bundle) { | 124 if (bundle) { |
122 uncompiled_sources = [] | 125 uncompiled_sources = [] |
123 if (defined(invoker.uncompiled_sources)) { | 126 if (defined(invoker.uncompiled_sources)) { |
124 uncompiled_sources = invoker.uncompiled_sources | 127 uncompiled_sources = invoker.uncompiled_sources |
125 } | 128 } |
126 | 129 |
127 bundle_generator_schema_name = target_name + "_bundle_generator_schema" | 130 bundle_generator_schema_name = target_name + "_bundle_generator_schema" |
128 action(bundle_generator_schema_name) { | 131 action(bundle_generator_schema_name) { |
129 script = compiler_script | 132 script = compiler_script |
130 inputs = compiler_sources + sources + uncompiled_sources | 133 inputs = compiler_sources + invoker.sources + uncompiled_sources |
131 outputs = [ | 134 outputs = [ |
132 "$target_gen_dir/generated_schemas.cc", | 135 "$target_gen_dir/generated_schemas.cc", |
133 "$target_gen_dir/generated_schemas.h", | 136 "$target_gen_dir/generated_schemas.h", |
134 ] | 137 ] |
135 args = [ | 138 args = [ |
136 "--root=" + rebase_path("//", root_build_dir), | 139 "--root=" + rebase_path("//", root_build_dir), |
137 "--destdir=" + rebase_path(root_gen_dir, root_build_dir), | 140 "--destdir=" + rebase_path(root_gen_dir, root_build_dir), |
138 "--namespace=$root_namespace", | 141 "--namespace=$root_namespace", |
139 "--generator=cpp-bundle-schema", | 142 "--generator=cpp-bundle-schema", |
140 "--include-rules=$schema_include_rules", | 143 "--include-rules=$schema_include_rules", |
141 ] + rebase_path(sources, root_build_dir) + | 144 ] + rebase_path(invoker.sources, root_build_dir) + |
142 rebase_path(uncompiled_sources, root_build_dir) | 145 rebase_path(uncompiled_sources, root_build_dir) |
143 } | 146 } |
144 } | 147 } |
145 | 148 |
146 if (bundle_registration) { | 149 if (bundle_registration) { |
147 uncompiled_sources = [] | 150 uncompiled_sources = [] |
148 if (defined(invoker.uncompiled_sources)) { | 151 if (defined(invoker.uncompiled_sources)) { |
149 uncompiled_sources = invoker.uncompiled_sources | 152 uncompiled_sources = invoker.uncompiled_sources |
150 } | 153 } |
151 | 154 |
152 assert(defined(invoker.impl_dir), | 155 assert(defined(invoker.impl_dir), |
153 "\"impl_dir\" must be defined for the $target_name template.") | 156 "\"impl_dir\" must be defined for the $target_name template.") |
154 impl_dir = invoker.impl_dir | 157 impl_dir = invoker.impl_dir |
155 | 158 |
156 bundle_generator_registration_name = | 159 bundle_generator_registration_name = |
157 target_name + "_bundle_generator_registration" | 160 target_name + "_bundle_generator_registration" |
158 action(bundle_generator_registration_name) { | 161 action(bundle_generator_registration_name) { |
159 script = compiler_script | 162 script = compiler_script |
160 inputs = compiler_sources + sources + uncompiled_sources | 163 inputs = compiler_sources + invoker.sources + uncompiled_sources |
161 outputs = [ | 164 outputs = [ |
162 "$root_gen_dir/$impl_dir/generated_api_registration.cc", | 165 "$root_gen_dir/$impl_dir/generated_api_registration.cc", |
163 "$root_gen_dir/$impl_dir/generated_api_registration.h", | 166 "$root_gen_dir/$impl_dir/generated_api_registration.h", |
164 ] | 167 ] |
165 args = [ | 168 args = [ |
166 "--root=" + rebase_path("//", root_build_dir), | 169 "--root=" + rebase_path("//", root_build_dir), |
167 "--destdir=" + rebase_path(root_gen_dir, root_build_dir), | 170 "--destdir=" + rebase_path(root_gen_dir, root_build_dir), |
168 "--namespace=$root_namespace", | 171 "--namespace=$root_namespace", |
169 "--generator=cpp-bundle-registration", | 172 "--generator=cpp-bundle-registration", |
170 "--impl-dir=" + rebase_path(impl_dir, "//"), | 173 "--impl-dir=" + rebase_path(impl_dir, "//"), |
171 "--include-rules=$schema_include_rules", | 174 "--include-rules=$schema_include_rules", |
172 ] + rebase_path(sources, root_build_dir) + | 175 ] + rebase_path(invoker.sources, root_build_dir) + |
173 rebase_path(uncompiled_sources, root_build_dir) | 176 rebase_path(uncompiled_sources, root_build_dir) |
174 } | 177 } |
175 } | 178 } |
176 | 179 |
177 source_set(target_name) { | 180 # Compute the contents of the library/source set. |
178 sources = [] | 181 lib_sources = invoker.sources |
179 deps = [] | 182 lib_deps = [] |
180 public_deps = [] | 183 lib_public_deps = [] |
| 184 lib_extra_configs = [] |
181 | 185 |
182 if (schemas) { | 186 if (schemas) { |
183 sources += get_target_outputs(":$schema_generator_name") | 187 lib_sources += get_target_outputs(":$schema_generator_name") |
184 public_deps += [ ":$schema_generator_name" ] | 188 lib_public_deps += [ ":$schema_generator_name" ] |
185 deps += [ "//tools/json_schema_compiler:generated_api_util" ] | 189 lib_deps += [ "//tools/json_schema_compiler:generated_api_util" ] |
186 configs += [ "//build/config/compiler:no_size_t_to_int_warning" ] | 190 lib_extra_configs += [ "//build/config/compiler:no_size_t_to_int_warning" ] |
| 191 } |
| 192 |
| 193 if (bundle) { |
| 194 lib_sources += get_target_outputs(":$bundle_generator_schema_name") |
| 195 lib_deps += [ ":$bundle_generator_schema_name" ] |
| 196 } |
| 197 |
| 198 if (bundle_registration) { |
| 199 lib_sources += get_target_outputs(":$bundle_generator_registration_name") |
| 200 lib_deps += [ ":$bundle_generator_registration_name" ] |
| 201 } |
| 202 |
| 203 if (defined(invoker.deps)) { |
| 204 lib_deps += invoker.deps |
| 205 } |
| 206 |
| 207 # Generate either a static library or a source set. |
| 208 if (defined(invoker.generate_static_library) && |
| 209 invoker.generate_static_library) { |
| 210 static_library(target_name) { |
| 211 sources = lib_sources |
| 212 deps = lib_deps |
| 213 public_deps = lib_public_deps |
| 214 configs += lib_extra_configs |
| 215 public_configs = [ ":$generated_config_name" ] |
| 216 |
| 217 if (defined(invoker.visibility)) { |
| 218 visibility = invoker.visibility |
| 219 } |
| 220 if (defined(invoker.output_name)) { |
| 221 output_name = invoker.output_name |
| 222 } |
187 } | 223 } |
| 224 } else { |
| 225 source_set(target_name) { |
| 226 sources = lib_sources |
| 227 deps = lib_deps |
| 228 public_deps = lib_public_deps |
| 229 configs += lib_extra_configs |
| 230 public_configs = [ ":$generated_config_name" ] |
188 | 231 |
189 if (bundle) { | 232 if (defined(invoker.visibility)) { |
190 sources += get_target_outputs(":$bundle_generator_schema_name") | 233 visibility = invoker.visibility |
191 deps += [ ":$bundle_generator_schema_name" ] | 234 } |
192 } | 235 if (defined(invoker.output_name)) { |
193 | 236 output_name = invoker.output_name |
194 if (bundle_registration) { | 237 } |
195 sources += get_target_outputs(":$bundle_generator_registration_name") | |
196 deps += [ ":$bundle_generator_registration_name" ] | |
197 } | |
198 | |
199 if (defined(invoker.deps)) { | |
200 deps += invoker.deps | |
201 } | |
202 public_configs = [ ":$generated_config_name" ] | |
203 | |
204 if (defined(invoker.visibility)) { | |
205 visibility = invoker.visibility | |
206 } | |
207 if (defined(invoker.output_name)) { | |
208 output_name = invoker.output_name | |
209 } | 238 } |
210 } | 239 } |
211 } | 240 } |
OLD | NEW |