Chromium Code Reviews| 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 string | 7 import string |
| 8 import optparse | 8 import optparse |
| 9 import re | 9 import re |
| 10 try: | 10 try: |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 module_path, os.pardir, os.pardir, os.pardir, os.pardir)) | 26 module_path, os.pardir, os.pardir, os.pardir, os.pardir)) |
| 27 | 27 |
| 28 # jinja2 is in chromium's third_party directory. | 28 # jinja2 is in chromium's third_party directory. |
| 29 # Insert at 1 so at front to override system libraries, and | 29 # Insert at 1 so at front to override system libraries, and |
| 30 # after path[0] == invoking script dir | 30 # after path[0] == invoking script dir |
| 31 sys.path.insert(1, third_party_dir) | 31 sys.path.insert(1, third_party_dir) |
| 32 import jinja2 | 32 import jinja2 |
| 33 | 33 |
| 34 cmdline_parser = optparse.OptionParser() | 34 cmdline_parser = optparse.OptionParser() |
| 35 cmdline_parser.add_option("--output_dir") | 35 cmdline_parser.add_option("--output_dir") |
| 36 cmdline_parser.add_option("--template_dir") | 36 cmdline_parser.add_option("--generate_dispatcher") |
| 37 | 37 |
| 38 try: | 38 try: |
| 39 arg_options, arg_values = cmdline_parser.parse_args() | 39 arg_options, arg_values = cmdline_parser.parse_args() |
| 40 if (len(arg_values) != 1): | 40 if (len(arg_values) == 0): |
| 41 raise Exception("Exactly one plain argument expected (found %s)" % len(a rg_values)) | 41 raise Exception("At least one plain argument expected (found %s)" % len( arg_values)) |
| 42 input_json_filename = arg_values[0] | |
| 43 output_dirname = arg_options.output_dir | 42 output_dirname = arg_options.output_dir |
| 43 generate_dispatcher = arg_options.generate_dispatcher | |
|
dgozman
2016/03/17 20:39:23
You don't use this.
| |
| 44 if not output_dirname: | 44 if not output_dirname: |
| 45 raise Exception("Output directory must be specified") | 45 raise Exception("Output directory must be specified") |
| 46 except Exception: | 46 except Exception: |
| 47 # Work with python 2 and 3 http://docs.python.org/py3k/howto/pyporting.html | 47 # Work with python 2 and 3 http://docs.python.org/py3k/howto/pyporting.html |
| 48 exc = sys.exc_info()[1] | 48 exc = sys.exc_info()[1] |
| 49 sys.stderr.write("Failed to parse command-line arguments: %s\n\n" % exc) | 49 sys.stderr.write("Failed to parse command-line arguments: %s\n\n" % exc) |
| 50 sys.stderr.write("Usage: <script> --output_dir <output_dir> protocol.json\n" ) | 50 sys.stderr.write("Usage: <script> --output_dir <output_dir> blink_protocol.j son v8_protocol.json ...\n") |
| 51 exit(1) | 51 exit(1) |
| 52 | 52 |
| 53 input_file = open(input_json_filename, "r") | 53 json_api = {"domains": []} |
| 54 json_string = input_file.read() | |
| 55 json_api = json.loads(json_string) | |
| 56 | 54 |
| 55 for filename in arg_values: | |
| 56 input_file = open(filename, "r") | |
| 57 json_string = input_file.read() | |
| 58 parsed_json = json.loads(json_string) | |
| 59 json_api["domains"] += parsed_json["domains"] | |
| 57 | 60 |
| 58 def to_title_case(name): | 61 def to_title_case(name): |
| 59 return name[:1].upper() + name[1:] | 62 return name[:1].upper() + name[1:] |
| 60 | 63 |
| 61 | 64 |
| 62 def dash_to_camelcase(word): | 65 def dash_to_camelcase(word): |
| 63 return ''.join(to_title_case(x) or '-' for x in word.split('-')) | 66 return ''.join(to_title_case(x) or '-' for x in word.split('-')) |
| 64 | 67 |
| 65 | 68 |
| 66 def initialize_jinja_env(cache_dir): | 69 def initialize_jinja_env(cache_dir): |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 261 cpp_template = jinja_env.get_template("/%s_cpp.template" % class_name) | 264 cpp_template = jinja_env.get_template("/%s_cpp.template" % class_name) |
| 262 h_file = output_file(output_dirname + "/" + class_name + ".h") | 265 h_file = output_file(output_dirname + "/" + class_name + ".h") |
| 263 cpp_file = output_file(output_dirname + "/" + class_name + ".cpp") | 266 cpp_file = output_file(output_dirname + "/" + class_name + ".cpp") |
| 264 h_file.write(h_template.render(template_context)) | 267 h_file.write(h_template.render(template_context)) |
| 265 cpp_file.write(cpp_template.render(template_context)) | 268 cpp_file.write(cpp_template.render(template_context)) |
| 266 h_file.close() | 269 h_file.close() |
| 267 cpp_file.close() | 270 cpp_file.close() |
| 268 | 271 |
| 269 | 272 |
| 270 jinja_env = initialize_jinja_env(output_dirname) | 273 jinja_env = initialize_jinja_env(output_dirname) |
| 274 generate("Backend") | |
| 271 generate("Dispatcher") | 275 generate("Dispatcher") |
| 272 generate("Frontend") | 276 generate("Frontend") |
| 273 generate("TypeBuilder") | 277 generate("TypeBuilder") |
| OLD | NEW |