| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 2 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 3 # for details. All rights reserved. Use of this source code is governed by a | 3 # for details. All rights reserved. Use of this source code is governed by a |
| 4 # BSD-style license that can be found in the LICENSE file. | 4 # BSD-style license that can be found in the LICENSE file. |
| 5 | 5 |
| 6 """This is the entry point to create Dart APIs from the IDL database.""" | 6 """This is the entry point to create Dart APIs from the IDL database.""" |
| 7 | 7 |
| 8 import dartgenerator | 8 import dartgenerator |
| 9 import database | 9 import database |
| 10 import logging.config | 10 import logging.config |
| 11 import os | 11 import os |
| 12 import shutil | 12 import shutil |
| 13 import sys | 13 import sys |
| 14 | 14 |
| 15 DOM_LIBRARY = 'dom.dart' | 15 DOM_LIBRARY = 'dom.dart' |
| 16 DOM_DEFAULT_LIBRARY = 'wrapping_dom.dart' | 16 DOM_DEFAULT_LIBRARY = 'wrapping_dom.dart' |
| 17 | 17 |
| 18 _logger = logging.getLogger('dartdomgenerator') | 18 _logger = logging.getLogger('dartdomgenerator') |
| 19 | 19 |
| 20 _webkit_renames = { | 20 _webkit_renames = { |
| 21 # W3C -> WebKit name conversion | 21 # W3C -> WebKit name conversion |
| 22 # TODO(vsm): Maybe Store these renames in the IDLs. | 22 # TODO(vsm): Maybe Store these renames in the IDLs. |
| 23 'ApplicationCache': 'DOMApplicationCache', | 23 'ApplicationCache': 'DOMApplicationCache', |
| 24 'BarProp': 'BarInfo', | 24 'BarProp': 'BarInfo', |
| 25 'DedicatedWorkerGlobalScope': 'DedicatedWorkerContext', | 25 'DedicatedWorkerGlobalScope': 'DedicatedWorkerContext', |
| 26 'FormData': 'DOMFormData', | 26 'FormData': 'DOMFormData', |
| 27 'Selection': 'DOMSelection', | 27 'Selection': 'DOMSelection', |
| 28 'SharedWorkerGlobalScope': 'SharedWorkercontext', | 28 'SharedWorkerGlobalScope': 'SharedWorkerContext', |
| 29 'Window': 'DOMWindow', | 29 'Window': 'DOMWindow', |
| 30 'WorkerGlobalScope': 'WorkerContext'} | 30 'WorkerGlobalScope': 'WorkerContext'} |
| 31 | 31 |
| 32 _webkit_renames_inverse = dict((v,k) for k, v in _webkit_renames.iteritems()) | 32 _webkit_renames_inverse = dict((v,k) for k, v in _webkit_renames.iteritems()) |
| 33 | 33 |
| 34 def GenerateDOM(): | 34 def GenerateDOM(output_dir): |
| 35 # TODO(sra): Make this entry point also generate HTML. | 35 # TODO(sra): Make this entry point also generate HTML. |
| 36 current_dir = os.path.dirname(__file__) | 36 current_dir = os.path.dirname(__file__) |
| 37 | 37 |
| 38 generator = dartgenerator.DartGenerator( | 38 generator = dartgenerator.DartGenerator( |
| 39 auxiliary_dir=os.path.join(current_dir, '..', 'src'), | 39 auxiliary_dir=os.path.join(current_dir, '..', 'src'), |
| 40 template_dir=os.path.join(current_dir, '..', 'templates'), |
| 40 base_package='') | 41 base_package='') |
| 41 generator.LoadAuxiliary() | 42 generator.LoadAuxiliary() |
| 42 | 43 |
| 43 common_database = database.Database( | 44 common_database = database.Database( |
| 44 os.path.join(current_dir, '..', 'database')) | 45 os.path.join(current_dir, '..', 'database')) |
| 45 common_database.Load() | 46 common_database.Load() |
| 46 # Remove these types since they are mapped directly to dart. | 47 # Remove these types since they are mapped directly to dart. |
| 47 common_database.DeleteInterface('DOMStringMap') | 48 common_database.DeleteInterface('DOMStringMap') |
| 48 common_database.DeleteInterface('DOMStringList') | 49 common_database.DeleteInterface('DOMStringList') |
| 49 generator.RenameTypes(common_database, { | 50 generator.RenameTypes(common_database, { |
| 50 # W3C -> Dart renames | 51 # W3C -> Dart renames |
| 51 'AbstractView': 'Window', | 52 'AbstractView': 'Window', |
| 52 'Function': 'EventListener', | 53 'Function': 'EventListener', |
| 53 'DOMStringMap': 'Map<String, String>', | 54 'DOMStringMap': 'Map<String, String>', |
| 54 'DOMStringList': 'List<String>', | 55 'DOMStringList': 'List<String>', |
| 55 }) | 56 }) |
| 56 generator.FilterMembersWithUnidentifiedTypes(common_database) | 57 generator.FilterMembersWithUnidentifiedTypes(common_database) |
| 57 generator.ConvertToDartTypes(common_database) | 58 generator.ConvertToDartTypes(common_database) |
| 58 webkit_database = common_database.Clone() | 59 webkit_database = common_database.Clone() |
| 59 | 60 |
| 60 output_dir = os.path.join(current_dir, '..', 'generated') | 61 generated_output_dir = os.path.join(output_dir, 'generated') |
| 61 lib_dir = os.path.join(current_dir, '..') | 62 if os.path.exists(generated_output_dir): |
| 62 if os.path.exists(output_dir): | 63 _logger.info('Cleaning output directory %s' % generated_output_dir) |
| 63 _logger.info('Cleaning output directory %s' % output_dir) | 64 shutil.rmtree(generated_output_dir) |
| 64 shutil.rmtree(output_dir) | |
| 65 | 65 |
| 66 | 66 |
| 67 # Generate Dart interfaces for the WebKit DOM. | 67 # Generate Dart interfaces for the WebKit DOM. |
| 68 webkit_output_dir = output_dir | 68 webkit_output_dir = generated_output_dir |
| 69 generator.FilterInterfaces(database = webkit_database, | 69 generator.FilterInterfaces(database = webkit_database, |
| 70 or_annotations = ['WebKit', 'Dart'], | 70 or_annotations = ['WebKit', 'Dart'], |
| 71 exclude_displaced = ['WebKit'], | 71 exclude_displaced = ['WebKit'], |
| 72 exclude_suppressed = ['WebKit', 'Dart']) | 72 exclude_suppressed = ['WebKit', 'Dart']) |
| 73 generator.RenameTypes(webkit_database, _webkit_renames) | 73 generator.RenameTypes(webkit_database, _webkit_renames) |
| 74 | 74 |
| 75 generator.Generate(database = webkit_database, | 75 generator.Generate(database = webkit_database, |
| 76 output_dir = webkit_output_dir, | 76 output_dir = webkit_output_dir, |
| 77 lib_dir = lib_dir, | 77 lib_dir = output_dir, |
| 78 module_source_preference = ['WebKit', 'Dart'], | 78 module_source_preference = ['WebKit', 'Dart'], |
| 79 source_filter = ['WebKit', 'Dart'], | 79 source_filter = ['WebKit', 'Dart'], |
| 80 super_database = common_database, | 80 super_database = common_database, |
| 81 common_prefix = 'common', | 81 common_prefix = 'common', |
| 82 super_map = _webkit_renames_inverse) | 82 super_map = _webkit_renames_inverse) |
| 83 | 83 |
| 84 generator.Flush() | 84 generator.Flush() |
| 85 | 85 |
| 86 # Install default DOM library. | 86 # Install default DOM library. |
| 87 default = os.path.join(lib_dir, DOM_DEFAULT_LIBRARY) | 87 default = os.path.join(output_dir, DOM_DEFAULT_LIBRARY) |
| 88 target = os.path.join(lib_dir, DOM_LIBRARY) | 88 target = os.path.join(output_dir, DOM_LIBRARY) |
| 89 shutil.copyfile(default, target) | 89 shutil.copyfile(default, target) |
| 90 | 90 |
| 91 def main(): | 91 def main(): |
| 92 current_dir = os.path.dirname(__file__) | 92 current_dir = os.path.dirname(__file__) |
| 93 logging.config.fileConfig(os.path.join(current_dir, 'logging.conf')) | 93 logging.config.fileConfig(os.path.join(current_dir, 'logging.conf')) |
| 94 GenerateDOM() | 94 GenerateDOM(os.path.join(current_dir, '..', 'generated')) |
| 95 | 95 |
| 96 if __name__ == '__main__': | 96 if __name__ == '__main__': |
| 97 sys.exit(main()) | 97 sys.exit(main()) |
| OLD | NEW |