Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support run-ios on Mac target (Catalyst) #1024

Merged
merged 5 commits into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ describe('parseIOSDevicesList', () => {
);

expect(devices).toEqual([
{
name: 'Maxs MacBook Pro',
udid: '11111111-1111-1111-1111-111111111111',
},
{
name: "Max's iPhone",
udid: '11111111111111111111aaaaaaaaaaaaaaaaaaaa',
Expand Down
2 changes: 1 addition & 1 deletion packages/platform-ios/src/commands/runIOS/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function runIOS(_: Array<string>, ctx: Config, args: FlagsT) {
}),
);

if (devices.length === 0) {
if (devices.length === 1) {
robertying marked this conversation as resolved.
Show resolved Hide resolved
return logger.error('No iOS devices connected.');
}

Expand Down
15 changes: 14 additions & 1 deletion packages/platform-ios/src/commands/runIOS/parseIOSDevicesList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,22 @@ import {Device} from '../../types';
function parseIOSDevicesList(text: string): Array<Device> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, xcrun intruments -s devices returns all simulators + connected devices, it's kinda confusing that we run xcrun simctl few lines earlier in runOnIOSSimulator.

I think this code could be simplified to just rely on a single code path, now that we're at it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I just realized there is another parser. I could try to simplify the code.

There is a small difference between the output of two commands on my Mac:

It seems instruments are a broader concept for Xcode where we can have iPhone paired with Apple Watch, compared to simctl. Host mac only exists in instruments.

I will try to see if output from instruments is enough for booting any simulator.


xcrun instruments -s devices

Known Devices:
Rui’s Mac mini [A0428EFA-59EC-5E72-9612-5A4BAA8FE444]
Apple TV (13.3) [FF38ADAA-77F3-4F14-BF8F-EF90C2AA9129] (Simulator)
Apple TV 4K (13.3) [EC61B31B-1D91-4F3A-AD10-B18515342C0E] (Simulator)
Apple TV 4K (at 1080p) (13.3) [45EB9736-C847-40B1-9819-0D901FD1D730] (Simulator)
Apple Watch Series 4 - 40mm (6.1.1) [66383905-DCC7-4A1C-8BA5-B7365871687E] (Simulator)
Apple Watch Series 4 - 44mm (6.1.1) [E7AB1388-0235-4548-BC15-8C55B60C136F] (Simulator)
iPad (7th generation) (13.3) [C774831B-9DBC-46AD-857B-AA839F190EBD] (Simulator)
iPad Air (3rd generation) (13.3) [806B6284-AD20-4EBA-898E-488A055FC7A3] (Simulator)
iPad Pro (11-inch) (13.3) [0CFC0D8D-BB12-4BEF-A770-67F9D457C186] (Simulator)
iPad Pro (12.9-inch) (2nd generation) (13.3) [626DC537-EC7B-4474-A6DF-54B8F637D85F] (Simulator)
iPad Pro (12.9-inch) (3rd generation) (13.3) [FED06957-8E7E-4BA5-ACAB-4C0F0F6EF14C] (Simulator)
iPad Pro (9.7-inch) (13.3) [25D30125-2F67-4ABA-B63E-F7F3A86605D6] (Simulator)
iPhone 11 (13.3) [4540B5C1-F7F3-4A91-8E79-1971DD5D98BA] (Simulator)
iPhone 11 Pro (13.3) [9AAF3C5C-9CC4-4ED5-963A-269C8BE3D0FF] (Simulator)
iPhone 11 Pro (13.3) + Apple Watch Series 5 - 40mm (6.1.1) [BE7CF341-61F8-42B6-8D7D-19036226B673] (Simulator)
iPhone 11 Pro Max (13.3) [A1A44D6C-F87C-487A-AF81-319F569FE252] (Simulator)
iPhone 11 Pro Max (13.3) + Apple Watch Series 5 - 44mm (6.1.1) [0D801CF9-8489-4149-9806-5CC6EDA94481] (Simulator)
iPhone 8 (13.3) [EC2C0447-130D-4EA8-8D04-FF288F9EACFE] (Simulator)
iPhone 8 Plus (13.3) [F3D5F572-351D-4975-93D4-70320731CD2F] (Simulator)

xcrun simctl list devices

== Devices ==
-- iOS 13.3 --
    iPhone 8 (EC2C0447-130D-4EA8-8D04-FF288F9EACFE) (Shutdown) 
    iPhone 8 Plus (F3D5F572-351D-4975-93D4-70320731CD2F) (Shutdown) 
    iPhone 11 (4540B5C1-F7F3-4A91-8E79-1971DD5D98BA) (Shutdown) 
    iPhone 11 Pro (9AAF3C5C-9CC4-4ED5-963A-269C8BE3D0FF) (Shutdown) 
    iPhone 11 Pro Max (A1A44D6C-F87C-487A-AF81-319F569FE252) (Shutdown) 
    iPad Pro (9.7-inch) (25D30125-2F67-4ABA-B63E-F7F3A86605D6) (Shutdown) 
    iPad Pro (12.9-inch) (2nd generation) (626DC537-EC7B-4474-A6DF-54B8F637D85F) (Shutdown) 
    iPad (7th generation) (C774831B-9DBC-46AD-857B-AA839F190EBD) (Shutdown) 
    iPad Pro (11-inch) (0CFC0D8D-BB12-4BEF-A770-67F9D457C186) (Shutdown) 
    iPad Pro (12.9-inch) (3rd generation) (FED06957-8E7E-4BA5-ACAB-4C0F0F6EF14C) (Shutdown) 
    iPad Air (3rd generation) (806B6284-AD20-4EBA-898E-488A055FC7A3) (Shutdown) 
-- tvOS 13.3 --
    Apple TV (FF38ADAA-77F3-4F14-BF8F-EF90C2AA9129) (Shutdown) 
    Apple TV 4K (EC61B31B-1D91-4F3A-AD10-B18515342C0E) (Shutdown) 
    Apple TV 4K (at 1080p) (45EB9736-C847-40B1-9819-0D901FD1D730) (Shutdown) 
-- watchOS 6.1 --
    Apple Watch Series 4 - 40mm (66383905-DCC7-4A1C-8BA5-B7365871687E) (Shutdown) 
    Apple Watch Series 4 - 44mm (E7AB1388-0235-4548-BC15-8C55B60C136F) (Shutdown) 
    Apple Watch Series 5 - 40mm (BE7CF341-61F8-42B6-8D7D-19036226B673) (Shutdown) 
    Apple Watch Series 5 - 44mm (0D801CF9-8489-4149-9806-5CC6EDA94481) (Shutdown) 
-- Unavailable: com.apple.CoreSimulator.SimRuntime.iOS-13-4 --
    iPhone 8 (FA0FFDDD-1BB2-4DC8-8D5F-07CB981AD925) (Shutdown) (unavailable, runtime profile not found)
    iPhone 8 Plus (0DCC89C1-7DBF-48F2-95A5-88A0ECEFBB38) (Shutdown) (unavailable, runtime profile not found)
    iPhone 11 (F8BBF4A8-CD30-41D3-9438-524EF189B834) (Shutdown) (unavailable, runtime profile not found)
    iPhone 11 Pro (F358A003-BB9D-4B3A-8818-97372218B6FC) (Shutdown) (unavailable, runtime profile not found)
    iPhone 11 Pro Max (68FD3CCD-217E-41FC-BAAA-B93EA059254E) (Shutdown) (unavailable, runtime profile not found)
    iPad Pro (9.7-inch) (A26909EE-3B1F-4AFD-A5F0-93379AB8D904) (Shutdown) (unavailable, runtime profile not found)
    iPad (7th generation) (F32861D8-F194-47D1-ADE7-EA9DD8B51442) (Shutdown) (unavailable, runtime profile not found)
    iPad Pro (11-inch) (E5548F17-8342-47FE-81B3-22828E96C9F7) (Shutdown) (unavailable, runtime profile not found)
    iPad Pro (12.9-inch) (3rd generation) (07DDB8C8-8D6C-41FF-A5AB-DE20226C743D) (Shutdown) (unavailable, runtime profile not found)
    iPad Air (3rd generation) (25514C3D-8ECB-4333-A231-D5B968404B03) (Shutdown) (unavailable, runtime profile not found)
-- Unavailable: com.apple.CoreSimulator.SimRuntime.tvOS-13-4 --
    Apple TV (9F1A1F62-D1FA-40EF-93B8-411AF949311F) (Shutdown) (unavailable, runtime profile not found)
    Apple TV 4K (569553B7-2C58-4054-ABA2-7E5237A3F2CB) (Shutdown) (unavailable, runtime profile not found)
    Apple TV 4K (at 1080p) (97018EA9-58AA-49F3-BB41-A60CADB73226) (Shutdown) (unavailable, runtime profile not found)
-- Unavailable: com.apple.CoreSimulator.SimRuntime.watchOS-6-2 --
    Apple Watch Series 4 - 40mm (35033F4F-D7CD-4E9F-9A93-30166CA9F3D2) (Shutdown) (unavailable, runtime profile not found)
    Apple Watch Series 4 - 44mm (C4A1BB0D-EA96-44A9-82F1-91DD866194D0) (Shutdown) (unavailable, runtime profile not found)
    Apple Watch Series 5 - 40mm (18786B66-28E8-4A64-B52C-32BBC35B6784) (Shutdown) (unavailable, runtime profile not found)
    Apple Watch Series 5 - 44mm (92220F14-4647-4BA0-9F41-3CAAFFE70C87) (Shutdown) (unavailable, runtime profile not found)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be safer to tackle refactoring as a separate PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked at the code and realized xcrun simctl list devices is commonly used because the output of it indicates the simulator availability and state. However, the output does not contain real devices as xcrun instruments -s does.

For now, I'm afraid those two commands will have to co-exist.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, thanks for investigation. If you have any ideas on how to further simplify the code, please do :)

const devices: Array<Device> = [];

text.split('\n').forEach(line => {
text.split('\n').forEach((line, index) => {
const device = line.match(/(.*?) \((.*?)\) \[(.*?)\]/);
const noSimulator = line.match(/(.*?) \((.*?)\) \[(.*?)\] \((.*?)\)/);

if (index === 1) {
robertying marked this conversation as resolved.
Show resolved Hide resolved
const myMac = line.match(/(.*?) \[(.*?)\]/);
if (myMac) {
const name = myMac[1];
const udid = myMac[2];
devices.push({
udid,
name,
});
}
}

if (device != null && noSimulator == null) {
const name = device[1];
const version = device[2];
Expand Down