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

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

Issue 1173403004: Changed to use JSInterop (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Re-gen'd somehow diffs stopped showing up in CL Created 5 years, 5 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
« no previous file with comments | « tools/dom/scripts/css_code_generator.py ('k') | tools/dom/scripts/generator.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 css_code_generator 8 import css_code_generator
9 import os 9 import os
10 import sys 10 import sys
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 55
56 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..')) 56 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..'))
57 57
58 import utils 58 import utils
59 59
60 60
61 _logger = logging.getLogger('dartdomgenerator') 61 _logger = logging.getLogger('dartdomgenerator')
62 62
63 class GeneratorOptions(object): 63 class GeneratorOptions(object):
64 def __init__(self, templates, database, type_registry, renamer, 64 def __init__(self, templates, database, type_registry, renamer,
65 metadata): 65 metadata, dart_js_interop):
66 self.templates = templates 66 self.templates = templates
67 self.database = database 67 self.database = database
68 self.type_registry = type_registry 68 self.type_registry = type_registry
69 self.renamer = renamer 69 self.renamer = renamer
70 self.metadata = metadata; 70 self.metadata = metadata;
71 self.dart_js_interop = dart_js_interop
71 72
72 def LoadDatabase(database_dir, use_database_cache): 73 def LoadDatabase(database_dir, use_database_cache):
73 common_database = database.Database(database_dir) 74 common_database = database.Database(database_dir)
74 if use_database_cache: 75 if use_database_cache:
75 common_database.LoadFromCache() 76 common_database.LoadFromCache()
76 else: 77 else:
77 common_database.Load() 78 common_database.Load()
78 return common_database 79 return common_database
79 80
80 def GenerateFromDatabase(common_database, dart2js_output_dir, 81 def GenerateFromDatabase(common_database, dart2js_output_dir,
81 dartium_output_dir, update_dom_metadata=False, 82 dartium_output_dir, update_dom_metadata=False,
82 logging_level=logging.WARNING): 83 logging_level=logging.WARNING, dart_js_interop=False):
84 print '\n ----- Accessing DOM using %s -----\n' % ('dart:js' if dart_js_intero p else 'C++')
85
83 start_time = time.time() 86 start_time = time.time()
84 87
85 current_dir = os.path.dirname(__file__) 88 current_dir = os.path.dirname(__file__)
86 auxiliary_dir = os.path.join(current_dir, '..', 'src') 89 auxiliary_dir = os.path.join(current_dir, '..', 'src')
87 template_dir = os.path.join(current_dir, '..', 'templates') 90 template_dir = os.path.join(current_dir, '..', 'templates')
88 91
89 _logger.setLevel(logging_level) 92 _logger.setLevel(logging_level)
90 93
91 generator = dartgenerator.DartGenerator(logging_level) 94 generator = dartgenerator.DartGenerator(logging_level)
92 generator.LoadAuxiliary(auxiliary_dir) 95 generator.LoadAuxiliary(auxiliary_dir)
(...skipping 13 matching lines...) Expand all
106 metadata = DartMetadata( 109 metadata = DartMetadata(
107 os.path.join(current_dir, '..', 'dom.json'), 110 os.path.join(current_dir, '..', 'dom.json'),
108 os.path.join(current_dir, '..', 'docs', 'docs.json'), 111 os.path.join(current_dir, '..', 'docs', 'docs.json'),
109 logging_level) 112 logging_level)
110 renamer = HtmlRenamer(webkit_database, metadata) 113 renamer = HtmlRenamer(webkit_database, metadata)
111 type_registry = TypeRegistry(webkit_database, renamer) 114 type_registry = TypeRegistry(webkit_database, renamer)
112 115
113 print 'GenerateFromDatabase %s seconds' % round((time.time() - start_time), 2) 116 print 'GenerateFromDatabase %s seconds' % round((time.time() - start_time), 2)
114 117
115 def RunGenerator(dart_libraries, dart_output_dir, 118 def RunGenerator(dart_libraries, dart_output_dir,
116 template_loader, backend_factory): 119 template_loader, backend_factory, dart_js_interop):
117 options = GeneratorOptions( 120 options = GeneratorOptions(
118 template_loader, webkit_database, type_registry, renamer, 121 template_loader, webkit_database, type_registry, renamer,
119 metadata) 122 metadata, dart_js_interop)
120 dart_library_emitter = DartLibraryEmitter( 123 dart_library_emitter = DartLibraryEmitter(
121 emitters, dart_output_dir, dart_libraries) 124 emitters, dart_output_dir, dart_libraries)
122 event_generator = HtmlEventGenerator(webkit_database, renamer, metadata, 125 event_generator = HtmlEventGenerator(webkit_database, renamer, metadata,
123 template_loader) 126 template_loader)
124 127
125 def generate_interface(interface): 128 def generate_interface(interface):
126 backend = backend_factory(interface) 129 backend = backend_factory(interface)
127 interface_generator = HtmlDartInterfaceGenerator( 130 interface_generator = HtmlDartInterfaceGenerator(
128 options, dart_library_emitter, event_generator, interface, backend) 131 options, dart_library_emitter, event_generator, interface, backend)
129 interface_generator.Generate() 132 interface_generator.Generate()
130 133
131 generator.Generate(webkit_database, common_database, generate_interface) 134 generator.Generate(webkit_database, common_database, generate_interface)
132 135
133 dart_library_emitter.EmitLibraries(auxiliary_dir) 136 dart_library_emitter.EmitLibraries(auxiliary_dir, dart_js_interop)
134 137
135 if dart2js_output_dir: 138 if dart2js_output_dir:
136 template_paths = ['html/dart2js', 'html/impl', 'html/interface', ''] 139 template_paths = ['html/dart2js', 'html/impl', 'html/interface', '']
137 template_loader = TemplateLoader(template_dir, 140 template_loader = TemplateLoader(template_dir,
138 template_paths, 141 template_paths,
139 {'DARTIUM': False, 'DART2JS': True}) 142 {'DARTIUM': False,
143 'DART2JS': True,
144 'JSINTEROP': False})
140 backend_options = GeneratorOptions( 145 backend_options = GeneratorOptions(
141 template_loader, webkit_database, type_registry, renamer, 146 template_loader, webkit_database, type_registry, renamer,
142 metadata) 147 metadata, dart_js_interop)
143 backend_factory = lambda interface:\ 148 backend_factory = lambda interface:\
144 Dart2JSBackend(interface, backend_options, logging_level) 149 Dart2JSBackend(interface, backend_options, logging_level)
145 150
146 dart_output_dir = os.path.join(dart2js_output_dir, 'dart') 151 dart_output_dir = os.path.join(dart2js_output_dir, 'dart')
147 dart_libraries = DartLibraries( 152 dart_libraries = DartLibraries(
148 HTML_LIBRARY_NAMES, template_loader, 'dart2js', dart2js_output_dir) 153 HTML_LIBRARY_NAMES, template_loader, 'dart2js', dart2js_output_dir, dart _js_interop)
149 154
150 print '\nGenerating dart2js:\n' 155 print '\nGenerating dart2js:\n'
151 start_time = time.time() 156 start_time = time.time()
152 157
153 RunGenerator(dart_libraries, dart_output_dir, template_loader, 158 RunGenerator(dart_libraries, dart_output_dir, template_loader,
154 backend_factory) 159 backend_factory, dart_js_interop)
155 160
156 print 'Generated dart2js in %s seconds' % round(time.time() - start_time, 2) 161 print 'Generated dart2js in %s seconds' % round(time.time() - start_time, 2)
157 162
158 if dartium_output_dir: 163 if dartium_output_dir:
159 template_paths = ['html/dartium', 'html/impl', 'html/interface', ''] 164 template_paths = ['html/dartium', 'html/impl', 'html/interface', '']
160 template_loader = TemplateLoader(template_dir, 165 template_loader = TemplateLoader(template_dir,
161 template_paths, 166 template_paths,
162 {'DARTIUM': True, 'DART2JS': False}) 167 {'DARTIUM': True,
168 'DART2JS': False,
169 'JSINTEROP': dart_js_interop})
163 backend_options = GeneratorOptions( 170 backend_options = GeneratorOptions(
164 template_loader, webkit_database, type_registry, renamer, 171 template_loader, webkit_database, type_registry, renamer,
165 metadata) 172 metadata, dart_js_interop)
166 cpp_output_dir = os.path.join(dartium_output_dir, 'cpp') 173 cpp_output_dir = os.path.join(dartium_output_dir, 'cpp')
167 cpp_library_emitter = CPPLibraryEmitter(emitters, cpp_output_dir) 174 cpp_library_emitter = CPPLibraryEmitter(emitters, cpp_output_dir)
168 dart_output_dir = os.path.join(dartium_output_dir, 'dart') 175 dart_output_dir = os.path.join(dartium_output_dir, 'dart')
169 backend_factory = lambda interface:\ 176 backend_factory = lambda interface:\
170 DartiumBackend(interface, cpp_library_emitter, backend_options) 177 DartiumBackend(interface, cpp_library_emitter, backend_options)
171 dart_libraries = DartLibraries( 178 dart_libraries = DartLibraries(
172 HTML_LIBRARY_NAMES, template_loader, 'dartium', dartium_output_dir) 179 HTML_LIBRARY_NAMES, template_loader, 'dartium', dartium_output_dir, dart _js_interop)
173 180
174 print '\nGenerating dartium:\n' 181 print '\nGenerating dartium:\n'
175 start_time = time.time() 182 start_time = time.time()
176 183
177 RunGenerator(dart_libraries, dart_output_dir, 184 RunGenerator(dart_libraries, dart_output_dir, template_loader,
178 template_loader, backend_factory) 185 backend_factory, dart_js_interop)
179 print 'Generated dartium in %s seconds' % round(time.time() - start_time, 2) 186 print 'Generated dartium in %s seconds' % round(time.time() - start_time, 2)
180 187
181 cpp_library_emitter.EmitDerivedSources( 188 cpp_library_emitter.EmitDerivedSources(
182 template_loader.Load('cpp_derived_sources.template'), 189 template_loader.Load('cpp_derived_sources.template'),
183 dartium_output_dir) 190 dartium_output_dir)
184 cpp_library_emitter.EmitResolver( 191 cpp_library_emitter.EmitResolver(
185 template_loader.Load('cpp_resolver.template'), dartium_output_dir) 192 template_loader.Load('cpp_resolver.template'), dartium_output_dir)
186 cpp_library_emitter.EmitClassIdTable( 193 cpp_library_emitter.EmitClassIdTable(
187 webkit_database, dartium_output_dir, type_registry, renamer) 194 webkit_database, dartium_output_dir, type_registry, renamer)
188 emitters.Flush() 195 emitters.Flush()
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 help='''Update the metadata list of DOM APIs''') 239 help='''Update the metadata list of DOM APIs''')
233 parser.add_option('--verbose', dest='logging_level', 240 parser.add_option('--verbose', dest='logging_level',
234 action='store_false', default=logging.WARNING, 241 action='store_false', default=logging.WARNING,
235 help='Output all informational messages') 242 help='Output all informational messages')
236 parser.add_option('--examine', dest='examine_idls', 243 parser.add_option('--examine', dest='examine_idls',
237 action='store_true', default=None, 244 action='store_true', default=None,
238 help='Analyze IDL files') 245 help='Analyze IDL files')
239 parser.add_option('--logging', dest='logging', type='int', 246 parser.add_option('--logging', dest='logging', type='int',
240 action='store', default=logging.NOTSET, 247 action='store', default=logging.NOTSET,
241 help='Level of logging 20 is Info, 30 is Warnings, 40 is Err ors') 248 help='Level of logging 20 is Info, 30 is Warnings, 40 is Err ors')
249 parser.add_option('--gen-interop', dest='dart_js_interop',
250 action='store_true', default=False,
251 help='Use Javascript objects (dart:js) accessing the DOM in _blink')
242 252
243 (options, args) = parser.parse_args() 253 (options, args) = parser.parse_args()
244 254
245 current_dir = os.path.dirname(__file__) 255 current_dir = os.path.dirname(__file__)
246 database_dir = os.path.join(current_dir, '..', 'database') 256 database_dir = os.path.join(current_dir, '..', 'database')
247 logging.config.fileConfig(os.path.join(current_dir, 'logging.conf')) 257 logging.config.fileConfig(os.path.join(current_dir, 'logging.conf'))
248 systems = options.systems.split(',') 258 systems = options.systems.split(',')
249 259
250 output_dir = options.output_dir or os.path.join( 260 output_dir = options.output_dir or os.path.join(
251 current_dir, '..', '..', utils.GetBuildDir(utils.GuessOS()), 261 current_dir, '..', '..', utils.GetBuildDir(utils.GuessOS()),
(...skipping 10 matching lines...) Expand all
262 if options.logging == logging.NOTSET else options.logging 272 if options.logging == logging.NOTSET else options.logging
263 273
264 start_time = time.time() 274 start_time = time.time()
265 275
266 UpdateCssProperties() 276 UpdateCssProperties()
267 277
268 # Parse the IDL and create the database. 278 # Parse the IDL and create the database.
269 database = fremontcutbuilder.main(options.parallel, logging_level=logging_leve l, examine_idls=options.examine_idls) 279 database = fremontcutbuilder.main(options.parallel, logging_level=logging_leve l, examine_idls=options.examine_idls)
270 280
271 GenerateFromDatabase(database, dart2js_output_dir, dartium_output_dir, 281 GenerateFromDatabase(database, dart2js_output_dir, dartium_output_dir,
272 options.update_dom_metadata, logging_level) 282 options.update_dom_metadata, logging_level, options.dart_js_interop)
273 283
274 file_generation_start_time = time.time() 284 file_generation_start_time = time.time()
275 285
276 if 'htmldart2js' in systems: 286 if 'htmldart2js' in systems:
277 _logger.info('Generating dart2js single files.') 287 _logger.info('Generating dart2js single files.')
278 288
279 for library_name in HTML_LIBRARY_NAMES: 289 for library_name in HTML_LIBRARY_NAMES:
280 GenerateSingleFile( 290 GenerateSingleFile(
281 os.path.join(dart2js_output_dir, '%s_dart2js.dart' % library_name), 291 os.path.join(dart2js_output_dir, '%s_dart2js.dart' % library_name),
282 os.path.join('..', '..', '..', 'sdk', 'lib', library_name, 'dart2js')) 292 os.path.join('..', '..', '..', 'sdk', 'lib', library_name, 'dart2js'))
283 293
284 if 'htmldartium' in systems: 294 if 'htmldartium' in systems:
285 _logger.info('Generating dartium single files.') 295 _logger.info('Generating dartium single files.')
286 file_generation_start_time = time.time() 296 file_generation_start_time = time.time()
287 297
288 for library_name in HTML_LIBRARY_NAMES: 298 for library_name in HTML_LIBRARY_NAMES:
289 GenerateSingleFile( 299 GenerateSingleFile(
290 os.path.join(dartium_output_dir, '%s_dartium.dart' % library_name), 300 os.path.join(dartium_output_dir, '%s_dartium.dart' % library_name),
291 os.path.join('..', '..', '..', 'sdk', 'lib', library_name, 'dartium')) 301 os.path.join('..', '..', '..', 'sdk', 'lib', library_name, 'dartium'))
292 302
293 print '\nGenerating single file %s seconds' % round(time.time() - file_generat ion_start_time, 2) 303 print '\nGenerating single file %s seconds' % round(time.time() - file_generat ion_start_time, 2)
294 304
295 end_time = time.time() 305 end_time = time.time()
296 306
297 print '\nDone (dartdomgenerator) %s seconds' % round(end_time - start_time, 2) 307 print '\nDone (dartdomgenerator) %s seconds' % round(end_time - start_time, 2)
298 308
299 if __name__ == '__main__': 309 if __name__ == '__main__':
300 sys.exit(main()) 310 sys.exit(main())
OLDNEW
« no previous file with comments | « tools/dom/scripts/css_code_generator.py ('k') | tools/dom/scripts/generator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698