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

Unified Diff: dart/sdk/lib/_internal/compiler/implementation/dart2js.dart

Issue 11828043: Extend compiler API to support multiple outputs. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 11 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: dart/sdk/lib/_internal/compiler/implementation/dart2js.dart
diff --git a/dart/sdk/lib/_internal/compiler/implementation/dart2js.dart b/dart/sdk/lib/_internal/compiler/implementation/dart2js.dart
index 62286a07529c38c2a4dd5c804a6ba73332ec3c3b..dc7b2574c2e0f56b9feb83b43916cac132856d21 100644
--- a/dart/sdk/lib/_internal/compiler/implementation/dart2js.dart
+++ b/dart/sdk/lib/_internal/compiler/implementation/dart2js.dart
@@ -198,7 +198,7 @@ void compile(List<String> argv) {
Map<String, SourceFile> sourceFiles = <String, SourceFile>{};
int dartBytesRead = 0;
- Future<String> provider(Uri uri) {
+ Future<String> inputProvider(Uri uri) {
if (uri.scheme != 'file') {
throw new ArgumentError(uri);
}
@@ -232,13 +232,6 @@ void compile(List<String> argv) {
void handler(Uri uri, int begin, int end, String message,
api.Diagnostic kind) {
- if (identical(kind.name, 'source map')) {
- // TODO(podivilov): We should find a better way to return source maps from
- // emitter. Using diagnostic handler for that purpose is a temporary hack.
- writeString(sourceMapOut, message);
- return;
- }
-
if (isAborting) return;
isAborting = identical(kind, api.Diagnostic.CRASH);
bool fatal = (kind.ordinal & FATAL) != 0;
@@ -286,26 +279,60 @@ void compile(List<String> argv) {
info('package root is $packageRoot');
- // TODO(ahe): We expect the future to be complete and call value
- // directly. In effect, we don't support truly asynchronous API.
- String code = deprecatedFutureValue(
- api.compile(uri, libraryRoot, packageRoot, provider, handler, options));
- if (code == null) {
- fail('Error: Compilation failed.');
+ compilationDone(String code) {
+ if (code == null) {
+ fail('Error: Compilation failed.');
+ }
+ writeString(new Uri.fromString('$out.deps'), getDepsOutput(sourceFiles));
+ int bytesWritten = code.length;
+ info('compiled $dartBytesRead bytes Dart -> $bytesWritten bytes '
+ '$outputLanguage in ${relativize(cwd, out, isWindows)}');
+ if (!explicitOut) {
+ String input = uriPathToNative(arguments[0]);
+ String output = relativize(cwd, out, isWindows);
+ print('Dart file $input compiled to $outputLanguage: $output');
+ }
}
- String sourceMapFileName =
- sourceMapOut.path.substring(sourceMapOut.path.lastIndexOf('/') + 1);
- code = '$code\n//@ sourceMappingURL=${sourceMapFileName}';
- writeString(out, code);
- writeString(new Uri.fromString('$out.deps'), getDepsOutput(sourceFiles));
- int bytesWritten = code.length;
- info('compiled $dartBytesRead bytes Dart -> $bytesWritten bytes '
- '$outputLanguage in ${relativize(cwd, out, isWindows)}');
- if (!explicitOut) {
- String input = uriPathToNative(arguments[0]);
- String output = relativize(cwd, out, isWindows);
- print('Dart file $input compiled to $outputLanguage: $output');
+
+ Sink<String> outputProvider(String name, String extension) {
+ Uri uri;
+ String sourceMapFileName;
+ if (name == '') {
+ if (extension == 'js' || extension == 'dart') {
+ uri = out;
+ sourceMapFileName =
+ sourceMapOut.path.substring(sourceMapOut.path.lastIndexOf('/') + 1);
+ } else if (extension == 'js.map' || extension == 'dart.map') {
+ uri = sourceMapOut;
+ } else {
+ fail('Error: Unknown extension: $extension');
+ }
+ } else {
+ uri = out.resolve('$name.$extension');
+ }
+
+ if (uri.scheme != 'file') {
+ fail('Error: Unhandled scheme ${uri.scheme} in $uri.');
+ }
+ var outputStream = new File(uriPathToNative(uri.path)).openOutputStream();
+
+ onDone() {
+ if (sourceMapFileName != null) {
+ outputStream.writeString('//@ sourceMappingURL=');
+ outputStream.writeString(sourceMapFileName);
+ outputStream.writeString('\n');
+ }
+ outputStream.close();
+ }
+
+ return new StreamController<String>()
+ ..listen(outputStream.writeString, onDone: onDone);
}
+
+ api.compile(uri, libraryRoot, packageRoot,
+ inputProvider, handler,
+ options, outputProvider)
+ .then(compilationDone);
}
class AbortLeg {

Powered by Google App Engine
This is Rietveld 408576698