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 import collections | 8 import collections |
9 import functools | 9 import functools |
10 try: | 10 try: |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 | 322 |
323 | 323 |
324 def resolve_type(protocol, prop): | 324 def resolve_type(protocol, prop): |
325 if "$ref" in prop: | 325 if "$ref" in prop: |
326 return protocol.type_definitions[prop["$ref"]] | 326 return protocol.type_definitions[prop["$ref"]] |
327 if prop["type"] == "array": | 327 if prop["type"] == "array": |
328 return wrap_array_definition(resolve_type(protocol, prop["items"])) | 328 return wrap_array_definition(resolve_type(protocol, prop["items"])) |
329 return protocol.type_definitions[prop["type"]] | 329 return protocol.type_definitions[prop["type"]] |
330 | 330 |
331 | 331 |
332 def new_style(domain): | |
333 domains = [] | |
334 return domain["domain"] in domains | |
335 | |
336 | |
337 def join_arrays(dict, keys): | 332 def join_arrays(dict, keys): |
338 result = [] | 333 result = [] |
339 for key in keys: | 334 for key in keys: |
340 if key in dict: | 335 if key in dict: |
341 result += dict[key] | 336 result += dict[key] |
342 return result | 337 return result |
343 | 338 |
344 | 339 |
345 def has_disable(commands): | 340 def has_disable(commands): |
346 for command in commands: | 341 for command in commands: |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 | 413 |
419 for domain in protocol.json_api["domains"]: | 414 for domain in protocol.json_api["domains"]: |
420 class_name = domain["domain"] | 415 class_name = domain["domain"] |
421 template_context = { | 416 template_context = { |
422 "config": config, | 417 "config": config, |
423 "domain": domain, | 418 "domain": domain, |
424 "join_arrays": join_arrays, | 419 "join_arrays": join_arrays, |
425 "resolve_type": functools.partial(resolve_type, protocol), | 420 "resolve_type": functools.partial(resolve_type, protocol), |
426 "type_definition": functools.partial(type_definition, protocol), | 421 "type_definition": functools.partial(type_definition, protocol), |
427 "has_disable": has_disable, | 422 "has_disable": has_disable, |
428 "format_include": format_include, | 423 "format_include": format_include |
429 "new_style": new_style, | |
430 } | 424 } |
431 | 425 |
432 if domain["domain"] in protocol.generate_domains: | 426 if domain["domain"] in protocol.generate_domains: |
433 outputs[os.path.join(config.protocol.output, class_name + ".h")] = h
_template.render(template_context) | 427 outputs[os.path.join(config.protocol.output, class_name + ".h")] = h
_template.render(template_context) |
434 outputs[os.path.join(config.protocol.output, class_name + ".cpp")] =
cpp_template.render(template_context) | 428 outputs[os.path.join(config.protocol.output, class_name + ".cpp")] =
cpp_template.render(template_context) |
435 if domain["has_exports"]: | 429 if domain["has_exports"]: |
436 outputs[os.path.join(config.exported.output, class_name + ".h")]
= exported_template.render(template_context) | 430 outputs[os.path.join(config.exported.output, class_name + ".h")]
= exported_template.render(template_context) |
437 if domain["domain"] in protocol.imported_domains and domain["has_exports
"]: | 431 if domain["domain"] in protocol.imported_domains and domain["has_exports
"]: |
438 outputs[os.path.join(config.protocol.output, class_name + ".h")] = i
mported_template.render(template_context) | 432 outputs[os.path.join(config.protocol.output, class_name + ".h")] = i
mported_template.render(template_context) |
439 | 433 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 if up_to_date: | 489 if up_to_date: |
496 sys.exit() | 490 sys.exit() |
497 | 491 |
498 for file_name, content in outputs.iteritems(): | 492 for file_name, content in outputs.iteritems(): |
499 out_file = open(file_name, "w") | 493 out_file = open(file_name, "w") |
500 out_file.write(content) | 494 out_file.write(content) |
501 out_file.close() | 495 out_file.close() |
502 | 496 |
503 | 497 |
504 main() | 498 main() |
OLD | NEW |