| 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 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 # TODO(vsm): Maybe Store these renames in the IDLs. | 21 # TODO(vsm): Maybe Store these renames in the IDLs. |
| 22 'ApplicationCache': 'DOMApplicationCache', | 22 'ApplicationCache': 'DOMApplicationCache', |
| 23 'BarProp': 'BarInfo', | 23 'BarProp': 'BarInfo', |
| 24 'DedicatedWorkerGlobalScope': 'DedicatedWorkerContext', | 24 'DedicatedWorkerGlobalScope': 'DedicatedWorkerContext', |
| 25 'FormData': 'DOMFormData', | 25 'FormData': 'DOMFormData', |
| 26 'Selection': 'DOMSelection', | 26 'Selection': 'DOMSelection', |
| 27 'SharedWorkerGlobalScope': 'SharedWorkerContext', | 27 'SharedWorkerGlobalScope': 'SharedWorkerContext', |
| 28 'Window': 'DOMWindow', | 28 'Window': 'DOMWindow', |
| 29 'WorkerGlobalScope': 'WorkerContext'} | 29 'WorkerGlobalScope': 'WorkerContext'} |
| 30 | 30 |
| 31 _webkit_renames_inverse = dict((v,k) for k, v in _webkit_renames.iteritems()) | 31 _html_strip_webkit_prefix_classes = [ |
| 32 'Animation', |
| 33 'AnimationEvent', |
| 34 'AnimationList', |
| 35 'BlobBuilder', |
| 36 'CSSKeyframeRule', |
| 37 'CSSKeyframesRule', |
| 38 'CSSMatrix', |
| 39 'CSSTransformValue', |
| 40 'Flags', |
| 41 'LoseContext', |
| 42 'Point', |
| 43 'TransitionEvent'] |
| 32 | 44 |
| 33 def GenerateDOM(systems, output_dir): | 45 def HasAncestor(interface, names_to_match, database): |
| 34 # TODO(sra): Make this entry point also generate HTML. | 46 for parent in interface.parents: |
| 47 if (parent.type.id in names_to_match or |
| 48 (database.HasInterface(parent.type.id) and |
| 49 HasAncestor(database.GetInterface(parent.type.id), names_to_match, |
| 50 database))): |
| 51 return True |
| 52 return False |
| 53 |
| 54 def _MakeHtmlRenames(common_database): |
| 55 html_renames = {} |
| 56 |
| 57 for interface in common_database.GetInterfaces(): |
| 58 if (interface.id.startswith("HTML") and |
| 59 HasAncestor(interface, ['Element', 'Document'], common_database)): |
| 60 html_renames[interface.id] = interface.id[4:] |
| 61 |
| 62 for subclass in _html_strip_webkit_prefix_classes: |
| 63 html_renames['WebKit' + subclass] = subclass |
| 64 |
| 65 # TODO(jacobr): we almost want to add this commented out line back. |
| 66 # html_renames['HTMLCollection'] = 'ElementList' |
| 67 # html_renames['NodeList'] = 'ElementList' |
| 68 # html_renames['HTMLOptionsCollection'] = 'ElementList' |
| 69 html_renames['DOMWindow'] = 'Window' |
| 70 |
| 71 return html_renames |
| 72 |
| 73 def GenerateDOM(systems, generate_html_systems, output_dir, use_database_cache): |
| 35 current_dir = os.path.dirname(__file__) | 74 current_dir = os.path.dirname(__file__) |
| 36 | 75 |
| 37 generator = dartgenerator.DartGenerator( | 76 generator = dartgenerator.DartGenerator( |
| 38 auxiliary_dir=os.path.join(current_dir, '..', 'src'), | 77 auxiliary_dir=os.path.join(current_dir, '..', 'src'), |
| 39 template_dir=os.path.join(current_dir, '..', 'templates'), | 78 template_dir=os.path.join(current_dir, '..', 'templates'), |
| 40 base_package='') | 79 base_package='') |
| 41 generator.LoadAuxiliary() | 80 generator.LoadAuxiliary() |
| 42 | 81 |
| 43 common_database = database.Database( | 82 common_database = database.Database( |
| 44 os.path.join(current_dir, '..', 'database')) | 83 os.path.join(current_dir, '..', 'database')) |
| 45 common_database.Load() | 84 if use_database_cache: |
| 85 common_database.LoadFromCache() |
| 86 else: |
| 87 common_database.Load() |
| 46 # Remove these types since they are mapped directly to dart. | 88 # Remove these types since they are mapped directly to dart. |
| 47 common_database.DeleteInterface('DOMStringMap') | 89 common_database.DeleteInterface('DOMStringMap') |
| 48 common_database.DeleteInterface('DOMStringList') | 90 common_database.DeleteInterface('DOMStringList') |
| 91 |
| 49 generator.RenameTypes(common_database, { | 92 generator.RenameTypes(common_database, { |
| 50 # W3C -> Dart renames | 93 # W3C -> Dart renames |
| 51 'AbstractView': 'Window', | 94 'AbstractView': 'Window', |
| 52 'Function': 'EventListener', | 95 'Function': 'EventListener', |
| 53 'DOMStringMap': 'Map<String, String>', | 96 'DOMStringMap': 'Map<String, String>', |
| 54 'DOMStringList': 'List<String>', | 97 'DOMStringList': 'List<String>', |
| 55 }) | 98 }, False) |
| 56 generator.FilterMembersWithUnidentifiedTypes(common_database) | 99 generator.FilterMembersWithUnidentifiedTypes(common_database) |
| 57 generator.ConvertToDartTypes(common_database) | 100 generator.ConvertToDartTypes(common_database) |
| 58 webkit_database = common_database.Clone() | 101 webkit_database = common_database.Clone() |
| 59 | 102 |
| 60 generated_output_dir = os.path.join(output_dir, 'generated') | 103 generated_output_dir = os.path.join(output_dir, |
| 104 '../html/generated' if generate_html_systems else 'generated') |
| 61 if os.path.exists(generated_output_dir): | 105 if os.path.exists(generated_output_dir): |
| 62 _logger.info('Cleaning output directory %s' % generated_output_dir) | 106 _logger.info('Cleaning output directory %s' % generated_output_dir) |
| 63 shutil.rmtree(generated_output_dir) | 107 shutil.rmtree(generated_output_dir) |
| 64 | 108 |
| 65 | 109 |
| 66 # Generate Dart interfaces for the WebKit DOM. | 110 # Generate Dart interfaces for the WebKit DOM. |
| 67 webkit_output_dir = generated_output_dir | 111 webkit_output_dir = generated_output_dir |
| 68 generator.FilterInterfaces(database = webkit_database, | 112 generator.FilterInterfaces(database = webkit_database, |
| 69 or_annotations = ['WebKit', 'Dart'], | 113 or_annotations = ['WebKit', 'Dart'], |
| 70 exclude_displaced = ['WebKit'], | 114 exclude_displaced = ['WebKit'], |
| 71 exclude_suppressed = ['WebKit', 'Dart']) | 115 exclude_suppressed = ['WebKit', 'Dart']) |
| 72 generator.RenameTypes(webkit_database, _webkit_renames) | 116 generator.RenameTypes(webkit_database, _webkit_renames, False) |
| 117 |
| 118 if generate_html_systems: |
| 119 html_renames = _MakeHtmlRenames(common_database) |
| 120 generator.RenameTypes(webkit_database, html_renames, True) |
| 121 html_renames_inverse = dict((v,k) for k, v in html_renames.iteritems()) |
| 122 else: |
| 123 html_renames_inverse = {} |
| 124 |
| 125 webkit_renames_inverse = dict((v,k) for k, v in _webkit_renames.iteritems()) |
| 73 | 126 |
| 74 generator.Generate(database = webkit_database, | 127 generator.Generate(database = webkit_database, |
| 75 output_dir = webkit_output_dir, | 128 output_dir = webkit_output_dir, |
| 76 lib_dir = output_dir, | 129 lib_dir = output_dir, |
| 77 module_source_preference = ['WebKit', 'Dart'], | 130 module_source_preference = ['WebKit', 'Dart'], |
| 78 source_filter = ['WebKit', 'Dart'], | 131 source_filter = ['WebKit', 'Dart'], |
| 79 super_database = common_database, | 132 super_database = common_database, |
| 80 common_prefix = 'common', | 133 common_prefix = 'common', |
| 81 super_map = _webkit_renames_inverse, | 134 super_map = webkit_renames_inverse, |
| 135 html_map = html_renames_inverse, |
| 82 systems = systems) | 136 systems = systems) |
| 83 | 137 |
| 84 generator.Flush() | 138 generator.Flush() |
| 85 | 139 |
| 140 if 'frog' in systems: |
| 141 _logger.info('Copy dom_frog to frog/') |
| 142 subprocess.call(['cd .. ; ../tools/copy_dart.py frog dom_frog.dart'], |
| 143 shell=True); |
| 144 |
| 145 if 'htmlfrog' in systems: |
| 146 _logger.info('Copy html_frog to ../html/frog/') |
| 147 subprocess.call(['cd ../../html ; ../tools/copy_dart.py frog html_frog.dart'
], |
| 148 shell=True); |
| 149 |
| 86 def main(): | 150 def main(): |
| 87 parser = optparse.OptionParser() | 151 parser = optparse.OptionParser() |
| 88 parser.add_option('--systems', dest='systems', | 152 parser.add_option('--systems', dest='systems', |
| 89 action='store', type='string', | 153 action='store', type='string', |
| 90 default='frog,dummy,wrapping,htmlfrog', | 154 default='frog,dummy,wrapping', |
| 91 help='Systems to generate (frog, native, dummy, ' | 155 help='Systems to generate (frog, native, dummy, ' |
| 92 'htmlfrog)') | 156 'htmlfrog, htmldartium)') |
| 93 parser.add_option('--output-dir', dest='output_dir', | 157 parser.add_option('--output-dir', dest='output_dir', |
| 94 action='store', type='string', | 158 action='store', type='string', |
| 95 default=None, | 159 default=None, |
| 96 help='Directory to put the generated files') | 160 help='Directory to put the generated files') |
| 161 parser.add_option('--use-database-cache', dest='use_database_cache', |
| 162 action='store', |
| 163 default=False, |
| 164 help='''Use the cached database from the previous run to |
| 165 improve startup performance''') |
| 97 (options, args) = parser.parse_args() | 166 (options, args) = parser.parse_args() |
| 98 | 167 |
| 99 current_dir = os.path.dirname(__file__) | 168 current_dir = os.path.dirname(__file__) |
| 100 output_dir = options.output_dir or os.path.join(current_dir, '..') | |
| 101 systems = options.systems.split(',') | 169 systems = options.systems.split(',') |
| 170 num_html_systems = ('htmlfrog' in systems) + ('htmldartium' in systems) |
| 171 if num_html_systems > 0 and num_html_systems < len(systems): |
| 172 print 'Cannot generate html and dom bindings at the same time' |
| 173 sys.exit(-1) |
| 174 |
| 175 use_database_cache = options.use_database_cache |
| 176 generate_html_systems = ('htmlfrog' in systems) or ('htmldartium' in systems) |
| 177 output_dir = options.output_dir or ( |
| 178 os.path.join(current_dir, '../../html') if generate_html_systems else |
| 179 os.path.join(current_dir, '..')) |
| 102 | 180 |
| 103 logging.config.fileConfig(os.path.join(current_dir, 'logging.conf')) | 181 logging.config.fileConfig(os.path.join(current_dir, 'logging.conf')) |
| 104 GenerateDOM(systems, output_dir) | |
| 105 | 182 |
| 106 # Copy Frog DOM to frog/dom_frog.dart. | 183 GenerateDOM(systems, generate_html_systems, output_dir, use_database_cache) |
| 107 if 'frog' in systems: | |
| 108 _logger.info('Copy dom_frog to frog/') | |
| 109 subprocess.call(['cd .. ; ../tools/copy_dart.py frog dom_frog.dart'], | |
| 110 shell=True); | |
| 111 | 184 |
| 112 # Copy dummy DOM where dartc build expects it. | 185 # Copy dummy DOM where dartc build expects it. |
| 113 if 'dummy' in systems: | 186 if 'dummy' in systems: |
| 114 # TODO(sra): Make other tools pick this up directly, or do a copy_dart into | 187 # TODO(sra): Make other tools pick this up directly, or do a copy_dart into |
| 115 # a specific directory. | 188 # a specific directory. |
| 116 source = os.path.join(output_dir, 'dom_dummy.dart') | 189 source = os.path.join(output_dir, 'dom_dummy.dart') |
| 117 target = os.path.join(output_dir, 'dom.dart') | 190 target = os.path.join(output_dir, 'dom.dart') |
| 118 shutil.copyfile(source, target) | 191 shutil.copyfile(source, target) |
| 119 | 192 |
| 120 if __name__ == '__main__': | 193 if __name__ == '__main__': |
| 121 sys.exit(main()) | 194 sys.exit(main()) |
| OLD | NEW |