@@ -40,7 +40,7 @@ import 'package:front_end/src/fasta/kernel/utils.dart' show serializeComponent;
40
40
41
41
import 'package:front_end/src/fasta/severity.dart' show Severity;
42
42
43
- import 'package:kernel/kernel.dart' show Component;
43
+ import 'package:kernel/kernel.dart' show Component, Library ;
44
44
45
45
import 'incremental_load_from_dill_test.dart' show getOptions;
46
46
@@ -56,24 +56,26 @@ class Tester {
56
56
Uri sdkSummary;
57
57
Uri initializeFrom;
58
58
Uri helperFile;
59
+ Uri helper2File;
59
60
Uri entryPoint;
61
+ Uri entryPointImportDartFoo;
60
62
Uri platformUri;
61
63
List <int > sdkSummaryData;
62
64
List <DiagnosticMessage > errorMessages;
63
65
List <DiagnosticMessage > warningMessages;
64
66
MemoryFileSystem fs;
65
67
CompilerOptions options;
68
+ IncrementalCompiler compiler;
66
69
67
- compileExpectInitializeFailAndSpecificWarning (
70
+ void compileExpectInitializeFailAndSpecificWarning (
68
71
Code expectedWarningCode, bool writeFileOnCrashReport) async {
69
72
errorMessages.clear ();
70
73
warningMessages.clear ();
71
74
options.writeFileOnCrashReport = writeFileOnCrashReport;
72
- DeleteTempFilesIncrementalCompiler compiler =
73
- new DeleteTempFilesIncrementalCompiler (
74
- new CompilerContext (
75
- new ProcessedOptions (options: options, inputs: [entryPoint])),
76
- initializeFrom);
75
+ compiler = new DeleteTempFilesIncrementalCompiler (
76
+ new CompilerContext (
77
+ new ProcessedOptions (options: options, inputs: [entryPoint])),
78
+ initializeFrom);
77
79
await compiler.computeDelta ();
78
80
if (compiler.initializedFromDill) {
79
81
Expect .fail ("Expected to not be able to initialized from dill, but did." );
@@ -91,13 +93,40 @@ class Tester {
91
93
}
92
94
}
93
95
96
+ Future <Component > compileExpectOk (
97
+ bool initializedFromDill, Uri compileThis) async {
98
+ errorMessages.clear ();
99
+ warningMessages.clear ();
100
+ options.writeFileOnCrashReport = false ;
101
+ compiler = new DeleteTempFilesIncrementalCompiler (
102
+ new CompilerContext (
103
+ new ProcessedOptions (options: options, inputs: [compileThis])),
104
+ initializeFrom);
105
+ Component component = await compiler.computeDelta ();
106
+
107
+ if (compiler.initializedFromDill != initializedFromDill) {
108
+ Expect .fail ("Expected initializedFromDill to be $initializedFromDill "
109
+ "but was ${compiler .initializedFromDill }" );
110
+ }
111
+ if (errorMessages.isNotEmpty) {
112
+ Expect .fail ("Got unexpected errors: " + joinMessages (errorMessages));
113
+ }
114
+ if (warningMessages.isNotEmpty) {
115
+ Expect .fail ("Got unexpected warnings: " + joinMessages (warningMessages));
116
+ }
117
+
118
+ return component;
119
+ }
120
+
94
121
initialize () async {
95
122
sdkRoot = computePlatformBinariesLocation (forceBuildDir: true );
96
123
base = Uri .parse ("org-dartlang-test:///" );
97
124
sdkSummary = base .resolve ("vm_platform.dill" );
98
125
initializeFrom = base .resolve ("initializeFrom.dill" );
99
126
helperFile = base .resolve ("helper.dart" );
127
+ helper2File = base .resolve ("helper2.dart" );
100
128
entryPoint = base .resolve ("small.dart" );
129
+ entryPointImportDartFoo = base .resolve ("small_foo.dart" );
101
130
platformUri = sdkRoot.resolve ("vm_platform_strong.dill" );
102
131
sdkSummaryData = await new File .fromUri (platformUri).readAsBytes ();
103
132
errorMessages = < DiagnosticMessage > [];
@@ -108,6 +137,7 @@ class Tester {
108
137
options.fileSystem = fs;
109
138
options.sdkRoot = null ;
110
139
options.sdkSummary = sdkSummary;
140
+ options.omitPlatform = true ;
111
141
options.onDiagnostic = (DiagnosticMessage message) {
112
142
if (message.severity == Severity .error) {
113
143
errorMessages.add (message);
@@ -121,17 +151,28 @@ class Tester {
121
151
foo() {
122
152
print("hello from foo");
123
153
}
154
+ """ );
155
+ fs.entityForUri (helper2File).writeAsStringSync ("""
156
+ foo2() {
157
+ print("hello from foo2");
158
+ }
124
159
""" );
125
160
fs.entityForUri (entryPoint).writeAsStringSync ("""
126
161
import "helper.dart" as helper;
127
162
main() {
128
163
helper.foo();
129
164
}
165
+ """ );
166
+ fs.entityForUri (entryPointImportDartFoo).writeAsStringSync ("""
167
+ import "dart:foo" as helper;
168
+ main() {
169
+ helper.foo2();
170
+ }
130
171
""" );
131
172
}
132
173
133
174
Future <Null > test () async {
134
- IncrementalCompiler compiler = new IncrementalCompiler (
175
+ compiler = new IncrementalCompiler (
135
176
new CompilerContext (
136
177
new ProcessedOptions (options: options, inputs: [entryPoint])),
137
178
initializeFrom);
@@ -140,23 +181,32 @@ main() {
140
181
List <int > dataGood = serializeComponent (componentGood);
141
182
fs.entityForUri (initializeFrom).writeAsBytesSync (dataGood);
142
183
143
- // Initialize from good dill file should be ok.
184
+ // Create fake "dart:foo" library.
185
+ options.omitPlatform = false ;
144
186
compiler = new IncrementalCompiler (
145
187
new CompilerContext (
146
- new ProcessedOptions (options: options, inputs: [entryPoint ])),
188
+ new ProcessedOptions (options: options, inputs: [helper2File ])),
147
189
initializeFrom);
148
- compiler.invalidate (entryPoint);
149
- Component component = await compiler.computeDelta ();
150
- if (! compiler.initializedFromDill) {
151
- Expect .fail (
152
- "Expected to have sucessfully initialized from dill, but didn't." );
153
- }
154
- if (errorMessages.isNotEmpty) {
155
- Expect .fail ("Got unexpected errors: " + joinMessages (errorMessages));
156
- }
157
- if (warningMessages.isNotEmpty) {
158
- Expect .fail ("Got unexpected warnings: " + joinMessages (warningMessages));
190
+ Component componentHelper = await compiler.computeDelta ();
191
+ Library helper2Lib = componentHelper.libraries
192
+ .firstWhere ((lib) => lib.importUri == helper2File);
193
+ helper2Lib.importUri = new Uri (scheme: "dart" , path: "foo" );
194
+ List <int > sdkWithDartFoo = serializeComponent (componentHelper);
195
+ options.omitPlatform = true ;
196
+
197
+ // Compile with our fake sdk with dart:foo should be ok.
198
+ List <int > orgSdkBytes = await fs.entityForUri (sdkSummary).readAsBytes ();
199
+ fs.entityForUri (sdkSummary).writeAsBytesSync (sdkWithDartFoo);
200
+ Component component = await compileExpectOk (true , entryPointImportDartFoo);
201
+ fs.entityForUri (sdkSummary).writeAsBytesSync (orgSdkBytes);
202
+ if (component.libraries.length != 1 ) {
203
+ Expect .fail ("Expected 1 library, got ${component .libraries .length }: "
204
+ "${component .libraries }" );
159
205
}
206
+ List <int > dataLinkedToSdkWithFoo = serializeComponent (component);
207
+
208
+ // Initialize from good dill file should be ok.
209
+ await compileExpectOk (true , entryPoint);
160
210
161
211
// Create a partial dill file.
162
212
compiler.invalidate (entryPoint);
@@ -181,6 +231,11 @@ main() {
181
231
codeInitializeFromDillUnknownProblem, true );
182
232
await compileExpectInitializeFailAndSpecificWarning (
183
233
codeInitializeFromDillUnknownProblemNoDump, false );
234
+
235
+ // Create a dill with a reference to a non-existing sdk thing:
236
+ // Should be ok (for now), but we shouldn't actually initialize from dill.
237
+ fs.entityForUri (initializeFrom).writeAsBytesSync (dataLinkedToSdkWithFoo);
238
+ await compileExpectOk (false , entryPoint);
184
239
}
185
240
}
186
241
0 commit comments