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 |
11 import json | 11 import json |
12 import os | 12 import os |
13 import re | 13 import re |
14 | 14 |
15 # TODO(miket/asargent) - parameterize this. | 15 # TODO(miket/asargent) - parameterize this. |
16 SOURCE_BASE_PATH = 'chrome/common/extensions/api' | 16 SOURCE_BASE_PATH = 'chrome/common/extensions/api' |
17 | 17 |
18 class SchemaBundleGenerator(object): | 18 class SchemaBundleGenerator(object): |
19 """This class contains methods to generate code based on multiple schemas. | 19 """This class contains methods to generate code based on multiple schemas. |
20 """ | 20 """ |
21 | 21 |
22 def __init__(self, model, api_defs, cpp_type_generator): | 22 def __init__(self, root, model, api_defs, cpp_type_generator): |
| 23 self._root = root; |
23 self._model = model | 24 self._model = model |
24 self._api_defs = api_defs | 25 self._api_defs = api_defs |
25 self._cpp_type_generator = cpp_type_generator | 26 self._cpp_type_generator = cpp_type_generator |
26 | 27 |
27 def GenerateHeader(self, file_base, body_code): | 28 def GenerateHeader(self, file_base, body_code): |
28 """Generates a code.Code object for a header file | 29 """Generates a code.Code object for a header file |
29 | 30 |
30 Parameters: | 31 Parameters: |
31 - |file_base| - the base of the filename, e.g. 'foo' (for 'foo.h') | 32 - |file_base| - the base of the filename, e.g. 'foo' (for 'foo.h') |
32 - |body_code| - the code to put in between the multiple inclusion guards""" | 33 - |body_code| - the code to put in between the multiple inclusion guards""" |
(...skipping 28 matching lines...) Expand all Loading... |
61 | 62 |
62 def GenerateAPIHeader(self): | 63 def GenerateAPIHeader(self): |
63 """Generates the header for API registration / declaration""" | 64 """Generates the header for API registration / declaration""" |
64 c = code.Code() | 65 c = code.Code() |
65 | 66 |
66 c.Append('#include <string>') | 67 c.Append('#include <string>') |
67 c.Append() | 68 c.Append() |
68 c.Append('#include "base/basictypes.h"') | 69 c.Append('#include "base/basictypes.h"') |
69 | 70 |
70 for namespace in self._model.namespaces.values(): | 71 for namespace in self._model.namespaces.values(): |
71 ifdefs = self._GetPlatformIfdefs(namespace) | |
72 if ifdefs is not None: | |
73 c.Append("#if %s" % ifdefs, indent_level=0) | |
74 | |
75 namespace_name = namespace.unix_name.replace("experimental_", "") | 72 namespace_name = namespace.unix_name.replace("experimental_", "") |
76 implementation_header = namespace.compiler_options.get( | 73 implementation_header = namespace.compiler_options.get( |
77 "implemented_in", | 74 "implemented_in", |
78 "chrome/browser/extensions/api/%s/%s_api.h" % (namespace_name, | 75 "chrome/browser/extensions/api/%s/%s_api.h" % (namespace_name, |
79 namespace_name)) | 76 namespace_name)) |
| 77 if not os.path.exists( |
| 78 os.path.join(self._root, os.path.normpath(implementation_header))): |
| 79 if "implemented_in" in namespace.compiler_options: |
| 80 raise ValueError('Header file for namespace "%s" specified in ' |
| 81 'compiler_options not found: %s' % |
| 82 (namespace.unix_name, implementation_header)) |
| 83 continue |
| 84 ifdefs = self._GetPlatformIfdefs(namespace) |
| 85 if ifdefs is not None: |
| 86 c.Append("#if %s" % ifdefs, indent_level=0) |
| 87 |
80 c.Append('#include "%s"' % implementation_header) | 88 c.Append('#include "%s"' % implementation_header) |
81 | 89 |
82 if ifdefs is not None: | 90 if ifdefs is not None: |
83 c.Append("#endif // %s" % ifdefs, indent_level=0) | 91 c.Append("#endif // %s" % ifdefs, indent_level=0) |
84 | 92 |
85 c.Append() | 93 c.Append() |
86 c.Append("class ExtensionFunctionRegistry;") | 94 c.Append("class ExtensionFunctionRegistry;") |
87 c.Append() | 95 c.Append() |
88 | 96 |
89 c.Concat(self._cpp_type_generator.GetRootNamespaceStart()) | 97 c.Concat(self._cpp_type_generator.GetRootNamespaceStart()) |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 for index, line in enumerate(lines): | 189 for index, line in enumerate(lines): |
182 line = ' "%s"' % line | 190 line = ' "%s"' % line |
183 if index == len(lines) - 1: | 191 if index == len(lines) - 1: |
184 line += ';' | 192 line += ';' |
185 c.Append(line) | 193 c.Append(line) |
186 c.Eblock('}') | 194 c.Eblock('}') |
187 c.Append() | 195 c.Append() |
188 c.Concat(self._cpp_type_generator.GetRootNamespaceEnd()) | 196 c.Concat(self._cpp_type_generator.GetRootNamespaceEnd()) |
189 c.Append() | 197 c.Append() |
190 return c | 198 return c |
OLD | NEW |