Remove the old canvaskit artifacts to not confuse the web runner. (#124641)

Remove the old canvaskit artifacts to not confuse the web runner.
This commit is contained in:
Jackson Gardner 2023-04-12 09:57:41 -07:00 committed by GitHub
parent e68086e910
commit ac9b501dc2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 58 additions and 0 deletions

View file

@ -38,6 +38,7 @@ class FlutterCache extends Cache {
registerArtifact(AndroidInternalBuildArtifacts(this));
registerArtifact(IOSEngineArtifacts(this, platform: platform));
registerArtifact(FlutterWebSdk(this));
registerArtifact(LegacyCanvasKitRemover(this));
registerArtifact(FlutterSdk(this, platform: platform));
registerArtifact(WindowsEngineArtifacts(this, platform: platform));
registerArtifact(MacOSEngineArtifacts(this, platform: platform));
@ -184,6 +185,38 @@ class FlutterWebSdk extends CachedArtifact {
}
}
// In previous builds, CanvasKit artifacts were stored in a different location
// than they are now. Leaving those old artifacts in the cache confuses the
// in-memory filesystem that the web runner uses, so this artifact will evict
// them from our cache if they are there.
class LegacyCanvasKitRemover extends ArtifactSet {
LegacyCanvasKitRemover(this.cache) : super(DevelopmentArtifact.web);
final Cache cache;
@override
String get name => 'legacy_canvaskit_remover';
Directory _getLegacyCanvasKitDirectory(FileSystem fileSystem) =>
fileSystem.directory(fileSystem.path.join(
cache.getRoot().path,
'canvaskit',
));
@override
Future<bool> isUpToDate(FileSystem fileSystem) async =>
!(await _getLegacyCanvasKitDirectory(fileSystem).exists());
@override
Future<void> update(
ArtifactUpdater artifactUpdater,
Logger logger,
FileSystem fileSystem,
OperatingSystemUtils operatingSystemUtils,
{bool offline = false}
) => _getLegacyCanvasKitDirectory(fileSystem).delete(recursive: true);
}
/// A cached artifact containing the dart:ui source code.
class FlutterSdk extends EngineCachedArtifact {
FlutterSdk(Cache cache, {

View file

@ -880,6 +880,31 @@ void main() {
));
});
testWithoutContext('LegacyCanvasKitRemover removes old canvaskit artifacts if they exist', () async {
final FileExceptionHandler handler = FileExceptionHandler();
final MemoryFileSystem fileSystem = MemoryFileSystem.test(opHandle: handler.opHandle);
final Cache cache = Cache.test(processManager: FakeProcessManager.any(), fileSystem: fileSystem);
final File canvasKitWasm = fileSystem.file(fileSystem.path.join(
cache.getRoot().path,
'canvaskit',
'canvaskit.wasm',
));
canvasKitWasm.createSync(recursive: true);
canvasKitWasm.writeAsStringSync('hello world');
final LegacyCanvasKitRemover remover = LegacyCanvasKitRemover(cache);
expect(await remover.isUpToDate(fileSystem), false);
await remover.update(
FakeArtifactUpdater(),
BufferLogger.test(),
fileSystem,
FakeOperatingSystemUtils(),
);
expect(await remover.isUpToDate(fileSystem), true);
expect(canvasKitWasm.existsSync(), isFalse);
});
testWithoutContext('Cache handles exception thrown if stamp file cannot be parsed', () {
final FileExceptionHandler exceptionHandler = FileExceptionHandler();
final FileSystem fileSystem = MemoryFileSystem.test(opHandle: exceptionHandler.opHandle);