| 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 multiemitter | 11 import multiemitter |
| 12 import optparse | 12 import optparse |
| 13 import os | 13 import os |
| 14 import shutil | 14 import shutil |
| 15 import subprocess | 15 import subprocess |
| 16 import sys | 16 import sys |
| 17 from generator import TypeRegistry | 17 from generator import TypeRegistry |
| 18 from htmlrenamer import HtmlRenamer | 18 from htmlrenamer import HtmlRenamer |
| 19 from systembase import GeneratorOptions | 19 from systembase import GeneratorOptions |
| 20 from systemfrog import FrogSystem | 20 from systemdart2js import Dart2JSSystem |
| 21 from systemhtml import HtmlInterfacesSystem, HtmlFrogSystem | 21 from systemhtml import HtmlInterfacesSystem, HtmlDart2JSSystem |
| 22 from systeminterface import InterfacesSystem | 22 from systeminterface import InterfacesSystem |
| 23 from systemnative import NativeImplementationSystem | 23 from systemnative import NativeImplementationSystem |
| 24 from templateloader import TemplateLoader | 24 from templateloader import TemplateLoader |
| 25 | 25 |
| 26 _logger = logging.getLogger('dartdomgenerator') | 26 _logger = logging.getLogger('dartdomgenerator') |
| 27 | 27 |
| 28 _webkit_renames = { | 28 _webkit_renames = { |
| 29 # W3C -> WebKit name conversion | 29 # W3C -> WebKit name conversion |
| 30 # TODO(vsm): Maybe Store these renames in the IDLs. | 30 # TODO(vsm): Maybe Store these renames in the IDLs. |
| 31 'ApplicationCache': 'DOMApplicationCache', | 31 'ApplicationCache': 'DOMApplicationCache', |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 output_dir) | 71 output_dir) |
| 72 | 72 |
| 73 def Generate(system): | 73 def Generate(system): |
| 74 generator.Generate(webkit_database, system, | 74 generator.Generate(webkit_database, system, |
| 75 super_database=common_database, | 75 super_database=common_database, |
| 76 webkit_renames=_webkit_renames) | 76 webkit_renames=_webkit_renames) |
| 77 | 77 |
| 78 emitters = multiemitter.MultiEmitter() | 78 emitters = multiemitter.MultiEmitter() |
| 79 | 79 |
| 80 for system_name in system_names: | 80 for system_name in system_names: |
| 81 if system_name in ['htmlfrog', 'htmldartium']: | 81 if system_name in ['htmldart2js', 'htmldartium']: |
| 82 renamer = HtmlRenamer(webkit_database) | 82 renamer = HtmlRenamer(webkit_database) |
| 83 type_registry = TypeRegistry(webkit_database, renamer) | 83 type_registry = TypeRegistry(webkit_database, renamer) |
| 84 if system_name == 'htmlfrog': | 84 if system_name == 'htmldart2js': |
| 85 options = CreateGeneratorOptions( | 85 options = CreateGeneratorOptions( |
| 86 ['html/frog', 'html/impl', 'html', ''], | 86 ['html/dart2js', 'html/impl', 'html', ''], |
| 87 {'DARTIUM': False, 'FROG': True}, | 87 {'DARTIUM': False, 'DART2JS': True}, |
| 88 type_registry, html_output_dir, renamer) | 88 type_registry, html_output_dir, renamer) |
| 89 backend = HtmlFrogSystem(options) | 89 backend = HtmlDart2JSSystem(options) |
| 90 else: | 90 else: |
| 91 options = CreateGeneratorOptions( | 91 options = CreateGeneratorOptions( |
| 92 ['dom/native', 'html/dartium', 'html/impl', ''], | 92 ['dom/native', 'html/dartium', 'html/impl', ''], |
| 93 {'DARTIUM': True, 'FROG': False}, | 93 {'DARTIUM': True, 'DART2JS': False}, |
| 94 type_registry, html_output_dir, renamer) | 94 type_registry, html_output_dir, renamer) |
| 95 backend = NativeImplementationSystem(options, auxiliary_dir) | 95 backend = NativeImplementationSystem(options, auxiliary_dir) |
| 96 options = CreateGeneratorOptions( | 96 options = CreateGeneratorOptions( |
| 97 ['html/interface', 'html/impl', 'html', ''], {}, | 97 ['html/interface', 'html/impl', 'html', ''], {}, |
| 98 type_registry, html_output_dir, renamer) | 98 type_registry, html_output_dir, renamer) |
| 99 html_system = HtmlInterfacesSystem(options, backend) | 99 html_system = HtmlInterfacesSystem(options, backend) |
| 100 Generate(html_system) | 100 Generate(html_system) |
| 101 else: | 101 else: |
| 102 type_registry = TypeRegistry(webkit_database) | 102 type_registry = TypeRegistry(webkit_database) |
| 103 options = CreateGeneratorOptions( | 103 options = CreateGeneratorOptions( |
| 104 ['dom/interface', 'dom', ''], {}, type_registry, dom_output_dir) | 104 ['dom/interface', 'dom', ''], {}, type_registry, dom_output_dir) |
| 105 interface_system = InterfacesSystem(options) | 105 interface_system = InterfacesSystem(options) |
| 106 if system_name == 'dummy': | 106 if system_name == 'dummy': |
| 107 options = CreateGeneratorOptions( | 107 options = CreateGeneratorOptions( |
| 108 ['dom/dummy', 'dom', ''], {}, type_registry, dom_output_dir) | 108 ['dom/dummy', 'dom', ''], {}, type_registry, dom_output_dir) |
| 109 implementation_system = dartgenerator.DummyImplementationSystem( | 109 implementation_system = dartgenerator.DummyImplementationSystem( |
| 110 options) | 110 options) |
| 111 elif system_name == 'frog': | 111 elif system_name == 'dart2js': |
| 112 options = CreateGeneratorOptions( | 112 options = CreateGeneratorOptions( |
| 113 ['dom/frog', 'dom', ''], {}, type_registry, dom_output_dir) | 113 ['dom/dart2js', 'dom', ''], {}, type_registry, dom_output_dir) |
| 114 implementation_system = FrogSystem(options) | 114 implementation_system = Dart2JSSystem(options) |
| 115 else: | 115 else: |
| 116 raise Exception('Unsupported system_name %s' % system_name) | 116 raise Exception('Unsupported system_name %s' % system_name) |
| 117 | 117 |
| 118 # Makes interface files available for listing in the library for the | 118 # Makes interface files available for listing in the library for the |
| 119 # implementation system. | 119 # implementation system. |
| 120 implementation_system._interface_system = interface_system | 120 implementation_system._interface_system = interface_system |
| 121 Generate(interface_system) | 121 Generate(interface_system) |
| 122 Generate(implementation_system) | 122 Generate(implementation_system) |
| 123 | 123 |
| 124 _logger.info('Flush...') | 124 _logger.info('Flush...') |
| 125 emitters.Flush() | 125 emitters.Flush() |
| 126 | 126 |
| 127 def GenerateSingleFile(systems): | 127 def GenerateSingleFile(systems): |
| 128 if 'frog' in systems: | 128 if 'dart2js' in systems: |
| 129 _logger.info('Copy dom_frog to frog/') | 129 _logger.info('Copy dom_dart2js to dart2js/') |
| 130 subprocess.call(['cd ../generated ; ' | 130 subprocess.call(['cd ../generated ; ' |
| 131 '../../../tools/copy_dart.py ../frog dom_frog.dart'], | 131 '../../../tools/copy_dart.py ../dart2js dom_dart2js.dart'], |
| 132 shell=True) | 132 shell=True) |
| 133 | 133 |
| 134 if 'htmlfrog' in systems: | 134 if 'htmldart2js' in systems: |
| 135 _logger.info('Copy html_frog to ../html/frog/') | 135 _logger.info('Copy html_dart2js to ../html/dart2js/') |
| 136 subprocess.call(['cd ../../html/generated ; ' | 136 subprocess.call(['cd ../../html/generated ; ' |
| 137 '../../../tools/copy_dart.py ../frog html_frog.dart'], | 137 '../../../tools/copy_dart.py ../dart2js html_dart2js.dart']
, |
| 138 shell=True) | 138 shell=True) |
| 139 | 139 |
| 140 if 'htmldartium' in systems: | 140 if 'htmldartium' in systems: |
| 141 _logger.info('Copy html_dartium to ../html/dartium/') | 141 _logger.info('Copy html_dartium to ../html/dartium/') |
| 142 subprocess.call(['cd ../../html/generated ; ' | 142 subprocess.call(['cd ../../html/generated ; ' |
| 143 '../../../tools/copy_dart.py ../dartium html_dartium.dart']
, | 143 '../../../tools/copy_dart.py ../dartium html_dartium.dart']
, |
| 144 shell=True) | 144 shell=True) |
| 145 | 145 |
| 146 # Copy dummy DOM where dartc build expects it. | 146 # Copy dummy DOM where dartc build expects it. |
| 147 if 'dummy' in systems: | 147 if 'dummy' in systems: |
| 148 _logger.info('Copy dom_dummy to dom.dart') | 148 _logger.info('Copy dom_dummy to dom.dart') |
| 149 subprocess.call(['cd ../generated ; ' | 149 subprocess.call(['cd ../generated ; ' |
| 150 '../../../tools/copy_dart.py dummy dom_dummy.dart ;' | 150 '../../../tools/copy_dart.py dummy dom_dummy.dart ;' |
| 151 'cp dummy/dom_dummy.dart ../dom.dart'], | 151 'cp dummy/dom_dummy.dart ../dom.dart'], |
| 152 shell=True) | 152 shell=True) |
| 153 | 153 |
| 154 def main(): | 154 def main(): |
| 155 parser = optparse.OptionParser() | 155 parser = optparse.OptionParser() |
| 156 parser.add_option('--systems', dest='systems', | 156 parser.add_option('--systems', dest='systems', |
| 157 action='store', type='string', | 157 action='store', type='string', |
| 158 default='frog,dummy,htmlfrog,htmldartium', | 158 default='dart2js,dummy,htmldart2js,htmldartium', |
| 159 help='Systems to generate (frog, dummy, ' | 159 help='Systems to generate (dart2js, dummy, ' |
| 160 'htmlfrog, htmldartium)') | 160 'htmldart2js, htmldartium)') |
| 161 parser.add_option('--output-dir', dest='output_dir', | 161 parser.add_option('--output-dir', dest='output_dir', |
| 162 action='store', type='string', | 162 action='store', type='string', |
| 163 default=None, | 163 default=None, |
| 164 help='Directory to put the generated files') | 164 help='Directory to put the generated files') |
| 165 parser.add_option('--use-database-cache', dest='use_database_cache', | 165 parser.add_option('--use-database-cache', dest='use_database_cache', |
| 166 action='store_true', | 166 action='store_true', |
| 167 default=False, | 167 default=False, |
| 168 help='''Use the cached database from the previous run to | 168 help='''Use the cached database from the previous run to |
| 169 improve startup performance''') | 169 improve startup performance''') |
| 170 (options, args) = parser.parse_args() | 170 (options, args) = parser.parse_args() |
| 171 | 171 |
| 172 current_dir = os.path.dirname(__file__) | 172 current_dir = os.path.dirname(__file__) |
| 173 database_dir = os.path.join(current_dir, '..', 'database') | 173 database_dir = os.path.join(current_dir, '..', 'database') |
| 174 logging.config.fileConfig(os.path.join(current_dir, 'logging.conf')) | 174 logging.config.fileConfig(os.path.join(current_dir, 'logging.conf')) |
| 175 systems = options.systems.split(',') | 175 systems = options.systems.split(',') |
| 176 | 176 |
| 177 dom_output_dir = options.output_dir or os.path.join(current_dir, | 177 dom_output_dir = options.output_dir or os.path.join(current_dir, |
| 178 '../generated') | 178 '../generated') |
| 179 html_output_dir = options.output_dir or os.path.join(current_dir, | 179 html_output_dir = options.output_dir or os.path.join(current_dir, |
| 180 '../../html/generated') | 180 '../../html/generated') |
| 181 Generate(systems, database_dir, options.use_database_cache, | 181 Generate(systems, database_dir, options.use_database_cache, |
| 182 dom_output_dir, html_output_dir) | 182 dom_output_dir, html_output_dir) |
| 183 GenerateSingleFile(systems) | 183 GenerateSingleFile(systems) |
| 184 | 184 |
| 185 if __name__ == '__main__': | 185 if __name__ == '__main__': |
| 186 sys.exit(main()) | 186 sys.exit(main()) |
| OLD | NEW |