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

Side by Side Diff: CodeGenerator.py

Issue 2482093004: [inspector_protocol] Allow overriding specific config values. (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
« no previous file with comments | « no previous file | inspector_protocol.gni » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
66 except Exception: 68 except Exception:
67 # Work with python 2 and 3 http://docs.python.org/py3k/howto/pyporting.h tml 69 # Work with python 2 and 3 http://docs.python.org/py3k/howto/pyporting.h tml
68 exc = sys.exc_info()[1] 70 exc = sys.exc_info()[1]
69 sys.stderr.write("Failed to parse command-line arguments: %s\n\n" % exc) 71 sys.stderr.write("Failed to parse command-line arguments: %s\n\n" % exc)
70 exit(1) 72 exit(1)
71 73
72 try: 74 try:
73 config_json_file = open(config_file, "r") 75 config_json_file = open(config_file, "r")
74 config_json_string = config_json_file.read() 76 config_json_string = config_json_file.read()
75 config_partial = json_to_object(config_json_string, output_base, config_ base) 77 config_partial = json_to_object(config_json_string, output_base, config_ base)
76 config_json_file.close() 78 config_json_file.close()
77 defaults = { 79 defaults = {
78 ".imported": False, 80 ".imported": False,
79 ".imported.export_macro": "", 81 ".imported.export_macro": "",
80 ".imported.export_header": False, 82 ".imported.export_header": False,
81 ".imported.header": False, 83 ".imported.header": False,
82 ".imported.package": False, 84 ".imported.package": False,
83 ".protocol.export_macro": "", 85 ".protocol.export_macro": "",
84 ".protocol.export_header": False, 86 ".protocol.export_header": False,
85 ".protocol.options": False, 87 ".protocol.options": False,
86 ".exported": False, 88 ".exported": False,
87 ".exported.export_macro": "", 89 ".exported.export_macro": "",
88 ".exported.export_header": False, 90 ".exported.export_header": False,
89 ".lib": False, 91 ".lib": False,
90 ".lib.export_macro": "", 92 ".lib.export_macro": "",
91 ".lib.export_header": False, 93 ".lib.export_header": False,
92 } 94 }
95 for key_value in config_values:
96 parts = key_value.split("=")
97 if len(parts) == 2:
98 defaults["." + parts[0]] = parts[1]
93 return (jinja_dir, config_file, init_defaults(config_partial, "", defaul ts)) 99 return (jinja_dir, config_file, init_defaults(config_partial, "", defaul ts))
94 except Exception: 100 except Exception:
95 # Work with python 2 and 3 http://docs.python.org/py3k/howto/pyporting.h tml 101 # Work with python 2 and 3 http://docs.python.org/py3k/howto/pyporting.h tml
96 exc = sys.exc_info()[1] 102 exc = sys.exc_info()[1]
97 sys.stderr.write("Failed to parse config file: %s\n\n" % exc) 103 sys.stderr.write("Failed to parse config file: %s\n\n" % exc)
98 exit(1) 104 exit(1)
99 105
100 106
101 def to_title_case(name): 107 def to_title_case(name):
102 return name[:1].upper() + name[1:] 108 return name[:1].upper() + name[1:]
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 return { 286 return {
281 "return_type": "std::unique_ptr<protocol::Array<%s>>" % type["raw_type"] , 287 "return_type": "std::unique_ptr<protocol::Array<%s>>" % type["raw_type"] ,
282 "pass_type": "std::unique_ptr<protocol::Array<%s>>" % type["raw_type"], 288 "pass_type": "std::unique_ptr<protocol::Array<%s>>" % type["raw_type"],
283 "to_raw_type": "%s.get()", 289 "to_raw_type": "%s.get()",
284 "to_pass_type": "std::move(%s)", 290 "to_pass_type": "std::move(%s)",
285 "to_rvalue": "std::move(%s)", 291 "to_rvalue": "std::move(%s)",
286 "type": "std::unique_ptr<protocol::Array<%s>>" % type["raw_type"], 292 "type": "std::unique_ptr<protocol::Array<%s>>" % type["raw_type"],
287 "raw_type": "protocol::Array<%s>" % type["raw_type"], 293 "raw_type": "protocol::Array<%s>" % type["raw_type"],
288 "raw_pass_type": "protocol::Array<%s>*" % type["raw_type"], 294 "raw_pass_type": "protocol::Array<%s>*" % type["raw_type"],
289 "raw_return_type": "protocol::Array<%s>*" % type["raw_type"], 295 "raw_return_type": "protocol::Array<%s>*" % type["raw_type"],
296 "create_type": "wrapUnique(new protocol::Array<%s>())" % type["raw_type" ],
kozy 2016/11/08 23:13:43 Hm...
dgozman 2016/11/08 23:19:36 Accidental. Removed.
290 "out_type": "protocol::Array<%s>&" % type["raw_type"], 297 "out_type": "protocol::Array<%s>&" % type["raw_type"],
291 } 298 }
292 299
293 300
294 def create_type_definitions(protocol, imported_namespace): 301 def create_type_definitions(protocol, imported_namespace):
295 protocol.type_definitions = {} 302 protocol.type_definitions = {}
296 protocol.type_definitions["number"] = create_primitive_type_definition("numb er") 303 protocol.type_definitions["number"] = create_primitive_type_definition("numb er")
297 protocol.type_definitions["integer"] = create_primitive_type_definition("int eger") 304 protocol.type_definitions["integer"] = create_primitive_type_definition("int eger")
298 protocol.type_definitions["boolean"] = create_primitive_type_definition("boo lean") 305 protocol.type_definitions["boolean"] = create_primitive_type_definition("boo lean")
299 protocol.type_definitions["object"] = create_object_type_definition() 306 protocol.type_definitions["object"] = create_object_type_definition()
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 if up_to_date: 541 if up_to_date:
535 sys.exit() 542 sys.exit()
536 543
537 for file_name, content in outputs.iteritems(): 544 for file_name, content in outputs.iteritems():
538 out_file = open(file_name, "w") 545 out_file = open(file_name, "w")
539 out_file.write(content) 546 out_file.write(content)
540 out_file.close() 547 out_file.close()
541 548
542 549
543 main() 550 main()
OLDNEW
« no previous file with comments | « no previous file | inspector_protocol.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698