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