Chromium Code Reviews| 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 script_dir = os.path.dirname(os.path.abspath(__file__)) |
|
Devlin
2017/06/03 01:21:27
nit: comments showing the translation here would b
Dan Beam
2017/06/03 01:24:16
Done.
| |
| 41 src_root = os.path.normpath(os.path.join(script_dir, '..', '..')) | |
| 42 src_to_script = os.path.relpath(script_dir, src_root) | |
| 43 compiler_path = os.path.join(src_to_script, 'compiler.py') | |
| 44 (c.Append(self._GetHeader(compiler_path, self._namespace.name)) | |
| 41 .Append()) | 45 .Append()) |
| 42 | 46 |
| 43 self._AppendNamespaceObject(c) | 47 self._AppendNamespaceObject(c) |
| 44 | 48 |
| 45 for js_type in self._namespace.types.values(): | 49 for js_type in self._namespace.types.values(): |
| 46 self._AppendType(c, js_type) | 50 self._AppendType(c, js_type) |
| 47 | 51 |
| 48 for function in self._namespace.functions.values(): | 52 for function in self._namespace.functions.values(): |
| 49 self._AppendFunction(c, function) | 53 self._AppendFunction(c, function) |
| 50 | 54 |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 219 For example, it might return "chrome.namespace". | 223 For example, it might return "chrome.namespace". |
| 220 | 224 |
| 221 Also optionally includes the class name if this is in the context | 225 Also optionally includes the class name if this is in the context |
| 222 of outputting the members of a class. | 226 of outputting the members of a class. |
| 223 | 227 |
| 224 For example, "chrome.namespace.ClassName.prototype" | 228 For example, "chrome.namespace.ClassName.prototype" |
| 225 """ | 229 """ |
| 226 if self._class_name: | 230 if self._class_name: |
| 227 return 'chrome.%s.%s.prototype' % (self._namespace.name, self._class_name) | 231 return 'chrome.%s.%s.prototype' % (self._namespace.name, self._class_name) |
| 228 return 'chrome.%s' % self._namespace.name | 232 return 'chrome.%s' % self._namespace.name |
| OLD | NEW |