Use polymorphic IOSBridge to perform iOS target listing
Summary: Bulding on the work from prior diffs we can use the created bridge directly. No need to have if statements calling out to sub-functions, just use the base type itself which will use the appropriate implementation. There's no behavioural change here. Either idb was queried for sims/devices or simctl was queried for just sims, they were always mutually exclusive. Reviewed By: passy Differential Revision: D33842604 fbshipit-source-id: 0bf63ffc34368c70df31c105ea0ba5df941e72cc
This commit is contained in:
committed by
Facebook GitHub Bot
parent
b0046c8ddb
commit
757b82757e
@@ -9,7 +9,6 @@
|
|||||||
|
|
||||||
import {checkXcodeVersionMismatch} from '../iOSDeviceManager';
|
import {checkXcodeVersionMismatch} from '../iOSDeviceManager';
|
||||||
import {getLogger} from 'flipper-common';
|
import {getLogger} from 'flipper-common';
|
||||||
import {IOSBridge} from '../IOSBridge';
|
|
||||||
import {FlipperServerImpl} from '../../../FlipperServerImpl';
|
import {FlipperServerImpl} from '../../../FlipperServerImpl';
|
||||||
// eslint-disable-next-line node/no-extraneous-import
|
// eslint-disable-next-line node/no-extraneous-import
|
||||||
import {getRenderHostInstance} from 'flipper-ui-core';
|
import {getRenderHostInstance} from 'flipper-ui-core';
|
||||||
@@ -19,7 +18,9 @@ import {
|
|||||||
} from '../../../FlipperServerConfig';
|
} from '../../../FlipperServerConfig';
|
||||||
|
|
||||||
let fakeSimctlBridge: any;
|
let fakeSimctlBridge: any;
|
||||||
|
let fakeIDBBridge: any;
|
||||||
let hasCalledSimctlActiveDevices = false;
|
let hasCalledSimctlActiveDevices = false;
|
||||||
|
let hasCalledIDBActiveDevices = false;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
hasCalledSimctlActiveDevices = false;
|
hasCalledSimctlActiveDevices = false;
|
||||||
@@ -29,6 +30,12 @@ beforeEach(() => {
|
|||||||
return [];
|
return [];
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
fakeIDBBridge = {
|
||||||
|
getActiveDevices: async (_bootedOnly: boolean) => {
|
||||||
|
hasCalledIDBActiveDevices = true;
|
||||||
|
return [];
|
||||||
|
},
|
||||||
|
};
|
||||||
setFlipperServerConfig(getRenderHostInstance().serverConfig);
|
setFlipperServerConfig(getRenderHostInstance().serverConfig);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -58,26 +65,28 @@ test('test checkXcodeVersionMismatch with an incorrect Simulator.app', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('test getAllPromisesForQueryingDevices when xcode detected', () => {
|
test('test queryDevices when simctl used', () => {
|
||||||
const flipperServer = new FlipperServerImpl(
|
const flipperServer = new FlipperServerImpl(
|
||||||
getFlipperServerConfig(),
|
getFlipperServerConfig(),
|
||||||
getLogger(),
|
getLogger(),
|
||||||
);
|
);
|
||||||
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;
|
||||||
flipperServer.ios.getPromiseForQueryingDevices(false);
|
flipperServer.ios.iosBridge = fakeSimctlBridge;
|
||||||
|
flipperServer.ios.queryDevices(fakeSimctlBridge);
|
||||||
expect(hasCalledSimctlActiveDevices).toEqual(true);
|
expect(hasCalledSimctlActiveDevices).toEqual(true);
|
||||||
|
expect(hasCalledIDBActiveDevices).toEqual(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('test getAllPromisesForQueryingDevices when idb is available', () => {
|
test('test queryDevices when idb used', () => {
|
||||||
const flipperServer = new FlipperServerImpl(
|
const flipperServer = new FlipperServerImpl(
|
||||||
getFlipperServerConfig(),
|
getFlipperServerConfig(),
|
||||||
getLogger(),
|
getLogger(),
|
||||||
);
|
);
|
||||||
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;
|
||||||
flipperServer.ios.getPromiseForQueryingDevices(true);
|
flipperServer.ios.iosBridge = fakeIDBBridge;
|
||||||
|
flipperServer.ios.queryDevices(fakeIDBBridge);
|
||||||
expect(hasCalledSimctlActiveDevices).toEqual(false);
|
expect(hasCalledSimctlActiveDevices).toEqual(false);
|
||||||
|
expect(hasCalledIDBActiveDevices).toEqual(true);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -17,14 +17,12 @@ import IOSDevice from './IOSDevice';
|
|||||||
import {
|
import {
|
||||||
ERR_NO_IDB_OR_XCODE_AVAILABLE,
|
ERR_NO_IDB_OR_XCODE_AVAILABLE,
|
||||||
IOSBridge,
|
IOSBridge,
|
||||||
IDBBridge,
|
|
||||||
makeIOSBridge,
|
makeIOSBridge,
|
||||||
SimctlBridge,
|
SimctlBridge,
|
||||||
} from './IOSBridge';
|
} from './IOSBridge';
|
||||||
import {FlipperServerImpl} from '../../FlipperServerImpl';
|
import {FlipperServerImpl} from '../../FlipperServerImpl';
|
||||||
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';
|
|
||||||
|
|
||||||
export class IOSDeviceManager {
|
export class IOSDeviceManager {
|
||||||
private portForwarders: Array<ChildProcess> = [];
|
private portForwarders: Array<ChildProcess> = [];
|
||||||
@@ -88,25 +86,10 @@ export class IOSDeviceManager {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
getPromiseForQueryingDevices(isIdbAvailable: boolean): Promise<any> {
|
queryDevices(bridge: IOSBridge): Promise<any> {
|
||||||
assertNotNull(this.idbConfig);
|
return bridge
|
||||||
return isIdbAvailable
|
.getActiveDevices(true)
|
||||||
? getActiveDevices(
|
.then((devices) => this.processDevices(devices));
|
||||||
this.idbConfig.idbPath,
|
|
||||||
this.idbConfig.enablePhysicalIOS,
|
|
||||||
).then((devices: IOSDeviceParams[]) => {
|
|
||||||
this.processDevices(devices);
|
|
||||||
})
|
|
||||||
: this.getSimulators(true).then((devices) =>
|
|
||||||
this.processDevices(devices),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async queryDevices(): Promise<any> {
|
|
||||||
assertNotNull(this.idbConfig);
|
|
||||||
const isIdbAvailable = await iosUtil.isAvailable(this.idbConfig.idbPath);
|
|
||||||
console.debug(`[conn] queryDevices. isIdbAvailable ${isIdbAvailable}`);
|
|
||||||
return this.getPromiseForQueryingDevices(isIdbAvailable);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private processDevices(activeDevices: IOSDeviceParams[]) {
|
private processDevices(activeDevices: IOSDeviceParams[]) {
|
||||||
@@ -166,7 +149,7 @@ export class IOSDeviceManager {
|
|||||||
);
|
);
|
||||||
// Check for version mismatch now for immediate error handling.
|
// Check for version mismatch now for immediate error handling.
|
||||||
await this.checkXcodeVersionMismatch();
|
await this.checkXcodeVersionMismatch();
|
||||||
this.queryDevicesForever();
|
this.queryDevicesForever(this.iosBridge);
|
||||||
} 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.
|
||||||
if (err.message === ERR_NO_IDB_OR_XCODE_AVAILABLE) {
|
if (err.message === ERR_NO_IDB_OR_XCODE_AVAILABLE) {
|
||||||
@@ -198,12 +181,12 @@ export class IOSDeviceManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private queryDevicesForever() {
|
private queryDevicesForever(bridge: IOSBridge) {
|
||||||
return this.queryDevices()
|
return this.queryDevices(bridge)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
// It's important to schedule the next check AFTER the current one has completed
|
// It's important to schedule the next check AFTER the current one has completed
|
||||||
// to avoid simultaneous queries which can cause multiple user input prompts.
|
// to avoid simultaneous queries which can cause multiple user input prompts.
|
||||||
setTimeout(() => this.queryDevicesForever(), 3000);
|
setTimeout(() => this.queryDevicesForever(bridge), 3000);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.warn('Failed to continuously query devices:', err);
|
console.warn('Failed to continuously query devices:', err);
|
||||||
@@ -259,10 +242,3 @@ export function checkXcodeVersionMismatch(
|
|||||||
}
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getActiveDevices(
|
|
||||||
idbPath: string,
|
|
||||||
isPhysicalDeviceEnabled: boolean,
|
|
||||||
): Promise<Array<IOSDeviceParams>> {
|
|
||||||
return new IDBBridge(idbPath, isPhysicalDeviceEnabled).getActiveDevices(true);
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user