| 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 |
| 332 def join_arrays(dict, keys): | 337 def join_arrays(dict, keys): |
| 333 result = [] | 338 result = [] |
| 334 for key in keys: | 339 for key in keys: |
| 335 if key in dict: | 340 if key in dict: |
| 336 result += dict[key] | 341 result += dict[key] |
| 337 return result | 342 return result |
| 338 | 343 |
| 339 | 344 |
| 340 def has_disable(commands): | 345 def has_disable(commands): |
| 341 for command in commands: | 346 for command in commands: |
| 342 if command["name"] == "disable": | 347 if command["name"] == "disable" and (not ("handlers" in command) or "ren
derer" in command["handlers"]): |
| 343 return True | 348 return True |
| 344 return False | 349 return False |
| 345 | 350 |
| 346 | 351 |
| 347 def format_include(header): | 352 def format_include(header): |
| 348 return "\"" + header + "\"" if header[0] not in "<\"" else header | 353 return "\"" + header + "\"" if header[0] not in "<\"" else header |
| 349 | 354 |
| 350 | 355 |
| 351 def read_protocol_file(file_name, json_api): | 356 def read_protocol_file(file_name, json_api): |
| 352 input_file = open(file_name, "r") | 357 input_file = open(file_name, "r") |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 for domain in protocol.json_api["domains"]: | 419 for domain in protocol.json_api["domains"]: |
| 415 class_name = domain["domain"] | 420 class_name = domain["domain"] |
| 416 template_context = { | 421 template_context = { |
| 417 "config": config, | 422 "config": config, |
| 418 "domain": domain, | 423 "domain": domain, |
| 419 "join_arrays": join_arrays, | 424 "join_arrays": join_arrays, |
| 420 "resolve_type": functools.partial(resolve_type, protocol), | 425 "resolve_type": functools.partial(resolve_type, protocol), |
| 421 "type_definition": functools.partial(type_definition, protocol), | 426 "type_definition": functools.partial(type_definition, protocol), |
| 422 "has_disable": has_disable, | 427 "has_disable": has_disable, |
| 423 "format_include": format_include, | 428 "format_include": format_include, |
| 429 "new_style": new_style, |
| 424 } | 430 } |
| 425 | 431 |
| 426 if domain["domain"] in protocol.generate_domains: | 432 if domain["domain"] in protocol.generate_domains: |
| 427 outputs[os.path.join(config.protocol.output, class_name + ".h")] = h
_template.render(template_context) | 433 outputs[os.path.join(config.protocol.output, class_name + ".h")] = h
_template.render(template_context) |
| 428 outputs[os.path.join(config.protocol.output, class_name + ".cpp")] =
cpp_template.render(template_context) | 434 outputs[os.path.join(config.protocol.output, class_name + ".cpp")] =
cpp_template.render(template_context) |
| 429 if domain["has_exports"]: | 435 if domain["has_exports"]: |
| 430 outputs[os.path.join(config.exported.output, class_name + ".h")]
= exported_template.render(template_context) | 436 outputs[os.path.join(config.exported.output, class_name + ".h")]
= exported_template.render(template_context) |
| 431 if domain["domain"] in protocol.imported_domains and domain["has_exports
"]: | 437 if domain["domain"] in protocol.imported_domains and domain["has_exports
"]: |
| 432 outputs[os.path.join(config.protocol.output, class_name + ".h")] = i
mported_template.render(template_context) | 438 outputs[os.path.join(config.protocol.output, class_name + ".h")] = i
mported_template.render(template_context) |
| 433 | 439 |
| 434 if config.lib: | 440 if config.lib: |
| 435 template_context = { | 441 template_context = { |
| 436 "config": config, | 442 "config": config, |
| 437 "format_include": format_include, | 443 "format_include": format_include, |
| 438 } | 444 } |
| 439 | 445 |
| 440 lib_templates_dir = os.path.join(module_path, "lib") | 446 lib_templates_dir = os.path.join(module_path, "lib") |
| 441 # Note these should be sorted in the right order. | 447 # Note these should be sorted in the right order. |
| 442 # TODO(dgozman): sort them programmatically based on commented includes. | 448 # TODO(dgozman): sort them programmatically based on commented includes. |
| 443 lib_h_templates = [ | 449 lib_h_templates = [ |
| 444 "Collections_h.template", | 450 "Collections_h.template", |
| 445 "ErrorSupport_h.template", | 451 "ErrorSupport_h.template", |
| 446 "Values_h.template", | 452 "Values_h.template", |
| 447 "Object_h.template", | 453 "Object_h.template", |
| 448 "ValueConversions_h.template", | 454 "ValueConversions_h.template", |
| 449 "Maybe_h.template", | 455 "Maybe_h.template", |
| 450 "Array_h.template", | 456 "Array_h.template", |
| 451 "BackendCallback_h.template", | |
| 452 "DispatcherBase_h.template", | 457 "DispatcherBase_h.template", |
| 453 "Parser_h.template", | 458 "Parser_h.template", |
| 454 ] | 459 ] |
| 455 | 460 |
| 456 lib_cpp_templates = [ | 461 lib_cpp_templates = [ |
| 457 "Protocol_cpp.template", | 462 "Protocol_cpp.template", |
| 458 "ErrorSupport_cpp.template", | 463 "ErrorSupport_cpp.template", |
| 459 "Values_cpp.template", | 464 "Values_cpp.template", |
| 460 "Object_cpp.template", | 465 "Object_cpp.template", |
| 461 "DispatcherBase_cpp.template", | 466 "DispatcherBase_cpp.template", |
| (...skipping 28 matching lines...) Expand all Loading... |
| 490 if up_to_date: | 495 if up_to_date: |
| 491 sys.exit() | 496 sys.exit() |
| 492 | 497 |
| 493 for file_name, content in outputs.iteritems(): | 498 for file_name, content in outputs.iteritems(): |
| 494 out_file = open(file_name, "w") | 499 out_file = open(file_name, "w") |
| 495 out_file.write(content) | 500 out_file.write(content) |
| 496 out_file.close() | 501 out_file.close() |
| 497 | 502 |
| 498 | 503 |
| 499 main() | 504 main() |
| OLD | NEW |