| 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('dart2js'); | 5 #library('dart2js'); |
| 6 | 6 |
| 7 #import('dart:io'); | 7 #import('dart:io'); |
| 8 #import('dart:uri'); | 8 #import('dart:uri'); |
| 9 #import('dart:utf'); | 9 #import('dart:utf'); |
| 10 | 10 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 helpAndFail('Error: Extra arguments: ${Strings.join(extra, " ")}'); | 102 helpAndFail('Error: Extra arguments: ${Strings.join(extra, " ")}'); |
| 103 } | 103 } |
| 104 | 104 |
| 105 Map<String, SourceFile> sourceFiles = <SourceFile>{}; | 105 Map<String, SourceFile> sourceFiles = <SourceFile>{}; |
| 106 int dartBytesRead = 0; | 106 int dartBytesRead = 0; |
| 107 | 107 |
| 108 Future<String> provider(Uri uri) { | 108 Future<String> provider(Uri uri) { |
| 109 if (uri.scheme != 'file') { | 109 if (uri.scheme != 'file') { |
| 110 throw new IllegalArgumentException(uri); | 110 throw new IllegalArgumentException(uri); |
| 111 } | 111 } |
| 112 String source = readAll(uriPathToNative(uri.path)); | 112 String source; |
| 113 try { |
| 114 source = readAll(uriPathToNative(uri.path)); |
| 115 } catch (FileIOException ex) { |
| 116 throw 'Error: Cannot read "${relativize(cwd, uri)}" (${ex.osError}).'; |
| 117 } |
| 113 dartBytesRead += source.length; | 118 dartBytesRead += source.length; |
| 114 sourceFiles[uri.toString()] = | 119 sourceFiles[uri.toString()] = |
| 115 new SourceFile(relativize(cwd, uri), source); | 120 new SourceFile(relativize(cwd, uri), source); |
| 116 Completer<String> completer = new Completer<String>(); | 121 Completer<String> completer = new Completer<String>(); |
| 117 completer.complete(source); | 122 completer.complete(source); |
| 118 return completer.future; | 123 return completer.future; |
| 119 } | 124 } |
| 120 | 125 |
| 121 void info(var message) { | 126 void info(var message) { |
| 122 if (verbose) print('${colors.green("info:")} $message'); | 127 if (verbose) print('${colors.green("info:")} $message'); |
| 123 } | 128 } |
| 124 | 129 |
| 130 bool isAborting = false; |
| 131 |
| 125 void handler(Uri uri, int begin, int end, String message, bool fatal) { | 132 void handler(Uri uri, int begin, int end, String message, bool fatal) { |
| 133 if (isAborting) return; |
| 126 if (uri === null && !fatal) { | 134 if (uri === null && !fatal) { |
| 127 info(message); | 135 info(message); |
| 128 return; | 136 return; |
| 129 } | 137 } |
| 130 if (uri === null) { | 138 if (uri === null) { |
| 131 assert(fatal); | 139 assert(fatal); |
| 132 print(message); | 140 print(message); |
| 133 } else if (fatal || showWarnings) { | 141 } else if (fatal || showWarnings) { |
| 134 SourceFile file = sourceFiles[uri.toString()]; | 142 SourceFile file = sourceFiles[uri.toString()]; |
| 135 print(file.getLocationMessage(message, begin, end, true)); | 143 print(file.getLocationMessage(message, begin, end, true)); |
| 136 } | 144 } |
| 137 if (fatal && throwOnError) throw new AbortLeg(message); | 145 if (fatal && throwOnError) { |
| 146 isAborting = true; |
| 147 throw new AbortLeg(message); |
| 148 } |
| 138 } | 149 } |
| 139 | 150 |
| 140 Uri uri = cwd.resolve(arguments[0]); | 151 Uri uri = cwd.resolve(arguments[0]); |
| 141 info('compiling $uri'); | 152 info('compiling $uri'); |
| 142 | 153 |
| 143 // TODO(ahe): We expect the future to be complete and call value | 154 // TODO(ahe): We expect the future to be complete and call value |
| 144 // directly. In effect, we don't support truly asynchronous API. | 155 // directly. In effect, we don't support truly asynchronous API. |
| 145 String code = api.compile(uri, libraryRoot, provider, handler, options).value; | 156 String code = api.compile(uri, libraryRoot, provider, handler, options).value; |
| 146 if (code === null) { | 157 if (code === null) { |
| 147 fail('Error: Compilation failed.'); | 158 fail('Error: Compilation failed.'); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 } catch (var ignored) { | 281 } catch (var ignored) { |
| 271 print('Internal error: error while printing exception'); | 282 print('Internal error: error while printing exception'); |
| 272 } | 283 } |
| 273 try { | 284 try { |
| 274 print(trace); | 285 print(trace); |
| 275 } finally { | 286 } finally { |
| 276 exit(253); // 253 is recognized as a crash by our test scripts. | 287 exit(253); // 253 is recognized as a crash by our test scripts. |
| 277 } | 288 } |
| 278 } | 289 } |
| 279 } | 290 } |
| OLD | NEW |