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