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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 | 148 |
149 type_generator = cpp_type_generator.CppTypeGenerator(root_namespace) | 149 type_generator = cpp_type_generator.CppTypeGenerator(root_namespace) |
150 for referenced_namespace in api_model.namespaces.values(): | 150 for referenced_namespace in api_model.namespaces.values(): |
151 type_generator.AddNamespace( | 151 type_generator.AddNamespace( |
152 referenced_namespace, | 152 referenced_namespace, |
153 referenced_namespace.unix_name) | 153 referenced_namespace.unix_name) |
154 | 154 |
155 generator = schema_bundle_generator.SchemaBundleGenerator( | 155 generator = schema_bundle_generator.SchemaBundleGenerator( |
156 root, api_model, api_defs, type_generator) | 156 root, api_model, api_defs, type_generator) |
157 api_h_code = generator.GenerateAPIHeader().Render() | 157 api_h_code = generator.GenerateAPIHeader().Render() |
| 158 api_cc_code = generator.GenerateAPICC().Render() |
158 schemas_h_code = generator.GenerateSchemasHeader().Render() | 159 schemas_h_code = generator.GenerateSchemasHeader().Render() |
159 schemas_cc_code = generator.GenerateSchemasCC().Render() | 160 schemas_cc_code = generator.GenerateSchemasCC().Render() |
160 | 161 |
161 if dest_dir: | 162 if dest_dir: |
162 basedir = os.path.join(dest_dir, 'chrome/common/extensions/api') | 163 basedir = os.path.join(dest_dir, 'chrome/common/extensions/api') |
163 with open(os.path.join(basedir, 'generated_api.h'), 'w') as h_file: | 164 with open(os.path.join(basedir, 'generated_api.h'), 'w') as h_file: |
164 h_file.write(api_h_code) | 165 h_file.write(api_h_code) |
| 166 with open(os.path.join(basedir, 'generated_api.cc'), 'w') as cc_file: |
| 167 cc_file.write(api_cc_code) |
165 with open(os.path.join(basedir, 'generated_schemas.h'), 'w') as h_file: | 168 with open(os.path.join(basedir, 'generated_schemas.h'), 'w') as h_file: |
166 h_file.write(schemas_h_code) | 169 h_file.write(schemas_h_code) |
167 with open(os.path.join(basedir, 'generated_schemas.cc'), 'w') as cc_file: | 170 with open(os.path.join(basedir, 'generated_schemas.cc'), 'w') as cc_file: |
168 cc_file.write(schemas_cc_code) | 171 cc_file.write(schemas_cc_code) |
169 else: | 172 else: |
170 print 'generated_api.h' | 173 print 'generated_api.h' |
171 print | 174 print |
172 print api_h_code | 175 print api_h_code |
173 print | 176 print |
| 177 print 'generated_api.cc' |
| 178 print |
| 179 print api_cc_code |
| 180 print |
174 print 'generated_schemas.h' | 181 print 'generated_schemas.h' |
175 print | 182 print |
176 print schemas_h_code | 183 print schemas_h_code |
177 print | 184 print |
178 print 'generated_schemas.cc' | 185 print 'generated_schemas.cc' |
179 print | 186 print |
180 print schemas_cc_code | 187 print schemas_cc_code |
181 | 188 |
182 if __name__ == '__main__': | 189 if __name__ == '__main__': |
183 parser = optparse.OptionParser( | 190 parser = optparse.OptionParser( |
(...skipping 14 matching lines...) Expand all Loading... |
198 | 205 |
199 if not args: | 206 if not args: |
200 sys.exit(0) # This is OK as a no-op | 207 sys.exit(0) # This is OK as a no-op |
201 dest_dir = opts.destdir | 208 dest_dir = opts.destdir |
202 root_namespace = opts.namespace | 209 root_namespace = opts.namespace |
203 | 210 |
204 if opts.bundle: | 211 if opts.bundle: |
205 handle_bundle_schema(args, dest_dir, opts.root, root_namespace) | 212 handle_bundle_schema(args, dest_dir, opts.root, root_namespace) |
206 else: | 213 else: |
207 handle_single_schema(args[0], dest_dir, opts.root, root_namespace) | 214 handle_single_schema(args[0], dest_dir, opts.root, root_namespace) |
OLD | NEW |