Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions packages/flutter_tools/lib/src/flutter_cache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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, {
Expand Down
25 changes: 25 additions & 0 deletions packages/flutter_tools/test/general.shard/cache_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down