From 6c9259ae7c68696ca16e2c48a780a00f6cd7b671 Mon Sep 17 00:00:00 2001 From: Jenn Magder Date: Fri, 15 Oct 2021 09:41:03 -0700 Subject: [PATCH] Revert "Migrate desktop_device to null safety (#91705)" (#91911) This reverts commit 59a6ba7cf81093267b5e8ac1a9b35e3fae836db1. --- .../flutter_tools/lib/src/bundle_builder.dart | 38 ++++++------ .../flutter_tools/lib/src/desktop_device.dart | 59 ++++++++++--------- .../flutter_tools/lib/src/preview_device.dart | 57 +++++++++--------- .../general.shard/desktop_device_test.dart | 39 ++++++------ 4 files changed, 102 insertions(+), 91 deletions(-) diff --git a/packages/flutter_tools/lib/src/bundle_builder.dart b/packages/flutter_tools/lib/src/bundle_builder.dart index f437a50eb6e..86a7fa83a8e 100644 --- a/packages/flutter_tools/lib/src/bundle_builder.dart +++ b/packages/flutter_tools/lib/src/bundle_builder.dart @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// @dart = 2.8 + import 'package:meta/meta.dart'; import 'package:pool/pool.dart'; @@ -27,15 +29,15 @@ class BundleBuilder { /// The default `mainPath` is `lib/main.dart`. /// The default `manifestPath` is `pubspec.yaml` Future build({ - required TargetPlatform platform, - required BuildInfo buildInfo, - FlutterProject? project, - String? mainPath, + @required TargetPlatform platform, + @required BuildInfo buildInfo, + FlutterProject project, + String mainPath, String manifestPath = defaultManifestPath, - String? applicationKernelFilePath, - String? depfilePath, - String? assetDirPath, - @visibleForTesting BuildSystem? buildSystem, + String applicationKernelFilePath, + String depfilePath, + String assetDirPath, + @visibleForTesting BuildSystem buildSystem }) async { project ??= FlutterProject.current(); mainPath ??= defaultMainPath; @@ -50,7 +52,7 @@ class BundleBuilder { buildDir: project.dartTool.childDirectory('flutter_build'), cacheDir: globals.cache.getRoot(), flutterRootDir: globals.fs.directory(Cache.flutterRoot), - engineVersion: globals.artifacts!.isLocalEngine + engineVersion: globals.artifacts.isLocalEngine ? null : globals.flutterVersion.engineRevision, defines: { @@ -60,7 +62,7 @@ class BundleBuilder { kDeferredComponents: 'false', ...buildInfo.toBuildSystemEnvironment(), }, - artifacts: globals.artifacts!, + artifacts: globals.artifacts, fileSystem: globals.fs, logger: globals.logger, processManager: globals.processManager, @@ -70,7 +72,7 @@ class BundleBuilder { final Target target = buildInfo.mode == BuildMode.debug ? const CopyFlutterBundle() : const ReleaseCopyFlutterBundle(); - final BuildResult result = await buildSystem!.build(target, environment); + final BuildResult result = await buildSystem.build(target, environment); if (!result.success) { for (final ExceptionMeasurement measurement in result.exceptions.values) { @@ -106,14 +108,14 @@ class BundleBuilder { } } -Future buildAssets({ - required String manifestPath, - String? assetDirPath, - String? packagesPath, - TargetPlatform? targetPlatform, +Future buildAssets({ + String manifestPath, + String assetDirPath, + @required String packagesPath, + TargetPlatform targetPlatform, }) async { assetDirPath ??= getAssetBuildDirectory(); - packagesPath ??= globals.fs.path.absolute('.packages'); + packagesPath ??= globals.fs.path.absolute(packagesPath); // Build the asset bundle. final AssetBundle assetBundle = AssetBundleFactory.instance.createBundle(); @@ -133,7 +135,7 @@ Future buildAssets({ Future writeBundle( Directory bundleDir, Map assetEntries, - { Logger? loggerOverride } + { Logger loggerOverride } ) async { loggerOverride ??= globals.logger; if (bundleDir.existsSync()) { diff --git a/packages/flutter_tools/lib/src/desktop_device.dart b/packages/flutter_tools/lib/src/desktop_device.dart index 2e4eabe852a..a506c204a01 100644 --- a/packages/flutter_tools/lib/src/desktop_device.dart +++ b/packages/flutter_tools/lib/src/desktop_device.dart @@ -2,8 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// @dart = 2.8 + import 'dart:async'; +import 'package:meta/meta.dart'; import 'package:process/process.dart'; import 'application_package.dart'; @@ -23,12 +26,12 @@ import 'protocol_discovery.dart'; /// from, containing implementations that are common to all desktop devices. abstract class DesktopDevice extends Device { DesktopDevice(String identifier, { - required PlatformType platformType, - required bool ephemeral, - required Logger logger, - required ProcessManager processManager, - required FileSystem fileSystem, - required OperatingSystemUtils operatingSystemUtils, + @required PlatformType platformType, + @required bool ephemeral, + @required Logger logger, + @required ProcessManager processManager, + @required FileSystem fileSystem, + @required OperatingSystemUtils operatingSystemUtils, }) : _logger = logger, _processManager = processManager, _fileSystem = fileSystem, @@ -57,7 +60,7 @@ abstract class DesktopDevice extends Device { @override Future isAppInstalled( ApplicationPackage app, { - String? userIdentifier, + String userIdentifier, }) async => true; // Since the host and target devices are the same, no work needs to be done @@ -70,7 +73,7 @@ abstract class DesktopDevice extends Device { @override Future installApp( ApplicationPackage app, { - String? userIdentifier, + String userIdentifier, }) async => true; // Since the host and target devices are the same, no work needs to be done @@ -78,14 +81,14 @@ abstract class DesktopDevice extends Device { @override Future uninstallApp( ApplicationPackage app, { - String? userIdentifier, + String userIdentifier, }) async => true; @override Future get isLocalEmulator async => false; @override - Future get emulatorId async => null; + Future get emulatorId async => null; @override DevicePortForwarder get portForwarder => const NoOpDevicePortForwarder(); @@ -98,7 +101,7 @@ abstract class DesktopDevice extends Device { @override DeviceLogReader getLogReader({ - ApplicationPackage? app, + ApplicationPackage app, bool includePastLogs = false, }) { assert(!includePastLogs, 'Past log reading not supported on desktop.'); @@ -111,13 +114,13 @@ abstract class DesktopDevice extends Device { @override Future startApp( ApplicationPackage package, { - String? mainPath, - String? route, - required DebuggingOptions debuggingOptions, + String mainPath, + String route, + @required DebuggingOptions debuggingOptions, Map platformArgs = const {}, bool prebuiltApplication = false, bool ipv6 = false, - String? userIdentifier, + String userIdentifier, }) async { if (!prebuiltApplication) { await buildForDevice( @@ -128,9 +131,9 @@ abstract class DesktopDevice extends Device { } // Ensure that the executable is locatable. - final BuildMode buildMode = debuggingOptions.buildInfo.mode; - final bool traceStartup = platformArgs['trace-startup'] as bool? ?? false; - final String? executable = executablePathForDevice(package, buildMode); + final BuildMode buildMode = debuggingOptions?.buildInfo?.mode; + final bool traceStartup = platformArgs['trace-startup'] as bool ?? false; + final String executable = executablePathForDevice(package, buildMode); if (executable == null) { _logger.printError('Unable to find executable to run'); return LaunchResult.failed(); @@ -139,7 +142,7 @@ abstract class DesktopDevice extends Device { Process process; final List command = [ executable, - ...debuggingOptions.dartEntrypointArgs, + ...?debuggingOptions?.dartEntrypointArgs, ]; try { process = await _processManager.start( @@ -154,17 +157,17 @@ abstract class DesktopDevice extends Device { unawaited(process.exitCode.then((_) => _runningProcesses.remove(process))); _deviceLogReader.initializeProcess(process); - if (debuggingOptions.buildInfo.isRelease == true) { + if (debuggingOptions?.buildInfo?.isRelease == true) { return LaunchResult.succeeded(); } final ProtocolDiscovery observatoryDiscovery = ProtocolDiscovery.observatory(_deviceLogReader, - devicePort: debuggingOptions.deviceVmServicePort, - hostPort: debuggingOptions.hostVmServicePort, + devicePort: debuggingOptions?.deviceVmServicePort, + hostPort: debuggingOptions?.hostVmServicePort, ipv6: ipv6, logger: _logger, ); try { - final Uri? observatoryUri = await observatoryDiscovery.uri; + final Uri observatoryUri = await observatoryDiscovery.uri; if (observatoryUri != null) { onAttached(package, buildMode, process); return LaunchResult.succeeded(observatoryUri: observatoryUri); @@ -184,7 +187,7 @@ abstract class DesktopDevice extends Device { @override Future stopApp( ApplicationPackage app, { - String? userIdentifier, + String userIdentifier, }) async { bool succeeded = true; // Walk a copy of _runningProcesses, since the exit handler removes from the @@ -197,19 +200,19 @@ abstract class DesktopDevice extends Device { @override Future dispose() async { - await portForwarder.dispose(); + await portForwarder?.dispose(); } /// Builds the current project for this device, with the given options. Future buildForDevice( ApplicationPackage package, { - String? mainPath, + String mainPath, BuildInfo buildInfo, }); /// Returns the path to the executable to run for [package] on this device for /// the given [buildMode]. - String? executablePathForDevice(ApplicationPackage package, BuildMode buildMode); + String executablePathForDevice(ApplicationPackage package, BuildMode buildMode); /// Called after a process is attached, allowing any device-specific extra /// steps to be run. @@ -222,7 +225,7 @@ abstract class DesktopDevice extends Device { /// The format of the environment variables is: /// * FLUTTER_ENGINE_SWITCHES to the number of switches. /// * FLUTTER_ENGINE_SWITCH_ (indexing from 1) to the individual switches. - Map _computeEnvironment(DebuggingOptions debuggingOptions, bool traceStartup, String? route) { + Map _computeEnvironment(DebuggingOptions debuggingOptions, bool traceStartup, String route) { int flags = 0; final Map environment = {}; diff --git a/packages/flutter_tools/lib/src/preview_device.dart b/packages/flutter_tools/lib/src/preview_device.dart index ff11752bd7c..42edf5e3539 100644 --- a/packages/flutter_tools/lib/src/preview_device.dart +++ b/packages/flutter_tools/lib/src/preview_device.dart @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// @dart = 2.8 + import 'dart:async'; import 'package:meta/meta.dart'; @@ -35,10 +37,10 @@ BundleBuilder _defaultBundleBuilder() { /// device is not currently discoverable. class PreviewDevice extends Device { PreviewDevice({ - required Platform platform, - required ProcessManager processManager, - required Logger logger, - required FileSystem fileSystem, + @required Platform platform, + @required ProcessManager processManager, + @required Logger logger, + @required FileSystem fileSystem, @visibleForTesting BundleBuilderFactory builderFactory = _defaultBundleBuilder, }) : _platform = platform, _processManager = processManager, @@ -60,18 +62,18 @@ class PreviewDevice extends Device { Future dispose() async { } @override - Future get emulatorId async => null; + Future get emulatorId async => null; final DesktopLogReader _logReader = DesktopLogReader(); @override - FutureOr getLogReader({covariant ApplicationPackage? app, bool includePastLogs = false}) => _logReader; + FutureOr getLogReader({covariant ApplicationPackage app, bool includePastLogs = false}) => _logReader; @override - Future installApp(covariant ApplicationPackage? app, {String? userIdentifier}) async => true; + Future installApp(covariant ApplicationPackage app, {String userIdentifier}) async => true; @override - Future isAppInstalled(covariant ApplicationPackage app, {String? userIdentifier}) async => false; + Future isAppInstalled(covariant ApplicationPackage app, {String userIdentifier}) async => false; @override Future isLatestBuildInstalled(covariant ApplicationPackage app) async => false; @@ -94,23 +96,24 @@ class PreviewDevice extends Device { @override Future get sdkNameAndVersion async => 'preview'; - Process? _process; + Process _process; + Directory _assetDirectory; @override Future startApp(covariant ApplicationPackage package, { - String? mainPath, - String? route, - required DebuggingOptions debuggingOptions, - Map platformArgs = const {}, + String mainPath, + String route, + @required DebuggingOptions debuggingOptions, + Map platformArgs, bool prebuiltApplication = false, bool ipv6 = false, - String? userIdentifier, + String userIdentifier, }) async { - final Directory assetDirectory = _fileSystem.systemTempDirectory + _assetDirectory = _fileSystem.systemTempDirectory .createTempSync('flutter_preview.'); // Build assets and perform initial compilation. - Status? status; + Status status; try { status = _logger.startProgress('Compiling application for preview...'); await _bundleBuilderFactory().build( @@ -121,32 +124,32 @@ class PreviewDevice extends Device { ); copyDirectory(_fileSystem.directory( getAssetBuildDirectory()), - assetDirectory.childDirectory('data').childDirectory('flutter_assets'), + _assetDirectory.childDirectory('data').childDirectory('flutter_assets'), ); } finally { - status?.stop(); + status.stop(); } // Merge with precompiled executable. - final Directory precompiledDirectory = _fileSystem.directory(_fileSystem.path.join(Cache.flutterRoot!, 'artifacts_temp', 'Debug')); - copyDirectory(precompiledDirectory, assetDirectory); + final Directory precompiledDirectory = _fileSystem.directory(_fileSystem.path.join(Cache.flutterRoot, 'artifacts_temp', 'Debug')); + copyDirectory(precompiledDirectory, _assetDirectory); final Process process = await _processManager.start( [ - assetDirectory.childFile('splash').path, + _assetDirectory.childFile('splash').path, ], ); _process = process; _logReader.initializeProcess(process); final ProtocolDiscovery observatoryDiscovery = ProtocolDiscovery.observatory(_logReader, - devicePort: debuggingOptions.deviceVmServicePort, - hostPort: debuggingOptions.hostVmServicePort, + devicePort: debuggingOptions?.deviceVmServicePort, + hostPort: debuggingOptions?.hostVmServicePort, ipv6: ipv6, logger: _logger, ); try { - final Uri? observatoryUri = await observatoryDiscovery.uri; + final Uri observatoryUri = await observatoryDiscovery.uri; if (observatoryUri != null) { return LaunchResult.succeeded(observatoryUri: observatoryUri); } @@ -163,8 +166,8 @@ class PreviewDevice extends Device { } @override - Future stopApp(covariant ApplicationPackage app, {String? userIdentifier}) async { - return _process?.kill() == true; + Future stopApp(covariant ApplicationPackage app, {String userIdentifier}) async { + return _process?.kill(); } @override @@ -176,7 +179,7 @@ class PreviewDevice extends Device { } @override - Future uninstallApp(covariant ApplicationPackage app, {String? userIdentifier}) async { + Future uninstallApp(covariant ApplicationPackage app, {String userIdentifier}) async { return true; } diff --git a/packages/flutter_tools/test/general.shard/desktop_device_test.dart b/packages/flutter_tools/test/general.shard/desktop_device_test.dart index c99bd6166b9..451fb5dc922 100644 --- a/packages/flutter_tools/test/general.shard/desktop_device_test.dart +++ b/packages/flutter_tools/test/general.shard/desktop_device_test.dart @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// @dart = 2.8 + import 'dart:async'; import 'package:file/memory.dart'; @@ -16,6 +18,7 @@ import 'package:flutter_tools/src/device.dart'; import 'package:flutter_tools/src/device_port_forwarder.dart'; import 'package:flutter_tools/src/project.dart'; +import 'package:meta/meta.dart'; import 'package:test/fake.dart'; import '../src/common.dart'; @@ -47,8 +50,8 @@ void main() { testWithoutContext('Install checks always return true', () async { final FakeDesktopDevice device = setUpDesktopDevice(); - expect(await device.isAppInstalled(FakeApplicationPackage()), true); - expect(await device.isLatestBuildInstalled(FakeApplicationPackage()), true); + expect(await device.isAppInstalled(null), true); + expect(await device.isLatestBuildInstalled(null), true); expect(device.category, Category.desktop); }); @@ -86,7 +89,7 @@ void main() { ), ]); final FakeDesktopDevice device = setUpDesktopDevice(processManager: processManager, fileSystem: fileSystem); - final String? executableName = device.executablePathForDevice(FakeApplicationPackage(), BuildMode.debug); + final String executableName = device.executablePathForDevice(null, BuildMode.debug); fileSystem.file(executableName).writeAsStringSync('\n'); final FakeApplicationPackage package = FakeApplicationPackage(); final LaunchResult result = await device.startApp( @@ -245,7 +248,7 @@ void main() { testWithoutContext('createDevFSWriter returns a LocalDevFSWriter', () { final FakeDesktopDevice device = setUpDesktopDevice(); - expect(device.createDevFSWriter(FakeApplicationPackage(), ''), isA()); + expect(device.createDevFSWriter(null, ''), isA()); }); testWithoutContext('startApp supports dartEntrypointArgs', () async { @@ -305,10 +308,10 @@ void main() { } FakeDesktopDevice setUpDesktopDevice({ - FileSystem? fileSystem, - Logger? logger, - ProcessManager? processManager, - OperatingSystemUtils? operatingSystemUtils, + FileSystem fileSystem, + Logger logger, + ProcessManager processManager, + OperatingSystemUtils operatingSystemUtils, bool nullExecutablePathForDevice = false, }) { return FakeDesktopDevice( @@ -323,11 +326,11 @@ FakeDesktopDevice setUpDesktopDevice({ /// A trivial subclass of DesktopDevice for testing the shared functionality. class FakeDesktopDevice extends DesktopDevice { FakeDesktopDevice({ - required ProcessManager processManager, - required Logger logger, - required FileSystem fileSystem, - required OperatingSystemUtils operatingSystemUtils, - this.nullExecutablePathForDevice = false, + @required ProcessManager processManager, + @required Logger logger, + @required FileSystem fileSystem, + @required OperatingSystemUtils operatingSystemUtils, + this.nullExecutablePathForDevice, }) : super( 'dummy', platformType: PlatformType.linux, @@ -339,10 +342,10 @@ class FakeDesktopDevice extends DesktopDevice { ); /// The [mainPath] last passed to [buildForDevice]. - String? lastBuiltMainPath; + String lastBuiltMainPath; /// The [buildInfo] last passed to [buildForDevice]. - BuildInfo? lastBuildInfo; + BuildInfo lastBuildInfo; final bool nullExecutablePathForDevice; @@ -361,8 +364,8 @@ class FakeDesktopDevice extends DesktopDevice { @override Future buildForDevice( ApplicationPackage package, { - String? mainPath, - BuildInfo? buildInfo, + String mainPath, + BuildInfo buildInfo, }) async { lastBuiltMainPath = mainPath; lastBuildInfo = buildInfo; @@ -370,7 +373,7 @@ class FakeDesktopDevice extends DesktopDevice { // Dummy implementation that just returns the build mode name. @override - String? executablePathForDevice(ApplicationPackage package, BuildMode buildMode) { + String executablePathForDevice(ApplicationPackage package, BuildMode buildMode) { if (nullExecutablePathForDevice) { return null; }