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

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 output_dir 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 Generate(systems, database_dir, use_database_cache, dom_output_dir,
74 database_dir, use_database_cache): 80 html_output_dir):
75 current_dir = os.path.dirname(__file__) 81 current_dir = os.path.dirname(__file__)
82 auxiliary_dir = os.path.join(current_dir, '..', 'src')
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 dom_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 = dom_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(dom_database, _webkit_renames, True)
103 generator.FixEventTargets(dom_database)
98 104
105 emitters = multiemitter.MultiEmitter()
99 html_renames = _MakeHtmlRenames(common_database) 106 html_renames = _MakeHtmlRenames(common_database)
100 if generate_html_systems:
101 generator.RenameTypes(webkit_database, html_renames, False)
102 107
103 generator.Generate(database = webkit_database, 108 html_database = None
104 output_dir = output_dir, 109 if set(systems) & set(['htmlfrog', 'htmldartium']):
105 lib_dir = output_dir, 110 html_database = dom_database.Clone()
106 module_source_preference = ['WebKit', 'Dart'], 111 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 112
114 generator.Flush() 113 for system in systems:
114 if system in ['htmlfrog', 'htmldartium']:
115 target_database = html_database
116 output_dir = html_output_dir
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 output_dir = dom_output_dir
123 interface_system = InterfacesSystem(
124 TemplateLoader(template_dir, ['dom/interface', 'dom', '']),
125 target_database, emitters, output_dir)
115 126
116 def GenerateSingleFile(systems): 127 if system == 'dummy':
128 implementation_system = dartgenerator.DummyImplementationSystem(
129 TemplateLoader(template_dir, ['dom/dummy', 'dom', '']),
130 target_database, emitters, output_dir)
131 elif system == 'frog':
132 implementation_system = FrogSystem(
133 TemplateLoader(template_dir, ['dom/frog', 'dom', '']),
134 target_database, emitters, output_dir)
135 elif system == 'htmlfrog':
136 implementation_system = HtmlFrogSystem(
137 TemplateLoader(template_dir,
138 ['html/frog', 'html/impl', 'html', ''],
139 {'DARTIUM': False, 'FROG': True}),
140 target_database, emitters, output_dir)
141 elif system == 'htmldartium':
142 implementation_system = HtmlDartiumSystem(
143 TemplateLoader(template_dir,
144 ['html/dartium', 'html/impl', 'html', ''],
145 {'DARTIUM': True, 'FROG': False}),
146 target_database, emitters, auxiliary_dir,
147 output_dir)
148 elif system == 'native':
149 implementation_system = NativeImplementationSystem(
150 TemplateLoader(template_dir, ['dom/native', 'dom', '']),
151 target_database, html_renames, emitters, auxiliary_dir,
152 output_dir)
153 else:
154 raise Exception('Unsupported system %s' % system_name)
155
156 # Makes interface files available for listing in the library for the
157 # implementation system.
158 implementation_system._interface_system = interface_system
159
160 for system in [interface_system, implementation_system]:
161 generator.Generate(target_database, system,
162 source_filter=['WebKit', 'Dart'],
163 super_database=common_database,
164 common_prefix='common',
165 webkit_renames=_webkit_renames,
166 html_renames=html_renames)
167
168 _logger.info('Flush...')
169 emitters.Flush()
170
117 if 'frog' in systems: 171 if 'frog' in systems:
118 _logger.info('Copy dom_frog to frog/') 172 _logger.info('Copy dom_frog to frog/')
119 subprocess.call(['cd ../generated ; ' 173 subprocess.call(['cd ../generated ; '
120 '../../../tools/copy_dart.py ../frog dom_frog.dart'], 174 '../../../tools/copy_dart.py ../frog dom_frog.dart'],
121 shell=True); 175 shell=True);
122 176
123 if 'htmlfrog' in systems: 177 if 'htmlfrog' in systems:
124 _logger.info('Copy html_frog to ../html/frog/') 178 _logger.info('Copy html_frog to ../html/frog/')
125 subprocess.call(['cd ../../html/generated ; ' 179 subprocess.call(['cd ../../html/generated ; '
126 '../../../tools/copy_dart.py ../frog html_frog.dart'], 180 '../../../tools/copy_dart.py ../frog html_frog.dart'],
(...skipping 25 matching lines...) Expand all
152 default=None, 206 default=None,
153 help='Directory to put the generated files') 207 help='Directory to put the generated files')
154 parser.add_option('--use-database-cache', dest='use_database_cache', 208 parser.add_option('--use-database-cache', dest='use_database_cache',
155 action='store_true', 209 action='store_true',
156 default=False, 210 default=False,
157 help='''Use the cached database from the previous run to 211 help='''Use the cached database from the previous run to
158 improve startup performance''') 212 improve startup performance''')
159 (options, args) = parser.parse_args() 213 (options, args) = parser.parse_args()
160 214
161 current_dir = os.path.dirname(__file__) 215 current_dir = os.path.dirname(__file__)
216 database_dir = os.path.join(current_dir, '..', 'database')
217 logging.config.fileConfig(os.path.join(current_dir, 'logging.conf'))
162 systems = options.systems.split(',') 218 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 219
167 database_dir = os.path.join(current_dir, '..', 'database') 220 dom_output_dir = options.output_dir or os.path.join(current_dir,
168 use_database_cache = options.use_database_cache 221 '../generated')
169 logging.config.fileConfig(os.path.join(current_dir, 'logging.conf')) 222 html_output_dir = options.output_dir or os.path.join(current_dir,
170 223 '../../html/generated')
171 if dom_systems: 224 Generate(systems, database_dir, options.use_database_cache,
172 output_dir = options.output_dir or os.path.join(current_dir, 225 dom_output_dir, html_output_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 226
185 if __name__ == '__main__': 227 if __name__ == '__main__':
186 sys.exit(main()) 228 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