| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 root_namespace, namespace, namespace.unix_name) | 75 root_namespace, namespace, namespace.unix_name) |
| 76 for referenced_namespace in api_model.namespaces.values(): | 76 for referenced_namespace in api_model.namespaces.values(): |
| 77 if referenced_namespace == namespace: | 77 if referenced_namespace == namespace: |
| 78 continue | 78 continue |
| 79 type_generator.AddNamespace( | 79 type_generator.AddNamespace( |
| 80 referenced_namespace, | 80 referenced_namespace, |
| 81 referenced_namespace.unix_name) | 81 referenced_namespace.unix_name) |
| 82 | 82 |
| 83 h_code = (h_generator.HGenerator(namespace, type_generator) | 83 h_code = (h_generator.HGenerator(namespace, type_generator) |
| 84 .Generate().Render()) | 84 .Generate().Render()) |
| 85 cc_code = (cc_generator.CCGenerator(namespace, type_generator) | 85 cc_code = (cc_generator.CCGenerator(namespace, type_generator, |
| 86 referenced_schemas) |
| 86 .Generate().Render()) | 87 .Generate().Render()) |
| 87 | 88 |
| 88 if dest_dir: | 89 if dest_dir: |
| 89 with open( | 90 with open( |
| 90 os.path.join(dest_dir, namespace.source_file_dir, out_file + '.cc'), | 91 os.path.join(dest_dir, namespace.source_file_dir, out_file + '.cc'), |
| 91 'w') as cc_file: | 92 'w') as cc_file: |
| 92 cc_file.write(cc_code) | 93 cc_file.write(cc_code) |
| 93 with open( | 94 with open( |
| 94 os.path.join(dest_dir, namespace.source_file_dir, out_file + '.h'), | 95 os.path.join(dest_dir, namespace.source_file_dir, out_file + '.h'), |
| 95 'w') as h_file: | 96 'w') as h_file: |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 | 169 |
| 169 if not args: | 170 if not args: |
| 170 sys.exit(0) # This is OK as a no-op | 171 sys.exit(0) # This is OK as a no-op |
| 171 dest_dir = opts.destdir | 172 dest_dir = opts.destdir |
| 172 root_namespace = opts.namespace | 173 root_namespace = opts.namespace |
| 173 | 174 |
| 174 if opts.bundle: | 175 if opts.bundle: |
| 175 handle_bundle_schema(args, dest_dir, opts.root, root_namespace) | 176 handle_bundle_schema(args, dest_dir, opts.root, root_namespace) |
| 176 else: | 177 else: |
| 177 handle_single_schema(args[0], dest_dir, opts.root, root_namespace) | 178 handle_single_schema(args[0], dest_dir, opts.root, root_namespace) |
| OLD | NEW |