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 import re | 10 import re |
| 11 import copy |
11 try: | 12 try: |
12 import json | 13 import json |
13 except ImportError: | 14 except ImportError: |
14 import simplejson as json | 15 import simplejson as json |
15 | 16 |
16 # Path handling for libraries and templates | 17 # Path handling for libraries and templates |
17 # Paths have to be normalized because Jinja uses the exact template path to | 18 # Paths have to be normalized because Jinja uses the exact template path to |
18 # determine the hash used in the cache filename, and we need a pre-caching step | 19 # determine the hash used in the cache filename, and we need a pre-caching step |
19 # to be concurrency-safe. Use absolute path because __file__ is absolute if | 20 # to be concurrency-safe. Use absolute path because __file__ is absolute if |
20 # module is imported, and relative if executed directly. | 21 # module is imported, and relative if executed directly. |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 | 463 |
463 def main(): | 464 def main(): |
464 jinja_dir, config_file, config = read_config() | 465 jinja_dir, config_file, config = read_config() |
465 | 466 |
466 protocol = Protocol() | 467 protocol = Protocol() |
467 protocol.json_api = {"domains": []} | 468 protocol.json_api = {"domains": []} |
468 protocol.generate_domains = read_protocol_file(config.protocol.path, protoco
l.json_api) | 469 protocol.generate_domains = read_protocol_file(config.protocol.path, protoco
l.json_api) |
469 protocol.imported_domains = read_protocol_file(config.imported.path, protoco
l.json_api) if config.imported else [] | 470 protocol.imported_domains = read_protocol_file(config.imported.path, protoco
l.json_api) if config.imported else [] |
470 patch_full_qualified_refs(protocol) | 471 patch_full_qualified_refs(protocol) |
471 calculate_imports_and_exports(config, protocol) | 472 calculate_imports_and_exports(config, protocol) |
| 473 |
| 474 for domain in protocol.json_api["domains"]: |
| 475 if "events" in domain: |
| 476 for event in domain["events"]: |
| 477 event_type = dict() |
| 478 event_type["description"] = "Wrapper for notification params" |
| 479 event_type["type"] = "object" |
| 480 event_type["id"] = to_title_case(event["name"]) + "Notification" |
| 481 if "parameters" in event: |
| 482 event_type["properties"] = copy.deepcopy(event["parameters"]
) |
| 483 if "types" not in domain: |
| 484 domain["types"] = list() |
| 485 domain["types"].append(event_type) |
| 486 |
472 create_type_definitions(protocol, "::".join(config.imported.namespace) if co
nfig.imported else "") | 487 create_type_definitions(protocol, "::".join(config.imported.namespace) if co
nfig.imported else "") |
473 | 488 |
474 if not config.exported and len(protocol.exported_domains): | 489 if not config.exported and len(protocol.exported_domains): |
475 sys.stderr.write("Domains [%s] are exported, but config is missing expor
t entry\n\n" % ", ".join(protocol.exported_domains)) | 490 sys.stderr.write("Domains [%s] are exported, but config is missing expor
t entry\n\n" % ", ".join(protocol.exported_domains)) |
476 exit(1) | 491 exit(1) |
477 | 492 |
478 if not os.path.exists(config.protocol.output): | 493 if not os.path.exists(config.protocol.output): |
479 os.mkdir(config.protocol.output) | 494 os.mkdir(config.protocol.output) |
480 if len(protocol.exported_domains) and not os.path.exists(config.exported.out
put): | 495 if len(protocol.exported_domains) and not os.path.exists(config.exported.out
put): |
481 os.mkdir(config.exported.output) | 496 os.mkdir(config.exported.output) |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 if up_to_date: | 596 if up_to_date: |
582 sys.exit() | 597 sys.exit() |
583 | 598 |
584 for file_name, content in outputs.iteritems(): | 599 for file_name, content in outputs.iteritems(): |
585 out_file = open(file_name, "w") | 600 out_file = open(file_name, "w") |
586 out_file.write(content) | 601 out_file.write(content) |
587 out_file.close() | 602 out_file.close() |
588 | 603 |
589 | 604 |
590 main() | 605 main() |
OLD | NEW |