@@ -63,22 +63,27 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
63
63
entryPoint ?? = context.options.inputs.single;
64
64
return context.runInContext <Future <Component >>((CompilerContext c) async {
65
65
IncrementalCompilerData data = new IncrementalCompilerData ();
66
- if (dillLoadedData == null ) {
67
- UriTranslator uriTranslator = await c.options.getUriTranslator ();
68
- ticker.logMs ("Read packages file" );
69
66
67
+ // TODO(jensj): We should only bypass the cache if .packages has been
68
+ // invalidated, but Flutter does not currently invalidate .packages.
69
+ UriTranslator uriTranslator =
70
+ await c.options.getUriTranslator (bypassCache: true );
71
+ ticker.logMs ("Read packages file" );
72
+
73
+ if (dillLoadedData == null ) {
70
74
List <int > summaryBytes = await c.options.loadSdkSummaryBytes ();
71
75
int bytesLength = prepareSummary (summaryBytes, uriTranslator, c, data);
72
76
if (initializeFromDillUri != null ) {
73
77
try {
74
- bytesLength += await initializeFromDill (summaryBytes, c, data);
78
+ bytesLength +=
79
+ await initializeFromDill (summaryBytes, uriTranslator, c, data);
75
80
} catch (e) {
76
81
// We might have loaded x out of y libraries into the component.
77
82
// To avoid any unforeseen problems start over.
78
83
bytesLength = prepareSummary (summaryBytes, uriTranslator, c, data);
79
84
}
80
85
}
81
- appendLibraries (data, bytesLength, uriTranslator );
86
+ appendLibraries (data, bytesLength);
82
87
83
88
try {
84
89
await dillLoadedData.buildOutlines ();
@@ -89,7 +94,7 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
89
94
initializedFromDill = false ;
90
95
data.reset ();
91
96
bytesLength = prepareSummary (summaryBytes, uriTranslator, c, data);
92
- appendLibraries (data, bytesLength, uriTranslator );
97
+ appendLibraries (data, bytesLength);
93
98
await dillLoadedData.buildOutlines ();
94
99
}
95
100
summaryBytes = null ;
@@ -112,7 +117,7 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
112
117
}
113
118
114
119
List <LibraryBuilder > reusedLibraries =
115
- computeReusedLibraries (invalidatedUris);
120
+ computeReusedLibraries (invalidatedUris, uriTranslator );
116
121
Set <Uri > reusedLibraryUris =
117
122
new Set <Uri >.from (reusedLibraries.map ((b) => b.uri));
118
123
for (Uri uri in new Set <Uri >.from (dillLoadedData.loader.builders.keys)
@@ -128,7 +133,7 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
128
133
129
134
KernelIncrementalTarget userCodeOld = userCode;
130
135
userCode = new KernelIncrementalTarget (
131
- c.fileSystem, false , dillLoadedData, dillLoadedData. uriTranslator,
136
+ c.fileSystem, false , dillLoadedData, uriTranslator,
132
137
uriToSource: c.uriToSource);
133
138
134
139
for (LibraryBuilder library in reusedLibraries) {
@@ -258,7 +263,10 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
258
263
}
259
264
260
265
// This procedure will try to load the dill file and will crash if it cannot.
261
- Future <int > initializeFromDill (List <int > summaryBytes, CompilerContext c,
266
+ Future <int > initializeFromDill (
267
+ List <int > summaryBytes,
268
+ UriTranslator uriTranslator,
269
+ CompilerContext c,
262
270
IncrementalCompilerData data) async {
263
271
int bytesLength = 0 ;
264
272
FileSystemEntity entity =
@@ -277,6 +285,20 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
277
285
new BinaryBuilder (initializationBytes, disableLazyReading: true )
278
286
.readComponent (data.component);
279
287
288
+ // Check the any package-urls still point to the same file
289
+ // (e.g. the package still exists and hasn't been updated).
290
+ for (Library lib in data.component.libraries) {
291
+ if (lib.importUri.scheme == "package" &&
292
+ uriTranslator.translate (lib.importUri, false ) != lib.fileUri) {
293
+ // Package has been removed or updated.
294
+ // This library should be thrown away.
295
+ // Everything that depends on it should be thrown away.
296
+ // TODO(jensj): Anything that doesn't depend on it can be kept.
297
+ // For now just don't initialize from this dill.
298
+ throw "Changed package" ;
299
+ }
300
+ }
301
+
280
302
initializedFromDill = true ;
281
303
bytesLength += initializationBytes.length;
282
304
for (Library lib in data.component.libraries) {
@@ -294,27 +316,16 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
294
316
return bytesLength;
295
317
}
296
318
297
- void appendLibraries (IncrementalCompilerData data, int bytesLength,
298
- UriTranslator uriTranslator) {
319
+ void appendLibraries (IncrementalCompilerData data, int bytesLength) {
299
320
if (data.component != null ) {
300
- List <Library > keepLibraries = < Library > [];
301
- for (Library lib in data.component.libraries) {
302
- if (lib.importUri.scheme != "package" ||
303
- uriTranslator.translate (lib.importUri, false ) != null ) {
304
- keepLibraries.add (lib);
305
- }
306
- }
307
- data.component.libraries
308
- ..clear ()
309
- ..addAll (keepLibraries);
310
-
311
321
dillLoadedData.loader
312
322
.appendLibraries (data.component, byteCount: bytesLength);
313
323
}
314
324
ticker.logMs ("Appended libraries" );
315
325
}
316
326
317
- List <LibraryBuilder > computeReusedLibraries (Iterable <Uri > invalidatedUris) {
327
+ List <LibraryBuilder > computeReusedLibraries (
328
+ Iterable <Uri > invalidatedUris, UriTranslator uriTranslator) {
318
329
if (userCode == null && userBuilders == null ) {
319
330
return < LibraryBuilder > [];
320
331
}
@@ -338,7 +349,10 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
338
349
invalidatedFileUris.contains (library.fileUri)) ||
339
350
(library is DillLibraryBuilder &&
340
351
uri != library.library.fileUri &&
341
- invalidatedFileUris.contains (library.library.fileUri))) {
352
+ invalidatedFileUris.contains (library.library.fileUri)) ||
353
+ (library.uri.scheme == "package" &&
354
+ uriTranslator.translate (library.uri, false ) !=
355
+ library.target.fileUri)) {
342
356
invalidatedImportUris.add (uri);
343
357
}
344
358
if (! recursive) return ;
0 commit comments