OLD | NEW |
1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 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 os.path | 5 import os.path |
6 import sys | 6 import sys |
7 import optparse | 7 import optparse |
8 try: | 8 try: |
9 import json | 9 import json |
10 except ImportError: | 10 except ImportError: |
(...skipping 25 matching lines...) Expand all Loading... |
36 | 36 |
37 if os.path.isdir(deps_dir): | 37 if os.path.isdir(deps_dir): |
38 sys.path.insert(1, os.path.join(deps_dir, "jinja2")) | 38 sys.path.insert(1, os.path.join(deps_dir, "jinja2")) |
39 sys.path.insert(1, os.path.join(deps_dir, "markupsafe")) | 39 sys.path.insert(1, os.path.join(deps_dir, "markupsafe")) |
40 | 40 |
41 import jinja2 | 41 import jinja2 |
42 | 42 |
43 cmdline_parser = optparse.OptionParser() | 43 cmdline_parser = optparse.OptionParser() |
44 cmdline_parser.add_option("--protocol") | 44 cmdline_parser.add_option("--protocol") |
45 cmdline_parser.add_option("--include") | 45 cmdline_parser.add_option("--include") |
| 46 cmdline_parser.add_option("--include_package") |
46 cmdline_parser.add_option("--string_type") | 47 cmdline_parser.add_option("--string_type") |
47 cmdline_parser.add_option("--export_macro") | 48 cmdline_parser.add_option("--export_macro") |
48 cmdline_parser.add_option("--output_dir") | 49 cmdline_parser.add_option("--output_dir") |
49 cmdline_parser.add_option("--output_package") | 50 cmdline_parser.add_option("--output_package") |
| 51 cmdline_parser.add_option("--exported_dir") |
| 52 cmdline_parser.add_option("--exported_package") |
50 | 53 |
51 try: | 54 try: |
52 arg_options, arg_values = cmdline_parser.parse_args() | 55 arg_options, arg_values = cmdline_parser.parse_args() |
53 protocol_file = arg_options.protocol | 56 protocol_file = arg_options.protocol |
54 if not protocol_file: | 57 if not protocol_file: |
55 raise Exception("Protocol directory must be specified") | 58 raise Exception("Protocol directory must be specified") |
56 include_file = arg_options.include | 59 include_file = arg_options.include |
| 60 include_package = arg_options.include_package |
| 61 if include_file and not include_package: |
| 62 raise Exception("Include package must be specified when using include fi
le") |
| 63 if include_package and not include_file: |
| 64 raise Exception("Include file must be specified when using include packa
ge") |
57 output_dirname = arg_options.output_dir | 65 output_dirname = arg_options.output_dir |
58 if not output_dirname: | 66 if not output_dirname: |
59 raise Exception("Output directory must be specified") | 67 raise Exception("Output directory must be specified") |
60 output_package = arg_options.output_package | 68 output_package = arg_options.output_package |
61 if not output_package: | 69 if not output_package: |
62 raise Exception("Output package must be specified") | 70 raise Exception("Output package must be specified") |
| 71 exported_dirname = arg_options.exported_dir |
| 72 if not exported_dirname: |
| 73 exported_dirname = os.path.join(output_dirname, "exported") |
| 74 exported_package = arg_options.exported_package |
| 75 if not exported_package: |
| 76 exported_package = os.path.join(output_package, "exported") |
63 string_type = arg_options.string_type | 77 string_type = arg_options.string_type |
64 if not string_type: | 78 if not string_type: |
65 raise Exception("String type must be specified") | 79 raise Exception("String type must be specified") |
66 export_macro = arg_options.export_macro | 80 export_macro = arg_options.export_macro |
67 if not export_macro: | 81 if not export_macro: |
68 raise Exception("Export macro must be specified") | 82 raise Exception("Export macro must be specified") |
69 except Exception: | 83 except Exception: |
70 # Work with python 2 and 3 http://docs.python.org/py3k/howto/pyporting.html | 84 # Work with python 2 and 3 http://docs.python.org/py3k/howto/pyporting.html |
71 exc = sys.exc_info()[1] | 85 exc = sys.exc_info()[1] |
72 sys.stderr.write("Failed to parse command-line arguments: %s\n\n" % exc) | 86 sys.stderr.write("Failed to parse command-line arguments: %s\n\n" % exc) |
73 exit(1) | 87 exit(1) |
74 | 88 |
75 | 89 |
76 input_file = open(protocol_file, "r") | 90 input_file = open(protocol_file, "r") |
77 json_string = input_file.read() | 91 json_string = input_file.read() |
78 parsed_json = json.loads(json_string) | 92 parsed_json = json.loads(json_string) |
79 | 93 |
80 | 94 |
81 # Make gyp / make generatos happy, otherwise make rebuilds world. | 95 # Make gyp / make generatos happy, otherwise make rebuilds world. |
82 def up_to_date(): | 96 def up_to_date(): |
83 template_ts = max( | 97 template_ts = max( |
84 os.path.getmtime(__file__), | 98 os.path.getmtime(__file__), |
85 os.path.getmtime(os.path.join(templates_dir, "TypeBuilder_h.template")), | 99 os.path.getmtime(os.path.join(templates_dir, "TypeBuilder_h.template")), |
86 os.path.getmtime(os.path.join(templates_dir, "TypeBuilder_cpp.template")
), | 100 os.path.getmtime(os.path.join(templates_dir, "TypeBuilder_cpp.template")
), |
| 101 os.path.getmtime(os.path.join(templates_dir, "Exported_h.template")), |
| 102 os.path.getmtime(os.path.join(templates_dir, "Imported_h.template")), |
87 os.path.getmtime(protocol_file)) | 103 os.path.getmtime(protocol_file)) |
88 | 104 |
89 for domain in parsed_json["domains"]: | 105 for domain in parsed_json["domains"]: |
90 name = domain["domain"] | 106 name = domain["domain"] |
91 h_path = os.path.join(output_dirname, name + ".h") | 107 paths = [] |
92 cpp_path = os.path.join(output_dirname, name + ".cpp") | 108 if name in generate_domains: |
93 if not os.path.exists(h_path) or not os.path.exists(cpp_path): | 109 paths = [os.path.join(output_dirname, name + ".h"), os.path.join(out
put_dirname, name + ".cpp")] |
94 return False | 110 if domain["has_exports"]: |
95 generated_ts = max(os.path.getmtime(h_path), os.path.getmtime(cpp_path)) | 111 paths.append(os.path.join(exported_dirname, name + ".h")) |
96 if generated_ts < template_ts: | 112 if name in include_domains and domain["has_exports"]: |
97 return False | 113 paths = [os.path.join(output_dirname, name + '.h')] |
| 114 for path in paths: |
| 115 if not os.path.exists(path): |
| 116 return False |
| 117 generated_ts = os.path.getmtime(path) |
| 118 if generated_ts < template_ts: |
| 119 return False |
98 return True | 120 return True |
99 | 121 |
100 | 122 |
101 if up_to_date(): | |
102 sys.exit() | |
103 | |
104 | |
105 def to_title_case(name): | 123 def to_title_case(name): |
106 return name[:1].upper() + name[1:] | 124 return name[:1].upper() + name[1:] |
107 | 125 |
108 | 126 |
109 def dash_to_camelcase(word): | 127 def dash_to_camelcase(word): |
110 return "".join(to_title_case(x) or "-" for x in word.split("-")) | 128 return "".join(to_title_case(x) or "-" for x in word.split("-")) |
111 | 129 |
112 | 130 |
113 def initialize_jinja_env(cache_dir): | 131 def initialize_jinja_env(cache_dir): |
114 jinja_env = jinja2.Environment( | 132 jinja_env = jinja2.Environment( |
(...skipping 22 matching lines...) Expand all Loading... |
137 if not isinstance(json, dict): | 155 if not isinstance(json, dict): |
138 return | 156 return |
139 for key in json: | 157 for key in json: |
140 if key == "type" and json[key] == "string": | 158 if key == "type" and json[key] == "string": |
141 json[key] = domain_name + ".string" | 159 json[key] = domain_name + ".string" |
142 if key != "$ref": | 160 if key != "$ref": |
143 patch_full_qualified_refs_in_domain(json[key], domain_name) | 161 patch_full_qualified_refs_in_domain(json[key], domain_name) |
144 continue | 162 continue |
145 if json["$ref"].find(".") == -1: | 163 if json["$ref"].find(".") == -1: |
146 json["$ref"] = domain_name + "." + json["$ref"] | 164 json["$ref"] = domain_name + "." + json["$ref"] |
| 165 return |
147 | 166 |
148 for domain in json_api["domains"]: | 167 for domain in json_api["domains"]: |
149 patch_full_qualified_refs_in_domain(domain, domain["domain"]) | 168 patch_full_qualified_refs_in_domain(domain, domain["domain"]) |
150 | 169 |
151 | 170 |
| 171 def calculate_exports(): |
| 172 def calculate_exports_in_json(json_value): |
| 173 has_exports = False |
| 174 if isinstance(json_value, list): |
| 175 for item in json_value: |
| 176 has_exports = calculate_exports_in_json(item) or has_exports |
| 177 if isinstance(json_value, dict): |
| 178 has_exports = ("exported" in json_value and json_value["exported"])
or has_exports |
| 179 for key in json_value: |
| 180 has_exports = calculate_exports_in_json(json_value[key]) or has_
exports |
| 181 return has_exports |
| 182 |
| 183 json_api["has_exports"] = False |
| 184 for domain_json in json_api["domains"]: |
| 185 domain_json["has_exports"] = calculate_exports_in_json(domain_json) |
| 186 json_api["has_exports"] = json_api["has_exports"] or domain_json["has_ex
ports"] |
| 187 |
| 188 |
| 189 def create_include_type_definition(domain_name, type): |
| 190 # pylint: disable=W0622 |
| 191 return { |
| 192 "return_type": "std::unique_ptr<protocol::%s::API::%s>" % (domain_name,
type["id"]), |
| 193 "pass_type": "std::unique_ptr<protocol::%s::API::%s>" % (domain_name, ty
pe["id"]), |
| 194 "to_raw_type": "%s.get()", |
| 195 "to_pass_type": "std::move(%s)", |
| 196 "to_rvalue": "std::move(%s)", |
| 197 "type": "std::unique_ptr<protocol::%s::API::%s>" % (domain_name, type["i
d"]), |
| 198 "raw_type": "protocol::%s::API::%s" % (domain_name, type["id"]), |
| 199 "raw_pass_type": "protocol::%s::API::%s*" % (domain_name, type["id"]), |
| 200 "raw_return_type": "protocol::%s::API::%s*" % (domain_name, type["id"]), |
| 201 } |
| 202 |
| 203 |
152 def create_user_type_definition(domain_name, type): | 204 def create_user_type_definition(domain_name, type): |
| 205 # pylint: disable=W0622 |
153 return { | 206 return { |
154 "return_type": "std::unique_ptr<protocol::%s::%s>" % (domain_name, type[
"id"]), | 207 "return_type": "std::unique_ptr<protocol::%s::%s>" % (domain_name, type[
"id"]), |
155 "pass_type": "std::unique_ptr<protocol::%s::%s>" % (domain_name, type["i
d"]), | 208 "pass_type": "std::unique_ptr<protocol::%s::%s>" % (domain_name, type["i
d"]), |
156 "to_raw_type": "%s.get()", | 209 "to_raw_type": "%s.get()", |
157 "to_pass_type": "std::move(%s)", | 210 "to_pass_type": "std::move(%s)", |
158 "to_rvalue": "std::move(%s)", | 211 "to_rvalue": "std::move(%s)", |
159 "type": "std::unique_ptr<protocol::%s::%s>" % (domain_name, type["id"]), | 212 "type": "std::unique_ptr<protocol::%s::%s>" % (domain_name, type["id"]), |
160 "raw_type": "protocol::%s::%s" % (domain_name, type["id"]), | 213 "raw_type": "protocol::%s::%s" % (domain_name, type["id"]), |
161 "raw_pass_type": "protocol::%s::%s*" % (domain_name, type["id"]), | 214 "raw_pass_type": "protocol::%s::%s*" % (domain_name, type["id"]), |
162 "raw_return_type": "protocol::%s::%s*" % (domain_name, type["id"]), | 215 "raw_return_type": "protocol::%s::%s*" % (domain_name, type["id"]), |
163 } | 216 } |
164 | 217 |
165 | 218 |
166 def create_object_type_definition(): | 219 def create_object_type_definition(): |
| 220 # pylint: disable=W0622 |
167 return { | 221 return { |
168 "return_type": "std::unique_ptr<protocol::DictionaryValue>", | 222 "return_type": "std::unique_ptr<protocol::DictionaryValue>", |
169 "pass_type": "std::unique_ptr<protocol::DictionaryValue>", | 223 "pass_type": "std::unique_ptr<protocol::DictionaryValue>", |
170 "to_raw_type": "%s.get()", | 224 "to_raw_type": "%s.get()", |
171 "to_pass_type": "std::move(%s)", | 225 "to_pass_type": "std::move(%s)", |
172 "to_rvalue": "std::move(%s)", | 226 "to_rvalue": "std::move(%s)", |
173 "type": "std::unique_ptr<protocol::DictionaryValue>", | 227 "type": "std::unique_ptr<protocol::DictionaryValue>", |
174 "raw_type": "protocol::DictionaryValue", | 228 "raw_type": "protocol::DictionaryValue", |
175 "raw_pass_type": "protocol::DictionaryValue*", | 229 "raw_pass_type": "protocol::DictionaryValue*", |
176 "raw_return_type": "protocol::DictionaryValue*", | 230 "raw_return_type": "protocol::DictionaryValue*", |
177 } | 231 } |
178 | 232 |
179 | 233 |
180 def create_any_type_definition(): | 234 def create_any_type_definition(): |
| 235 # pylint: disable=W0622 |
181 return { | 236 return { |
182 "return_type": "std::unique_ptr<protocol::Value>", | 237 "return_type": "std::unique_ptr<protocol::Value>", |
183 "pass_type": "std::unique_ptr<protocol::Value>", | 238 "pass_type": "std::unique_ptr<protocol::Value>", |
184 "to_raw_type": "%s.get()", | 239 "to_raw_type": "%s.get()", |
185 "to_pass_type": "std::move(%s)", | 240 "to_pass_type": "std::move(%s)", |
186 "to_rvalue": "std::move(%s)", | 241 "to_rvalue": "std::move(%s)", |
187 "type": "std::unique_ptr<protocol::Value>", | 242 "type": "std::unique_ptr<protocol::Value>", |
188 "raw_type": "protocol::Value", | 243 "raw_type": "protocol::Value", |
189 "raw_pass_type": "protocol::Value*", | 244 "raw_pass_type": "protocol::Value*", |
190 "raw_return_type": "protocol::Value*", | 245 "raw_return_type": "protocol::Value*", |
191 } | 246 } |
192 | 247 |
193 | 248 |
194 def create_string_type_definition(domain): | 249 def create_string_type_definition(domain): |
| 250 # pylint: disable=W0622 |
195 return { | 251 return { |
196 "return_type": string_type, | 252 "return_type": string_type, |
197 "pass_type": ("const %s&" % string_type), | 253 "pass_type": ("const %s&" % string_type), |
198 "to_pass_type": "%s", | 254 "to_pass_type": "%s", |
199 "to_raw_type": "%s", | 255 "to_raw_type": "%s", |
200 "to_rvalue": "%s", | 256 "to_rvalue": "%s", |
201 "type": string_type, | 257 "type": string_type, |
202 "raw_type": string_type, | 258 "raw_type": string_type, |
203 "raw_pass_type": ("const %s&" % string_type), | 259 "raw_pass_type": ("const %s&" % string_type), |
204 "raw_return_type": string_type, | 260 "raw_return_type": string_type, |
205 } | 261 } |
206 | 262 |
207 | 263 |
208 def create_primitive_type_definition(type): | 264 def create_primitive_type_definition(type): |
| 265 # pylint: disable=W0622 |
209 typedefs = { | 266 typedefs = { |
210 "number": "double", | 267 "number": "double", |
211 "integer": "int", | 268 "integer": "int", |
212 "boolean": "bool" | 269 "boolean": "bool" |
213 } | 270 } |
214 defaults = { | 271 defaults = { |
215 "number": "0", | 272 "number": "0", |
216 "integer": "0", | 273 "integer": "0", |
217 "boolean": "false" | 274 "boolean": "false" |
218 } | 275 } |
(...skipping 18 matching lines...) Expand all Loading... |
237 | 294 |
238 type_definitions = {} | 295 type_definitions = {} |
239 type_definitions["number"] = create_primitive_type_definition("number") | 296 type_definitions["number"] = create_primitive_type_definition("number") |
240 type_definitions["integer"] = create_primitive_type_definition("integer") | 297 type_definitions["integer"] = create_primitive_type_definition("integer") |
241 type_definitions["boolean"] = create_primitive_type_definition("boolean") | 298 type_definitions["boolean"] = create_primitive_type_definition("boolean") |
242 type_definitions["object"] = create_object_type_definition() | 299 type_definitions["object"] = create_object_type_definition() |
243 type_definitions["any"] = create_any_type_definition() | 300 type_definitions["any"] = create_any_type_definition() |
244 | 301 |
245 | 302 |
246 def wrap_array_definition(type): | 303 def wrap_array_definition(type): |
| 304 # pylint: disable=W0622 |
247 return { | 305 return { |
248 "return_type": "std::unique_ptr<protocol::Array<%s>>" % type["raw_type"]
, | 306 "return_type": "std::unique_ptr<protocol::Array<%s>>" % type["raw_type"]
, |
249 "pass_type": "std::unique_ptr<protocol::Array<%s>>" % type["raw_type"], | 307 "pass_type": "std::unique_ptr<protocol::Array<%s>>" % type["raw_type"], |
250 "to_raw_type": "%s.get()", | 308 "to_raw_type": "%s.get()", |
251 "to_pass_type": "std::move(%s)", | 309 "to_pass_type": "std::move(%s)", |
252 "to_rvalue": "std::move(%s)", | 310 "to_rvalue": "std::move(%s)", |
253 "type": "std::unique_ptr<protocol::Array<%s>>" % type["raw_type"], | 311 "type": "std::unique_ptr<protocol::Array<%s>>" % type["raw_type"], |
254 "raw_type": "protocol::Array<%s>" % type["raw_type"], | 312 "raw_type": "protocol::Array<%s>" % type["raw_type"], |
255 "raw_pass_type": "protocol::Array<%s>*" % type["raw_type"], | 313 "raw_pass_type": "protocol::Array<%s>*" % type["raw_type"], |
256 "raw_return_type": "protocol::Array<%s>*" % type["raw_type"], | 314 "raw_return_type": "protocol::Array<%s>*" % type["raw_type"], |
257 "create_type": "wrapUnique(new protocol::Array<%s>())" % type["raw_type"
], | 315 "create_type": "wrapUnique(new protocol::Array<%s>())" % type["raw_type"
], |
258 "out_type": "protocol::Array<%s>&" % type["raw_type"], | 316 "out_type": "protocol::Array<%s>&" % type["raw_type"], |
259 } | 317 } |
260 | 318 |
261 | 319 |
262 def create_type_definitions(): | 320 def create_type_definitions(): |
263 for domain in json_api["domains"]: | 321 for domain in json_api["domains"]: |
264 type_definitions[domain["domain"] + ".string"] = create_string_type_defi
nition(domain["domain"]) | 322 type_definitions[domain["domain"] + ".string"] = create_string_type_defi
nition(domain["domain"]) |
265 if not ("types" in domain): | 323 if not ("types" in domain): |
266 continue | 324 continue |
267 for type in domain["types"]: | 325 for type in domain["types"]: |
268 if type["type"] == "object": | 326 type_name = domain["domain"] + "." + type["id"] |
269 type_definitions[domain["domain"] + "." + type["id"]] = create_u
ser_type_definition(domain["domain"], type) | 327 if type["type"] == "object" and domain["domain"] in include_domains: |
| 328 type_definitions[type_name] = create_include_type_definition(dom
ain["domain"], type) |
| 329 elif type["type"] == "object": |
| 330 type_definitions[type_name] = create_user_type_definition(domain
["domain"], type) |
270 elif type["type"] == "array": | 331 elif type["type"] == "array": |
271 items_type = type["items"]["type"] | 332 items_type = type["items"]["type"] |
272 type_definitions[domain["domain"] + "." + type["id"]] = wrap_arr
ay_definition(type_definitions[items_type]) | 333 type_definitions[type_name] = wrap_array_definition(type_definit
ions[items_type]) |
273 elif type["type"] == domain["domain"] + ".string": | 334 elif type["type"] == domain["domain"] + ".string": |
274 type_definitions[domain["domain"] + "." + type["id"]] = create_s
tring_type_definition(domain["domain"]) | 335 type_definitions[type_name] = create_string_type_definition(doma
in["domain"]) |
275 else: | 336 else: |
276 type_definitions[domain["domain"] + "." + type["id"]] = create_p
rimitive_type_definition(type["type"]) | 337 type_definitions[type_name] = create_primitive_type_definition(t
ype["type"]) |
277 | 338 |
278 | 339 |
279 def type_definition(name): | 340 def type_definition(name): |
280 return type_definitions[name] | 341 return type_definitions[name] |
281 | 342 |
282 | 343 |
283 def resolve_type(property): | 344 def resolve_type(property): |
284 if "$ref" in property: | 345 if "$ref" in property: |
285 return type_definitions[property["$ref"]] | 346 return type_definitions[property["$ref"]] |
286 if property["type"] == "array": | 347 if property["type"] == "array": |
287 return wrap_array_definition(resolve_type(property["items"])) | 348 return wrap_array_definition(resolve_type(property["items"])) |
288 return type_definitions[property["type"]] | 349 return type_definitions[property["type"]] |
289 | 350 |
290 | 351 |
291 def join_arrays(dict, keys): | 352 def join_arrays(dict, keys): |
292 result = [] | 353 result = [] |
293 for key in keys: | 354 for key in keys: |
294 if key in dict: | 355 if key in dict: |
295 result += dict[key] | 356 result += dict[key] |
296 return result | 357 return result |
297 | 358 |
298 | 359 |
299 def has_disable(commands): | 360 def has_disable(commands): |
300 for command in commands: | 361 for command in commands: |
301 if command["name"] == "disable": | 362 if command["name"] == "disable": |
302 return True | 363 return True |
303 return False | 364 return False |
304 | 365 |
305 | 366 |
| 367 def generate(domain_object, template, file_name): |
| 368 template_context = { |
| 369 "domain": domain_object, |
| 370 "join_arrays": join_arrays, |
| 371 "resolve_type": resolve_type, |
| 372 "type_definition": type_definition, |
| 373 "has_disable": has_disable, |
| 374 "export_macro": export_macro, |
| 375 "output_package": output_package, |
| 376 "exported_package": exported_package, |
| 377 "include_package": include_package |
| 378 } |
| 379 out_file = output_file(file_name) |
| 380 out_file.write(template.render(template_context)) |
| 381 out_file.close() |
| 382 |
| 383 |
306 generate_domains = [] | 384 generate_domains = [] |
| 385 include_domains = [] |
307 json_api = {} | 386 json_api = {} |
308 json_api["domains"] = parsed_json["domains"] | 387 json_api["domains"] = parsed_json["domains"] |
309 | 388 |
310 for domain in parsed_json["domains"]: | 389 for domain in parsed_json["domains"]: |
311 generate_domains.append(domain["domain"]) | 390 generate_domains.append(domain["domain"]) |
312 | 391 |
313 if include_file: | 392 if include_file: |
314 input_file = open(include_file, "r") | 393 input_file = open(include_file, "r") |
315 json_string = input_file.read() | 394 json_string = input_file.read() |
316 parsed_json = json.loads(json_string) | 395 parsed_json = json.loads(json_string) |
| 396 for domain in parsed_json["domains"]: |
| 397 include_domains.append(domain["domain"]) |
317 json_api["domains"] += parsed_json["domains"] | 398 json_api["domains"] += parsed_json["domains"] |
318 | 399 |
319 | |
320 patch_full_qualified_refs() | 400 patch_full_qualified_refs() |
| 401 calculate_exports() |
321 create_type_definitions() | 402 create_type_definitions() |
322 | 403 |
| 404 if up_to_date(): |
| 405 sys.exit() |
323 if not os.path.exists(output_dirname): | 406 if not os.path.exists(output_dirname): |
324 os.mkdir(output_dirname) | 407 os.mkdir(output_dirname) |
| 408 if json_api["has_exports"] and not os.path.exists(exported_dirname): |
| 409 os.mkdir(exported_dirname) |
| 410 |
325 jinja_env = initialize_jinja_env(output_dirname) | 411 jinja_env = initialize_jinja_env(output_dirname) |
326 | 412 h_template = jinja_env.get_template("/TypeBuilder_h.template") |
327 h_template_name = "/TypeBuilder_h.template" | 413 cpp_template = jinja_env.get_template("/TypeBuilder_cpp.template") |
328 cpp_template_name = "/TypeBuilder_cpp.template" | 414 exported_template = jinja_env.get_template("/Exported_h.template") |
329 h_template = jinja_env.get_template(h_template_name) | 415 imported_template = jinja_env.get_template("/Imported_h.template") |
330 cpp_template = jinja_env.get_template(cpp_template_name) | |
331 | |
332 | |
333 def generate(domain): | |
334 class_name = domain["domain"] | |
335 h_file_name = output_dirname + "/" + class_name + ".h" | |
336 cpp_file_name = output_dirname + "/" + class_name + ".cpp" | |
337 | |
338 template_context = { | |
339 "domain": domain, | |
340 "join_arrays": join_arrays, | |
341 "resolve_type": resolve_type, | |
342 "type_definition": type_definition, | |
343 "has_disable": has_disable, | |
344 "export_macro": export_macro, | |
345 "output_package": output_package, | |
346 } | |
347 h_file = output_file(h_file_name) | |
348 cpp_file = output_file(cpp_file_name) | |
349 h_file.write(h_template.render(template_context)) | |
350 cpp_file.write(cpp_template.render(template_context)) | |
351 h_file.close() | |
352 cpp_file.close() | |
353 | |
354 | 416 |
355 for domain in json_api["domains"]: | 417 for domain in json_api["domains"]: |
| 418 class_name = domain["domain"] |
356 if domain["domain"] in generate_domains: | 419 if domain["domain"] in generate_domains: |
357 generate(domain) | 420 generate(domain, h_template, output_dirname + "/" + class_name + ".h") |
| 421 generate(domain, cpp_template, output_dirname + "/" + class_name + ".cpp
") |
| 422 if domain["has_exports"]: |
| 423 generate(domain, exported_template, exported_dirname + "/" + class_n
ame + ".h") |
| 424 if domain["domain"] in include_domains and domain["has_exports"]: |
| 425 generate(domain, imported_template, output_dirname + "/" + class_name +
".h") |
OLD | NEW |