OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import code | 5 import code |
6 import cpp_util | 6 import cpp_util |
7 from model import Platforms | 7 from model import Platforms |
8 from schema_util import CapitalizeFirstLetter | 8 from schema_util import CapitalizeFirstLetter |
9 from schema_util import JsFunctionNameToClassName | 9 from schema_util import JsFunctionNameToClassName |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... |
33 class CppBundleGenerator(object): | 33 class CppBundleGenerator(object): |
34 """This class contains methods to generate code based on multiple schemas. | 34 """This class contains methods to generate code based on multiple schemas. |
35 """ | 35 """ |
36 | 36 |
37 def __init__(self, | 37 def __init__(self, |
38 root, | 38 root, |
39 model, | 39 model, |
40 api_defs, | 40 api_defs, |
41 cpp_type_generator, | 41 cpp_type_generator, |
42 cpp_namespace, | 42 cpp_namespace, |
43 source_file_dir): | 43 source_file_dir, |
| 44 impl_dir): |
44 self._root = root | 45 self._root = root |
45 self._model = model | 46 self._model = model |
46 self._api_defs = api_defs | 47 self._api_defs = api_defs |
47 self._cpp_type_generator = cpp_type_generator | 48 self._cpp_type_generator = cpp_type_generator |
48 self._cpp_namespace = cpp_namespace | 49 self._cpp_namespace = cpp_namespace |
49 self._source_file_dir = source_file_dir | 50 self._source_file_dir = source_file_dir |
| 51 self._impl_dir = impl_dir |
50 | 52 |
51 self.api_cc_generator = _APICCGenerator(self) | 53 self.api_cc_generator = _APICCGenerator(self) |
52 self.api_h_generator = _APIHGenerator(self) | 54 self.api_h_generator = _APIHGenerator(self) |
53 self.schemas_cc_generator = _SchemasCCGenerator(self) | 55 self.schemas_cc_generator = _SchemasCCGenerator(self) |
54 self.schemas_h_generator = _SchemasHGenerator(self) | 56 self.schemas_h_generator = _SchemasHGenerator(self) |
55 | 57 |
56 def _GenerateHeader(self, file_base, body_code): | 58 def _GenerateHeader(self, file_base, body_code): |
57 """Generates a code.Code object for a header file | 59 """Generates a code.Code object for a header file |
58 | 60 |
59 Parameters: | 61 Parameters: |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 c = code.Code() | 178 c = code.Code() |
177 c.Append(cpp_util.CHROMIUM_LICENSE) | 179 c.Append(cpp_util.CHROMIUM_LICENSE) |
178 c.Append() | 180 c.Append() |
179 c.Append('#include "%s"' % (os.path.join(self._bundle._source_file_dir, | 181 c.Append('#include "%s"' % (os.path.join(self._bundle._source_file_dir, |
180 'generated_api.h'))) | 182 'generated_api.h'))) |
181 c.Append() | 183 c.Append() |
182 for namespace in self._bundle._model.namespaces.values(): | 184 for namespace in self._bundle._model.namespaces.values(): |
183 namespace_name = namespace.unix_name.replace("experimental_", "") | 185 namespace_name = namespace.unix_name.replace("experimental_", "") |
184 implementation_header = namespace.compiler_options.get( | 186 implementation_header = namespace.compiler_options.get( |
185 "implemented_in", | 187 "implemented_in", |
186 "chrome/browser/extensions/api/%s/%s_api.h" % (namespace_name, | 188 "%s/%s/%s_api.h" % (self._bundle._impl_dir, |
187 namespace_name)) | 189 namespace_name, |
| 190 namespace_name)) |
188 if not os.path.exists( | 191 if not os.path.exists( |
189 os.path.join(self._bundle._root, | 192 os.path.join(self._bundle._root, |
190 os.path.normpath(implementation_header))): | 193 os.path.normpath(implementation_header))): |
191 if "implemented_in" in namespace.compiler_options: | 194 if "implemented_in" in namespace.compiler_options: |
192 raise ValueError('Header file for namespace "%s" specified in ' | 195 raise ValueError('Header file for namespace "%s" specified in ' |
193 'compiler_options not found: %s' % | 196 'compiler_options not found: %s' % |
194 (namespace.unix_name, implementation_header)) | 197 (namespace.unix_name, implementation_header)) |
195 continue | 198 continue |
196 ifdefs = self._bundle._GetPlatformIfdefs(namespace) | 199 ifdefs = self._bundle._GetPlatformIfdefs(namespace) |
197 if ifdefs is not None: | 200 if ifdefs is not None: |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 c.Eblock('}') | 302 c.Eblock('}') |
300 c.Append() | 303 c.Append() |
301 c.Append('// static') | 304 c.Append('// static') |
302 c.Sblock('bool GeneratedSchemas::IsGenerated(std::string name) {') | 305 c.Sblock('bool GeneratedSchemas::IsGenerated(std::string name) {') |
303 c.Append('return g_lazy_instance.Get().schemas.count(name) > 0;') | 306 c.Append('return g_lazy_instance.Get().schemas.count(name) > 0;') |
304 c.Eblock('}') | 307 c.Eblock('}') |
305 c.Append() | 308 c.Append() |
306 c.Concat(cpp_util.CloseNamespace(self._bundle._cpp_namespace)) | 309 c.Concat(cpp_util.CloseNamespace(self._bundle._cpp_namespace)) |
307 c.Append() | 310 c.Append() |
308 return c | 311 return c |
OLD | NEW |