OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 import "dart:async"; |
| 6 import "dart:io"; |
| 7 |
| 8 import "package:expect/expect.dart"; |
| 9 import "package:async_helper/async_helper.dart"; |
| 10 |
| 11 import '../../../sdk/lib/_internal/compiler/compiler.dart' as compiler; |
| 12 import '../../../sdk/lib/_internal/compiler/implementation/filenames.dart'; |
| 13 |
| 14 const SOURCES = const { |
| 15 "/main.dart": """ |
| 16 import "foo.dart"; |
| 17 main() => foo(); |
| 18 """, |
| 19 "/foo.dart": """ |
| 20 library foo; |
| 21 import "bar.dart"; |
| 22 foo() => bar(); |
| 23 """, |
| 24 "/bar.dart": """ |
| 25 library bar; |
| 26 bar() => print("bar"); |
| 27 """ |
| 28 }; |
| 29 |
| 30 Future<String> provideInput(Uri uri) { |
| 31 var source = SOURCES[uri.path]; |
| 32 if (source == null) { |
| 33 // Not one of our source files, so assume it's a built-in. |
| 34 source = new File(uriPathToNative(uri.path)).readAsStringSync(); |
| 35 } |
| 36 |
| 37 // Deliver the input asynchronously. |
| 38 return new Future(() => source); |
| 39 } |
| 40 |
| 41 main() { |
| 42 var entrypoint = Uri.parse("file:///main.dart"); |
| 43 |
| 44 // Find the path to sdk/ in the repo relative to this script. |
| 45 Uri script = currentDirectory.resolve(nativeToUriPath(Platform.script)); |
| 46 Uri libraryRoot = script.resolve('../../../sdk/'); |
| 47 Uri packageRoot = script.resolve('./packages/'); |
| 48 |
| 49 asyncStart(); |
| 50 compiler.compile(entrypoint, libraryRoot, packageRoot, |
| 51 provideInput, handleDiagnostic, []).then((code) { |
| 52 Expect.isNotNull(code); |
| 53 }).whenComplete(() => asyncEnd()); |
| 54 } |
| 55 |
| 56 void handleDiagnostic(Uri uri, int begin, int end, String message, |
| 57 compiler.Diagnostic kind) { |
| 58 print(message); |
| 59 if (kind != compiler.Diagnostic.VERBOSE_INFO) { |
| 60 throw 'Unexpected diagnostic kind $kind'; |
| 61 } |
| 62 } |
OLD | NEW |