| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/python | |
| 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 | |
| 4 # BSD-style license that can be found in the LICENSE file. | |
| 5 | |
| 6 """This is the entry point to create Dart APIs from the IDL database.""" | |
| 7 | |
| 8 import dartgenerator | |
| 9 import database | |
| 10 import logging.config | |
| 11 import multiemitter | |
| 12 import optparse | |
| 13 import os | |
| 14 import shutil | |
| 15 import subprocess | |
| 16 import sys | |
| 17 from generator import TypeRegistry | |
| 18 from htmlrenamer import HtmlRenamer | |
| 19 from systembase import GeneratorOptions | |
| 20 from systemdart2js import Dart2JSSystem | |
| 21 from systemhtml import HtmlInterfacesSystem, HtmlDart2JSSystem | |
| 22 from systeminterface import InterfacesSystem | |
| 23 from systemnative import NativeImplementationSystem | |
| 24 from templateloader import TemplateLoader | |
| 25 | |
| 26 _logger = logging.getLogger('dartdomgenerator') | |
| 27 | |
| 28 _webkit_renames = { | |
| 29 # W3C -> WebKit name conversion | |
| 30 # TODO(vsm): Maybe Store these renames in the IDLs. | |
| 31 'ApplicationCache': 'DOMApplicationCache', | |
| 32 'BarProp': 'BarInfo', | |
| 33 'DedicatedWorkerGlobalScope': 'DedicatedWorkerContext', | |
| 34 'FormData': 'DOMFormData', | |
| 35 'Selection': 'DOMSelection', | |
| 36 'SharedWorkerGlobalScope': 'SharedWorkerContext', | |
| 37 'Window': 'DOMWindow', | |
| 38 'WorkerGlobalScope': 'WorkerContext'} | |
| 39 | |
| 40 def Generate(system_names, database_dir, use_database_cache, | |
| 41 html_output_dir): | |
| 42 current_dir = os.path.dirname(__file__) | |
| 43 auxiliary_dir = os.path.join(current_dir, '..', 'src') | |
| 44 template_dir = os.path.join(current_dir, '..', 'templates') | |
| 45 | |
| 46 generator = dartgenerator.DartGenerator() | |
| 47 generator.LoadAuxiliary(auxiliary_dir) | |
| 48 | |
| 49 common_database = database.Database(database_dir) | |
| 50 if use_database_cache: | |
| 51 common_database.LoadFromCache() | |
| 52 else: | |
| 53 common_database.Load() | |
| 54 | |
| 55 generator.FilterMembersWithUnidentifiedTypes(common_database) | |
| 56 webkit_database = common_database.Clone() | |
| 57 | |
| 58 # Generate Dart interfaces for the WebKit DOM. | |
| 59 generator.FilterInterfaces(database = webkit_database, | |
| 60 or_annotations = ['WebKit', 'Dart'], | |
| 61 exclude_displaced = ['WebKit'], | |
| 62 exclude_suppressed = ['WebKit', 'Dart']) | |
| 63 generator.RenameTypes(webkit_database, _webkit_renames, True) | |
| 64 generator.FixEventTargets(webkit_database) | |
| 65 generator.AddMissingArguments(webkit_database) | |
| 66 | |
| 67 def CreateGeneratorOptions(template_paths, conditions, type_registry, output_d
ir, | |
| 68 renamer=None): | |
| 69 template_loader = TemplateLoader(template_dir, template_paths, conditions) | |
| 70 return GeneratorOptions( | |
| 71 template_loader, webkit_database, emitters, type_registry, renamer, | |
| 72 output_dir) | |
| 73 | |
| 74 def Generate(system): | |
| 75 generator.Generate(webkit_database, system, | |
| 76 super_database=common_database, | |
| 77 webkit_renames=_webkit_renames) | |
| 78 | |
| 79 emitters = multiemitter.MultiEmitter() | |
| 80 | |
| 81 for system_name in system_names: | |
| 82 renamer = HtmlRenamer(webkit_database) | |
| 83 type_registry = TypeRegistry(webkit_database, renamer) | |
| 84 if system_name == 'htmldart2js': | |
| 85 options = CreateGeneratorOptions( | |
| 86 ['html/dart2js', 'html/impl', 'html', ''], | |
| 87 {'DARTIUM': False, 'DART2JS': True}, | |
| 88 type_registry, html_output_dir, renamer) | |
| 89 backend = HtmlDart2JSSystem(options) | |
| 90 else: | |
| 91 options = CreateGeneratorOptions( | |
| 92 ['html/dartium', 'html/impl', ''], | |
| 93 {'DARTIUM': True, 'DART2JS': False}, | |
| 94 type_registry, html_output_dir, renamer) | |
| 95 backend = NativeImplementationSystem(options, auxiliary_dir) | |
| 96 options = CreateGeneratorOptions( | |
| 97 ['html/interface', 'html/impl', 'html', ''], {}, | |
| 98 type_registry, html_output_dir, renamer) | |
| 99 html_system = HtmlInterfacesSystem(options, backend) | |
| 100 Generate(html_system) | |
| 101 | |
| 102 _logger.info('Flush...') | |
| 103 emitters.Flush() | |
| 104 | |
| 105 def GenerateSingleFile(systems): | |
| 106 if 'htmldart2js' in systems: | |
| 107 _logger.info('Copy html_dart2js to ../html/dart2js/') | |
| 108 subprocess.call(['cd ../../html/generated ; ' | |
| 109 '../../../tools/copy_dart.py ../dart2js html_dart2js.dart']
, | |
| 110 shell=True) | |
| 111 | |
| 112 if 'htmldartium' in systems: | |
| 113 _logger.info('Copy html_dartium to ../html/dartium/') | |
| 114 subprocess.call(['cd ../../html/generated ; ' | |
| 115 '../../../tools/copy_dart.py ../dartium html_dartium.dart']
, | |
| 116 shell=True) | |
| 117 | |
| 118 def main(): | |
| 119 parser = optparse.OptionParser() | |
| 120 parser.add_option('--systems', dest='systems', | |
| 121 action='store', type='string', | |
| 122 default='htmldart2js,htmldartium', | |
| 123 help='Systems to generate (htmldart2js, htmldartium)') | |
| 124 parser.add_option('--output-dir', dest='output_dir', | |
| 125 action='store', type='string', | |
| 126 default=None, | |
| 127 help='Directory to put the generated files') | |
| 128 parser.add_option('--use-database-cache', dest='use_database_cache', | |
| 129 action='store_true', | |
| 130 default=False, | |
| 131 help='''Use the cached database from the previous run to | |
| 132 improve startup performance''') | |
| 133 (options, args) = parser.parse_args() | |
| 134 | |
| 135 current_dir = os.path.dirname(__file__) | |
| 136 database_dir = os.path.join(current_dir, '..', 'database') | |
| 137 logging.config.fileConfig(os.path.join(current_dir, 'logging.conf')) | |
| 138 systems = options.systems.split(',') | |
| 139 | |
| 140 html_output_dir = options.output_dir or os.path.join(current_dir, | |
| 141 '../../html/generated') | |
| 142 Generate(systems, database_dir, options.use_database_cache, | |
| 143 html_output_dir) | |
| 144 GenerateSingleFile(systems) | |
| 145 | |
| 146 if __name__ == '__main__': | |
| 147 sys.exit(main()) | |
| OLD | NEW |