Chromium Code Reviews| 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/src/kernel_generator_impl.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 ..compileSdk = true | |
| 683 ..strongMode = true | |
| 684 ..sdkRoot = Uri.parse('file:///sdk/') | |
| 685 ..target = new NoneTarget(new TargetFlags(strongMode: true)); | |
| 686 var inputs = [Uri.parse('dart:core')]; | |
| 687 var result = await generateKernel( | |
|
Siggi Cherem (dart-lang)
2017/08/05 03:22:47
any reason why not use the public API instead? (`s
scheglov
2017/08/06 21:04:06
Well, this is what build uses.
And an attempt to u
Siggi Cherem (dart-lang)
2017/08/07 15:29:52
Hopefully just setting `options.chaseDependencies
scheglov
2017/08/07 15:51:26
Yes, this fixed the problem.
| |
| 688 new ProcessedOptions(options, false, inputs), | |
| 689 buildSummary: true); | |
| 690 return result.summary; | |
| 691 } | |
| 692 | |
| 650 /// Create new [KernelDriver] instance and put it into the [driver] field. | 693 /// Create new [KernelDriver] instance and put it into the [driver] field. |
| 651 void _createDriver( | 694 void _createDriver( |
| 652 {Map<String, Uri> packages, KernelDriverFileAddedFn fileAddedFn}) { | 695 {List<int> sdkOutlineBytes, |
| 696 Map<String, Uri> packages, | |
| 697 KernelDriverFileAddedFn fileAddedFn}) { | |
| 653 Map<String, Uri> dartLibraries = createSdkFiles(fileSystem); | 698 Map<String, Uri> dartLibraries = createSdkFiles(fileSystem); |
| 654 var uriTranslator = | 699 var uriTranslator = |
| 655 new UriTranslatorImpl(dartLibraries, {}, new MapPackages(packages)); | 700 new UriTranslatorImpl(dartLibraries, {}, new MapPackages(packages)); |
| 656 driver = new KernelDriver( | 701 |
| 657 new ProcessedOptions(new CompilerOptions() | 702 var options = new CompilerOptions() |
| 658 ..logger = new PerformanceLog(null) | 703 ..logger = new PerformanceLog(null) |
| 659 ..fileSystem = fileSystem | 704 ..fileSystem = fileSystem |
| 660 ..byteStore = new MemoryByteStore() | 705 ..byteStore = new MemoryByteStore() |
| 661 ..strongMode = true | 706 ..strongMode = true |
| 662 ..target = new NoneTarget(new TargetFlags(strongMode: true))), | 707 ..target = new NoneTarget(new TargetFlags(strongMode: true)); |
| 663 uriTranslator, | 708 |
| 664 fileAddedFn: fileAddedFn); | 709 driver = new KernelDriver(new ProcessedOptions(options), uriTranslator, |
| 710 sdkOutlineBytes: sdkOutlineBytes, fileAddedFn: fileAddedFn); | |
| 665 } | 711 } |
| 666 | 712 |
| 667 Library _getLibrary(KernelResult result, Uri uri) { | 713 Library _getLibrary(KernelResult result, Uri uri) { |
| 668 for (var cycleResult in result.results) { | 714 for (var cycleResult in result.results) { |
| 669 for (var library in cycleResult.kernelLibraries) { | 715 for (var library in cycleResult.kernelLibraries) { |
| 670 if (library.importUri == uri) return library; | 716 if (library.importUri == uri) return library; |
| 671 } | 717 } |
| 672 } | 718 } |
| 673 throw fail('No library found with URI "$uri"'); | 719 throw fail('No library found with URI "$uri"'); |
| 674 } | 720 } |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 686 .writeLibraryFile(library); | 732 .writeLibraryFile(library); |
| 687 return buffer.toString(); | 733 return buffer.toString(); |
| 688 } | 734 } |
| 689 | 735 |
| 690 /// Return the [Uri] for the given Posix [path]. | 736 /// Return the [Uri] for the given Posix [path]. |
| 691 static Uri _folderUri(String path) { | 737 static Uri _folderUri(String path) { |
| 692 if (!path.endsWith('/')) path += '/'; | 738 if (!path.endsWith('/')) path += '/'; |
| 693 return Uri.parse('file://$path'); | 739 return Uri.parse('file://$path'); |
| 694 } | 740 } |
| 695 } | 741 } |
| OLD | NEW |