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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 sys.exit("Filename %s is illegal. Name files using unix_hacker style." % | 146 sys.exit("Filename %s is illegal. Name files using unix_hacker style." % |
147 schema_filename) | 147 schema_filename) |
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 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 schemas_h_code = generator.GenerateSchemasHeader().Render() | 158 schemas_h_code = generator.GenerateSchemasHeader().Render() |
159 schemas_cc_code = generator.GenerateSchemasCC().Render() | 159 schemas_cc_code = generator.GenerateSchemasCC().Render() |
160 | 160 |
161 if dest_dir: | 161 if dest_dir: |
162 basedir = os.path.join(dest_dir, 'chrome/common/extensions/api') | 162 basedir = os.path.join(dest_dir, 'chrome/common/extensions/api') |
163 with open(os.path.join(basedir, 'generated_api.h'), 'w') as h_file: | 163 with open(os.path.join(basedir, 'generated_api.h'), 'w') as h_file: |
164 h_file.write(api_h_code) | 164 h_file.write(api_h_code) |
165 with open(os.path.join(basedir, 'generated_schemas.h'), 'w') as h_file: | 165 with open(os.path.join(basedir, 'generated_schemas.h'), 'w') as h_file: |
166 h_file.write(schemas_h_code) | 166 h_file.write(schemas_h_code) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 | 198 |
199 if not args: | 199 if not args: |
200 sys.exit(0) # This is OK as a no-op | 200 sys.exit(0) # This is OK as a no-op |
201 dest_dir = opts.destdir | 201 dest_dir = opts.destdir |
202 root_namespace = opts.namespace | 202 root_namespace = opts.namespace |
203 | 203 |
204 if opts.bundle: | 204 if opts.bundle: |
205 handle_bundle_schema(args, dest_dir, opts.root, root_namespace) | 205 handle_bundle_schema(args, dest_dir, opts.root, root_namespace) |
206 else: | 206 else: |
207 handle_single_schema(args[0], dest_dir, opts.root, root_namespace) | 207 handle_single_schema(args[0], dest_dir, opts.root, root_namespace) |
OLD | NEW |