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:
committed by
Facebook GitHub Bot
parent
e16662a28f
commit
b0046c8ddb
@@ -66,15 +66,11 @@ test('test getAllPromisesForQueryingDevices when xcode detected', () => {
|
|||||||
flipperServer.ios.iosBridge = {} as IOSBridge;
|
flipperServer.ios.iosBridge = {} as IOSBridge;
|
||||||
(flipperServer.ios as any).idbConfig = getFlipperServerConfig().settings;
|
(flipperServer.ios as any).idbConfig = getFlipperServerConfig().settings;
|
||||||
flipperServer.ios.simctlBridge = fakeSimctlBridge;
|
flipperServer.ios.simctlBridge = fakeSimctlBridge;
|
||||||
const promises = flipperServer.ios.getAllPromisesForQueryingDevices(
|
flipperServer.ios.getPromiseForQueryingDevices(false);
|
||||||
true,
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
expect(promises.length).toEqual(2);
|
|
||||||
expect(hasCalledSimctlActiveDevices).toEqual(true);
|
expect(hasCalledSimctlActiveDevices).toEqual(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('test getAllPromisesForQueryingDevices when xcode is not detected', () => {
|
test('test getAllPromisesForQueryingDevices when idb is available', () => {
|
||||||
const flipperServer = new FlipperServerImpl(
|
const flipperServer = new FlipperServerImpl(
|
||||||
getFlipperServerConfig(),
|
getFlipperServerConfig(),
|
||||||
getLogger(),
|
getLogger(),
|
||||||
@@ -82,42 +78,6 @@ test('test getAllPromisesForQueryingDevices when xcode is not detected', () => {
|
|||||||
flipperServer.ios.iosBridge = {} as IOSBridge;
|
flipperServer.ios.iosBridge = {} as IOSBridge;
|
||||||
(flipperServer.ios as any).idbConfig = getFlipperServerConfig().settings;
|
(flipperServer.ios as any).idbConfig = getFlipperServerConfig().settings;
|
||||||
flipperServer.ios.simctlBridge = fakeSimctlBridge;
|
flipperServer.ios.simctlBridge = fakeSimctlBridge;
|
||||||
const promises = flipperServer.ios.getAllPromisesForQueryingDevices(
|
flipperServer.ios.getPromiseForQueryingDevices(true);
|
||||||
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);
|
|
||||||
expect(hasCalledSimctlActiveDevices).toEqual(false);
|
expect(hasCalledSimctlActiveDevices).toEqual(false);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import {
|
|||||||
SimctlBridge,
|
SimctlBridge,
|
||||||
} from './IOSBridge';
|
} from './IOSBridge';
|
||||||
import {FlipperServerImpl} from '../../FlipperServerImpl';
|
import {FlipperServerImpl} from '../../FlipperServerImpl';
|
||||||
import {notNull} from '../../utils/typeUtils';
|
|
||||||
import {getFlipperServerConfig} from '../../FlipperServerConfig';
|
import {getFlipperServerConfig} from '../../FlipperServerConfig';
|
||||||
import {IdbConfig, setIdbConfig} from './idbConfig';
|
import {IdbConfig, setIdbConfig} from './idbConfig';
|
||||||
import {assertNotNull} from 'flipper-server-core/src/comms/Utilities';
|
import {assertNotNull} from 'flipper-server-core/src/comms/Utilities';
|
||||||
@@ -40,7 +39,6 @@ export class IOSDeviceManager {
|
|||||||
);
|
);
|
||||||
iosBridge: IOSBridge | undefined;
|
iosBridge: IOSBridge | undefined;
|
||||||
simctlBridge: SimctlBridge = new SimctlBridge();
|
simctlBridge: SimctlBridge = new SimctlBridge();
|
||||||
private xcodeVersionMismatchFound = false;
|
|
||||||
public xcodeCommandLineToolsDetected = false;
|
public xcodeCommandLineToolsDetected = false;
|
||||||
|
|
||||||
constructor(private flipperServer: FlipperServerImpl) {}
|
constructor(private flipperServer: FlipperServerImpl) {}
|
||||||
@@ -90,39 +88,25 @@ export class IOSDeviceManager {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
getAllPromisesForQueryingDevices(
|
getPromiseForQueryingDevices(isIdbAvailable: boolean): Promise<any> {
|
||||||
isXcodeDetected: boolean,
|
|
||||||
isIdbAvailable: boolean,
|
|
||||||
): Array<Promise<any>> {
|
|
||||||
assertNotNull(this.idbConfig);
|
assertNotNull(this.idbConfig);
|
||||||
return [
|
return isIdbAvailable
|
||||||
isIdbAvailable
|
? getActiveDevices(
|
||||||
? getActiveDevices(
|
this.idbConfig.idbPath,
|
||||||
this.idbConfig.idbPath,
|
this.idbConfig.enablePhysicalIOS,
|
||||||
this.idbConfig.enablePhysicalIOS,
|
).then((devices: IOSDeviceParams[]) => {
|
||||||
).then((devices: IOSDeviceParams[]) => {
|
this.processDevices(devices);
|
||||||
this.processDevices(devices);
|
})
|
||||||
})
|
: this.getSimulators(true).then((devices) =>
|
||||||
: null,
|
this.processDevices(devices),
|
||||||
!isIdbAvailable && isXcodeDetected
|
);
|
||||||
? this.getSimulators(true).then((devices) =>
|
|
||||||
this.processDevices(devices),
|
|
||||||
)
|
|
||||||
: null,
|
|
||||||
isXcodeDetected ? this.checkXcodeVersionMismatch() : null,
|
|
||||||
].filter(notNull);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async queryDevices(): Promise<any> {
|
private async queryDevices(): Promise<any> {
|
||||||
assertNotNull(this.idbConfig);
|
assertNotNull(this.idbConfig);
|
||||||
const isXcodeInstalled = await iosUtil.isXcodeDetected();
|
|
||||||
const isIdbAvailable = await iosUtil.isAvailable(this.idbConfig.idbPath);
|
const isIdbAvailable = await iosUtil.isAvailable(this.idbConfig.idbPath);
|
||||||
console.debug(
|
console.debug(`[conn] queryDevices. isIdbAvailable ${isIdbAvailable}`);
|
||||||
`[conn] queryDevices. isXcodeInstalled ${isXcodeInstalled}, isIdbAvailable ${isIdbAvailable}`,
|
return this.getPromiseForQueryingDevices(isIdbAvailable);
|
||||||
);
|
|
||||||
return Promise.all(
|
|
||||||
this.getAllPromisesForQueryingDevices(isXcodeInstalled, isIdbAvailable),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private processDevices(activeDevices: IOSDeviceParams[]) {
|
private processDevices(activeDevices: IOSDeviceParams[]) {
|
||||||
@@ -180,6 +164,8 @@ export class IOSDeviceManager {
|
|||||||
isDetected,
|
isDetected,
|
||||||
settings.enablePhysicalIOS,
|
settings.enablePhysicalIOS,
|
||||||
);
|
);
|
||||||
|
// Check for version mismatch now for immediate error handling.
|
||||||
|
await this.checkXcodeVersionMismatch();
|
||||||
this.queryDevicesForever();
|
this.queryDevicesForever();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// This case is expected if both Xcode and idb are missing.
|
// This case is expected if both Xcode and idb are missing.
|
||||||
@@ -225,9 +211,6 @@ export class IOSDeviceManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async checkXcodeVersionMismatch() {
|
async checkXcodeVersionMismatch() {
|
||||||
if (this.xcodeVersionMismatchFound) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
let {stdout: xcodeCLIVersion} = await exec('xcode-select -p');
|
let {stdout: xcodeCLIVersion} = await exec('xcode-select -p');
|
||||||
xcodeCLIVersion = xcodeCLIVersion!.toString().trim();
|
xcodeCLIVersion = xcodeCLIVersion!.toString().trim();
|
||||||
@@ -250,7 +233,6 @@ export class IOSDeviceManager {
|
|||||||
title: 'Xcode version mismatch',
|
title: 'Xcode version mismatch',
|
||||||
description: '' + errorMessage,
|
description: '' + errorMessage,
|
||||||
});
|
});
|
||||||
this.xcodeVersionMismatchFound = true;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user