Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(205)

Side by Side Diff: third_party/inspector_protocol/CodeGenerator.py

Issue 2475663004: [DevTools] Roll third_party/inspector_protocol to 3c6f5ff8ab6653b47cf226233d488701a527d761. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 config_partial = json_to_object(config_json_string, output_base, config_ base) 75 config_partial = json_to_object(config_json_string, output_base, config_ base)
76 config_json_file.close() 76 config_json_file.close()
77 defaults = { 77 defaults = {
78 ".imported": False, 78 ".imported": False,
79 ".imported.export_macro": "", 79 ".imported.export_macro": "",
80 ".imported.export_header": False, 80 ".imported.export_header": False,
81 ".imported.header": False, 81 ".imported.header": False,
82 ".imported.package": False, 82 ".imported.package": False,
83 ".protocol.export_macro": "", 83 ".protocol.export_macro": "",
84 ".protocol.export_header": False, 84 ".protocol.export_header": False,
85 ".protocol.options": False,
85 ".exported": False, 86 ".exported": False,
86 ".exported.export_macro": "", 87 ".exported.export_macro": "",
87 ".exported.export_header": False, 88 ".exported.export_header": False,
88 ".lib": False, 89 ".lib": False,
89 ".lib.export_macro": "", 90 ".lib.export_macro": "",
90 ".lib.export_header": False, 91 ".lib.export_header": False,
91 } 92 }
92 return (jinja_dir, config_file, init_defaults(config_partial, "", defaul ts)) 93 return (jinja_dir, config_file, init_defaults(config_partial, "", defaul ts))
93 except Exception: 94 except Exception:
94 # Work with python 2 and 3 http://docs.python.org/py3k/howto/pyporting.h tml 95 # Work with python 2 and 3 http://docs.python.org/py3k/howto/pyporting.h tml
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 331
331 332
332 def join_arrays(dict, keys): 333 def join_arrays(dict, keys):
333 result = [] 334 result = []
334 for key in keys: 335 for key in keys:
335 if key in dict: 336 if key in dict:
336 result += dict[key] 337 result += dict[key]
337 return result 338 return result
338 339
339 340
340 def has_disable(commands): 341 def entity_options(protocol, config, domain, entity, entity_name):
341 for command in commands: 342 def update(generate, async, rule, property, suffix):
342 if command["name"] == "disable" and (not ("handlers" in command) or "ren derer" in command["handlers"]): 343 if not hasattr(rule, property):
343 return True 344 return generate, async
344 return False 345 value = getattr(rule, property)
346 if value == "+" + suffix:
347 generate = True
348 if hasattr(rule, "async"):
349 async = getattr(rule, "async")
350 if value == "-" + suffix:
351 generate = False
352 return generate, async
353
354 if not config.protocol.options:
355 return (domain in protocol.generate_domain, False)
356
357 generate, async = False, False
358 for rule in config.protocol.options:
359 generate, async = update(generate, async, rule, "domain", domain)
360 generate, async = update(generate, async, rule, entity, domain + "." + e ntity_name)
361 return generate, async
362
363
364 def generate_command(protocol, config, domain, command):
365 generate, _ = entity_options(protocol, config, domain, "command", command)
366 return generate
367
368
369 def generate_event(protocol, config, domain, event):
370 generate, _ = entity_options(protocol, config, domain, "event", event)
371 return generate
372
373
374 def is_async_command(protocol, config, domain, command):
375 _, async = entity_options(protocol, config, domain, "command", command)
376 return async
377
378
379 def generate_disable(protocol, config, domain):
380 if "commands" not in domain:
381 return True
382 for command in domain["commands"]:
383 if command["name"] == "disable" and generate_command(protocol, config, d omain["domain"], "disable"):
384 return False
385 return True
345 386
346 387
347 def format_include(header): 388 def format_include(header):
348 return "\"" + header + "\"" if header[0] not in "<\"" else header 389 return "\"" + header + "\"" if header[0] not in "<\"" else header
349 390
350 391
351 def read_protocol_file(file_name, json_api): 392 def read_protocol_file(file_name, json_api):
352 input_file = open(file_name, "r") 393 input_file = open(file_name, "r")
353 json_string = input_file.read() 394 json_string = input_file.read()
354 input_file.close() 395 input_file.close()
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 outputs = dict() 453 outputs = dict()
413 454
414 for domain in protocol.json_api["domains"]: 455 for domain in protocol.json_api["domains"]:
415 class_name = domain["domain"] 456 class_name = domain["domain"]
416 template_context = { 457 template_context = {
417 "config": config, 458 "config": config,
418 "domain": domain, 459 "domain": domain,
419 "join_arrays": join_arrays, 460 "join_arrays": join_arrays,
420 "resolve_type": functools.partial(resolve_type, protocol), 461 "resolve_type": functools.partial(resolve_type, protocol),
421 "type_definition": functools.partial(type_definition, protocol), 462 "type_definition": functools.partial(type_definition, protocol),
422 "has_disable": has_disable, 463 "generate_command": functools.partial(generate_command, protocol, co nfig),
464 "generate_event": functools.partial(generate_event, protocol, config ),
465 "is_async_command": functools.partial(is_async_command, protocol, co nfig),
466 "generate_disable": functools.partial(generate_disable, protocol, co nfig),
423 "format_include": format_include 467 "format_include": format_include
424 } 468 }
425 469
426 if domain["domain"] in protocol.generate_domains: 470 if domain["domain"] in protocol.generate_domains:
427 outputs[os.path.join(config.protocol.output, class_name + ".h")] = h _template.render(template_context) 471 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) 472 outputs[os.path.join(config.protocol.output, class_name + ".cpp")] = cpp_template.render(template_context)
429 if domain["has_exports"]: 473 if domain["has_exports"]:
430 outputs[os.path.join(config.exported.output, class_name + ".h")] = exported_template.render(template_context) 474 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 "]: 475 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) 476 outputs[os.path.join(config.protocol.output, class_name + ".h")] = i mported_template.render(template_context)
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 if up_to_date: 533 if up_to_date:
490 sys.exit() 534 sys.exit()
491 535
492 for file_name, content in outputs.iteritems(): 536 for file_name, content in outputs.iteritems():
493 out_file = open(file_name, "w") 537 out_file = open(file_name, "w")
494 out_file.write(content) 538 out_file.write(content)
495 out_file.close() 539 out_file.close()
496 540
497 541
498 main() 542 main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698