| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #library('frog_leg'); | 5 #library('frog_leg'); |
| 6 | 6 |
| 7 #import('dart:io'); | 7 #import('dart:io'); |
| 8 #import('dart:uri'); | 8 #import('dart:uri'); |
| 9 | 9 |
| 10 #import('lang.dart', prefix: 'frog'); | 10 #import('lang.dart', prefix: 'frog'); |
| 11 #import('../lib/compiler/compiler.dart', prefix: 'compiler'); | 11 #import('../lib/compiler/compiler.dart', prefix: 'compiler'); |
| 12 #import('../lib/compiler/implementation/filenames.dart'); |
| 12 | 13 |
| 13 String relativize(Uri base, Uri uri) { | 14 String relativize(Uri base, Uri uri) { |
| 14 if (base.scheme == 'file' && | 15 if (base.scheme == 'file' && |
| 15 base.scheme == uri.scheme && | 16 base.scheme == uri.scheme && |
| 16 base.userInfo == uri.userInfo && | 17 base.userInfo == uri.userInfo && |
| 17 base.domain == uri.domain && | 18 base.domain == uri.domain && |
| 18 base.port == uri.port && | 19 base.port == uri.port && |
| 19 uri.query == "" && uri.fragment == "") { | 20 uri.query == "" && uri.fragment == "") { |
| 20 if (uri.path.startsWith(base.path)) { | 21 if (uri.path.startsWith(base.path)) { |
| 21 return uri.path.substring(base.path.length); | 22 return uri.path.substring(base.path.length); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 38 return sb.toString(); | 39 return sb.toString(); |
| 39 } | 40 } |
| 40 return uri.toString(); | 41 return uri.toString(); |
| 41 } | 42 } |
| 42 | 43 |
| 43 bool compile(frog.World world) { | 44 bool compile(frog.World world) { |
| 44 final throwOnError = frog.options.throwOnErrors; | 45 final throwOnError = frog.options.throwOnErrors; |
| 45 final showWarnings = frog.options.showWarnings; | 46 final showWarnings = frog.options.showWarnings; |
| 46 final allowMockCompilation = frog.options.allowMockCompilation; | 47 final allowMockCompilation = frog.options.allowMockCompilation; |
| 47 Uri cwd = new Uri(scheme: 'file', path: getCurrentDirectory()); | 48 Uri cwd = new Uri(scheme: 'file', path: getCurrentDirectory()); |
| 48 Uri uri = cwd.resolve(frog.options.dartScript); | 49 Uri uri = cwd.resolve(nativeToUriPath(frog.options.dartScript)); |
| 49 String frogLibDir = frog.options.libDir; | 50 String frogLibDir = nativeToUriPath(frog.options.libDir); |
| 50 if (!frogLibDir.endsWith("/")) frogLibDir = "$frogLibDir/"; | 51 if (!frogLibDir.endsWith("/")) frogLibDir = "$frogLibDir/"; |
| 51 Uri frogLib = new Uri(scheme: 'file', path: frogLibDir); | 52 Uri frogLib = new Uri(scheme: 'file', path: frogLibDir); |
| 52 Uri libraryRoot = frogLib.resolve('../../'); | 53 Uri libraryRoot = frogLib.resolve('../../'); |
| 53 Map<String, frog.SourceFile> sourceFiles = <frog.SourceFile>{}; | 54 Map<String, frog.SourceFile> sourceFiles = <frog.SourceFile>{}; |
| 54 | 55 |
| 55 Future<String> provider(Uri uri) { | 56 Future<String> provider(Uri uri) { |
| 56 if (uri.scheme != 'file') { | 57 if (uri.scheme != 'file') { |
| 57 throw new IllegalArgumentException(uri); | 58 throw new IllegalArgumentException(uri); |
| 58 } | 59 } |
| 59 String source = world.files.readAll(uri.path); | 60 String source = world.files.readAll(uriPathToNative(uri.path)); |
| 60 world.dartBytesRead += source.length; | 61 world.dartBytesRead += source.length; |
| 61 sourceFiles[uri.toString()] = | 62 sourceFiles[uri.toString()] = |
| 62 new frog.SourceFile(relativize(cwd, uri), source); | 63 new frog.SourceFile(relativize(cwd, uri), source); |
| 63 Completer<String> completer = new Completer<String>(); | 64 Completer<String> completer = new Completer<String>(); |
| 64 completer.complete(source); | 65 completer.complete(source); |
| 65 return completer.future; | 66 return completer.future; |
| 66 } | 67 } |
| 67 | 68 |
| 68 void handler(Uri uri, int begin, int end, String message, bool fatal) { | 69 void handler(Uri uri, int begin, int end, String message, bool fatal) { |
| 69 if (uri === null && !fatal) { | 70 if (uri === null && !fatal) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 97 final message; | 98 final message; |
| 98 AbortLeg(this.message); | 99 AbortLeg(this.message); |
| 99 toString() => 'Aborted due to --throw-on-error: $message'; | 100 toString() => 'Aborted due to --throw-on-error: $message'; |
| 100 } | 101 } |
| 101 | 102 |
| 102 String getCurrentDirectory() { | 103 String getCurrentDirectory() { |
| 103 String dir = new File(".").fullPathSync(); | 104 String dir = new File(".").fullPathSync(); |
| 104 if (dir.endsWith("/")) return dir; | 105 if (dir.endsWith("/")) return dir; |
| 105 return "$dir/"; | 106 return "$dir/"; |
| 106 } | 107 } |
| OLD | NEW |