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