OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2012 The Chromium Authors. All rights reserved. | 2 # Copyright 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 | 5 |
6 # Format for the JSON schema file: | 6 # Format for the JSON schema file: |
7 # { | 7 # { |
8 # "type_name": "DesiredCStructName", | 8 # "type_name": "DesiredCStructName", |
9 # "headers": [ // Optional list of headers to be included by the .h. | 9 # "headers": [ // Optional list of headers to be included by the .h. |
10 # "path/to/header.h" | 10 # "path/to/header.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 namespace: A string corresponding to the C++ namespace to use. | 92 namespace: A string corresponding to the C++ namespace to use. |
93 schema: A dict containing the schema. See comment at the top of this file. | 93 schema: A dict containing the schema. See comment at the top of this file. |
94 description: A dict containing the description. See comment at the top of | 94 description: A dict containing the description. See comment at the top of |
95 this file. | 95 this file. |
96 """ | 96 """ |
97 | 97 |
98 h_filename = fileroot + '.h' | 98 h_filename = fileroot + '.h' |
99 with open(os.path.join(basepath, h_filename), 'w') as f: | 99 with open(os.path.join(basepath, h_filename), 'w') as f: |
100 f.write(head) | 100 f.write(head) |
101 | 101 |
102 f.write('#include <cstddef>\n') | |
103 f.write('\n') | |
104 | |
105 header_guard = _GenerateHeaderGuard(h_filename) | 102 header_guard = _GenerateHeaderGuard(h_filename) |
106 f.write('#ifndef %s\n' % header_guard) | 103 f.write('#ifndef %s\n' % header_guard) |
107 f.write('#define %s\n' % header_guard) | 104 f.write('#define %s\n' % header_guard) |
108 f.write('\n') | 105 f.write('\n') |
109 | 106 |
107 f.write('#include <cstddef>\n') | |
108 f.write('\n') | |
Peter Kasting
2014/07/09 22:19:54
This just ensures the generated code puts all the
| |
109 | |
110 for header in schema.get('headers', []): | 110 for header in schema.get('headers', []): |
111 f.write('#include "%s"\n' % header) | 111 f.write('#include "%s"\n' % header) |
112 f.write('\n') | 112 f.write('\n') |
113 | 113 |
114 if namespace: | 114 if namespace: |
115 f.write('namespace %s {\n' % namespace) | 115 f.write('namespace %s {\n' % namespace) |
116 f.write('\n') | 116 f.write('\n') |
117 | 117 |
118 f.write(struct_generator.GenerateStruct( | 118 f.write(struct_generator.GenerateStruct( |
119 schema['type_name'], schema['schema'])) | 119 schema['type_name'], schema['schema'])) |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
202 basepath = os.path.normpath(opts.destbase) | 202 basepath = os.path.normpath(opts.destbase) |
203 else: | 203 else: |
204 basepath = '' | 204 basepath = '' |
205 | 205 |
206 schema = _Load(opts.schema) | 206 schema = _Load(opts.schema) |
207 description = _Load(description_filename) | 207 description = _Load(description_filename) |
208 | 208 |
209 head = HEAD % (datetime.now().year, opts.schema, description_filename) | 209 head = HEAD % (datetime.now().year, opts.schema, description_filename) |
210 _GenerateH(basepath, output_root, head, opts.namespace, schema, description) | 210 _GenerateH(basepath, output_root, head, opts.namespace, schema, description) |
211 _GenerateCC(basepath, output_root, head, opts.namespace, schema, description) | 211 _GenerateCC(basepath, output_root, head, opts.namespace, schema, description) |
OLD | NEW |