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);
} }
...@@ -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