OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 import 'dart:async'; | 5 import 'dart:async'; |
6 | 6 |
7 import 'package:front_end/compiler_options.dart'; | 7 import 'package:front_end/compiler_options.dart'; |
8 import 'package:front_end/memory_file_system.dart'; | 8 import 'package:front_end/memory_file_system.dart'; |
9 import 'package:front_end/src/base/performace_logger.dart'; | 9 import 'package:front_end/src/base/performace_logger.dart'; |
10 import 'package:front_end/src/base/processed_options.dart'; | 10 import 'package:front_end/src/base/processed_options.dart'; |
11 import 'package:front_end/src/fasta/kernel/utils.dart'; | 11 import 'package:front_end/src/fasta/kernel/utils.dart'; |
12 import 'package:front_end/src/fasta/uri_translator_impl.dart'; | 12 import 'package:front_end/src/fasta/uri_translator_impl.dart'; |
13 import 'package:front_end/src/incremental/byte_store.dart'; | 13 import 'package:front_end/src/incremental/byte_store.dart'; |
14 import 'package:front_end/src/incremental/kernel_driver.dart'; | 14 import 'package:front_end/src/incremental/kernel_driver.dart'; |
| 15 import 'package:front_end/summary_generator.dart'; |
15 import 'package:kernel/ast.dart'; | 16 import 'package:kernel/ast.dart'; |
16 import 'package:kernel/binary/ast_from_binary.dart'; | 17 import 'package:kernel/binary/ast_from_binary.dart'; |
17 import 'package:kernel/target/targets.dart'; | 18 import 'package:kernel/target/targets.dart'; |
18 import 'package:kernel/text/ast_to_text.dart'; | 19 import 'package:kernel/text/ast_to_text.dart'; |
19 import 'package:kernel/verifier.dart'; | 20 import 'package:kernel/verifier.dart'; |
20 import 'package:package_config/src/packages_impl.dart'; | 21 import 'package:package_config/src/packages_impl.dart'; |
21 import 'package:test/test.dart'; | 22 import 'package:test/test.dart'; |
22 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 23 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
23 | 24 |
24 import 'mock_sdk.dart'; | 25 import 'mock_sdk.dart'; |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 test_compile_typeEnvironment() async { | 280 test_compile_typeEnvironment() async { |
280 writeFile('/test/.packages', 'test:lib/'); | 281 writeFile('/test/.packages', 'test:lib/'); |
281 String aPath = '/test/lib/a.dart'; | 282 String aPath = '/test/lib/a.dart'; |
282 Uri aUri = writeFile(aPath, 'class A {}'); | 283 Uri aUri = writeFile(aPath, 'class A {}'); |
283 | 284 |
284 KernelResult result = await driver.getKernel(aUri); | 285 KernelResult result = await driver.getKernel(aUri); |
285 expect(result.types.coreTypes.intClass, isNotNull); | 286 expect(result.types.coreTypes.intClass, isNotNull); |
286 expect(result.types.hierarchy, isNotNull); | 287 expect(result.types.hierarchy, isNotNull); |
287 } | 288 } |
288 | 289 |
| 290 test_compile_useSdkOutline() async { |
| 291 List<int> sdkOutlineBytes = await _computeSdkOutlineBytes(); |
| 292 |
| 293 // Configure the driver to use the SDK outline. |
| 294 _createDriver(sdkOutlineBytes: sdkOutlineBytes); |
| 295 |
| 296 writeFile('/test/.packages', 'test:lib/'); |
| 297 String aPath = '/test/lib/a.dart'; |
| 298 Uri aUri = writeFile(aPath, r''' |
| 299 import 'dart:async'; |
| 300 var a = 1; |
| 301 Future<String> b; |
| 302 '''); |
| 303 |
| 304 KernelResult result = await driver.getKernel(aUri); |
| 305 |
| 306 // The result does not include SDK libraries. |
| 307 _assertLibraryUris(result, |
| 308 includes: [aUri], |
| 309 excludes: [Uri.parse('dart:core'), Uri.parse('dart:core')]); |
| 310 |
| 311 // The types of top-level variables are resolved. |
| 312 var library = _getLibrary(result, aUri); |
| 313 expect(library.fields[0].type.toString(), 'dart.core::int'); |
| 314 expect(library.fields[1].type.toString(), |
| 315 'dart.async::Future<dart.core::String>'); |
| 316 } |
| 317 |
289 test_limitedStore_exportDependencies() async { | 318 test_limitedStore_exportDependencies() async { |
290 writeFile('/test/.packages', 'test:lib/'); | 319 writeFile('/test/.packages', 'test:lib/'); |
291 String aPath = '/test/lib/a.dart'; | 320 String aPath = '/test/lib/a.dart'; |
292 String bPath = '/test/lib/b.dart'; | 321 String bPath = '/test/lib/b.dart'; |
293 String cPath = '/test/lib/c.dart'; | 322 String cPath = '/test/lib/c.dart'; |
294 Uri aUri = writeFile(aPath, 'class A {}'); | 323 Uri aUri = writeFile(aPath, 'class A {}'); |
295 var bUri = writeFile(bPath, 'export "a.dart";'); | 324 var bUri = writeFile(bPath, 'export "a.dart";'); |
296 Uri cUri = writeFile(cPath, r''' | 325 Uri cUri = writeFile(cPath, r''' |
297 import 'b.dart'; | 326 import 'b.dart'; |
298 A a; | 327 A a; |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 .expand((uris) => uris) | 669 .expand((uris) => uris) |
641 .toList(); | 670 .toList(); |
642 for (var shouldInclude in includes) { | 671 for (var shouldInclude in includes) { |
643 expect(libraryUris, contains(shouldInclude)); | 672 expect(libraryUris, contains(shouldInclude)); |
644 } | 673 } |
645 for (var shouldExclude in excludes) { | 674 for (var shouldExclude in excludes) { |
646 expect(libraryUris, isNot(contains(shouldExclude))); | 675 expect(libraryUris, isNot(contains(shouldExclude))); |
647 } | 676 } |
648 } | 677 } |
649 | 678 |
| 679 Future<List<int>> _computeSdkOutlineBytes() async { |
| 680 var options = new CompilerOptions() |
| 681 ..fileSystem = fileSystem |
| 682 ..sdkRoot = Uri.parse('file:///sdk/') |
| 683 ..compileSdk = true |
| 684 ..chaseDependencies = true |
| 685 ..strongMode = true |
| 686 ..target = new NoneTarget(new TargetFlags(strongMode: true)); |
| 687 var inputs = [Uri.parse('dart:core')]; |
| 688 return summaryFor(inputs, options); |
| 689 } |
| 690 |
650 /// Create new [KernelDriver] instance and put it into the [driver] field. | 691 /// Create new [KernelDriver] instance and put it into the [driver] field. |
651 void _createDriver( | 692 void _createDriver( |
652 {Map<String, Uri> packages, KernelDriverFileAddedFn fileAddedFn}) { | 693 {List<int> sdkOutlineBytes, |
| 694 Map<String, Uri> packages, |
| 695 KernelDriverFileAddedFn fileAddedFn}) { |
653 var uriTranslator = new UriTranslatorImpl( | 696 var uriTranslator = new UriTranslatorImpl( |
654 createSdkFiles(fileSystem), new MapPackages(packages)); | 697 createSdkFiles(fileSystem), new MapPackages(packages)); |
655 driver = new KernelDriver( | 698 |
656 new ProcessedOptions(new CompilerOptions() | 699 var options = new CompilerOptions() |
657 ..logger = new PerformanceLog(null) | 700 ..logger = new PerformanceLog(null) |
658 ..fileSystem = fileSystem | 701 ..fileSystem = fileSystem |
659 ..byteStore = new MemoryByteStore() | 702 ..byteStore = new MemoryByteStore() |
660 ..strongMode = true | 703 ..strongMode = true |
661 ..target = new NoneTarget(new TargetFlags(strongMode: true))), | 704 ..target = new NoneTarget(new TargetFlags(strongMode: true)); |
662 uriTranslator, | 705 |
663 fileAddedFn: fileAddedFn); | 706 driver = new KernelDriver(new ProcessedOptions(options), uriTranslator, |
| 707 sdkOutlineBytes: sdkOutlineBytes, fileAddedFn: fileAddedFn); |
664 } | 708 } |
665 | 709 |
666 Library _getLibrary(KernelResult result, Uri uri) { | 710 Library _getLibrary(KernelResult result, Uri uri) { |
667 for (var cycleResult in result.results) { | 711 for (var cycleResult in result.results) { |
668 for (var library in cycleResult.kernelLibraries) { | 712 for (var library in cycleResult.kernelLibraries) { |
669 if (library.importUri == uri) return library; | 713 if (library.importUri == uri) return library; |
670 } | 714 } |
671 } | 715 } |
672 throw fail('No library found with URI "$uri"'); | 716 throw fail('No library found with URI "$uri"'); |
673 } | 717 } |
(...skipping 11 matching lines...) Expand all Loading... |
685 .writeLibraryFile(library); | 729 .writeLibraryFile(library); |
686 return buffer.toString(); | 730 return buffer.toString(); |
687 } | 731 } |
688 | 732 |
689 /// Return the [Uri] for the given Posix [path]. | 733 /// Return the [Uri] for the given Posix [path]. |
690 static Uri _folderUri(String path) { | 734 static Uri _folderUri(String path) { |
691 if (!path.endsWith('/')) path += '/'; | 735 if (!path.endsWith('/')) path += '/'; |
692 return Uri.parse('file://$path'); | 736 return Uri.parse('file://$path'); |
693 } | 737 } |
694 } | 738 } |
OLD | NEW |