| 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 fremontcutbuilder | 10 import fremontcutbuilder |
| 11 import logging.config | 11 import logging.config |
| 12 import monitored | 12 import monitored |
| 13 import multiemitter | 13 import multiemitter |
| 14 import optparse | 14 import optparse |
| 15 import os | 15 import os |
| 16 import shutil | 16 import shutil |
| 17 import subprocess | 17 import subprocess |
| 18 import sys | 18 import sys |
| 19 from dartmetadata import DartMetadata |
| 19 from generator import TypeRegistry | 20 from generator import TypeRegistry |
| 20 from htmleventgenerator import HtmlEventGenerator | 21 from htmleventgenerator import HtmlEventGenerator |
| 21 from htmlrenamer import HtmlRenamer | 22 from htmlrenamer import HtmlRenamer |
| 22 from systemhtml import DartLibraryEmitter, Dart2JSBackend,\ | 23 from systemhtml import DartLibraryEmitter, Dart2JSBackend,\ |
| 23 HtmlDartInterfaceGenerator, DartLibrary, DartLibraries,\ | 24 HtmlDartInterfaceGenerator, DartLibrary, DartLibraries,\ |
| 24 HTML_LIBRARY_NAMES | 25 HTML_LIBRARY_NAMES |
| 25 from systemnative import CPPLibraryEmitter, DartiumBackend | 26 from systemnative import CPPLibraryEmitter, DartiumBackend |
| 26 from templateloader import TemplateLoader | 27 from templateloader import TemplateLoader |
| 27 | 28 |
| 28 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..')) | 29 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..')) |
| 29 import utils | 30 import utils |
| 30 | 31 |
| 31 _logger = logging.getLogger('dartdomgenerator') | 32 _logger = logging.getLogger('dartdomgenerator') |
| 32 | 33 |
| 33 class GeneratorOptions(object): | 34 class GeneratorOptions(object): |
| 34 def __init__(self, templates, database, type_registry, renamer): | 35 def __init__(self, templates, database, type_registry, renamer, |
| 36 metadata): |
| 35 self.templates = templates | 37 self.templates = templates |
| 36 self.database = database | 38 self.database = database |
| 37 self.type_registry = type_registry | 39 self.type_registry = type_registry |
| 38 self.renamer = renamer | 40 self.renamer = renamer |
| 41 self.metadata = metadata; |
| 39 | 42 |
| 40 def LoadDatabase(database_dir, use_database_cache): | 43 def LoadDatabase(database_dir, use_database_cache): |
| 41 common_database = database.Database(database_dir) | 44 common_database = database.Database(database_dir) |
| 42 if use_database_cache: | 45 if use_database_cache: |
| 43 common_database.LoadFromCache() | 46 common_database.LoadFromCache() |
| 44 else: | 47 else: |
| 45 common_database.Load() | 48 common_database.Load() |
| 46 return common_database | 49 return common_database |
| 47 | 50 |
| 48 def GenerateFromDatabase(common_database, dart2js_output_dir, | 51 def GenerateFromDatabase(common_database, dart2js_output_dir, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 61 generator.FilterInterfaces(database = webkit_database, | 64 generator.FilterInterfaces(database = webkit_database, |
| 62 or_annotations = ['WebKit', 'Dart'], | 65 or_annotations = ['WebKit', 'Dart'], |
| 63 exclude_displaced = ['WebKit'], | 66 exclude_displaced = ['WebKit'], |
| 64 exclude_suppressed = ['WebKit', 'Dart']) | 67 exclude_suppressed = ['WebKit', 'Dart']) |
| 65 generator.FixEventTargets(webkit_database) | 68 generator.FixEventTargets(webkit_database) |
| 66 generator.AddMissingArguments(webkit_database) | 69 generator.AddMissingArguments(webkit_database) |
| 67 | 70 |
| 68 emitters = multiemitter.MultiEmitter() | 71 emitters = multiemitter.MultiEmitter() |
| 69 renamer = HtmlRenamer(webkit_database) | 72 renamer = HtmlRenamer(webkit_database) |
| 70 type_registry = TypeRegistry(webkit_database, renamer) | 73 type_registry = TypeRegistry(webkit_database, renamer) |
| 74 metadata = DartMetadata( |
| 75 os.path.join(current_dir, '..', 'dom.json'), |
| 76 os.path.join(current_dir, '..', 'docs', 'docs.json')) |
| 71 | 77 |
| 72 def RunGenerator(dart_libraries, dart_output_dir, | 78 def RunGenerator(dart_libraries, dart_output_dir, |
| 73 template_loader, backend_factory): | 79 template_loader, backend_factory): |
| 74 options = GeneratorOptions( | 80 options = GeneratorOptions( |
| 75 template_loader, webkit_database, type_registry, renamer) | 81 template_loader, webkit_database, type_registry, renamer, |
| 82 metadata) |
| 76 dart_library_emitter = DartLibraryEmitter( | 83 dart_library_emitter = DartLibraryEmitter( |
| 77 emitters, dart_output_dir, dart_libraries) | 84 emitters, dart_output_dir, dart_libraries) |
| 78 event_generator = HtmlEventGenerator(webkit_database, renamer, | 85 event_generator = HtmlEventGenerator(webkit_database, renamer, metadata, |
| 79 template_loader) | 86 template_loader) |
| 80 | 87 |
| 81 def generate_interface(interface): | 88 def generate_interface(interface): |
| 82 backend = backend_factory(interface) | 89 backend = backend_factory(interface) |
| 83 interface_generator = HtmlDartInterfaceGenerator( | 90 interface_generator = HtmlDartInterfaceGenerator( |
| 84 options, dart_library_emitter, event_generator, interface, backend) | 91 options, dart_library_emitter, event_generator, interface, backend) |
| 85 interface_generator.Generate() | 92 interface_generator.Generate() |
| 86 | 93 |
| 87 generator.Generate(webkit_database, common_database, generate_interface) | 94 generator.Generate(webkit_database, common_database, generate_interface) |
| 88 | 95 |
| 89 dart_library_emitter.EmitLibraries(auxiliary_dir) | 96 dart_library_emitter.EmitLibraries(auxiliary_dir) |
| 90 | 97 |
| 91 if dart2js_output_dir: | 98 if dart2js_output_dir: |
| 92 template_paths = ['html/dart2js', 'html/impl', 'html/interface', ''] | 99 template_paths = ['html/dart2js', 'html/impl', 'html/interface', ''] |
| 93 template_loader = TemplateLoader(template_dir, | 100 template_loader = TemplateLoader(template_dir, |
| 94 template_paths, | 101 template_paths, |
| 95 {'DARTIUM': False, 'DART2JS': True}) | 102 {'DARTIUM': False, 'DART2JS': True}) |
| 96 backend_options = GeneratorOptions( | 103 backend_options = GeneratorOptions( |
| 97 template_loader, webkit_database, type_registry, renamer) | 104 template_loader, webkit_database, type_registry, renamer, |
| 105 metadata) |
| 98 backend_factory = lambda interface:\ | 106 backend_factory = lambda interface:\ |
| 99 Dart2JSBackend(interface, backend_options) | 107 Dart2JSBackend(interface, backend_options) |
| 100 | 108 |
| 101 dart_output_dir = os.path.join(dart2js_output_dir, 'dart') | 109 dart_output_dir = os.path.join(dart2js_output_dir, 'dart') |
| 102 dart_libraries = DartLibraries( | 110 dart_libraries = DartLibraries( |
| 103 HTML_LIBRARY_NAMES, template_loader, 'dart2js', dart2js_output_dir) | 111 HTML_LIBRARY_NAMES, template_loader, 'dart2js', dart2js_output_dir) |
| 104 | 112 |
| 105 RunGenerator(dart_libraries, dart_output_dir, | 113 RunGenerator(dart_libraries, dart_output_dir, |
| 106 template_loader, backend_factory) | 114 template_loader, backend_factory) |
| 107 | 115 |
| 108 if dartium_output_dir: | 116 if dartium_output_dir: |
| 109 template_paths = ['html/dartium', 'html/impl', 'html/interface', ''] | 117 template_paths = ['html/dartium', 'html/impl', 'html/interface', ''] |
| 110 template_loader = TemplateLoader(template_dir, | 118 template_loader = TemplateLoader(template_dir, |
| 111 template_paths, | 119 template_paths, |
| 112 {'DARTIUM': True, 'DART2JS': False}) | 120 {'DARTIUM': True, 'DART2JS': False}) |
| 113 backend_options = GeneratorOptions( | 121 backend_options = GeneratorOptions( |
| 114 template_loader, webkit_database, type_registry, renamer) | 122 template_loader, webkit_database, type_registry, renamer, |
| 123 metadata) |
| 115 cpp_output_dir = os.path.join(dartium_output_dir, 'cpp') | 124 cpp_output_dir = os.path.join(dartium_output_dir, 'cpp') |
| 116 cpp_library_emitter = CPPLibraryEmitter(emitters, cpp_output_dir) | 125 cpp_library_emitter = CPPLibraryEmitter(emitters, cpp_output_dir) |
| 117 backend_factory = lambda interface:\ | 126 backend_factory = lambda interface:\ |
| 118 DartiumBackend(interface, cpp_library_emitter, backend_options) | 127 DartiumBackend(interface, cpp_library_emitter, backend_options) |
| 119 | 128 |
| 120 dart_output_dir = os.path.join(dartium_output_dir, 'dart') | 129 dart_output_dir = os.path.join(dartium_output_dir, 'dart') |
| 121 dart_libraries = DartLibraries( | 130 dart_libraries = DartLibraries( |
| 122 HTML_LIBRARY_NAMES, template_loader, 'dartium', dartium_output_dir) | 131 HTML_LIBRARY_NAMES, template_loader, 'dartium', dartium_output_dir) |
| 123 | 132 |
| 124 RunGenerator(dart_libraries, dart_output_dir, | 133 RunGenerator(dart_libraries, dart_output_dir, |
| 125 template_loader, backend_factory) | 134 template_loader, backend_factory) |
| 126 cpp_library_emitter.EmitDerivedSources( | 135 cpp_library_emitter.EmitDerivedSources( |
| 127 template_loader.Load('cpp_derived_sources.template'), | 136 template_loader.Load('cpp_derived_sources.template'), |
| 128 dartium_output_dir) | 137 dartium_output_dir) |
| 129 cpp_library_emitter.EmitResolver( | 138 cpp_library_emitter.EmitResolver( |
| 130 template_loader.Load('cpp_resolver.template'), dartium_output_dir) | 139 template_loader.Load('cpp_resolver.template'), dartium_output_dir) |
| 131 | 140 |
| 132 _logger.info('Flush...') | 141 _logger.info('Flush...') |
| 133 emitters.Flush() | 142 emitters.Flush() |
| 143 metadata.Flush() |
| 134 | 144 |
| 135 monitored.FinishMonitoring(dart2js_output_dir) | 145 monitored.FinishMonitoring(dart2js_output_dir) |
| 136 | 146 |
| 137 def GenerateSingleFile(library_path, output_dir, generated_output_dir=None): | 147 def GenerateSingleFile(library_path, output_dir, generated_output_dir=None): |
| 138 library_dir = os.path.dirname(library_path) | 148 library_dir = os.path.dirname(library_path) |
| 139 library_filename = os.path.basename(library_path) | 149 library_filename = os.path.basename(library_path) |
| 140 copy_dart_script = os.path.relpath('../../copy_dart.py', | 150 copy_dart_script = os.path.relpath('../../copy_dart.py', |
| 141 library_dir) | 151 library_dir) |
| 142 output_dir = os.path.relpath(output_dir, library_dir) | 152 output_dir = os.path.relpath(output_dir, library_dir) |
| 143 command = ' '.join(['cd', library_dir, ';', | 153 command = ' '.join(['cd', library_dir, ';', |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 os.path.join('..', '..', '..', 'sdk', 'lib', library_name, 'dart2js')) | 209 os.path.join('..', '..', '..', 'sdk', 'lib', library_name, 'dart2js')) |
| 200 if 'htmldartium' in systems: | 210 if 'htmldartium' in systems: |
| 201 _logger.info('Generating dartium single files.') | 211 _logger.info('Generating dartium single files.') |
| 202 for library_name in HTML_LIBRARY_NAMES: | 212 for library_name in HTML_LIBRARY_NAMES: |
| 203 GenerateSingleFile( | 213 GenerateSingleFile( |
| 204 os.path.join(dartium_output_dir, '%s_dartium.dart' % library_name), | 214 os.path.join(dartium_output_dir, '%s_dartium.dart' % library_name), |
| 205 os.path.join('..', '..', '..', 'sdk', 'lib', library_name, 'dartium')) | 215 os.path.join('..', '..', '..', 'sdk', 'lib', library_name, 'dartium')) |
| 206 | 216 |
| 207 if __name__ == '__main__': | 217 if __name__ == '__main__': |
| 208 sys.exit(main()) | 218 sys.exit(main()) |
| OLD | NEW |