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

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

Issue 2490473004: [DevTools] Roll third_party/inspector_protocol to e23134c5aa6131e5a3a3afbefce255becce3a3bd. (Closed)
Patch Set: ui_devtools 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 if optional_key.find(".") == -1 and optional_key not in keys: 45 if optional_key.find(".") == -1 and optional_key not in keys:
46 keys.append(optional_key) 46 keys.append(optional_key)
47 values.append(defaults[optional]) 47 values.append(defaults[optional])
48 return collections.namedtuple('X', keys)(*values) 48 return collections.namedtuple('X', keys)(*values)
49 49
50 try: 50 try:
51 cmdline_parser = optparse.OptionParser() 51 cmdline_parser = optparse.OptionParser()
52 cmdline_parser.add_option("--output_base") 52 cmdline_parser.add_option("--output_base")
53 cmdline_parser.add_option("--jinja_dir") 53 cmdline_parser.add_option("--jinja_dir")
54 cmdline_parser.add_option("--config") 54 cmdline_parser.add_option("--config")
55 cmdline_parser.add_option("--config_value", action="append", type="strin g")
55 arg_options, _ = cmdline_parser.parse_args() 56 arg_options, _ = cmdline_parser.parse_args()
56 jinja_dir = arg_options.jinja_dir 57 jinja_dir = arg_options.jinja_dir
57 if not jinja_dir: 58 if not jinja_dir:
58 raise Exception("jinja directory must be specified") 59 raise Exception("jinja directory must be specified")
59 output_base = arg_options.output_base 60 output_base = arg_options.output_base
60 if not output_base: 61 if not output_base:
61 raise Exception("Base output directory must be specified") 62 raise Exception("Base output directory must be specified")
62 config_file = arg_options.config 63 config_file = arg_options.config
63 if not config_file: 64 if not config_file:
64 raise Exception("Config file name must be specified") 65 raise Exception("Config file name must be specified")
65 config_base = os.path.dirname(config_file) 66 config_base = os.path.dirname(config_file)
67 config_values = arg_options.config_value
68 if not config_values:
69 config_values = []
66 except Exception: 70 except Exception:
67 # Work with python 2 and 3 http://docs.python.org/py3k/howto/pyporting.h tml 71 # Work with python 2 and 3 http://docs.python.org/py3k/howto/pyporting.h tml
68 exc = sys.exc_info()[1] 72 exc = sys.exc_info()[1]
69 sys.stderr.write("Failed to parse command-line arguments: %s\n\n" % exc) 73 sys.stderr.write("Failed to parse command-line arguments: %s\n\n" % exc)
70 exit(1) 74 exit(1)
71 75
72 try: 76 try:
73 config_json_file = open(config_file, "r") 77 config_json_file = open(config_file, "r")
74 config_json_string = config_json_file.read() 78 config_json_string = config_json_file.read()
75 config_partial = json_to_object(config_json_string, output_base, config_ base) 79 config_partial = json_to_object(config_json_string, output_base, config_ base)
76 config_json_file.close() 80 config_json_file.close()
77 defaults = { 81 defaults = {
78 ".imported": False, 82 ".imported": False,
79 ".imported.export_macro": "", 83 ".imported.export_macro": "",
80 ".imported.export_header": False, 84 ".imported.export_header": False,
81 ".imported.header": False, 85 ".imported.header": False,
82 ".imported.package": False, 86 ".imported.package": False,
83 ".protocol.export_macro": "", 87 ".protocol.export_macro": "",
84 ".protocol.export_header": False, 88 ".protocol.export_header": False,
85 ".protocol.options": False, 89 ".protocol.options": False,
86 ".exported": False, 90 ".exported": False,
87 ".exported.export_macro": "", 91 ".exported.export_macro": "",
88 ".exported.export_header": False, 92 ".exported.export_header": False,
89 ".lib": False, 93 ".lib": False,
90 ".lib.export_macro": "", 94 ".lib.export_macro": "",
91 ".lib.export_header": False, 95 ".lib.export_header": False,
92 } 96 }
97 for key_value in config_values:
98 parts = key_value.split("=")
99 if len(parts) == 2:
100 defaults["." + parts[0]] = parts[1]
93 return (jinja_dir, config_file, init_defaults(config_partial, "", defaul ts)) 101 return (jinja_dir, config_file, init_defaults(config_partial, "", defaul ts))
94 except Exception: 102 except Exception:
95 # Work with python 2 and 3 http://docs.python.org/py3k/howto/pyporting.h tml 103 # Work with python 2 and 3 http://docs.python.org/py3k/howto/pyporting.h tml
96 exc = sys.exc_info()[1] 104 exc = sys.exc_info()[1]
97 sys.stderr.write("Failed to parse config file: %s\n\n" % exc) 105 sys.stderr.write("Failed to parse config file: %s\n\n" % exc)
98 exit(1) 106 exit(1)
99 107
100 108
101 def to_title_case(name): 109 def to_title_case(name):
102 return name[:1].upper() + name[1:] 110 return name[:1].upper() + name[1:]
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 return { 288 return {
281 "return_type": "std::unique_ptr<protocol::Array<%s>>" % type["raw_type"] , 289 "return_type": "std::unique_ptr<protocol::Array<%s>>" % type["raw_type"] ,
282 "pass_type": "std::unique_ptr<protocol::Array<%s>>" % type["raw_type"], 290 "pass_type": "std::unique_ptr<protocol::Array<%s>>" % type["raw_type"],
283 "to_raw_type": "%s.get()", 291 "to_raw_type": "%s.get()",
284 "to_pass_type": "std::move(%s)", 292 "to_pass_type": "std::move(%s)",
285 "to_rvalue": "std::move(%s)", 293 "to_rvalue": "std::move(%s)",
286 "type": "std::unique_ptr<protocol::Array<%s>>" % type["raw_type"], 294 "type": "std::unique_ptr<protocol::Array<%s>>" % type["raw_type"],
287 "raw_type": "protocol::Array<%s>" % type["raw_type"], 295 "raw_type": "protocol::Array<%s>" % type["raw_type"],
288 "raw_pass_type": "protocol::Array<%s>*" % type["raw_type"], 296 "raw_pass_type": "protocol::Array<%s>*" % type["raw_type"],
289 "raw_return_type": "protocol::Array<%s>*" % type["raw_type"], 297 "raw_return_type": "protocol::Array<%s>*" % type["raw_type"],
290 "create_type": "wrapUnique(new protocol::Array<%s>())" % type["raw_type" ],
291 "out_type": "protocol::Array<%s>&" % type["raw_type"], 298 "out_type": "protocol::Array<%s>&" % type["raw_type"],
292 } 299 }
293 300
294 301
295 def create_type_definitions(protocol, imported_namespace): 302 def create_type_definitions(protocol, imported_namespace):
296 protocol.type_definitions = {} 303 protocol.type_definitions = {}
297 protocol.type_definitions["number"] = create_primitive_type_definition("numb er") 304 protocol.type_definitions["number"] = create_primitive_type_definition("numb er")
298 protocol.type_definitions["integer"] = create_primitive_type_definition("int eger") 305 protocol.type_definitions["integer"] = create_primitive_type_definition("int eger")
299 protocol.type_definitions["boolean"] = create_primitive_type_definition("boo lean") 306 protocol.type_definitions["boolean"] = create_primitive_type_definition("boo lean")
300 protocol.type_definitions["object"] = create_object_type_definition() 307 protocol.type_definitions["object"] = create_object_type_definition()
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 if up_to_date: 542 if up_to_date:
536 sys.exit() 543 sys.exit()
537 544
538 for file_name, content in outputs.iteritems(): 545 for file_name, content in outputs.iteritems():
539 out_file = open(file_name, "w") 546 out_file = open(file_name, "w")
540 out_file.write(content) 547 out_file.write(content)
541 out_file.close() 548 out_file.close()
542 549
543 550
544 main() 551 main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698