Migrate devicelab framework code to null safety. (#86325)
(Attempt to reland #85993)
This commit is contained in:
@@ -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 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
@@ -64,8 +62,8 @@ class _TaskRunner {
|
||||
_TaskRunner(this.task) {
|
||||
registerExtension('ext.cocoonRunTask',
|
||||
(String method, Map<String, String> parameters) async {
|
||||
final Duration taskTimeout = parameters.containsKey('timeoutInMinutes')
|
||||
? Duration(minutes: int.parse(parameters['timeoutInMinutes']))
|
||||
final Duration? taskTimeout = parameters.containsKey('timeoutInMinutes')
|
||||
? Duration(minutes: int.parse(parameters['timeoutInMinutes']!))
|
||||
: null;
|
||||
// This is only expected to be passed in unit test runs so they do not
|
||||
// kill the Dart process that is running them and waste time running config.
|
||||
@@ -82,7 +80,7 @@ class _TaskRunner {
|
||||
|
||||
final TaskFunction task;
|
||||
|
||||
Future<Device/*?*/> _getWorkingDeviceIfAvailable() async {
|
||||
Future<Device?> _getWorkingDeviceIfAvailable() async {
|
||||
try {
|
||||
return await devices.workingDevice;
|
||||
} on DeviceException {
|
||||
@@ -91,8 +89,8 @@ class _TaskRunner {
|
||||
}
|
||||
|
||||
// TODO(ianh): workaround for https://github.com/dart-lang/sdk/issues/23797
|
||||
RawReceivePort _keepAlivePort;
|
||||
Timer _startTaskTimeout;
|
||||
RawReceivePort? _keepAlivePort;
|
||||
Timer? _startTaskTimeout;
|
||||
bool _taskStarted = false;
|
||||
|
||||
final Completer<TaskResult> _completer = Completer<TaskResult>();
|
||||
@@ -102,7 +100,7 @@ class _TaskRunner {
|
||||
/// Signals that this task runner finished running the task.
|
||||
Future<TaskResult> get whenDone => _completer.future;
|
||||
|
||||
Future<TaskResult> run(Duration taskTimeout, {
|
||||
Future<TaskResult> run(Duration? taskTimeout, {
|
||||
bool runFlutterConfig = true,
|
||||
bool runProcessCleanup = true,
|
||||
}) async {
|
||||
@@ -110,7 +108,7 @@ class _TaskRunner {
|
||||
_taskStarted = true;
|
||||
print('Running task with a timeout of $taskTimeout.');
|
||||
final String exe = Platform.isWindows ? '.exe' : '';
|
||||
Set<RunningProcessInfo> beforeRunningDartInstances;
|
||||
late Set<RunningProcessInfo> beforeRunningDartInstances;
|
||||
if (runProcessCleanup) {
|
||||
section('Checking running Dart$exe processes');
|
||||
beforeRunningDartInstances = await getRunningProcesses(
|
||||
@@ -136,7 +134,7 @@ class _TaskRunner {
|
||||
'--enable-windows-desktop',
|
||||
'--enable-linux-desktop',
|
||||
'--enable-web',
|
||||
if (localEngine != null) ...<String>['--local-engine', localEngine],
|
||||
if (localEngine != null) ...<String>['--local-engine', localEngine!],
|
||||
], canFail: true);
|
||||
if (configResult != 0) {
|
||||
print('Failed to enable configuration, tasks may not run.');
|
||||
@@ -145,12 +143,12 @@ class _TaskRunner {
|
||||
print('Skipping enabling configs for macOS, Linux, Windows, and Web');
|
||||
}
|
||||
|
||||
final Device/*?*/ device = await _getWorkingDeviceIfAvailable();
|
||||
/*late*/ TaskResult result;
|
||||
IOSink/*?*/ sink;
|
||||
final Device? device = await _getWorkingDeviceIfAvailable();
|
||||
late TaskResult result;
|
||||
IOSink? sink;
|
||||
try {
|
||||
if (device != null && device.canStreamLogs && hostAgent.dumpDirectory != null) {
|
||||
sink = File(path.join(hostAgent.dumpDirectory.path, '${device.deviceId}.log')).openWrite();
|
||||
sink = File(path.join(hostAgent.dumpDirectory!.path, '${device.deviceId}.log')).openWrite();
|
||||
await device.startLoggingToSink(sink);
|
||||
}
|
||||
|
||||
@@ -212,7 +210,7 @@ class _TaskRunner {
|
||||
final File rebootFile = _rebootFile();
|
||||
int runCount;
|
||||
if (rebootFile.existsSync()) {
|
||||
runCount = int.tryParse(rebootFile.readAsStringSync().trim());
|
||||
runCount = int.tryParse(rebootFile.readAsStringSync().trim()) ?? 0;
|
||||
} else {
|
||||
runCount = 0;
|
||||
}
|
||||
@@ -283,10 +281,10 @@ class _TaskRunner {
|
||||
|
||||
File _rebootFile() {
|
||||
if (Platform.isLinux || Platform.isMacOS) {
|
||||
return File(path.join(Platform.environment['HOME'], '.reboot-count'));
|
||||
return File(path.join(Platform.environment['HOME']!, '.reboot-count'));
|
||||
}
|
||||
if (!Platform.isWindows) {
|
||||
throw StateError('Unexpected platform ${Platform.operatingSystem}');
|
||||
}
|
||||
return File(path.join(Platform.environment['USERPROFILE'], '.reboot-count'));
|
||||
return File(path.join(Platform.environment['USERPROFILE']!, '.reboot-count'));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user