Unverified Commit a0665aba authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Reland Replace ideviceinfo and idevice_id with xcdevice (#50252)

parent fbb3d281
...@@ -166,6 +166,11 @@ Future<T> runInContext<T>( ...@@ -166,6 +166,11 @@ Future<T> runInContext<T>(
fileSystem: globals.fs, fileSystem: globals.fs,
xcodeProjectInterpreter: xcodeProjectInterpreter, xcodeProjectInterpreter: xcodeProjectInterpreter,
), ),
XCDevice: () => XCDevice(
processManager: globals.processManager,
logger: globals.logger,
xcode: globals.xcode,
),
XcodeProjectInterpreter: () => XcodeProjectInterpreter( XcodeProjectInterpreter: () => XcodeProjectInterpreter(
logger: globals.logger, logger: globals.logger,
processManager: globals.processManager, processManager: globals.processManager,
......
...@@ -57,6 +57,8 @@ Xcode get xcode => context.get<Xcode>(); ...@@ -57,6 +57,8 @@ Xcode get xcode => context.get<Xcode>();
FlutterVersion get flutterVersion => context.get<FlutterVersion>(); FlutterVersion get flutterVersion => context.get<FlutterVersion>();
IMobileDevice get iMobileDevice => context.get<IMobileDevice>(); IMobileDevice get iMobileDevice => context.get<IMobileDevice>();
XCDevice get xcdevice => context.get<XCDevice>();
/// Display an error level message to the user. Commands should use this if they /// Display an error level message to the user. Commands should use this if they
/// fail in some way. /// fail in some way.
/// ///
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
import 'dart:async'; import 'dart:async';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:platform/platform.dart';
import '../application_package.dart'; import '../application_package.dart';
import '../artifacts.dart'; import '../artifacts.dart';
...@@ -18,6 +19,7 @@ import '../build_info.dart'; ...@@ -18,6 +19,7 @@ import '../build_info.dart';
import '../convert.dart'; import '../convert.dart';
import '../device.dart'; import '../device.dart';
import '../globals.dart' as globals; import '../globals.dart' as globals;
import '../macos/xcode.dart';
import '../mdns_discovery.dart'; import '../mdns_discovery.dart';
import '../project.dart'; import '../project.dart';
import '../protocol_discovery.dart'; import '../protocol_discovery.dart';
...@@ -111,11 +113,18 @@ class IOSDevices extends PollingDeviceDiscovery { ...@@ -111,11 +113,18 @@ class IOSDevices extends PollingDeviceDiscovery {
bool get canListAnything => iosWorkflow.canListDevices; bool get canListAnything => iosWorkflow.canListDevices;
@override @override
Future<List<Device>> pollingGetDevices() => IOSDevice.getAttachedDevices(); Future<List<Device>> pollingGetDevices() => IOSDevice.getAttachedDevices(globals.platform, globals.xcdevice);
@override
Future<List<String>> getDiagnostics() => IOSDevice.getDiagnostics(globals.platform, globals.xcdevice);
} }
class IOSDevice extends Device { class IOSDevice extends Device {
IOSDevice(String id, { this.name, String sdkVersion }) IOSDevice(String id, {
@required this.name,
@required this.cpuArchitecture,
@required String sdkVersion,
})
: _sdkVersion = sdkVersion, : _sdkVersion = sdkVersion,
super( super(
id, id,
...@@ -157,6 +166,8 @@ class IOSDevice extends Device { ...@@ -157,6 +166,8 @@ class IOSDevice extends Device {
@override @override
final String name; final String name;
final DarwinArch cpuArchitecture;
Map<IOSApp, DeviceLogReader> _logReaders; Map<IOSApp, DeviceLogReader> _logReaders;
DevicePortForwarder _portForwarder; DevicePortForwarder _portForwarder;
...@@ -170,34 +181,20 @@ class IOSDevice extends Device { ...@@ -170,34 +181,20 @@ class IOSDevice extends Device {
@override @override
bool get supportsStartPaused => false; bool get supportsStartPaused => false;
static Future<List<IOSDevice>> getAttachedDevices() async { static Future<List<IOSDevice>> getAttachedDevices(Platform platform, XCDevice xcdevice) async {
if (!globals.platform.isMacOS) { if (!platform.isMacOS) {
throw UnsupportedError('Control of iOS devices or simulators only supported on Mac OS.'); throw UnsupportedError('Control of iOS devices or simulators only supported on macOS.');
}
if (!globals.iMobileDevice.isInstalled) {
return <IOSDevice>[];
} }
final List<IOSDevice> devices = <IOSDevice>[]; return await xcdevice.getAvailableTetheredIOSDevices();
for (String id in (await globals.iMobileDevice.getAvailableDeviceIDs()).split('\n')) {
id = id.trim();
if (id.isEmpty) {
continue;
} }
try { static Future<List<String>> getDiagnostics(Platform platform, XCDevice xcdevice) async {
final String deviceName = await globals.iMobileDevice.getInfoForDevice(id, 'DeviceName'); if (!platform.isMacOS) {
final String sdkVersion = await globals.iMobileDevice.getInfoForDevice(id, 'ProductVersion'); return const <String>['Control of iOS devices or simulators only supported on macOS.'];
devices.add(IOSDevice(id, name: deviceName, sdkVersion: sdkVersion));
} on IOSDeviceNotFoundError catch (error) {
// Unable to find device with given udid. Possibly a network device.
globals.printTrace('Error getting attached iOS device: $error');
} on IOSDeviceNotTrustedError catch (error) {
globals.printTrace('Error getting attached iOS device information: $error');
UsageEvent('device', 'ios-trust-failure').send();
}
} }
return devices;
return await xcdevice.getDiagnostics();
} }
@override @override
...@@ -280,24 +277,13 @@ class IOSDevice extends Device { ...@@ -280,24 +277,13 @@ class IOSDevice extends Device {
// TODO(chinmaygarde): Use mainPath, route. // TODO(chinmaygarde): Use mainPath, route.
globals.printTrace('Building ${package.name} for $id'); globals.printTrace('Building ${package.name} for $id');
String cpuArchitecture;
try {
cpuArchitecture = await globals.iMobileDevice.getInfoForDevice(id, 'CPUArchitecture');
} on IOSDeviceNotFoundError catch (e) {
globals.printError(e.message);
return LaunchResult.failed();
}
final DarwinArch iosArch = getIOSArchForName(cpuArchitecture);
// Step 1: Build the precompiled/DBC application if necessary. // Step 1: Build the precompiled/DBC application if necessary.
final XcodeBuildResult buildResult = await buildXcodeProject( final XcodeBuildResult buildResult = await buildXcodeProject(
app: package as BuildableIOSApp, app: package as BuildableIOSApp,
buildInfo: debuggingOptions.buildInfo, buildInfo: debuggingOptions.buildInfo,
targetOverride: mainPath, targetOverride: mainPath,
buildForDevice: true, buildForDevice: true,
activeArch: iosArch, activeArch: cpuArchitecture,
); );
if (!buildResult.success) { if (!buildResult.success) {
globals.printError('Could not build the precompiled application for the device.'); globals.printError('Could not build the precompiled application for the device.');
......
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