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

Side by Side Diff: lib/html/scripts/systemhtml.py

Issue 10987019: Refactor file paths handling in generator. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 2 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
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 2 # Copyright (c) 2012, 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 module provides shared functionality for the system to generate 6 """This module provides shared functionality for the system to generate
7 Dart:html APIs from the IDL database.""" 7 Dart:html APIs from the IDL database."""
8 8
9 import emitter 9 import emitter
10 10
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 if events or interface.id in _html_explicit_event_classes: 430 if events or interface.id in _html_explicit_event_classes:
431 return True, events 431 return True, events
432 else: 432 else:
433 return False, None 433 return False, None
434 434
435 def IsPrivate(self, name): 435 def IsPrivate(self, name):
436 return name.startswith('_') 436 return name.startswith('_')
437 437
438 438
439 class HtmlInterfacesSystem(System): 439 class HtmlInterfacesSystem(System):
440 def __init__(self, options, backend): 440 def __init__(self, options, dart_library_generator, backend):
441 super(HtmlInterfacesSystem, self).__init__(options) 441 super(HtmlInterfacesSystem, self).__init__(options)
442 self._dart_library_generator = dart_library_generator
442 self._backend = backend 443 self._backend = backend
443 self._shared = HtmlSystemShared(options) 444 self._shared = HtmlSystemShared(options)
444 self._dart_file_paths = [] 445 self._dart_file_paths = []
445 self._elements_factory_emitter = None 446 self._elements_factory_emitter = None
446 447
447 def ProcessInterface(self, interface): 448 def ProcessInterface(self, interface):
448 HtmlDartInterfaceGenerator(self, interface).Generate() 449 HtmlDartInterfaceGenerator(self, interface).Generate()
449 450
450 def ProcessCallback(self, interface, info): 451 def ProcessCallback(self, interface, info):
451 """Generates a typedef for the callback interface.""" 452 """Generates a typedef for the callback interface."""
452 code = self._CreateEmitter('%s.dart' % interface.id) 453 code = self._CreateEmitter('%s.dart' % interface.id)
453 code.Emit(self._templates.Load('callback.darttemplate')) 454 code.Emit(self._templates.Load('callback.darttemplate'))
454 code.Emit('typedef $TYPE $NAME($PARAMS);\n', 455 code.Emit('typedef $TYPE $NAME($PARAMS);\n',
455 NAME=interface.id, 456 NAME=interface.id,
456 TYPE=DartType(info.type_name), 457 TYPE=DartType(info.type_name),
457 PARAMS=info.ParametersImplementationDeclaration(DartType)) 458 PARAMS=info.ParametersImplementationDeclaration(DartType))
458 self._backend.ProcessCallback(interface, info) 459 self._backend.ProcessCallback(interface, info)
459 460
460 def GenerateLibraries(self):
461 self._backend.GenerateLibraries(self._dart_file_paths)
462
463 def _CreateEmitter(self, filename): 461 def _CreateEmitter(self, filename):
464 path = os.path.join(self._output_dir, 'dart', filename) 462 return self._dart_library_generator.CreateFileEmitter(filename)
465 self._dart_file_paths.append(path)
466 return self._emitters.FileEmitter(path)
467 463
468 # ------------------------------------------------------------------------------ 464 # ------------------------------------------------------------------------------
469 465
470 class HtmlDartInterfaceGenerator(BaseGenerator): 466 class HtmlDartInterfaceGenerator(BaseGenerator):
471 """Generates dart interface and implementation for the DOM IDL interface.""" 467 """Generates dart interface and implementation for the DOM IDL interface."""
472 468
473 def __init__(self, system, interface): 469 def __init__(self, system, interface):
474 super(HtmlDartInterfaceGenerator, self).__init__( 470 super(HtmlDartInterfaceGenerator, self).__init__(
475 system._database, interface) 471 system._database, interface)
476 self._system = system 472 self._system = system
(...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after
1220 # ------------------------------------------------------------------------------ 1216 # ------------------------------------------------------------------------------
1221 1217
1222 class HtmlDart2JSSystem(System): 1218 class HtmlDart2JSSystem(System):
1223 1219
1224 def __init__(self, options): 1220 def __init__(self, options):
1225 super(HtmlDart2JSSystem, self).__init__(options) 1221 super(HtmlDart2JSSystem, self).__init__(options)
1226 1222
1227 def ImplementationGenerator(self, interface): 1223 def ImplementationGenerator(self, interface):
1228 return HtmlDart2JSClassGenerator(self, interface) 1224 return HtmlDart2JSClassGenerator(self, interface)
1229 1225
1230 def GenerateLibraries(self, dart_files):
1231 auxiliary_dir = os.path.relpath(self._auxiliary_dir, self._output_dir)
1232 self._GenerateLibFile(
1233 'html_dart2js.darttemplate',
1234 os.path.join(self._output_dir, 'html_dart2js.dart'),
1235 dart_files,
1236 AUXILIARY_DIR=systembase.MassagePath(auxiliary_dir))
1237 1226
1238 def Finish(self): 1227 class DartLibraryGenerator():
1239 pass 1228 def __init__(self, emitters, template, dart_sources_dir):
1229 self._emitters = emitters
1230 self._template = template
1231 self._dart_sources_dir = dart_sources_dir
1232 self._dart_sources_list = []
1233
1234 def CreateFileEmitter(self, filename):
1235 path = os.path.join(self._dart_sources_dir, filename)
1236 self._dart_sources_list.append(path)
1237 return self._emitters.FileEmitter(path)
1238
1239 def GenerateLibrary(self, library_file_path, auxiliary_dir):
1240 library_emitter = self._emitters.FileEmitter(library_file_path)
1241 library_file_dir = os.path.dirname(library_file_path)
1242 auxiliary_dir = os.path.relpath(auxiliary_dir, library_file_dir)
1243 imports_emitter = library_emitter.Emit(
1244 self._template, AUXILIARY_DIR=self.MassagePath(auxiliary_dir))
1245 for path in sorted(self._dart_sources_list):
1246 relpath = os.path.relpath(path, library_file_dir)
1247 imports_emitter.Emit(
1248 "#source('$PATH');\n", PATH=self.MassagePath(relpath))
1249
1250 def MassagePath(self, path):
Anton Muhin 2012/09/25 16:15:50 turn MassagePath into closure if it's not used out
podivilov1 2012/09/25 16:40:28 Done.
1251 # The most robust way to emit path separators is to use / always.
1252 return path.replace('\\', '/')
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698