Unverified Commit 6cbed01d authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Migrate windows_device to null safety (#92956)

parent 028954ce
......@@ -29,12 +29,13 @@ final RegExp errorMatcher = RegExp(r'(?:(?:.*:\d+:\d+|clang):\s)?(fatal\s)?(?:er
Future<void> buildLinux(
LinuxProject linuxProject,
BuildInfo buildInfo, {
String target = 'lib/main.dart',
String? target,
SizeAnalyzer? sizeAnalyzer,
bool needCrossBuild = false,
TargetPlatform targetPlatform = TargetPlatform.linux_x64,
required TargetPlatform targetPlatform,
String targetSysroot = '/',
}) async {
target ??= 'lib/main.dart';
if (!linuxProject.cmakeFile.existsSync()) {
throwToolExit('No Linux desktop project configured. See '
'https://flutter.dev/desktop#add-desktop-support-to-an-existing-flutter-app '
......
......@@ -2,9 +2,6 @@
// 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:process/process.dart';
import '../base/file_system.dart';
......@@ -23,10 +20,10 @@ import 'linux_workflow.dart';
/// A device that represents a desktop Linux target.
class LinuxDevice extends DesktopDevice {
LinuxDevice({
@required ProcessManager processManager,
@required Logger logger,
@required FileSystem fileSystem,
@required OperatingSystemUtils operatingSystemUtils,
required ProcessManager processManager,
required Logger logger,
required FileSystem fileSystem,
required OperatingSystemUtils operatingSystemUtils,
}) : _operatingSystemUtils = operatingSystemUtils,
super(
'linux',
......@@ -40,8 +37,6 @@ class LinuxDevice extends DesktopDevice {
final OperatingSystemUtils _operatingSystemUtils;
TargetPlatform _targetPlatform;
@override
bool isSupported() => true;
......@@ -49,17 +44,12 @@ class LinuxDevice extends DesktopDevice {
String get name => 'Linux';
@override
Future<TargetPlatform> get targetPlatform async {
if (_targetPlatform == null) {
if (_operatingSystemUtils.hostPlatform == HostPlatform.linux_x64) {
_targetPlatform = TargetPlatform.linux_x64;
} else {
_targetPlatform = TargetPlatform.linux_arm64;
}
late final Future<TargetPlatform> targetPlatform = () async {
if (_operatingSystemUtils.hostPlatform == HostPlatform.linux_x64) {
return TargetPlatform.linux_x64;
}
return _targetPlatform;
}
return TargetPlatform.linux_arm64;
}();
@override
bool isSupportedForProject(FlutterProject flutterProject) {
......@@ -69,14 +59,14 @@ class LinuxDevice extends DesktopDevice {
@override
Future<void> buildForDevice(
covariant LinuxApp package, {
String mainPath,
BuildInfo buildInfo,
String? mainPath,
required BuildInfo buildInfo,
}) async {
await buildLinux(
FlutterProject.current().linux,
buildInfo,
target: mainPath,
targetPlatform: _targetPlatform,
targetPlatform: await targetPlatform,
);
}
......@@ -88,12 +78,12 @@ class LinuxDevice extends DesktopDevice {
class LinuxDevices extends PollingDeviceDiscovery {
LinuxDevices({
@required Platform platform,
@required FeatureFlags featureFlags,
@required OperatingSystemUtils operatingSystemUtils,
@required FileSystem fileSystem,
@required ProcessManager processManager,
@required Logger logger,
required Platform platform,
required FeatureFlags featureFlags,
required OperatingSystemUtils operatingSystemUtils,
required FileSystem fileSystem,
required ProcessManager processManager,
required Logger logger,
}) : _platform = platform,
_linuxWorkflow = LinuxWorkflow(
platform: platform,
......@@ -119,7 +109,7 @@ class LinuxDevices extends PollingDeviceDiscovery {
bool get canListAnything => _linuxWorkflow.canListDevices;
@override
Future<List<Device>> pollingGetDevices({ Duration timeout }) async {
Future<List<Device>> pollingGetDevices({ Duration? timeout }) async {
if (!canListAnything) {
return const <Device>[];
}
......
......@@ -2,11 +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';
import 'package:process/process.dart';
import '../application_package.dart';
......@@ -26,10 +23,10 @@ import '../project.dart';
/// https://developer.apple.com/documentation/apple-silicon/running-your-ios-apps-on-macos
class MacOSDesignedForIPadDevice extends DesktopDevice {
MacOSDesignedForIPadDevice({
@required ProcessManager processManager,
@required Logger logger,
@required FileSystem fileSystem,
@required OperatingSystemUtils operatingSystemUtils,
required ProcessManager processManager,
required Logger logger,
required FileSystem fileSystem,
required OperatingSystemUtils operatingSystemUtils,
}) : _operatingSystemUtils = operatingSystemUtils,
super(
'designed-for-ipad',
......@@ -58,18 +55,18 @@ class MacOSDesignedForIPadDevice extends DesktopDevice {
}
@override
String executablePathForDevice(ApplicationPackage package, BuildMode buildMode) => null;
String? executablePathForDevice(ApplicationPackage package, BuildMode buildMode) => null;
@override
Future<LaunchResult> startApp(
IOSApp package, {
String mainPath,
String route,
@required DebuggingOptions debuggingOptions,
Map<String, dynamic> platformArgs = const <String, dynamic>{},
String? mainPath,
String? route,
required DebuggingOptions debuggingOptions,
Map<String, Object?> platformArgs = const <String, Object>{},
bool prebuiltApplication = false,
bool ipv6 = false,
String userIdentifier,
String? userIdentifier,
}) async {
// Only attaching to a running app launched from Xcode is supported.
throw UnimplementedError('Building for "$name" is not supported.');
......@@ -78,14 +75,14 @@ class MacOSDesignedForIPadDevice extends DesktopDevice {
@override
Future<bool> stopApp(
IOSApp app, {
String userIdentifier,
String? userIdentifier,
}) async => false;
@override
Future<void> buildForDevice(
covariant IOSApp package, {
String mainPath,
BuildInfo buildInfo,
String? mainPath,
required BuildInfo buildInfo,
}) async {
// Only attaching to a running app launched from Xcode is supported.
throw UnimplementedError('Building for "$name" is not supported.');
......@@ -94,12 +91,12 @@ class MacOSDesignedForIPadDevice extends DesktopDevice {
class MacOSDesignedForIPadDevices extends PollingDeviceDiscovery {
MacOSDesignedForIPadDevices({
@required Platform platform,
@required IOSWorkflow iosWorkflow,
@required ProcessManager processManager,
@required Logger logger,
@required FileSystem fileSystem,
@required OperatingSystemUtils operatingSystemUtils,
required Platform platform,
required IOSWorkflow iosWorkflow,
required ProcessManager processManager,
required Logger logger,
required FileSystem fileSystem,
required OperatingSystemUtils operatingSystemUtils,
}) : _logger = logger,
_platform = platform,
_iosWorkflow = iosWorkflow,
......@@ -128,7 +125,7 @@ class MacOSDesignedForIPadDevices extends PollingDeviceDiscovery {
static bool allowDiscovery = false;
@override
Future<List<Device>> pollingGetDevices({Duration timeout}) async {
Future<List<Device>> pollingGetDevices({Duration? timeout}) async {
if (!canListAnything) {
return const <Device>[];
}
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import '../artifacts.dart';
import '../base/analyze_size.dart';
import '../base/common.dart';
......@@ -32,9 +30,9 @@ const int kCurrentUwpTemplateVersion = 0;
/// Builds the Windows project using msbuild.
Future<void> buildWindows(WindowsProject windowsProject, BuildInfo buildInfo, {
String target,
VisualStudio visualStudioOverride,
SizeAnalyzer sizeAnalyzer,
String? target,
VisualStudio? visualStudioOverride,
SizeAnalyzer? sizeAnalyzer,
}) async {
if (!windowsProject.cmakeFile.existsSync()) {
throwToolExit(
......@@ -62,13 +60,13 @@ Future<void> buildWindows(WindowsProject windowsProject, BuildInfo buildInfo, {
logger: globals.logger,
processManager: globals.processManager,
);
final String cmakePath = visualStudio.cmakePath;
final String? cmakePath = visualStudio.cmakePath;
if (cmakePath == null) {
throwToolExit('Unable to find suitable Visual Studio toolchain. '
'Please run `flutter doctor` for more details.');
}
final String buildModeName = getNameForBuildMode(buildInfo.mode ?? BuildMode.release);
final String buildModeName = getNameForBuildMode(buildInfo.mode);
final Directory buildDirectory = globals.fs.directory(getWindowsBuildDirectory());
final Status status = globals.logger.startProgress(
'Building Windows application...',
......@@ -85,7 +83,7 @@ Future<void> buildWindows(WindowsProject windowsProject, BuildInfo buildInfo, {
.childFile('snapshot.$arch.json');
final File precompilerTrace = globals.fs.directory(buildInfo.codeSizeDirectory)
.childFile('trace.$arch.json');
final Map<String, Object> output = await sizeAnalyzer.analyzeAotSnapshot(
final Map<String, Object?> output = await sizeAnalyzer.analyzeAotSnapshot(
aotSnapshot: codeSizeFile,
// This analysis is only supported for release builds.
outputDirectory: globals.fs.directory(
......@@ -118,8 +116,8 @@ Future<void> buildWindows(WindowsProject windowsProject, BuildInfo buildInfo, {
///
/// Note that this feature is currently unfinished.
Future<void> buildWindowsUwp(WindowsUwpProject windowsProject, BuildInfo buildInfo, {
String target,
VisualStudio visualStudioOverride,
String? target,
VisualStudio? visualStudioOverride,
}) async {
final Directory buildDirectory = globals.fs.directory(getWindowsBuildUwpDirectory());
if (!windowsProject.existsSync()) {
......@@ -153,13 +151,13 @@ Future<void> buildWindowsUwp(WindowsUwpProject windowsProject, BuildInfo buildIn
logger: globals.logger,
processManager: globals.processManager,
);
final String cmakePath = visualStudio.cmakePath;
final String? cmakePath = visualStudio.cmakePath;
if (cmakePath == null) {
throwToolExit('Unable to find suitable Visual Studio toolchain. '
'Please run `flutter doctor` for more details.');
}
final String buildModeName = getNameForBuildMode(buildInfo.mode ?? BuildMode.release);
final String buildModeName = getNameForBuildMode(buildInfo.mode);
final Status status = globals.logger.startProgress(
'Building Windows UWP application...',
);
......@@ -180,21 +178,22 @@ const Map<BuildMode, String> _targets = <BuildMode, String>{
BuildMode.release: 'release_bundle_windows_assets_uwp',
};
Future<void> _runFlutterBuild(Directory buildDirectory, BuildInfo buildInfo, String targetFile) async {
Future<void> _runFlutterBuild(Directory buildDirectory, BuildInfo buildInfo, String? targetFile) async {
await buildDirectory.create(recursive: true);
int result;
String flutterEngine;
String localEngine;
if (globals.artifacts is LocalEngineArtifacts) {
final LocalEngineArtifacts localEngineArtifacts = globals.artifacts as LocalEngineArtifacts;
final String engineOutPath = localEngineArtifacts.engineOutPath;
String? flutterEngine;
String? localEngine;
final Artifacts artifacts = globals.artifacts!;
if (artifacts is LocalEngineArtifacts) {
final String engineOutPath = artifacts.engineOutPath;
flutterEngine = globals.fs.path.dirname(globals.fs.path.dirname(engineOutPath));
localEngine = globals.fs.path.basename(engineOutPath);
}
try {
final String? buildMode = _targets[buildInfo.mode];
result = await globals.processUtils.stream(
<String>[
globals.fs.path.join(Cache.flutterRoot, 'bin', 'flutter'),
globals.fs.path.join(Cache.flutterRoot!, 'bin', 'flutter'),
if (globals.logger.isVerbose)
'--verbose',
if (flutterEngine != null) '--local-engine-src-path=$flutterEngine',
......@@ -220,7 +219,8 @@ Future<void> _runFlutterBuild(Directory buildDirectory, BuildInfo buildInfo, Str
'--ExtraGenSnapshotOptions=${buildInfo.extraGenSnapshotOptions}',
if (buildInfo.extraFrontEndOptions != null && buildInfo.extraFrontEndOptions.isNotEmpty)
'--ExtraFrontEndOptions=${buildInfo.extraFrontEndOptions}',
_targets[buildInfo.mode],
if (buildMode != null)
buildMode,
],
trace: true,
);
......@@ -305,21 +305,21 @@ Future<void> _runBuild(
void _writeGeneratedFlutterConfig(
WindowsProject windowsProject,
BuildInfo buildInfo,
String target,
String? target,
) {
final Map<String, String> environment = <String, String>{
'FLUTTER_ROOT': Cache.flutterRoot,
'FLUTTER_ROOT': Cache.flutterRoot!,
'FLUTTER_EPHEMERAL_DIR': windowsProject.ephemeralDirectory.path,
'PROJECT_DIR': windowsProject.parent.directory.path,
if (target != null)
'FLUTTER_TARGET': target,
...buildInfo.toEnvironmentConfig(),
};
if (globals.artifacts is LocalEngineArtifacts) {
final LocalEngineArtifacts localEngineArtifacts = globals.artifacts as LocalEngineArtifacts;
final String engineOutPath = localEngineArtifacts.engineOutPath;
final Artifacts artifacts = globals.artifacts!;
if (artifacts is LocalEngineArtifacts) {
final String engineOutPath = artifacts.engineOutPath;
environment['FLUTTER_ENGINE'] = globals.fs.path.dirname(globals.fs.path.dirname(engineOutPath));
environment['LOCAL_ENGINE'] = globals.fs.path.basename(engineOutPath);
}
writeGeneratedCmakeConfig(Cache.flutterRoot, windowsProject, environment);
writeGeneratedCmakeConfig(Cache.flutterRoot!, windowsProject, environment);
}
......@@ -2,11 +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';
import 'package:process/process.dart';
import '../application_package.dart';
......@@ -28,10 +25,10 @@ import 'windows_workflow.dart';
/// A device that represents a desktop Windows target.
class WindowsDevice extends DesktopDevice {
WindowsDevice({
@required ProcessManager processManager,
@required Logger logger,
@required FileSystem fileSystem,
@required OperatingSystemUtils operatingSystemUtils,
required ProcessManager processManager,
required Logger logger,
required FileSystem fileSystem,
required OperatingSystemUtils operatingSystemUtils,
}) : super(
'windows',
platformType: PlatformType.windows,
......@@ -59,8 +56,8 @@ class WindowsDevice extends DesktopDevice {
@override
Future<void> buildForDevice(
covariant WindowsApp package, {
String mainPath,
BuildInfo buildInfo,
String? mainPath,
required BuildInfo buildInfo,
}) async {
await buildWindows(
FlutterProject.current().windows,
......@@ -78,11 +75,11 @@ class WindowsDevice extends DesktopDevice {
// A device that represents a desktop Windows UWP target.
class WindowsUWPDevice extends Device {
WindowsUWPDevice({
@required ProcessManager processManager,
@required Logger logger,
@required FileSystem fileSystem,
@required OperatingSystemUtils operatingSystemUtils,
@required UwpTool uwptool,
required ProcessManager processManager,
required Logger logger,
required FileSystem fileSystem,
required OperatingSystemUtils operatingSystemUtils,
required UwpTool uwptool,
}) : _logger = logger,
_processManager = processManager,
_operatingSystemUtils = operatingSystemUtils,
......@@ -100,9 +97,9 @@ class WindowsUWPDevice extends Device {
final FileSystem _fileSystem;
final OperatingSystemUtils _operatingSystemUtils;
final UwpTool _uwptool;
BuildMode _buildMode;
BuildMode? _buildMode;
int _processId;
int? _processId;
@override
bool isSupported() => true;
......@@ -125,10 +122,10 @@ class WindowsUWPDevice extends Device {
Future<void> dispose() async { }
@override
Future<String> get emulatorId async => null;
Future<String?> get emulatorId async => null;
@override
FutureOr<DeviceLogReader> getLogReader({covariant BuildableUwpApp app, bool includePastLogs = false}) {
FutureOr<DeviceLogReader> getLogReader({covariant BuildableUwpApp? app, bool includePastLogs = false}) {
return NoOpDeviceLogReader('winuwp');
}
......@@ -162,7 +159,7 @@ class WindowsUWPDevice extends Device {
}
// Walks the build directory for any dependent packages for the specified architecture.
String/*?*/ _getAppPackagePath(String buildDirectory) {
String? _getAppPackagePath(String buildDirectory) {
final List<String> packagePaths = _getPackagePaths(buildDirectory);
return packagePaths.isNotEmpty ? packagePaths.first : null;
}
......@@ -173,7 +170,7 @@ class WindowsUWPDevice extends Device {
return _getPackagePaths(depsDirectory);
}
String _getPackageName(String binaryName, String version, String config, {String/*?*/ architecture}) {
String _getPackageName(String binaryName, String version, String config, {String? architecture}) {
final List<String> components = <String>[
binaryName,
version,
......@@ -184,12 +181,12 @@ class WindowsUWPDevice extends Device {
}
@override
Future<bool> installApp(covariant BuildableUwpApp app, {String userIdentifier}) async {
Future<bool> installApp(covariant BuildableUwpApp app, {String? userIdentifier}) async {
/// The cmake build generates an install powershell script.
/// build\winuwp\runner_uwp\AppPackages\<app-name>\<app-name>_<app-version>_<cmake-config>\Add-AppDevPackage.ps1
final String binaryName = app.name;
final String packageVersion = app.projectVersion;
if (packageVersion == null) {
final String? binaryName = app.name;
final String? packageVersion = app.projectVersion;
if (binaryName == null || packageVersion == null) {
return false;
}
final String binaryDir = _fileSystem.path.absolute(
......@@ -204,9 +201,9 @@ class WindowsUWPDevice extends Device {
// Single-archtitecture package.
_getPackageName(binaryName, packageVersion, config, architecture: 'x64'),
];
String packageName;
String buildDirectory;
String packagePath;
String? packageName;
String? buildDirectory;
String? packagePath;
for (final String name in packageNames) {
packageName = name;
buildDirectory = _fileSystem.path.join(binaryDir, '${packageName}_Test');
......@@ -225,7 +222,7 @@ class WindowsUWPDevice extends Device {
// Verify package signature.
if (!await _uwptool.isSignatureValid(packagePath)) {
// If signature is invalid, install the developer certificate.
final String certificatePath = _fileSystem.path.join(buildDirectory, '$packageName.cer');
final String certificatePath = _fileSystem.path.join(buildDirectory!, '$packageName.cer');
if (_logger.terminal.stdinHasTerminal) {
final String response = await _logger.terminal.promptForCharInput(
<String>['Y', 'y', 'N', 'n'],
......@@ -253,14 +250,14 @@ class WindowsUWPDevice extends Device {
// Install the application and dependencies.
final String packageUri = Uri.file(packagePath).toString();
final List<String> dependencyUris = _getDependencyPaths(buildDirectory, 'x64')
final List<String> dependencyUris = _getDependencyPaths(buildDirectory!, 'x64')
.map((String path) => Uri.file(path).toString())
.toList();
return _uwptool.installApp(packageUri, dependencyUris);
}
@override
Future<bool> isAppInstalled(covariant ApplicationPackage app, {String userIdentifier}) async {
Future<bool> isAppInstalled(covariant ApplicationPackage app, {String? userIdentifier}) async {
final String packageName = app.id;
return await _uwptool.getPackageFamilyName(packageName) != null;
}
......@@ -279,13 +276,13 @@ class WindowsUWPDevice extends Device {
@override
Future<LaunchResult> startApp(covariant BuildableUwpApp package, {
String mainPath,
String route,
DebuggingOptions debuggingOptions,
Map<String, dynamic> platformArgs,
String? mainPath,
String? route,
required DebuggingOptions debuggingOptions,
Map<String, Object?> platformArgs = const <String, Object>{},
bool prebuiltApplication = false,
bool ipv6 = false,
String userIdentifier,
String? userIdentifier,
}) async {
_buildMode = debuggingOptions.buildInfo.mode;
if (!prebuiltApplication) {
......@@ -310,7 +307,11 @@ class WindowsUWPDevice extends Device {
return LaunchResult.failed();
}
final String packageFamily = await _uwptool.getPackageFamilyName(packageName);
final String? packageFamily = await _uwptool.getPackageFamilyName(packageName);
if (packageFamily == null) {
_logger.printError('Could not find package family name from $packageName');
return LaunchResult.failed();
}
if (debuggingOptions.buildInfo.mode.isRelease) {
_processId = await _uwptool.launchApp(packageFamily, <String>[]);
......@@ -361,7 +362,7 @@ class WindowsUWPDevice extends Device {
if (debuggingOptions.verboseSystemLogs) '--verbose-logging',
if (debuggingOptions.cacheSkSL) '--cache-sksl',
if (debuggingOptions.purgePersistentCache) '--purge-persistent-cache',
if (platformArgs['trace-startup'] as bool ?? false) '--trace-startup',
if (platformArgs['trace-startup'] as bool? ?? false) '--trace-startup',
];
_processId = await _uwptool.launchApp(packageFamily, args);
if (_processId == null) {
......@@ -371,21 +372,21 @@ class WindowsUWPDevice extends Device {
}
@override
Future<bool> stopApp(covariant BuildableUwpApp app, {String userIdentifier}) async {
Future<bool> stopApp(covariant BuildableUwpApp app, {String? userIdentifier}) async {
if (_processId != null) {
return _processManager.killPid(_processId);
return _processManager.killPid(_processId!);
}
return false;
}
@override
Future<bool> uninstallApp(covariant BuildableUwpApp app, {String userIdentifier}) async {
Future<bool> uninstallApp(covariant BuildableUwpApp app, {String? userIdentifier}) async {
final String packageName = app.id;
if (packageName == null) {
_logger.printError('Could not find PACKAGE_GUID in ${app.project.runnerCmakeFile.path}');
return false;
}
final String packageFamily = await _uwptool.getPackageFamilyName(packageName);
final String? packageFamily = await _uwptool.getPackageFamilyName(packageName);
if (packageFamily == null) {
// App is not installed.
return true;
......@@ -399,13 +400,13 @@ class WindowsUWPDevice extends Device {
class WindowsDevices extends PollingDeviceDiscovery {
WindowsDevices({
@required ProcessManager processManager,
@required Logger logger,
@required FileSystem fileSystem,
@required OperatingSystemUtils operatingSystemUtils,
@required WindowsWorkflow windowsWorkflow,
@required FeatureFlags featureFlags,
@required UwpTool uwptool,
required ProcessManager processManager,
required Logger logger,
required FileSystem fileSystem,
required OperatingSystemUtils operatingSystemUtils,
required WindowsWorkflow windowsWorkflow,
required FeatureFlags featureFlags,
required UwpTool uwptool,
}) : _fileSystem = fileSystem,
_logger = logger,
_processManager = processManager,
......@@ -430,7 +431,7 @@ class WindowsDevices extends PollingDeviceDiscovery {
bool get canListAnything => _windowsWorkflow.canListDevices;
@override
Future<List<Device>> pollingGetDevices({ Duration timeout }) async {
Future<List<Device>> pollingGetDevices({ Duration? timeout }) async {
if (!canListAnything) {
return const <Device>[];
}
......
......@@ -136,7 +136,7 @@ void main() {
expect(await device.stopApp(null), isFalse);
await expectLater(() => device.startApp(null, debuggingOptions: null), throwsA(isA<UnimplementedError>()));
await expectLater(() => device.buildForDevice(null), throwsA(isA<UnimplementedError>()));
await expectLater(() => device.buildForDevice(null, buildInfo: BuildInfo.debug), throwsA(isA<UnimplementedError>()));
expect(device.executablePathForDevice(null, null), null);
});
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment