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