Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 """Generator for C++ structs from api json files. | 5 """Generator for C++ structs from api json files. |
| 6 | 6 |
| 7 The purpose of this tool is to remove the need for hand-written code that | 7 The purpose of this tool is to remove the need for hand-written code that |
| 8 converts to and from base::Value types when receiving javascript api calls. | 8 converts to and from base::Value types when receiving javascript api calls. |
| 9 Originally written for generating code for extension apis. Reference schemas | 9 Originally written for generating code for extension apis. Reference schemas |
| 10 are in chrome/common/extensions/api. | 10 are in chrome/common/extensions/api. |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 78 cpp_namespace_pattern)) | 78 cpp_namespace_pattern)) |
| 79 | 79 |
| 80 if default_namespace is None: | 80 if default_namespace is None: |
| 81 default_namespace = namespace | 81 default_namespace = namespace |
| 82 | 82 |
| 83 if src_path is None: | 83 if src_path is None: |
| 84 src_path = namespace.source_file_dir | 84 src_path = namespace.source_file_dir |
| 85 else: | 85 else: |
| 86 src_path = os.path.commonprefix((src_path, namespace.source_file_dir)) | 86 src_path = os.path.commonprefix((src_path, namespace.source_file_dir)) |
| 87 | 87 |
| 88 path, filename = os.path.split(file_path) | 88 filename = os.path.split(file_path)[1] |
|
not at google - send to devlin
2015/01/14 22:44:41
maybe change it to
_, filename = ...
then? I pre
not at google - send to devlin
2015/01/14 23:06:59
no idea. I just like to be explicit when something
| |
| 89 filename_base, _ = os.path.splitext(filename) | 89 filename_base, _ = os.path.splitext(filename) |
| 90 | 90 |
| 91 # Construct the type generator with all the namespaces in this model. | 91 # Construct the type generator with all the namespaces in this model. |
| 92 type_generator = CppTypeGenerator(api_model, | 92 type_generator = CppTypeGenerator(api_model, |
| 93 schema_loader, | 93 schema_loader, |
| 94 default_namespace) | 94 default_namespace) |
| 95 if generator_name in ('cpp-bundle-registration', 'cpp-bundle-schema'): | 95 if generator_name in ('cpp-bundle-registration', 'cpp-bundle-schema'): |
| 96 cpp_bundle_generator = CppBundleGenerator(root, | 96 cpp_bundle_generator = CppBundleGenerator(root, |
| 97 api_model, | 97 api_model, |
| 98 api_defs, | 98 api_defs, |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 116 generators = [ | 116 generators = [ |
| 117 ('%s.h' % filename_base, cpp_generator.h_generator), | 117 ('%s.h' % filename_base, cpp_generator.h_generator), |
| 118 ('%s.cc' % filename_base, cpp_generator.cc_generator) | 118 ('%s.cc' % filename_base, cpp_generator.cc_generator) |
| 119 ] | 119 ] |
| 120 elif generator_name == 'dart': | 120 elif generator_name == 'dart': |
| 121 generators = [ | 121 generators = [ |
| 122 ('%s.dart' % namespace.unix_name, DartGenerator( | 122 ('%s.dart' % namespace.unix_name, DartGenerator( |
| 123 dart_overrides_dir)) | 123 dart_overrides_dir)) |
| 124 ] | 124 ] |
| 125 else: | 125 else: |
| 126 raise Exception('Unrecognised generator %s' % generator) | 126 raise Exception('Unrecognised generator %s' % generator_name) |
| 127 | 127 |
| 128 output_code = [] | 128 output_code = [] |
| 129 for filename, generator in generators: | 129 for filename, generator in generators: |
| 130 code = generator.Generate(namespace).Render() | 130 code = generator.Generate(namespace).Render() |
| 131 if destdir: | 131 if destdir: |
| 132 if generator_name == 'cpp-bundle-registration': | 132 if generator_name == 'cpp-bundle-registration': |
| 133 # Function registrations must be output to impl_dir, since they link in | 133 # Function registrations must be output to impl_dir, since they link in |
| 134 # API implementations. | 134 # API implementations. |
| 135 output_dir = os.path.join(destdir, impl_dir) | 135 output_dir = os.path.join(destdir, impl_dir) |
| 136 else: | 136 else: |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 include_rules = [] | 189 include_rules = [] |
| 190 if opts.include_rules: | 190 if opts.include_rules: |
| 191 include_rules = map(split_path_and_namespace, | 191 include_rules = map(split_path_and_namespace, |
| 192 shlex.split(opts.include_rules)) | 192 shlex.split(opts.include_rules)) |
| 193 | 193 |
| 194 result = GenerateSchema(opts.generator, file_paths, opts.root, opts.destdir, | 194 result = GenerateSchema(opts.generator, file_paths, opts.root, opts.destdir, |
| 195 opts.namespace, opts.dart_overrides_dir, | 195 opts.namespace, opts.dart_overrides_dir, |
| 196 opts.impl_dir, include_rules) | 196 opts.impl_dir, include_rules) |
| 197 if not opts.destdir: | 197 if not opts.destdir: |
| 198 print result | 198 print result |
| OLD | NEW |