| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 Generator that produces an externs file for the Closure Compiler. | 5 Generator that produces an externs file for the Closure Compiler. |
| 6 Note: This is a work in progress, and generated externs may require tweaking. | 6 Note: This is a work in progress, and generated externs may require tweaking. |
| 7 | 7 |
| 8 See https://developers.google.com/closure/compiler/docs/api-tutorial3#externs | 8 See https://developers.google.com/closure/compiler/docs/api-tutorial3#externs |
| 9 """ | 9 """ |
| 10 | 10 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 class _Generator(object): | 30 class _Generator(object): |
| 31 def __init__(self, namespace): | 31 def __init__(self, namespace): |
| 32 self._namespace = namespace | 32 self._namespace = namespace |
| 33 self._class_name = None | 33 self._class_name = None |
| 34 self._js_util = JsUtil() | 34 self._js_util = JsUtil() |
| 35 | 35 |
| 36 def Generate(self): | 36 def Generate(self): |
| 37 """Generates a Code object with the schema for the entire namespace. | 37 """Generates a Code object with the schema for the entire namespace. |
| 38 """ | 38 """ |
| 39 c = Code() | 39 c = Code() |
| 40 (c.Append(self._GetHeader(sys.argv[0], self._namespace.name)) | 40 # /abs/path/src/tools/json_schema_compiler/ |
| 41 script_dir = os.path.dirname(os.path.abspath(__file__)) |
| 42 # /abs/path/src/ |
| 43 src_root = os.path.normpath(os.path.join(script_dir, '..', '..')) |
| 44 # tools/json_schema_compiler/ |
| 45 src_to_script = os.path.relpath(script_dir, src_root) |
| 46 # tools/json_schema_compiler/compiler.py |
| 47 compiler_path = os.path.join(src_to_script, 'compiler.py') |
| 48 (c.Append(self._GetHeader(compiler_path, self._namespace.name)) |
| 41 .Append()) | 49 .Append()) |
| 42 | 50 |
| 43 self._AppendNamespaceObject(c) | 51 self._AppendNamespaceObject(c) |
| 44 | 52 |
| 45 for js_type in self._namespace.types.values(): | 53 for js_type in self._namespace.types.values(): |
| 46 self._AppendType(c, js_type) | 54 self._AppendType(c, js_type) |
| 47 | 55 |
| 48 for function in self._namespace.functions.values(): | 56 for function in self._namespace.functions.values(): |
| 49 self._AppendFunction(c, function) | 57 self._AppendFunction(c, function) |
| 50 | 58 |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 For example, it might return "chrome.namespace". | 227 For example, it might return "chrome.namespace". |
| 220 | 228 |
| 221 Also optionally includes the class name if this is in the context | 229 Also optionally includes the class name if this is in the context |
| 222 of outputting the members of a class. | 230 of outputting the members of a class. |
| 223 | 231 |
| 224 For example, "chrome.namespace.ClassName.prototype" | 232 For example, "chrome.namespace.ClassName.prototype" |
| 225 """ | 233 """ |
| 226 if self._class_name: | 234 if self._class_name: |
| 227 return 'chrome.%s.%s.prototype' % (self._namespace.name, self._class_name) | 235 return 'chrome.%s.%s.prototype' % (self._namespace.name, self._class_name) |
| 228 return 'chrome.%s' % self._namespace.name | 236 return 'chrome.%s' % self._namespace.name |
| OLD | NEW |