| 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/incremental_kernel_generator.dart'; | 8 import 'package:front_end/incremental_kernel_generator.dart'; |
| 9 import 'package:front_end/memory_file_system.dart'; | 9 import 'package:front_end/memory_file_system.dart'; |
| 10 import 'package:front_end/src/incremental/byte_store.dart'; | 10 import 'package:front_end/src/incremental/byte_store.dart'; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 import 'a.dart'; | 65 import 'a.dart'; |
| 66 var b = a; | 66 var b = a; |
| 67 '''); | 67 '''); |
| 68 Uri cUri = writeFile( | 68 Uri cUri = writeFile( |
| 69 cPath, | 69 cPath, |
| 70 r''' | 70 r''' |
| 71 import 'a.dart'; | 71 import 'a.dart'; |
| 72 import 'b.dart'; | 72 import 'b.dart'; |
| 73 var c1 = a; | 73 var c1 = a; |
| 74 var c2 = b; | 74 var c2 = b; |
| 75 void main() {} |
| 75 '''); | 76 '''); |
| 76 | 77 |
| 77 { | 78 { |
| 78 Program program = await getInitialState(cUri); | 79 Program program = await getInitialState(cUri); |
| 79 _assertLibraryUris(program, | 80 _assertLibraryUris(program, |
| 80 includes: [aUri, bUri, cUri, Uri.parse('dart:core')]); | 81 includes: [aUri, bUri, cUri, Uri.parse('dart:core')]); |
| 81 Library library = _getLibrary(program, cUri); | 82 Library library = _getLibrary(program, cUri); |
| 82 expect( | 83 expect( |
| 83 _getLibraryText(library), | 84 _getLibraryText(library), |
| 84 r''' | 85 r''' |
| 85 library; | 86 library; |
| 86 import self as self; | 87 import self as self; |
| 87 import "dart:core" as core; | 88 import "dart:core" as core; |
| 88 import "./a.dart" as a; | 89 import "./a.dart" as a; |
| 89 import "./b.dart" as b; | 90 import "./b.dart" as b; |
| 90 | 91 |
| 91 static field core::int c1 = a::a; | 92 static field core::int c1 = a::a; |
| 92 static field core::int c2 = b::b; | 93 static field core::int c2 = b::b; |
| 94 static method main() → void {} |
| 93 '''); | 95 '''); |
| 96 // The main method is set. |
| 97 expect(program.mainMethod, isNotNull); |
| 98 expect(program.mainMethod.enclosingLibrary.fileUri, cUri.toString()); |
| 94 } | 99 } |
| 95 | 100 |
| 96 // Update b.dart and recompile c.dart | 101 // Update b.dart and recompile c.dart |
| 97 writeFile( | 102 writeFile( |
| 98 bPath, | 103 bPath, |
| 99 r''' | 104 r''' |
| 100 import 'a.dart'; | 105 import 'a.dart'; |
| 101 var b = 1.2; | 106 var b = 1.2; |
| 102 '''); | 107 '''); |
| 103 incrementalKernelGenerator.invalidate(bUri); | 108 incrementalKernelGenerator.invalidate(bUri); |
| 104 { | 109 { |
| 105 DeltaProgram delta = await incrementalKernelGenerator.computeDelta(); | 110 DeltaProgram delta = await incrementalKernelGenerator.computeDelta(); |
| 106 Program program = delta.newProgram; | 111 Program program = delta.newProgram; |
| 107 _assertLibraryUris(program, | 112 _assertLibraryUris(program, |
| 108 includes: [bUri, cUri], excludes: [aUri, Uri.parse('dart:core')]); | 113 includes: [bUri, cUri], excludes: [aUri, Uri.parse('dart:core')]); |
| 109 Library library = _getLibrary(program, cUri); | 114 Library library = _getLibrary(program, cUri); |
| 110 expect( | 115 expect( |
| 111 _getLibraryText(library), | 116 _getLibraryText(library), |
| 112 r''' | 117 r''' |
| 113 library; | 118 library; |
| 114 import self as self; | 119 import self as self; |
| 115 import "dart:core" as core; | 120 import "dart:core" as core; |
| 116 import "./a.dart" as a; | 121 import "./a.dart" as a; |
| 117 import "./b.dart" as b; | 122 import "./b.dart" as b; |
| 118 | 123 |
| 119 static field core::int c1 = a::a; | 124 static field core::int c1 = a::a; |
| 120 static field core::double c2 = b::b; | 125 static field core::double c2 = b::b; |
| 126 static method main() → void {} |
| 121 '''); | 127 '''); |
| 128 // The main method is set even though not the entry point is updated. |
| 129 expect(program.mainMethod, isNotNull); |
| 130 expect(program.mainMethod.enclosingLibrary.fileUri, cUri.toString()); |
| 122 } | 131 } |
| 123 } | 132 } |
| 124 | 133 |
| 125 test_compile_export() async { | 134 test_compile_export() async { |
| 126 writeFile('/test/.packages', 'test:lib/'); | 135 writeFile('/test/.packages', 'test:lib/'); |
| 127 String aPath = '/test/lib/a.dart'; | 136 String aPath = '/test/lib/a.dart'; |
| 128 String bPath = '/test/lib/b.dart'; | 137 String bPath = '/test/lib/b.dart'; |
| 129 String cPath = '/test/lib/c.dart'; | 138 String cPath = '/test/lib/c.dart'; |
| 130 writeFile(aPath, 'class A {}'); | 139 writeFile(aPath, 'class A {}'); |
| 131 writeFile(bPath, 'export "a.dart";'); | 140 writeFile(bPath, 'export "a.dart";'); |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 initialKernelText = _getLibraryText(initialLibrary); | 423 initialKernelText = _getLibraryText(initialLibrary); |
| 415 | 424 |
| 416 var byteSink = new ByteSink(); | 425 var byteSink = new ByteSink(); |
| 417 var printer = new LimitedBinaryPrinter( | 426 var printer = new LimitedBinaryPrinter( |
| 418 byteSink, (library) => library.importUri == bUri); | 427 byteSink, (library) => library.importUri == bUri); |
| 419 printer.writeProgramFile(program); | 428 printer.writeProgramFile(program); |
| 420 bytes = byteSink.builder.takeBytes(); | 429 bytes = byteSink.builder.takeBytes(); |
| 421 | 430 |
| 422 // Remove b.dart from the program. | 431 // Remove b.dart from the program. |
| 423 // So, the program is now ready for re-adding the library. | 432 // So, the program is now ready for re-adding the library. |
| 433 program.mainMethod = null; |
| 424 program.libraries.remove(initialLibrary); | 434 program.libraries.remove(initialLibrary); |
| 425 program.root.removeChild(initialLibrary.importUri.toString()); | 435 program.root.removeChild(initialLibrary.importUri.toString()); |
| 426 } | 436 } |
| 427 | 437 |
| 428 // Load b.dart from bytes using the initial name root, so that | 438 // Load b.dart from bytes using the initial name root, so that |
| 429 // serialized canonical names can be linked to corresponding nodes. | 439 // serialized canonical names can be linked to corresponding nodes. |
| 430 Library loadedLibrary; | 440 Library loadedLibrary; |
| 431 { | 441 { |
| 432 var programForLoading = new Program(nameRoot: program.root); | 442 var programForLoading = new Program(nameRoot: program.root); |
| 433 var reader = new BinaryBuilder(bytes); | 443 var reader = new BinaryBuilder(bytes); |
| 434 reader.readProgram(programForLoading); | 444 reader.readProgram(programForLoading); |
| 435 loadedLibrary = _getLibrary(programForLoading, bUri); | 445 loadedLibrary = _getLibrary(programForLoading, bUri); |
| 436 } | 446 } |
| 437 | 447 |
| 438 // Add the library into the program. | 448 // Add the library into the program. |
| 439 program.libraries.add(loadedLibrary); | 449 program.libraries.add(loadedLibrary); |
| 440 loadedLibrary.parent = program; | 450 loadedLibrary.parent = program; |
| 451 program.mainMethod = loadedLibrary.procedures |
| 452 .firstWhere((procedure) => procedure.name.name == 'main'); |
| 441 | 453 |
| 442 expect(_getLibraryText(loadedLibrary), initialKernelText); | 454 expect(_getLibraryText(loadedLibrary), initialKernelText); |
| 443 verifyProgram(program); | 455 verifyProgram(program); |
| 444 } | 456 } |
| 445 | 457 |
| 446 test_updateEntryPoint() async { | 458 test_updateEntryPoint() async { |
| 447 writeFile('/test/.packages', 'test:lib/'); | 459 writeFile('/test/.packages', 'test:lib/'); |
| 448 String path = '/test/lib/test.dart'; | 460 String path = '/test/lib/test.dart'; |
| 449 Uri uri = writeFile( | 461 Uri uri = writeFile( |
| 450 path, | 462 path, |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 683 throw fail('No library found with URI "$uri"'); | 695 throw fail('No library found with URI "$uri"'); |
| 684 } | 696 } |
| 685 | 697 |
| 686 String _getLibraryText(Library library) { | 698 String _getLibraryText(Library library) { |
| 687 StringBuffer buffer = new StringBuffer(); | 699 StringBuffer buffer = new StringBuffer(); |
| 688 new Printer(buffer, syntheticNames: new NameSystem()) | 700 new Printer(buffer, syntheticNames: new NameSystem()) |
| 689 .writeLibraryFile(library); | 701 .writeLibraryFile(library); |
| 690 return buffer.toString(); | 702 return buffer.toString(); |
| 691 } | 703 } |
| 692 } | 704 } |
| OLD | NEW |