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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 # Construct the type generator with all the namespaces in this model. | 80 # Construct the type generator with all the namespaces in this model. |
81 type_generator = CppTypeGenerator(api_model, | 81 type_generator = CppTypeGenerator(api_model, |
82 schema_loader, | 82 schema_loader, |
83 default_namespace=default_namespace) | 83 default_namespace=default_namespace) |
84 | 84 |
85 if generator == 'cpp-bundle': | 85 if generator == 'cpp-bundle': |
86 cpp_bundle_generator = CppBundleGenerator(root, | 86 cpp_bundle_generator = CppBundleGenerator(root, |
87 api_model, | 87 api_model, |
88 api_defs, | 88 api_defs, |
89 type_generator, | 89 type_generator, |
90 root_namespace) | 90 root_namespace, |
| 91 namespace.source_file_dir) |
91 generators = [ | 92 generators = [ |
92 ('generated_api.cc', cpp_bundle_generator.api_cc_generator), | 93 ('generated_api.cc', cpp_bundle_generator.api_cc_generator), |
93 ('generated_api.h', cpp_bundle_generator.api_h_generator), | 94 ('generated_api.h', cpp_bundle_generator.api_h_generator), |
94 ('generated_schemas.cc', cpp_bundle_generator.schemas_cc_generator), | 95 ('generated_schemas.cc', cpp_bundle_generator.schemas_cc_generator), |
95 ('generated_schemas.h', cpp_bundle_generator.schemas_h_generator) | 96 ('generated_schemas.h', cpp_bundle_generator.schemas_h_generator) |
96 ] | 97 ] |
97 elif generator == 'cpp': | 98 elif generator == 'cpp': |
98 cpp_generator = CppGenerator(type_generator, root_namespace) | 99 cpp_generator = CppGenerator(type_generator, root_namespace) |
99 generators = [ | 100 generators = [ |
100 ('%s.h' % namespace.unix_name, cpp_generator.h_generator), | 101 ('%s.h' % namespace.unix_name, cpp_generator.h_generator), |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 # Unless in bundle mode, only one file should be specified. | 147 # Unless in bundle mode, only one file should be specified. |
147 if opts.generator != 'cpp-bundle' and len(filenames) > 1: | 148 if opts.generator != 'cpp-bundle' and len(filenames) > 1: |
148 # TODO(sashab): Could also just use filenames[0] here and not complain. | 149 # TODO(sashab): Could also just use filenames[0] here and not complain. |
149 raise Exception( | 150 raise Exception( |
150 "Unless in bundle mode, only one file can be specified at a time.") | 151 "Unless in bundle mode, only one file can be specified at a time.") |
151 | 152 |
152 result = GenerateSchema(opts.generator, filenames, opts.root, opts.destdir, | 153 result = GenerateSchema(opts.generator, filenames, opts.root, opts.destdir, |
153 opts.namespace, opts.dart_overrides_dir) | 154 opts.namespace, opts.dart_overrides_dir) |
154 if not opts.destdir: | 155 if not opts.destdir: |
155 print result | 156 print result |
OLD | NEW |