@@ -63,22 +63,27 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
6363 entryPoint ?? = context.options.inputs.single;
6464 return context.runInContext <Future <Component >>((CompilerContext c) async {
6565 IncrementalCompilerData data = new IncrementalCompilerData ();
66- if (dillLoadedData == null ) {
67- UriTranslator uriTranslator = await c.options.getUriTranslator ();
68- ticker.logMs ("Read packages file" );
6966
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 ) {
7074 List <int > summaryBytes = await c.options.loadSdkSummaryBytes ();
7175 int bytesLength = prepareSummary (summaryBytes, uriTranslator, c, data);
7276 if (initializeFromDillUri != null ) {
7377 try {
74- bytesLength += await initializeFromDill (summaryBytes, c, data);
78+ bytesLength +=
79+ await initializeFromDill (summaryBytes, uriTranslator, c, data);
7580 } catch (e) {
7681 // We might have loaded x out of y libraries into the component.
7782 // To avoid any unforeseen problems start over.
7883 bytesLength = prepareSummary (summaryBytes, uriTranslator, c, data);
7984 }
8085 }
81- appendLibraries (data, bytesLength, uriTranslator );
86+ appendLibraries (data, bytesLength);
8287
8388 try {
8489 await dillLoadedData.buildOutlines ();
@@ -89,7 +94,7 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
8994 initializedFromDill = false ;
9095 data.reset ();
9196 bytesLength = prepareSummary (summaryBytes, uriTranslator, c, data);
92- appendLibraries (data, bytesLength, uriTranslator );
97+ appendLibraries (data, bytesLength);
9398 await dillLoadedData.buildOutlines ();
9499 }
95100 summaryBytes = null ;
@@ -112,7 +117,7 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
112117 }
113118
114119 List <LibraryBuilder > reusedLibraries =
115- computeReusedLibraries (invalidatedUris);
120+ computeReusedLibraries (invalidatedUris, uriTranslator );
116121 Set <Uri > reusedLibraryUris =
117122 new Set <Uri >.from (reusedLibraries.map ((b) => b.uri));
118123 for (Uri uri in new Set <Uri >.from (dillLoadedData.loader.builders.keys)
@@ -128,7 +133,7 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
128133
129134 KernelIncrementalTarget userCodeOld = userCode;
130135 userCode = new KernelIncrementalTarget (
131- c.fileSystem, false , dillLoadedData, dillLoadedData. uriTranslator,
136+ c.fileSystem, false , dillLoadedData, uriTranslator,
132137 uriToSource: c.uriToSource);
133138
134139 for (LibraryBuilder library in reusedLibraries) {
@@ -258,7 +263,10 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
258263 }
259264
260265 // 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,
262270 IncrementalCompilerData data) async {
263271 int bytesLength = 0 ;
264272 FileSystemEntity entity =
@@ -277,6 +285,20 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
277285 new BinaryBuilder (initializationBytes, disableLazyReading: true )
278286 .readComponent (data.component);
279287
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+
280302 initializedFromDill = true ;
281303 bytesLength += initializationBytes.length;
282304 for (Library lib in data.component.libraries) {
@@ -294,27 +316,16 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
294316 return bytesLength;
295317 }
296318
297- void appendLibraries (IncrementalCompilerData data, int bytesLength,
298- UriTranslator uriTranslator) {
319+ void appendLibraries (IncrementalCompilerData data, int bytesLength) {
299320 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-
311321 dillLoadedData.loader
312322 .appendLibraries (data.component, byteCount: bytesLength);
313323 }
314324 ticker.logMs ("Appended libraries" );
315325 }
316326
317- List <LibraryBuilder > computeReusedLibraries (Iterable <Uri > invalidatedUris) {
327+ List <LibraryBuilder > computeReusedLibraries (
328+ Iterable <Uri > invalidatedUris, UriTranslator uriTranslator) {
318329 if (userCode == null && userBuilders == null ) {
319330 return < LibraryBuilder > [];
320331 }
@@ -338,7 +349,10 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
338349 invalidatedFileUris.contains (library.fileUri)) ||
339350 (library is DillLibraryBuilder &&
340351 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)) {
342356 invalidatedImportUris.add (uri);
343357 }
344358 if (! recursive) return ;
0 commit comments