From f688b0d56b1182aec31de91879c2ffb8f0d8d07f Mon Sep 17 00:00:00 2001 From: Ian Hickson Date: Sat, 18 Aug 2018 16:45:41 -0700 Subject: [PATCH] Delete all temporary files in flutter test. (#20679) Turns out we weren't deleting the dill directory or the fonts directory. --- .../lib/src/test/flutter_platform.dart | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/packages/flutter_tools/lib/src/test/flutter_platform.dart b/packages/flutter_tools/lib/src/test/flutter_platform.dart index f5b56bb75f..6da0a83919 100644 --- a/packages/flutter_tools/lib/src/test/flutter_platform.dart +++ b/packages/flutter_tools/lib/src/test/flutter_platform.dart @@ -206,6 +206,8 @@ class _Compiler { .createTempSync('flutter_test_compiler.'); final File outputDill = outputDillDirectory.childFile('output.dill'); + printTrace('Compiler will use the following file as its incremental dill file: ${outputDill.path}'); + bool suppressOutput = false; void reportCompilerMessage(String message) { if (suppressOutput) @@ -230,6 +232,7 @@ class _Compiler { ); } + printTrace('Listening to compiler controller...'); compilerController.stream.listen((_CompilationRequest request) async { final bool isEmpty = compilationQueue.isEmpty; compilationQueue.add(request); @@ -240,6 +243,7 @@ class _Compiler { while (compilationQueue.isNotEmpty) { final _CompilationRequest request = compilationQueue.first; printTrace('Compiling ${request.path}'); + final Stopwatch compilerTime = new Stopwatch()..start(); compiler ??= createCompiler(); suppressOutput = false; final CompilerOutput compilerOutput = await handleTimeout( @@ -256,7 +260,7 @@ class _Compiler { // a weird state. if (outputPath == null || compilerOutput.errorCount > 0) { request.result.complete(null); - await shutdown(); + await _shutdown(); } else { final File kernelReadyToRun = await fs.file(outputPath).copy('${request.path}.dill'); @@ -264,11 +268,13 @@ class _Compiler { compiler.accept(); compiler.reset(); } + printTrace('Compiling ${request.path} took ${compilerTime.elapsedMilliseconds}ms'); // Only remove now when we finished processing the element compilationQueue.removeAt(0); } } }, onDone: () { + printTrace('Deleting ${outputDillDirectory.path}...'); outputDillDirectory.deleteSync(recursive: true); }); } @@ -284,7 +290,7 @@ class _Compiler { return handleTimeout(completer.future, mainDart); } - Future shutdown() async { + Future _shutdown() async { // Check for null in case this instance is shut down before the // lazily-created compiler has been created. if (compiler != null) { @@ -293,6 +299,11 @@ class _Compiler { } } + Future dispose() async { + await _shutdown(); + await compilerController.close(); + } + static Future handleTimeout(Future value, String path) { return value.timeout(const Duration(minutes: 5), onTimeout: () { printError('Compilation of $path timed out after 5 minutes.'); @@ -330,6 +341,7 @@ class _FlutterPlatform extends PlatformPlugin { final bool trackWidgetCreation; final bool updateGoldens; + Directory fontsDirectory; _Compiler compiler; // Each time loadChannel() is called, we spin up a local WebSocket server, @@ -740,9 +752,14 @@ class _FlutterPlatform extends PlatformPlugin { @override Future close() async { if (compiler != null) { - await compiler.shutdown(); + await compiler.dispose(); compiler = null; } + if (fontsDirectory != null) { + printTrace('Deleting ${fontsDirectory.path}...'); + fontsDirectory.deleteSync(recursive: true); + fontsDirectory = null; + } } /// Returns a Fontconfig config file that limits font fallback to the @@ -757,8 +774,12 @@ class _FlutterPlatform extends PlatformPlugin { sb.writeln(' /var/cache/fontconfig'); sb.writeln(''); - final Directory fontsDir = fs.systemTempDirectory.createTempSync('flutter_test_fonts.'); - _cachedFontConfig = fs.file('${fontsDir.path}/fonts.conf'); + if (fontsDirectory == null) { + fontsDirectory = fs.systemTempDirectory.createTempSync('flutter_test_fonts.'); + printTrace('Using this directory for fonts configuration: ${fontsDirectory.path}'); + } + + _cachedFontConfig = fs.file('${fontsDirectory.path}/fonts.conf'); _cachedFontConfig.createSync(); _cachedFontConfig.writeAsStringSync(sb.toString()); return _cachedFontConfig;