Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(372)

Side by Side Diff: lib/dom/scripts/dartdomgenerator.py

Issue 10392147: Move systems creation to dartdomgenerator.py. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix performance issue. Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | lib/dom/scripts/dartgenerator.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 systemfrog import FrogSystem
18 from systemhtml import HtmlInterfacesSystem, HtmlFrogSystem, HtmlDartiumSystem
19 from systeminterface import InterfacesSystem
20 from systemnative import NativeImplementationSystem
21 from templateloader import TemplateLoader
16 22
17 _logger = logging.getLogger('dartdomgenerator') 23 _logger = logging.getLogger('dartdomgenerator')
18 24
19 _webkit_renames = { 25 _webkit_renames = {
20 # W3C -> WebKit name conversion 26 # W3C -> WebKit name conversion
21 # TODO(vsm): Maybe Store these renames in the IDLs. 27 # TODO(vsm): Maybe Store these renames in the IDLs.
22 'ApplicationCache': 'DOMApplicationCache', 28 'ApplicationCache': 'DOMApplicationCache',
23 'BarProp': 'BarInfo', 29 'BarProp': 'BarInfo',
24 'DedicatedWorkerGlobalScope': 'DedicatedWorkerContext', 30 'DedicatedWorkerGlobalScope': 'DedicatedWorkerContext',
25 'FormData': 'DOMFormData', 31 'FormData': 'DOMFormData',
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 html_renames['WebKit' + subclass] = subclass 69 html_renames['WebKit' + subclass] = subclass
64 70
65 # TODO(jacobr): we almost want to add this commented out line back. 71 # TODO(jacobr): we almost want to add this commented out line back.
66 # html_renames['HTMLCollection'] = 'ElementList' 72 # html_renames['HTMLCollection'] = 'ElementList'
67 # html_renames['NodeList'] = 'ElementList' 73 # html_renames['NodeList'] = 'ElementList'
68 # html_renames['HTMLOptionsCollection'] = 'ElementList' 74 # html_renames['HTMLOptionsCollection'] = 'ElementList'
69 html_renames['DOMWindow'] = 'Window' 75 html_renames['DOMWindow'] = 'Window'
70 76
71 return html_renames 77 return html_renames
72 78
73 def GenerateDOM(systems, generate_html_systems, output_dir, 79 def GenerateAll(systems, database_dir, use_database_cache, output_dir):
74 database_dir, use_database_cache):
75 current_dir = os.path.dirname(__file__) 80 current_dir = os.path.dirname(__file__)
81 auxiliary_dir = os.path.join(current_dir, '..', 'src')
82 template_dir = os.path.join(current_dir, '..', 'templates')
76 83
77 generator = dartgenerator.DartGenerator( 84 generator = dartgenerator.DartGenerator()
78 auxiliary_dir=os.path.join(current_dir, '..', 'src'), 85 generator.LoadAuxiliary(auxiliary_dir)
79 template_dir=os.path.join(current_dir, '..', 'templates'),
80 base_package='')
81 generator.LoadAuxiliary()
82 86
83 common_database = database.Database(database_dir) 87 common_database = database.Database(database_dir)
84 if use_database_cache: 88 if use_database_cache:
85 common_database.LoadFromCache() 89 common_database.LoadFromCache()
86 else: 90 else:
87 common_database.Load() 91 common_database.Load()
88 92
89 generator.FilterMembersWithUnidentifiedTypes(common_database) 93 generator.FilterMembersWithUnidentifiedTypes(common_database)
90 webkit_database = common_database.Clone() 94 dom_database = common_database.Clone()
91 95
92 # Generate Dart interfaces for the WebKit DOM. 96 # Generate Dart interfaces for the WebKit DOM.
93 generator.FilterInterfaces(database = webkit_database, 97 generator.FilterInterfaces(database = dom_database,
94 or_annotations = ['WebKit', 'Dart'], 98 or_annotations = ['WebKit', 'Dart'],
95 exclude_displaced = ['WebKit'], 99 exclude_displaced = ['WebKit'],
96 exclude_suppressed = ['WebKit', 'Dart']) 100 exclude_suppressed = ['WebKit', 'Dart'])
97 generator.RenameTypes(webkit_database, _webkit_renames, True) 101 generator.RenameTypes(dom_database, _webkit_renames, True)
102 generator.FixEventTargets(dom_database)
98 103
104 emitters = multiemitter.MultiEmitter()
99 html_renames = _MakeHtmlRenames(common_database) 105 html_renames = _MakeHtmlRenames(common_database)
100 if generate_html_systems:
101 generator.RenameTypes(webkit_database, html_renames, False)
102 106
103 generator.Generate(database = webkit_database, 107 html_database = None
104 output_dir = output_dir, 108 if set(systems) & set(['htmlfrog', 'htmldartium']):
105 lib_dir = output_dir, 109 html_database = dom_database.Clone()
106 module_source_preference = ['WebKit', 'Dart'], 110 generator.RenameTypes(html_database, html_renames, False)
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 111
114 generator.Flush() 112 for system in systems:
113 if system in ['htmlfrog', 'htmldartium']:
114 target_database = html_database
115 if not output_dir:
116 output_dir = os.path.join(current_dir, '../../html/generated')
Anton Muhin 2012/05/17 18:05:38 that will overwrite output_dir for other systems,
podivilov 2012/05/17 18:20:36 Thanks for spotting this!
117 interface_system = HtmlInterfacesSystem(
118 TemplateLoader(template_dir, ['html/interface', 'html', '']),
119 target_database, emitters, output_dir)
120 else:
121 target_database = dom_database
122 if not output_dir:
123 output_dir = os.path.join(current_dir, '../generated')
124 interface_system = InterfacesSystem(
125 TemplateLoader(template_dir, ['dom/interface', 'dom', '']),
126 target_database, emitters, output_dir)
115 127
116 def GenerateSingleFile(systems): 128 if system == 'dummy':
129 implementation_system = dartgenerator.DummyImplementationSystem(
130 TemplateLoader(template_dir, ['dom/dummy', 'dom', '']),
131 target_database, emitters, output_dir)
132 elif system == 'frog':
133 implementation_system = FrogSystem(
134 TemplateLoader(template_dir, ['dom/frog', 'dom', '']),
135 target_database, emitters, output_dir)
136 elif system == 'htmlfrog':
137 implementation_system = HtmlFrogSystem(
138 TemplateLoader(template_dir,
139 ['html/frog', 'html/impl', 'html', ''],
140 {'DARTIUM': False, 'FROG': True}),
141 target_database, emitters, output_dir)
142 elif system == 'htmldartium':
143 implementation_system = HtmlDartiumSystem(
144 TemplateLoader(template_dir,
145 ['html/dartium', 'html/impl', 'html', ''],
146 {'DARTIUM': True, 'FROG': False}),
147 target_database, emitters, auxiliary_dir,
148 output_dir)
149 elif system == 'native':
150 implementation_system = NativeImplementationSystem(
151 TemplateLoader(template_dir, ['dom/native', 'dom', '']),
152 target_database, html_renames, emitters, auxiliary_dir,
153 output_dir)
154 else:
155 raise Exception('Unsupported system %s' % system_name)
156
157 # Makes interface files available for listing in the library for the
158 # implementation system.
159 implementation_system._interface_system = interface_system
160
161 for system in [interface_system, implementation_system]:
162 generator.Generate(target_database, system,
163 source_filter=['WebKit', 'Dart'],
164 super_database=common_database,
165 common_prefix='common',
166 webkit_renames=_webkit_renames,
167 html_renames=html_renames)
168
169 _logger.info('Flush...')
170 emitters.Flush()
171
117 if 'frog' in systems: 172 if 'frog' in systems:
118 _logger.info('Copy dom_frog to frog/') 173 _logger.info('Copy dom_frog to frog/')
119 subprocess.call(['cd ../generated ; ' 174 subprocess.call(['cd ../generated ; '
120 '../../../tools/copy_dart.py ../frog dom_frog.dart'], 175 '../../../tools/copy_dart.py ../frog dom_frog.dart'],
121 shell=True); 176 shell=True);
122 177
123 if 'htmlfrog' in systems: 178 if 'htmlfrog' in systems:
124 _logger.info('Copy html_frog to ../html/frog/') 179 _logger.info('Copy html_frog to ../html/frog/')
125 subprocess.call(['cd ../../html/generated ; ' 180 subprocess.call(['cd ../../html/generated ; '
126 '../../../tools/copy_dart.py ../frog html_frog.dart'], 181 '../../../tools/copy_dart.py ../frog html_frog.dart'],
(...skipping 25 matching lines...) Expand all
152 default=None, 207 default=None,
153 help='Directory to put the generated files') 208 help='Directory to put the generated files')
154 parser.add_option('--use-database-cache', dest='use_database_cache', 209 parser.add_option('--use-database-cache', dest='use_database_cache',
155 action='store_true', 210 action='store_true',
156 default=False, 211 default=False,
157 help='''Use the cached database from the previous run to 212 help='''Use the cached database from the previous run to
158 improve startup performance''') 213 improve startup performance''')
159 (options, args) = parser.parse_args() 214 (options, args) = parser.parse_args()
160 215
161 current_dir = os.path.dirname(__file__) 216 current_dir = os.path.dirname(__file__)
217 database_dir = os.path.join(current_dir, '..', 'database')
218 logging.config.fileConfig(os.path.join(current_dir, 'logging.conf'))
162 systems = options.systems.split(',') 219 systems = options.systems.split(',')
163 html_system_names = ['htmldartium', 'htmlfrog'] 220 GenerateAll(systems, database_dir, options.use_database_cache,
164 html_systems = [s for s in systems if s in html_system_names] 221 options.output_dir)
165 dom_systems = [s for s in systems if s not in html_system_names]
166
167 database_dir = os.path.join(current_dir, '..', 'database')
168 use_database_cache = options.use_database_cache
169 logging.config.fileConfig(os.path.join(current_dir, 'logging.conf'))
170
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 222
185 if __name__ == '__main__': 223 if __name__ == '__main__':
186 sys.exit(main()) 224 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | lib/dom/scripts/dartgenerator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698