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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
67 include_compiler_options=True) | 67 include_compiler_options=True) |
68 if default_namespace is None: | 68 if default_namespace is None: |
69 default_namespace = namespace | 69 default_namespace = namespace |
70 | 70 |
71 path, filename = os.path.split(schema_filename) | 71 path, filename = os.path.split(schema_filename) |
72 short_filename, extension = os.path.splitext(filename) | 72 short_filename, extension = os.path.splitext(filename) |
73 | 73 |
74 # Filenames are checked against the unix_names of the namespaces they | 74 # Filenames are checked against the unix_names of the namespaces they |
75 # generate because the gyp uses the names of the JSON files to generate | 75 # generate because the gyp uses the names of the JSON files to generate |
76 # the names of the .cc and .h files. We want these to be using unix_names. | 76 # the names of the .cc and .h files. We want these to be using unix_names. |
77 if namespace.unix_name != short_filename: | 77 if (namespace.unix_name != short_filename and |
78 not namespace.allow_custom_filename): | |
78 sys.exit("Filename %s is illegal. Name files using unix_hacker style." % | 79 sys.exit("Filename %s is illegal. Name files using unix_hacker style." % |
David Tseng
2014/01/27 20:07:21
To expand, I'll have to get rid of this check. Is
not at google - send to devlin
2014/01/27 20:08:40
Yes that's fine.
| |
79 schema_filename) | 80 schema_filename) |
80 | 81 |
81 # Construct the type generator with all the namespaces in this model. | 82 # Construct the type generator with all the namespaces in this model. |
82 type_generator = CppTypeGenerator(api_model, | 83 type_generator = CppTypeGenerator(api_model, |
83 schema_loader, | 84 schema_loader, |
84 default_namespace=default_namespace) | 85 default_namespace=default_namespace) |
85 | 86 |
86 if generator == 'cpp-bundle': | 87 if generator == 'cpp-bundle': |
87 cpp_bundle_generator = CppBundleGenerator(root, | 88 cpp_bundle_generator = CppBundleGenerator(root, |
88 api_model, | 89 api_model, |
89 api_defs, | 90 api_defs, |
90 type_generator, | 91 type_generator, |
91 root_namespace, | 92 root_namespace, |
92 namespace.source_file_dir) | 93 namespace.source_file_dir) |
93 generators = [ | 94 generators = [ |
94 ('generated_api.cc', cpp_bundle_generator.api_cc_generator), | 95 ('generated_api.cc', cpp_bundle_generator.api_cc_generator), |
95 ('generated_api.h', cpp_bundle_generator.api_h_generator), | 96 ('generated_api.h', cpp_bundle_generator.api_h_generator), |
96 ('generated_schemas.cc', cpp_bundle_generator.schemas_cc_generator), | 97 ('generated_schemas.cc', cpp_bundle_generator.schemas_cc_generator), |
97 ('generated_schemas.h', cpp_bundle_generator.schemas_h_generator) | 98 ('generated_schemas.h', cpp_bundle_generator.schemas_h_generator) |
98 ] | 99 ] |
99 elif generator == 'cpp': | 100 elif generator == 'cpp': |
100 cpp_generator = CppGenerator(type_generator, root_namespace) | 101 cpp_generator = CppGenerator(type_generator, root_namespace) |
101 generators = [ | 102 generators = [ |
102 ('%s.h' % namespace.unix_name, cpp_generator.h_generator), | 103 ('%s.h' % short_filename, cpp_generator.h_generator), |
103 ('%s.cc' % namespace.unix_name, cpp_generator.cc_generator) | 104 ('%s.cc' % short_filename, cpp_generator.cc_generator) |
104 ] | 105 ] |
105 elif generator == 'dart': | 106 elif generator == 'dart': |
106 generators = [ | 107 generators = [ |
107 ('%s.dart' % namespace.unix_name, DartGenerator( | 108 ('%s.dart' % namespace.unix_name, DartGenerator( |
108 dart_overrides_dir)) | 109 dart_overrides_dir)) |
109 ] | 110 ] |
110 elif generator == 'ppapi': | 111 elif generator == 'ppapi': |
111 generator = PpapiGenerator() | 112 generator = PpapiGenerator() |
112 generators = [ | 113 generators = [ |
113 (os.path.join('api', 'ppb_%s.idl' % namespace.unix_name), | 114 (os.path.join('api', 'ppb_%s.idl' % namespace.unix_name), |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
154 # Unless in bundle mode, only one file should be specified. | 155 # Unless in bundle mode, only one file should be specified. |
155 if opts.generator != 'cpp-bundle' and len(filenames) > 1: | 156 if opts.generator != 'cpp-bundle' and len(filenames) > 1: |
156 # TODO(sashab): Could also just use filenames[0] here and not complain. | 157 # TODO(sashab): Could also just use filenames[0] here and not complain. |
157 raise Exception( | 158 raise Exception( |
158 "Unless in bundle mode, only one file can be specified at a time.") | 159 "Unless in bundle mode, only one file can be specified at a time.") |
159 | 160 |
160 result = GenerateSchema(opts.generator, filenames, opts.root, opts.destdir, | 161 result = GenerateSchema(opts.generator, filenames, opts.root, opts.destdir, |
161 opts.namespace, opts.dart_overrides_dir) | 162 opts.namespace, opts.dart_overrides_dir) |
162 if not opts.destdir: | 163 if not opts.destdir: |
163 print result | 164 print result |
OLD | NEW |