diff --git a/packages/flutter_tools/lib/src/application_package.dart b/packages/flutter_tools/lib/src/application_package.dart index 72a87fe8be..37a8076975 100644 --- a/packages/flutter_tools/lib/src/application_package.dart +++ b/packages/flutter_tools/lib/src/application_package.dart @@ -347,9 +347,6 @@ abstract class IOSApp extends ApplicationPackage { } else { // Try to unpack as an ipa. final Directory tempDir = globals.fs.systemTempDirectory.createTempSync('flutter_app.'); - shutdownHooks.addShutdownHook(() async { - await tempDir.delete(recursive: true); - }, ShutdownStage.STILL_RECORDING); globals.os.unzip(globals.fs.file(applicationBinary), tempDir); final Directory payloadDir = globals.fs.directory( globals.fs.path.join(tempDir.path, 'Payload'), diff --git a/packages/flutter_tools/lib/src/base/file_system.dart b/packages/flutter_tools/lib/src/base/file_system.dart index e1cad226e5..704c0c9ac1 100644 --- a/packages/flutter_tools/lib/src/base/file_system.dart +++ b/packages/flutter_tools/lib/src/base/file_system.dart @@ -235,7 +235,6 @@ class LocalFileSystem extends local_fs.LocalFileSystem { // exits normally. shutdownHooks?.addShutdownHook( _tryToDeleteTemp, - ShutdownStage.CLEANUP, ); } return _systemTemp; diff --git a/packages/flutter_tools/lib/src/base/process.dart b/packages/flutter_tools/lib/src/base/process.dart index 33b5bbf462..5215646f46 100644 --- a/packages/flutter_tools/lib/src/base/process.dart +++ b/packages/flutter_tools/lib/src/base/process.dart @@ -26,35 +26,6 @@ typedef ShutdownHook = FutureOr Function(); // See [here](https://github.com/flutter/flutter/pull/14535#discussion_r167041161) // for more details. -/// The stage in which a [ShutdownHook] will be run. All shutdown hooks within -/// a given stage will be started in parallel and will be guaranteed to run to -/// completion before shutdown hooks in the next stage are started. -class ShutdownStage implements Comparable { - const ShutdownStage._(this.priority); - - /// The stage priority. Smaller values will be run before larger values. - final int priority; - - /// The stage before the invocation recording (if one exists) is serialized - /// to disk. Tasks performed during this stage *will* be recorded. - static const ShutdownStage STILL_RECORDING = ShutdownStage._(1); - - /// The stage during which the invocation recording (if one exists) will be - /// serialized to disk. Invocations performed after this stage will not be - /// recorded. - static const ShutdownStage SERIALIZE_RECORDING = ShutdownStage._(2); - - /// The stage during which a serialized recording will be refined (e.g. - /// cleansed for tests, zipped up for bug reporting purposes, etc.). - static const ShutdownStage POST_PROCESS_RECORDING = ShutdownStage._(3); - - /// The stage during which temporary files and directories will be deleted. - static const ShutdownStage CLEANUP = ShutdownStage._(4); - - @override - int compareTo(ShutdownStage other) => priority.compareTo(other.priority); -} - ShutdownHooks get shutdownHooks => ShutdownHooks.instance; abstract class ShutdownHooks { @@ -67,14 +38,9 @@ abstract class ShutdownHooks { static ShutdownHooks get instance => context.get(); /// Registers a [ShutdownHook] to be executed before the VM exits. - /// - /// If [stage] is specified, the shutdown hook will be run during the specified - /// stage. By default, the shutdown hook will be run during the - /// [ShutdownStage.CLEANUP] stage. void addShutdownHook( - ShutdownHook shutdownHook, [ - ShutdownStage stage = ShutdownStage.CLEANUP, - ]); + ShutdownHook shutdownHook + ); /// Runs all registered shutdown hooks and returns a future that completes when /// all such hooks have finished. @@ -92,18 +58,16 @@ class _DefaultShutdownHooks implements ShutdownHooks { }) : _logger = logger; final Logger _logger; - - final Map> _shutdownHooks = >{}; + final List _shutdownHooks = []; bool _shutdownHooksRunning = false; @override void addShutdownHook( - ShutdownHook shutdownHook, [ - ShutdownStage stage = ShutdownStage.CLEANUP, - ]) { + ShutdownHook shutdownHook + ) { assert(!_shutdownHooksRunning); - _shutdownHooks.putIfAbsent(stage, () => []).add(shutdownHook); + _shutdownHooks.add(shutdownHook); } @override @@ -111,22 +75,17 @@ class _DefaultShutdownHooks implements ShutdownHooks { _logger.printTrace('Running shutdown hooks'); _shutdownHooksRunning = true; try { - for (final ShutdownStage stage in _shutdownHooks.keys.toList()..sort()) { - _logger.printTrace('Shutdown hook priority ${stage.priority}'); - final List hooks = _shutdownHooks.remove(stage); - final List> futures = >[]; - for (final ShutdownHook shutdownHook in hooks) { - final FutureOr result = shutdownHook(); - if (result is Future) { - futures.add(result); - } + final List> futures = >[]; + for (final ShutdownHook shutdownHook in _shutdownHooks) { + final FutureOr result = shutdownHook(); + if (result is Future) { + futures.add(result); } - await Future.wait(futures); } + await Future.wait(futures); } finally { _shutdownHooksRunning = false; } - assert(_shutdownHooks.isEmpty); _logger.printTrace('Shutdown hooks complete'); } } diff --git a/packages/flutter_tools/test/general.shard/base/process_test.dart b/packages/flutter_tools/test/general.shard/base/process_test.dart index ba2f39d8a3..03c97ea104 100644 --- a/packages/flutter_tools/test/general.shard/base/process_test.dart +++ b/packages/flutter_tools/test/general.shard/base/process_test.dart @@ -48,35 +48,17 @@ void main() { group('shutdownHooks', () { testWithoutContext('runInExpectedOrder', () async { int i = 1; - int serializeRecording1; - int serializeRecording2; - int postProcessRecording; int cleanup; final ShutdownHooks shutdownHooks = ShutdownHooks(logger: BufferLogger.test()); - shutdownHooks.addShutdownHook(() async { - serializeRecording1 = i++; - }, ShutdownStage.SERIALIZE_RECORDING); - shutdownHooks.addShutdownHook(() async { cleanup = i++; - }, ShutdownStage.CLEANUP); - - shutdownHooks.addShutdownHook(() async { - postProcessRecording = i++; - }, ShutdownStage.POST_PROCESS_RECORDING); - - shutdownHooks.addShutdownHook(() async { - serializeRecording2 = i++; - }, ShutdownStage.SERIALIZE_RECORDING); + }); await shutdownHooks.runShutdownHooks(); - expect(serializeRecording1, lessThanOrEqualTo(2)); - expect(serializeRecording2, lessThanOrEqualTo(2)); - expect(postProcessRecording, 3); - expect(cleanup, 4); + expect(cleanup, 1); }); });