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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 exported_domains = protocol.generate_domains | 194 exported_domains = protocol.generate_domains |
194 | 195 |
195 protocol.imported_domains = [] | 196 protocol.imported_domains = [] |
196 protocol.exported_domains = [] | 197 protocol.exported_domains = [] |
197 for domain_json in protocol.json_api["domains"]: | 198 for domain_json in protocol.json_api["domains"]: |
198 domain = domain_json["domain"] | 199 domain = domain_json["domain"] |
199 clear = domain not in exported_domains and domain not in imported_domain
s | 200 clear = domain not in exported_domains and domain not in imported_domain
s |
200 if not has_exports(domain_json, clear): | 201 if not has_exports(domain_json, clear): |
201 continue | 202 continue |
202 if domain in exported_domains: | 203 if domain in exported_domains: |
| 204 domain_json["has_exports"] = True |
203 protocol.exported_domains.append(domain) | 205 protocol.exported_domains.append(domain) |
204 if domain in imported_domains: | 206 if domain in imported_domains: |
205 protocol.imported_domains.append(domain) | 207 protocol.imported_domains.append(domain) |
206 | 208 |
207 | 209 |
208 def create_imported_type_definition(domain_name, type, imported_namespace): | 210 def create_imported_type_definition(domain_name, type, imported_namespace): |
209 # pylint: disable=W0622 | 211 # pylint: disable=W0622 |
210 return { | 212 return { |
211 "return_type": "std::unique_ptr<%s::%s::API::%s>" % (imported_namespace,
domain_name, type["id"]), | 213 "return_type": "std::unique_ptr<%s::%s::API::%s>" % (imported_namespace,
domain_name, type["id"]), |
212 "pass_type": "std::unique_ptr<%s::%s::API::%s>" % (imported_namespace, d
omain_name, type["id"]), | 214 "pass_type": "std::unique_ptr<%s::%s::API::%s>" % (imported_namespace, d
omain_name, type["id"]), |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 | 463 |
462 def main(): | 464 def main(): |
463 jinja_dir, config_file, config = read_config() | 465 jinja_dir, config_file, config = read_config() |
464 | 466 |
465 protocol = Protocol() | 467 protocol = Protocol() |
466 protocol.json_api = {"domains": []} | 468 protocol.json_api = {"domains": []} |
467 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) |
468 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 [] |
469 patch_full_qualified_refs(protocol) | 471 patch_full_qualified_refs(protocol) |
470 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 |
471 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 "") |
472 | 488 |
473 if not config.exported and len(protocol.exported_domains): | 489 if not config.exported and len(protocol.exported_domains): |
474 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)) |
475 exit(1) | 491 exit(1) |
476 | 492 |
477 if not os.path.exists(config.protocol.output): | 493 if not os.path.exists(config.protocol.output): |
478 os.mkdir(config.protocol.output) | 494 os.mkdir(config.protocol.output) |
479 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): |
480 os.mkdir(config.exported.output) | 496 os.mkdir(config.exported.output) |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 if up_to_date: | 596 if up_to_date: |
581 sys.exit() | 597 sys.exit() |
582 | 598 |
583 for file_name, content in outputs.iteritems(): | 599 for file_name, content in outputs.iteritems(): |
584 out_file = open(file_name, "w") | 600 out_file = open(file_name, "w") |
585 out_file.write(content) | 601 out_file.write(content) |
586 out_file.close() | 602 out_file.close() |
587 | 603 |
588 | 604 |
589 main() | 605 main() |
OLD | NEW |