Chromium Code Reviews| 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 optparse | 12 import optparse |
| 12 import os | 13 import os |
| 13 import shutil | 14 import shutil |
| 14 import subprocess | 15 import subprocess |
| 15 import sys | 16 import sys |
| 17 from systembase import * | |
|
Anton Muhin
2012/05/17 15:46:24
do we care about more specific imports?
podivilov
2012/05/17 17:44:01
Done.
| |
| 18 from systemfrog import * | |
| 19 from systemhtml import * | |
| 20 from systeminterface import * | |
| 21 from systemnative import * | |
| 22 from templateloader import TemplateLoader | |
| 16 | 23 |
| 17 _logger = logging.getLogger('dartdomgenerator') | 24 _logger = logging.getLogger('dartdomgenerator') |
| 18 | 25 |
| 19 _webkit_renames = { | 26 _webkit_renames = { |
| 20 # W3C -> WebKit name conversion | 27 # W3C -> WebKit name conversion |
| 21 # TODO(vsm): Maybe Store these renames in the IDLs. | 28 # TODO(vsm): Maybe Store these renames in the IDLs. |
| 22 'ApplicationCache': 'DOMApplicationCache', | 29 'ApplicationCache': 'DOMApplicationCache', |
| 23 'BarProp': 'BarInfo', | 30 'BarProp': 'BarInfo', |
| 24 'DedicatedWorkerGlobalScope': 'DedicatedWorkerContext', | 31 'DedicatedWorkerGlobalScope': 'DedicatedWorkerContext', |
| 25 'FormData': 'DOMFormData', | 32 'FormData': 'DOMFormData', |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 html_renames['WebKit' + subclass] = subclass | 70 html_renames['WebKit' + subclass] = subclass |
| 64 | 71 |
| 65 # TODO(jacobr): we almost want to add this commented out line back. | 72 # TODO(jacobr): we almost want to add this commented out line back. |
| 66 # html_renames['HTMLCollection'] = 'ElementList' | 73 # html_renames['HTMLCollection'] = 'ElementList' |
| 67 # html_renames['NodeList'] = 'ElementList' | 74 # html_renames['NodeList'] = 'ElementList' |
| 68 # html_renames['HTMLOptionsCollection'] = 'ElementList' | 75 # html_renames['HTMLOptionsCollection'] = 'ElementList' |
| 69 html_renames['DOMWindow'] = 'Window' | 76 html_renames['DOMWindow'] = 'Window' |
| 70 | 77 |
| 71 return html_renames | 78 return html_renames |
| 72 | 79 |
| 73 def GenerateDOM(systems, generate_html_systems, output_dir, | 80 def Generate(system_name, database_dir, use_database_cache, output_dir=None): |
| 74 database_dir, use_database_cache): | |
| 75 current_dir = os.path.dirname(__file__) | 81 current_dir = os.path.dirname(__file__) |
| 82 auxiliary_dir=os.path.join(current_dir, '..', 'src') | |
|
Anton Muhin
2012/05/17 15:46:24
nit: spaces around = here and below
podivilov
2012/05/17 17:44:01
Done.
| |
| 83 template_dir=os.path.join(current_dir, '..', 'templates') | |
| 76 | 84 |
| 77 generator = dartgenerator.DartGenerator( | 85 generator = dartgenerator.DartGenerator() |
| 78 auxiliary_dir=os.path.join(current_dir, '..', 'src'), | 86 generator.LoadAuxiliary(auxiliary_dir) |
| 79 template_dir=os.path.join(current_dir, '..', 'templates'), | |
| 80 base_package='') | |
| 81 generator.LoadAuxiliary() | |
| 82 | 87 |
| 83 common_database = database.Database(database_dir) | 88 common_database = database.Database(database_dir) |
| 84 if use_database_cache: | 89 if use_database_cache: |
| 85 common_database.LoadFromCache() | 90 common_database.LoadFromCache() |
| 86 else: | 91 else: |
| 87 common_database.Load() | 92 common_database.Load() |
| 88 | 93 |
| 89 generator.FilterMembersWithUnidentifiedTypes(common_database) | 94 generator.FilterMembersWithUnidentifiedTypes(common_database) |
| 90 webkit_database = common_database.Clone() | 95 webkit_database = common_database.Clone() |
| 91 | 96 |
| 92 # Generate Dart interfaces for the WebKit DOM. | 97 # Generate Dart interfaces for the WebKit DOM. |
| 93 generator.FilterInterfaces(database = webkit_database, | 98 generator.FilterInterfaces(database = webkit_database, |
| 94 or_annotations = ['WebKit', 'Dart'], | 99 or_annotations = ['WebKit', 'Dart'], |
| 95 exclude_displaced = ['WebKit'], | 100 exclude_displaced = ['WebKit'], |
| 96 exclude_suppressed = ['WebKit', 'Dart']) | 101 exclude_suppressed = ['WebKit', 'Dart']) |
| 97 generator.RenameTypes(webkit_database, _webkit_renames, True) | 102 generator.RenameTypes(webkit_database, _webkit_renames, True) |
| 103 generator.FixEventTargets(webkit_database) | |
| 98 | 104 |
| 105 emitters = multiemitter.MultiEmitter() | |
| 99 html_renames = _MakeHtmlRenames(common_database) | 106 html_renames = _MakeHtmlRenames(common_database) |
| 100 if generate_html_systems: | 107 |
| 108 if system_name in ['htmlfrog', 'htmldartium']: | |
| 101 generator.RenameTypes(webkit_database, html_renames, False) | 109 generator.RenameTypes(webkit_database, html_renames, False) |
| 110 if not output_dir: | |
| 111 output_dir = os.path.join(current_dir, '../../html/generated') | |
| 112 interface_system = HtmlInterfacesSystem( | |
| 113 TemplateLoader(template_dir, ['html/interface', 'html', '']), | |
| 114 webkit_database, emitters, output_dir) | |
| 115 else: | |
| 116 if not output_dir: | |
| 117 output_dir = os.path.join(current_dir, '../generated') | |
| 118 interface_system = InterfacesSystem( | |
| 119 TemplateLoader(template_dir, ['dom/interface', 'dom', '']), | |
| 120 webkit_database, emitters, output_dir) | |
| 121 | |
| 122 if system_name == 'dummy': | |
| 123 implementation_system = dartgenerator.DummyImplementationSystem( | |
| 124 TemplateLoader(template_dir, ['dom/dummy', 'dom', '']), | |
| 125 webkit_database, emitters, output_dir) | |
| 126 elif system_name == 'frog': | |
| 127 implementation_system = FrogSystem( | |
| 128 TemplateLoader(template_dir, ['dom/frog', 'dom', '']), | |
| 129 webkit_database, emitters, output_dir) | |
| 130 elif system_name == 'htmlfrog': | |
| 131 implementation_system = HtmlFrogSystem( | |
| 132 TemplateLoader(template_dir, | |
| 133 ['html/frog', 'html/impl', 'html', ''], | |
| 134 {'DARTIUM': False, 'FROG': True}), | |
| 135 webkit_database, emitters, output_dir) | |
| 136 elif system_name == 'htmldartium': | |
| 137 implementation_system = HtmlDartiumSystem( | |
| 138 TemplateLoader(template_dir, | |
| 139 ['html/dartium', 'html/impl', 'html', ''], | |
| 140 {'DARTIUM': True, 'FROG': False}), | |
| 141 webkit_database, emitters, auxiliary_dir, | |
| 142 output_dir) | |
| 143 elif system_name == 'native': | |
| 144 implementation_system = NativeImplementationSystem( | |
| 145 TemplateLoader(template_dir, ['dom/native', 'dom', '']), | |
| 146 webkit_database, html_renames, emitters, auxiliary_dir, | |
| 147 output_dir) | |
| 148 else: | |
| 149 raise Exception('Unsupported system %s' % system_name) | |
| 102 | 150 |
| 103 generator.Generate(database = webkit_database, | 151 # Makes interface files available for listing in the library for the |
| 104 output_dir = output_dir, | 152 # implementation system. |
| 105 lib_dir = output_dir, | 153 implementation_system._interface_system = interface_system |
| 106 module_source_preference = ['WebKit', 'Dart'], | |
| 107 source_filter = ['WebKit', 'Dart'], | |
| 108 super_database = common_database, | |
| 109 common_prefix = 'common', | |
| 110 webkit_renames = _webkit_renames, | |
| 111 html_renames = html_renames, | |
| 112 systems = systems) | |
| 113 | 154 |
| 114 generator.Flush() | 155 for system in [interface_system, implementation_system]: |
| 156 generator.Generate(webkit_database, system, | |
| 157 source_filter=['WebKit', 'Dart'], | |
| 158 super_database=common_database, | |
| 159 common_prefix='common', | |
| 160 webkit_renames=_webkit_renames, | |
| 161 html_renames=html_renames) | |
| 162 | |
| 163 _logger.info('Flush...') | |
| 164 emitters.Flush() | |
| 115 | 165 |
| 116 def GenerateSingleFile(systems): | 166 def GenerateSingleFile(systems): |
| 117 if 'frog' in systems: | 167 if 'frog' in systems: |
| 118 _logger.info('Copy dom_frog to frog/') | 168 _logger.info('Copy dom_frog to frog/') |
| 119 subprocess.call(['cd ../generated ; ' | 169 subprocess.call(['cd ../generated ; ' |
| 120 '../../../tools/copy_dart.py ../frog dom_frog.dart'], | 170 '../../../tools/copy_dart.py ../frog dom_frog.dart'], |
| 121 shell=True); | 171 shell=True); |
| 122 | 172 |
| 123 if 'htmlfrog' in systems: | 173 if 'htmlfrog' in systems: |
| 124 _logger.info('Copy html_frog to ../html/frog/') | 174 _logger.info('Copy html_frog to ../html/frog/') |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 152 default=None, | 202 default=None, |
| 153 help='Directory to put the generated files') | 203 help='Directory to put the generated files') |
| 154 parser.add_option('--use-database-cache', dest='use_database_cache', | 204 parser.add_option('--use-database-cache', dest='use_database_cache', |
| 155 action='store_true', | 205 action='store_true', |
| 156 default=False, | 206 default=False, |
| 157 help='''Use the cached database from the previous run to | 207 help='''Use the cached database from the previous run to |
| 158 improve startup performance''') | 208 improve startup performance''') |
| 159 (options, args) = parser.parse_args() | 209 (options, args) = parser.parse_args() |
| 160 | 210 |
| 161 current_dir = os.path.dirname(__file__) | 211 current_dir = os.path.dirname(__file__) |
| 212 database_dir = os.path.join(current_dir, '..', 'database') | |
| 213 logging.config.fileConfig(os.path.join(current_dir, 'logging.conf')) | |
| 162 systems = options.systems.split(',') | 214 systems = options.systems.split(',') |
| 163 html_system_names = ['htmldartium', 'htmlfrog'] | |
| 164 html_systems = [s for s in systems if s in html_system_names] | |
| 165 dom_systems = [s for s in systems if s not in html_system_names] | |
| 166 | 215 |
| 167 database_dir = os.path.join(current_dir, '..', 'database') | 216 for system in systems: |
| 168 use_database_cache = options.use_database_cache | 217 Generate(system, database_dir, options.use_database_cache, |
| 169 logging.config.fileConfig(os.path.join(current_dir, 'logging.conf')) | 218 options.output_dir) |
| 170 | 219 GenerateSingleFile(systems) |
| 171 if dom_systems: | |
| 172 output_dir = options.output_dir or os.path.join(current_dir, | |
| 173 '../generated') | |
| 174 GenerateDOM(dom_systems, False, output_dir, | |
| 175 database_dir, use_database_cache) | |
| 176 GenerateSingleFile(dom_systems) | |
| 177 | |
| 178 if html_systems: | |
| 179 output_dir = options.output_dir or os.path.join(current_dir, | |
| 180 '../../html/generated') | |
| 181 GenerateDOM(html_systems, True, output_dir, | |
| 182 database_dir, use_database_cache or dom_systems) | |
| 183 GenerateSingleFile(html_systems) | |
| 184 | 220 |
| 185 if __name__ == '__main__': | 221 if __name__ == '__main__': |
| 186 sys.exit(main()) | 222 sys.exit(main()) |
| OLD | NEW |