Unverified Commit 855af290 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Migrate ios_deploy to null safety (#88851)

parent ecd046e9
...@@ -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 'dart:async'; import 'dart:async';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
...@@ -29,11 +27,11 @@ const String unknownAppLaunchError = 'Error 0xe8000022'; ...@@ -29,11 +27,11 @@ const String unknownAppLaunchError = 'Error 0xe8000022';
class IOSDeploy { class IOSDeploy {
IOSDeploy({ IOSDeploy({
@required Artifacts artifacts, required Artifacts artifacts,
@required Cache cache, required Cache cache,
@required Logger logger, required Logger logger,
@required Platform platform, required Platform platform,
@required ProcessManager processManager, required ProcessManager processManager,
}) : _platform = platform, }) : _platform = platform,
_cache = cache, _cache = cache,
_processUtils = ProcessUtils(processManager: processManager, logger: logger), _processUtils = ProcessUtils(processManager: processManager, logger: logger),
...@@ -63,8 +61,8 @@ class IOSDeploy { ...@@ -63,8 +61,8 @@ class IOSDeploy {
/// ///
/// Uses ios-deploy and returns the exit code. /// Uses ios-deploy and returns the exit code.
Future<int> uninstallApp({ Future<int> uninstallApp({
@required String deviceId, required String deviceId,
@required String bundleId, required String bundleId,
}) async { }) async {
final List<String> launchCommand = <String>[ final List<String> launchCommand = <String>[
_binaryPath, _binaryPath,
...@@ -87,11 +85,11 @@ class IOSDeploy { ...@@ -87,11 +85,11 @@ class IOSDeploy {
/// ///
/// Uses ios-deploy and returns the exit code. /// Uses ios-deploy and returns the exit code.
Future<int> installApp({ Future<int> installApp({
@required String deviceId, required String deviceId,
@required String bundlePath, required String bundlePath,
@required Directory appDeltaDirectory, required List<String>launchArguments,
@required List<String>launchArguments, required IOSDeviceConnectionInterface interfaceType,
@required IOSDeviceConnectionInterface interfaceType, Directory? appDeltaDirectory,
}) async { }) async {
appDeltaDirectory?.createSync(recursive: true); appDeltaDirectory?.createSync(recursive: true);
final List<String> launchCommand = <String>[ final List<String> launchCommand = <String>[
...@@ -125,11 +123,11 @@ class IOSDeploy { ...@@ -125,11 +123,11 @@ class IOSDeploy {
/// This method does not install the app. Call [IOSDeployDebugger.launchAndAttach()] /// This method does not install the app. Call [IOSDeployDebugger.launchAndAttach()]
/// to install and attach the debugger to the specified app bundle. /// to install and attach the debugger to the specified app bundle.
IOSDeployDebugger prepareDebuggerForLaunch({ IOSDeployDebugger prepareDebuggerForLaunch({
@required String deviceId, required String deviceId,
@required String bundlePath, required String bundlePath,
@required Directory appDeltaDirectory, required List<String> launchArguments,
@required List<String> launchArguments, required IOSDeviceConnectionInterface interfaceType,
@required IOSDeviceConnectionInterface interfaceType, Directory? appDeltaDirectory,
}) { }) {
appDeltaDirectory?.createSync(recursive: true); appDeltaDirectory?.createSync(recursive: true);
// Interactive debug session to support sending the lldb detach command. // Interactive debug session to support sending the lldb detach command.
...@@ -167,11 +165,11 @@ class IOSDeploy { ...@@ -167,11 +165,11 @@ class IOSDeploy {
/// ///
/// Uses ios-deploy and returns the exit code. /// Uses ios-deploy and returns the exit code.
Future<int> launchApp({ Future<int> launchApp({
@required String deviceId, required String deviceId,
@required String bundlePath, required String bundlePath,
@required Directory appDeltaDirectory, required List<String> launchArguments,
@required List<String> launchArguments, required IOSDeviceConnectionInterface interfaceType,
@required IOSDeviceConnectionInterface interfaceType, Directory? appDeltaDirectory,
}) async { }) async {
appDeltaDirectory?.createSync(recursive: true); appDeltaDirectory?.createSync(recursive: true);
final List<String> launchCommand = <String>[ final List<String> launchCommand = <String>[
...@@ -202,8 +200,8 @@ class IOSDeploy { ...@@ -202,8 +200,8 @@ class IOSDeploy {
} }
Future<bool> isAppInstalled({ Future<bool> isAppInstalled({
@required String bundleId, required String bundleId,
@required String deviceId, required String deviceId,
}) async { }) async {
final List<String> launchCommand = <String>[ final List<String> launchCommand = <String>[
_binaryPath, _binaryPath,
...@@ -244,10 +242,10 @@ enum _IOSDeployDebuggerState { ...@@ -244,10 +242,10 @@ enum _IOSDeployDebuggerState {
/// Wrapper to launch app and attach the debugger with ios-deploy. /// Wrapper to launch app and attach the debugger with ios-deploy.
class IOSDeployDebugger { class IOSDeployDebugger {
IOSDeployDebugger({ IOSDeployDebugger({
@required Logger logger, required Logger logger,
@required ProcessUtils processUtils, required ProcessUtils processUtils,
@required List<String> launchCommand, required List<String> launchCommand,
@required Map<String, String> iosDeployEnv, required Map<String, String> iosDeployEnv,
}) : _processUtils = processUtils, }) : _processUtils = processUtils,
_logger = logger, _logger = logger,
_launchCommand = launchCommand, _launchCommand = launchCommand,
...@@ -259,8 +257,8 @@ class IOSDeployDebugger { ...@@ -259,8 +257,8 @@ class IOSDeployDebugger {
/// Sets the command to "ios-deploy" and environment to an empty map. /// Sets the command to "ios-deploy" and environment to an empty map.
@visibleForTesting @visibleForTesting
factory IOSDeployDebugger.test({ factory IOSDeployDebugger.test({
@required ProcessManager processManager, required ProcessManager processManager,
Logger logger, Logger? logger,
}) { }) {
final Logger debugLogger = logger ?? BufferLogger.test(); final Logger debugLogger = logger ?? BufferLogger.test();
return IOSDeployDebugger( return IOSDeployDebugger(
...@@ -276,7 +274,7 @@ class IOSDeployDebugger { ...@@ -276,7 +274,7 @@ class IOSDeployDebugger {
final List<String> _launchCommand; final List<String> _launchCommand;
final Map<String, String> _iosDeployEnv; final Map<String, String> _iosDeployEnv;
Process _iosDeployProcess; Process? _iosDeployProcess;
Stream<String> get logLines => _debuggerOutput.stream; Stream<String> get logLines => _debuggerOutput.stream;
final StreamController<String> _debuggerOutput = StreamController<String>.broadcast(); final StreamController<String> _debuggerOutput = StreamController<String>.broadcast();
...@@ -306,8 +304,8 @@ class IOSDeployDebugger { ...@@ -306,8 +304,8 @@ class IOSDeployDebugger {
_launchCommand, _launchCommand,
environment: _iosDeployEnv, environment: _iosDeployEnv,
); );
String lastLineFromDebugger; String? lastLineFromDebugger;
final StreamSubscription<String> stdoutSubscription = _iosDeployProcess.stdout final StreamSubscription<String> stdoutSubscription = _iosDeployProcess!.stdout
.transform<String>(utf8.decoder) .transform<String>(utf8.decoder)
.transform<String>(const LineSplitter()) .transform<String>(const LineSplitter())
.listen((String line) { .listen((String line) {
...@@ -346,7 +344,7 @@ class IOSDeployDebugger { ...@@ -346,7 +344,7 @@ class IOSDeployDebugger {
_logger.printTrace(line); _logger.printTrace(line);
return; return;
} }
if (lastLineFromDebugger != null && lastLineFromDebugger.isNotEmpty && line.isEmpty) { if (lastLineFromDebugger != null && lastLineFromDebugger!.isNotEmpty && line.isEmpty) {
// The lldb console stream from ios-deploy is separated lines by an extra \r\n. // The lldb console stream from ios-deploy is separated lines by an extra \r\n.
// To avoid all lines being double spaced, if the last line from the // To avoid all lines being double spaced, if the last line from the
// debugger was not an empty line, skip this empty line. // debugger was not an empty line, skip this empty line.
...@@ -356,14 +354,14 @@ class IOSDeployDebugger { ...@@ -356,14 +354,14 @@ class IOSDeployDebugger {
} }
lastLineFromDebugger = line; lastLineFromDebugger = line;
}); });
final StreamSubscription<String> stderrSubscription = _iosDeployProcess.stderr final StreamSubscription<String> stderrSubscription = _iosDeployProcess!.stderr
.transform<String>(utf8.decoder) .transform<String>(utf8.decoder)
.transform<String>(const LineSplitter()) .transform<String>(const LineSplitter())
.listen((String line) { .listen((String line) {
_monitorIOSDeployFailure(line, _logger); _monitorIOSDeployFailure(line, _logger);
_logger.printTrace(line); _logger.printTrace(line);
}); });
unawaited(_iosDeployProcess.exitCode.then((int status) { unawaited(_iosDeployProcess!.exitCode.then((int status) {
_logger.printTrace('ios-deploy exited with code $exitCode'); _logger.printTrace('ios-deploy exited with code $exitCode');
_debuggerState = _IOSDeployDebuggerState.detached; _debuggerState = _IOSDeployDebuggerState.detached;
unawaited(stdoutSubscription.cancel()); unawaited(stdoutSubscription.cancel());
...@@ -392,7 +390,7 @@ class IOSDeployDebugger { ...@@ -392,7 +390,7 @@ class IOSDeployDebugger {
} }
bool exit() { bool exit() {
final bool success = (_iosDeployProcess == null) || _iosDeployProcess.kill(); final bool success = (_iosDeployProcess == null) || _iosDeployProcess!.kill();
_iosDeployProcess = null; _iosDeployProcess = null;
return success; return success;
} }
...@@ -404,7 +402,7 @@ class IOSDeployDebugger { ...@@ -404,7 +402,7 @@ class IOSDeployDebugger {
try { try {
// Detach lldb from the app process. // Detach lldb from the app process.
_iosDeployProcess?.stdin?.writeln('process detach'); _iosDeployProcess?.stdin.writeln('process detach');
_debuggerState = _IOSDeployDebuggerState.detached; _debuggerState = _IOSDeployDebuggerState.detached;
} on SocketException catch (error) { } on SocketException catch (error) {
// Best effort, try to detach, but maybe the app already exited or already detached. // Best effort, try to detach, but maybe the app already exited or already detached.
......
...@@ -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 'dart:async'; import 'dart:async';
import 'dart:convert'; import 'dart:convert';
...@@ -22,9 +20,9 @@ import '../../src/fake_process_manager.dart'; ...@@ -22,9 +20,9 @@ import '../../src/fake_process_manager.dart';
import '../../src/fakes.dart'; import '../../src/fakes.dart';
void main () { void main () {
Artifacts artifacts; late Artifacts artifacts;
String iosDeployPath; late String iosDeployPath;
FileSystem fileSystem; late FileSystem fileSystem;
setUp(() { setUp(() {
artifacts = Artifacts.test(); artifacts = Artifacts.test();
...@@ -86,7 +84,7 @@ void main () { ...@@ -86,7 +84,7 @@ void main () {
group('IOSDeployDebugger', () { group('IOSDeployDebugger', () {
group('launch', () { group('launch', () {
BufferLogger logger; late BufferLogger logger;
setUp(() { setUp(() {
logger = BufferLogger.test(); logger = BufferLogger.test();
...@@ -322,7 +320,7 @@ void main () { ...@@ -322,7 +320,7 @@ void main () {
} }
IOSDeploy setUpIOSDeploy(ProcessManager processManager, { IOSDeploy setUpIOSDeploy(ProcessManager processManager, {
Artifacts artifacts, Artifacts? artifacts,
}) { }) {
final FakePlatform macPlatform = FakePlatform( final FakePlatform macPlatform = FakePlatform(
operatingSystem: 'macos', operatingSystem: 'macos',
......
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