Check for xcode mismatch once and only once

Summary:
We perform this *repeatedly* (every 2s!!!). Which is clearly excessive.

Let's perform this check once to avoid noise and a waste of system resources

Reviewed By: passy

Differential Revision: D33844194

fbshipit-source-id: 226dc9d67bb83b167afa8e28ade8e1911470ef8a
This commit is contained in:
Lawrence Lomax
2022-02-01 00:43:24 -08:00
committed by Facebook GitHub Bot
parent e16662a28f
commit b0046c8ddb
2 changed files with 18 additions and 76 deletions

View File

@@ -66,15 +66,11 @@ test('test getAllPromisesForQueryingDevices when xcode detected', () => {
flipperServer.ios.iosBridge = {} as IOSBridge;
(flipperServer.ios as any).idbConfig = getFlipperServerConfig().settings;
flipperServer.ios.simctlBridge = fakeSimctlBridge;
const promises = flipperServer.ios.getAllPromisesForQueryingDevices(
true,
false,
);
expect(promises.length).toEqual(2);
flipperServer.ios.getPromiseForQueryingDevices(false);
expect(hasCalledSimctlActiveDevices).toEqual(true);
});
test('test getAllPromisesForQueryingDevices when xcode is not detected', () => {
test('test getAllPromisesForQueryingDevices when idb is available', () => {
const flipperServer = new FlipperServerImpl(
getFlipperServerConfig(),
getLogger(),
@@ -82,42 +78,6 @@ test('test getAllPromisesForQueryingDevices when xcode is not detected', () => {
flipperServer.ios.iosBridge = {} as IOSBridge;
(flipperServer.ios as any).idbConfig = getFlipperServerConfig().settings;
flipperServer.ios.simctlBridge = fakeSimctlBridge;
const promises = flipperServer.ios.getAllPromisesForQueryingDevices(
false,
true,
);
expect(promises.length).toEqual(1);
expect(hasCalledSimctlActiveDevices).toEqual(false);
});
test('test getAllPromisesForQueryingDevices when xcode and idb are both unavailable', () => {
const flipperServer = new FlipperServerImpl(
getFlipperServerConfig(),
getLogger(),
);
flipperServer.ios.iosBridge = {} as IOSBridge;
(flipperServer.ios as any).idbConfig = getFlipperServerConfig().settings;
flipperServer.ios.simctlBridge = fakeSimctlBridge;
const promises = flipperServer.ios.getAllPromisesForQueryingDevices(
false,
false,
);
expect(promises.length).toEqual(0);
expect(hasCalledSimctlActiveDevices).toEqual(false);
});
test('test getAllPromisesForQueryingDevices when both idb and xcode are available', () => {
const flipperServer = new FlipperServerImpl(
getFlipperServerConfig(),
getLogger(),
);
flipperServer.ios.iosBridge = {} as IOSBridge;
(flipperServer.ios as any).idbConfig = getFlipperServerConfig().settings;
flipperServer.ios.simctlBridge = fakeSimctlBridge;
const promises = flipperServer.ios.getAllPromisesForQueryingDevices(
true,
true,
);
expect(promises.length).toEqual(2);
flipperServer.ios.getPromiseForQueryingDevices(true);
expect(hasCalledSimctlActiveDevices).toEqual(false);
});

View File

@@ -22,7 +22,6 @@ import {
SimctlBridge,
} from './IOSBridge';
import {FlipperServerImpl} from '../../FlipperServerImpl';
import {notNull} from '../../utils/typeUtils';
import {getFlipperServerConfig} from '../../FlipperServerConfig';
import {IdbConfig, setIdbConfig} from './idbConfig';
import {assertNotNull} from 'flipper-server-core/src/comms/Utilities';
@@ -40,7 +39,6 @@ export class IOSDeviceManager {
);
iosBridge: IOSBridge | undefined;
simctlBridge: SimctlBridge = new SimctlBridge();
private xcodeVersionMismatchFound = false;
public xcodeCommandLineToolsDetected = false;
constructor(private flipperServer: FlipperServerImpl) {}
@@ -90,39 +88,25 @@ export class IOSDeviceManager {
];
}
getAllPromisesForQueryingDevices(
isXcodeDetected: boolean,
isIdbAvailable: boolean,
): Array<Promise<any>> {
getPromiseForQueryingDevices(isIdbAvailable: boolean): Promise<any> {
assertNotNull(this.idbConfig);
return [
isIdbAvailable
return isIdbAvailable
? getActiveDevices(
this.idbConfig.idbPath,
this.idbConfig.enablePhysicalIOS,
).then((devices: IOSDeviceParams[]) => {
this.processDevices(devices);
})
: null,
!isIdbAvailable && isXcodeDetected
? this.getSimulators(true).then((devices) =>
: this.getSimulators(true).then((devices) =>
this.processDevices(devices),
)
: null,
isXcodeDetected ? this.checkXcodeVersionMismatch() : null,
].filter(notNull);
);
}
private async queryDevices(): Promise<any> {
assertNotNull(this.idbConfig);
const isXcodeInstalled = await iosUtil.isXcodeDetected();
const isIdbAvailable = await iosUtil.isAvailable(this.idbConfig.idbPath);
console.debug(
`[conn] queryDevices. isXcodeInstalled ${isXcodeInstalled}, isIdbAvailable ${isIdbAvailable}`,
);
return Promise.all(
this.getAllPromisesForQueryingDevices(isXcodeInstalled, isIdbAvailable),
);
console.debug(`[conn] queryDevices. isIdbAvailable ${isIdbAvailable}`);
return this.getPromiseForQueryingDevices(isIdbAvailable);
}
private processDevices(activeDevices: IOSDeviceParams[]) {
@@ -180,6 +164,8 @@ export class IOSDeviceManager {
isDetected,
settings.enablePhysicalIOS,
);
// Check for version mismatch now for immediate error handling.
await this.checkXcodeVersionMismatch();
this.queryDevicesForever();
} catch (err) {
// This case is expected if both Xcode and idb are missing.
@@ -225,9 +211,6 @@ export class IOSDeviceManager {
}
async checkXcodeVersionMismatch() {
if (this.xcodeVersionMismatchFound) {
return;
}
try {
let {stdout: xcodeCLIVersion} = await exec('xcode-select -p');
xcodeCLIVersion = xcodeCLIVersion!.toString().trim();
@@ -250,7 +233,6 @@ export class IOSDeviceManager {
title: 'Xcode version mismatch',
description: '' + errorMessage,
});
this.xcodeVersionMismatchFound = true;
break;
}
} catch (e) {