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

refactor: adapt getSimulators() for OOT platforms #2239

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
38 changes: 26 additions & 12 deletions packages/cli-platform-apple/src/commands/logCommand/createLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {spawnSync} from 'child_process';
import os from 'os';
import path from 'path';
import getSimulators from '../../tools/getSimulators';
import listDevices from '../../tools/listDevices';
import listDevices, {stripPlatform} from '../../tools/listDevices';
import {getPlatformInfo} from '../runCommand/getPlatformInfo';
import {BuilderCommand} from '../../types';
import {BuilderCommand, Device} from '../../types';
import {supportedPlatforms} from '../../config/supportedPlatforms';
import {promptForDeviceToTailLogs} from '../../tools/prompts';

Expand Down Expand Up @@ -50,12 +50,14 @@ const createLog =
return;
}

const bootedAndAvailableSimulators = bootedSimulators.map((booted) => {
const available = availableSimulators.find(
({udid}) => udid === booted.udid,
);
return {...available, ...booted};
});
const bootedAndAvailableSimulators = bootedSimulators
.map((booted) => {
const available = availableSimulators.find(
({udid}) => udid === booted.udid,
);
return {...available, ...booted};
})
.filter(({sdk}) => sdk && sdkNames.includes(stripPlatform(sdk)));

if (bootedAndAvailableSimulators.length === 0) {
logger.error(
Expand All @@ -70,22 +72,34 @@ const createLog =
bootedAndAvailableSimulators,
);

tailDeviceLogs(udid);
const simulator = bootedAndAvailableSimulators.find(
({udid: deviceUDID}) => deviceUDID === udid,
);

if (!simulator) {
throw new CLIError(
`Unable to find simulator with udid: ${udid} in booted simulators`,
);
}

tailDeviceLogs(simulator);
} else {
tailDeviceLogs(bootedAndAvailableSimulators[0].udid);
tailDeviceLogs(bootedAndAvailableSimulators[0]);
}
};

function tailDeviceLogs(udid: string) {
function tailDeviceLogs(device: Device) {
const logDir = path.join(
os.homedir(),
'Library',
'Logs',
'CoreSimulator',
udid,
device.udid,
'asl',
);

logger.info(`Tailing logs for device ${device.name} (${device.udid})`);

const log = spawnSync('syslog', ['-w', '-F', 'std', '-d', logDir], {
stdio: 'inherit',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
cacheManager,
} from '@react-native-community/cli-tools';
import getArchitecture from '../../tools/getArchitecture';
import getSimulators from '../../tools/getSimulators';
import listDevices from '../../tools/listDevices';
import resolvePods, {getPackageJson} from '../../tools/pods';
import {promptForDeviceSelection} from '../../tools/prompts';
Expand Down Expand Up @@ -208,12 +207,7 @@ const createRun =
const bootedDevices = availableDevices.filter(
({type}) => type === 'device',
);

const simulators = getSimulators();
const bootedSimulators = Object.keys(simulators.devices)
.map((key) => simulators.devices[key])
.reduce((acc, val) => acc.concat(val), [])
.filter(({state}) => state === 'Booted');
const bootedSimulators = devices.filter(({type}) => type === 'simulator');

const booted = [...bootedDevices, ...bootedSimulators];
if (booted.length === 0) {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-platform-apple/src/tools/listDevices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async function listDevices(sdkNames: string[]): Promise<Device[]> {
return parseXcdeviceList(out, sdkNames);
}

function stripPlatform(platform: string): string {
export function stripPlatform(platform: string): string {
return platform.replace('com.apple.platform.', '');
}

Expand Down