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

Unified 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, 3 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 side-by-side diff with in-line comments
Download patch
Index: lib/html/scripts/systemhtml.py
diff --git a/lib/html/scripts/systemhtml.py b/lib/html/scripts/systemhtml.py
index efa4a7d6d17439aad4577c507230c82aafa3ed55..8b01f451b3f2cb082203ee6b8a5e96446028060a 100644
--- a/lib/html/scripts/systemhtml.py
+++ b/lib/html/scripts/systemhtml.py
@@ -437,8 +437,9 @@ class HtmlSystemShared(object):
class HtmlInterfacesSystem(System):
- def __init__(self, options, backend):
+ def __init__(self, options, dart_library_generator, backend):
super(HtmlInterfacesSystem, self).__init__(options)
+ self._dart_library_generator = dart_library_generator
self._backend = backend
self._shared = HtmlSystemShared(options)
self._dart_file_paths = []
@@ -457,13 +458,8 @@ class HtmlInterfacesSystem(System):
PARAMS=info.ParametersImplementationDeclaration(DartType))
self._backend.ProcessCallback(interface, info)
- def GenerateLibraries(self):
- self._backend.GenerateLibraries(self._dart_file_paths)
-
def _CreateEmitter(self, filename):
- path = os.path.join(self._output_dir, 'dart', filename)
- self._dart_file_paths.append(path)
- return self._emitters.FileEmitter(path)
+ return self._dart_library_generator.CreateFileEmitter(filename)
# ------------------------------------------------------------------------------
@@ -1227,13 +1223,30 @@ class HtmlDart2JSSystem(System):
def ImplementationGenerator(self, interface):
return HtmlDart2JSClassGenerator(self, interface)
- def GenerateLibraries(self, dart_files):
- auxiliary_dir = os.path.relpath(self._auxiliary_dir, self._output_dir)
- self._GenerateLibFile(
- 'html_dart2js.darttemplate',
- os.path.join(self._output_dir, 'html_dart2js.dart'),
- dart_files,
- AUXILIARY_DIR=systembase.MassagePath(auxiliary_dir))
- def Finish(self):
- pass
+class DartLibraryGenerator():
+ def __init__(self, emitters, template, dart_sources_dir):
+ self._emitters = emitters
+ self._template = template
+ self._dart_sources_dir = dart_sources_dir
+ self._dart_sources_list = []
+
+ def CreateFileEmitter(self, filename):
+ path = os.path.join(self._dart_sources_dir, filename)
+ self._dart_sources_list.append(path)
+ return self._emitters.FileEmitter(path)
+
+ def GenerateLibrary(self, library_file_path, auxiliary_dir):
+ library_emitter = self._emitters.FileEmitter(library_file_path)
+ library_file_dir = os.path.dirname(library_file_path)
+ auxiliary_dir = os.path.relpath(auxiliary_dir, library_file_dir)
+ imports_emitter = library_emitter.Emit(
+ self._template, AUXILIARY_DIR=self.MassagePath(auxiliary_dir))
+ for path in sorted(self._dart_sources_list):
+ relpath = os.path.relpath(path, library_file_dir)
+ imports_emitter.Emit(
+ "#source('$PATH');\n", PATH=self.MassagePath(relpath))
+
+ 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.
+ # The most robust way to emit path separators is to use / always.
+ return path.replace('\\', '/')

Powered by Google App Engine
This is Rietveld 408576698