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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 api_defs = json.loads(schema_file.read()) | 66 api_defs = json.loads(schema_file.read()) |
67 | 67 |
68 for target_namespace in api_defs: | 68 for target_namespace in api_defs: |
69 # Gets the relative path from opts.root to the schema to correctly determine | 69 # Gets the relative path from opts.root to the schema to correctly determine |
70 # the include path. | 70 # the include path. |
71 relpath = os.path.relpath(schema, opts.root) | 71 relpath = os.path.relpath(schema, opts.root) |
72 namespace = api_model.AddNamespace(target_namespace, relpath) | 72 namespace = api_model.AddNamespace(target_namespace, relpath) |
73 if not namespace: | 73 if not namespace: |
74 continue | 74 continue |
75 | 75 |
76 out_file = cpp_util.CppName(namespace.name).lower() + filename_suffix | 76 out_file = namespace.name + filename_suffix |
77 type_generator = cpp_type_generator.CppTypeGenerator(root_namespace, | 77 type_generator = cpp_type_generator.CppTypeGenerator(root_namespace, |
78 namespace, out_file) | 78 namespace, out_file) |
79 for referenced_namespace in api_model.namespaces.values(): | 79 for referenced_namespace in api_model.namespaces.values(): |
80 type_generator.AddNamespace(referenced_namespace, | 80 type_generator.AddNamespace(referenced_namespace, |
81 cpp_util.CppName(referenced_namespace.name).lower() + filename_suffix) | 81 cpp_util.Classname(referenced_namespace.name).lower() + |
| 82 filename_suffix) |
82 cc_generator = cc_generator.CCGenerator(namespace, type_generator) | 83 cc_generator = cc_generator.CCGenerator(namespace, type_generator) |
83 cc_code = cc_generator.Generate().Render() | 84 cc_code = cc_generator.Generate().Render() |
84 h_generator = h_generator.HGenerator(namespace, type_generator) | 85 h_generator = h_generator.HGenerator(namespace, type_generator) |
85 h_code = h_generator.Generate().Render() | 86 h_code = h_generator.Generate().Render() |
86 | 87 |
87 if dest_dir: | 88 if dest_dir: |
88 with open(os.path.join(dest_dir, namespace.source_file_dir, | 89 with open(os.path.join(dest_dir, namespace.source_file_dir, |
89 out_file + '.cc'), 'w') as cc_file: | 90 out_file + '.cc'), 'w') as cc_file: |
90 cc_file.write(cc_code) | 91 cc_file.write(cc_code) |
91 with open(os.path.join(dest_dir, namespace.source_file_dir, | 92 with open(os.path.join(dest_dir, namespace.source_file_dir, |
92 out_file + '.h'), 'w') as h_file: | 93 out_file + '.h'), 'w') as h_file: |
93 h_file.write(h_code) | 94 h_file.write(h_code) |
94 else: | 95 else: |
95 print '%s.h' % out_file | 96 print '%s.h' % out_file |
96 print | 97 print |
97 print h_code | 98 print h_code |
98 print | 99 print |
99 print '%s.cc' % out_file | 100 print '%s.cc' % out_file |
100 print | 101 print |
101 print cc_code | 102 print cc_code |
OLD | NEW |