Support externally started IDB companion
Reviewed By: lblasa Differential Revision: D37453361 fbshipit-source-id: 2acd53ae40c8a3f8971ee47cb5161c371be6d3a9
This commit is contained in:
committed by
Facebook GitHub Bot
parent
9a72169819
commit
c88e8e07d0
@@ -101,23 +101,29 @@ export async function queryTargetsWithoutXcodeDependency(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parseIdbTarget(line: string): DeviceTarget | undefined {
|
||||||
|
const parsed: IdbTarget = JSON.parse(line);
|
||||||
|
if (parsed.state.toLocaleLowerCase() !== 'booted') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
udid: parsed.udid,
|
||||||
|
type:
|
||||||
|
(parsed.type || parsed.target_type) === 'simulator'
|
||||||
|
? 'emulator'
|
||||||
|
: ('physical' as DeviceType),
|
||||||
|
name: parsed.name,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function parseIdbTargets(lines: string): Array<DeviceTarget> {
|
function parseIdbTargets(lines: string): Array<DeviceTarget> {
|
||||||
const parsedIdbTargets = lines
|
const parsedIdbTargets = lines
|
||||||
.trim()
|
.trim()
|
||||||
.split('\n')
|
.split('\n')
|
||||||
.map((line) => line.trim())
|
.map((line) => line.trim())
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
.map((line) => JSON.parse(line))
|
.map((line) => parseIdbTarget(line))
|
||||||
.filter(({state}: IdbTarget) => state.toLocaleLowerCase() === 'booted')
|
.filter((target): target is DeviceTarget => !!target);
|
||||||
.map<IdbTarget>(({type, target_type, ...rest}: IdbTarget) => ({
|
|
||||||
type: (type || target_type) === 'simulator' ? 'emulator' : 'physical',
|
|
||||||
...rest,
|
|
||||||
}))
|
|
||||||
.map<DeviceTarget>((target: IdbTarget) => ({
|
|
||||||
udid: target.udid,
|
|
||||||
type: target.type as DeviceType,
|
|
||||||
name: target.name,
|
|
||||||
}));
|
|
||||||
|
|
||||||
// For some reason, idb can return duplicates
|
// For some reason, idb can return duplicates
|
||||||
// TODO: Raise the issue with idb
|
// TODO: Raise the issue with idb
|
||||||
@@ -146,6 +152,23 @@ export async function idbListTargets(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function idbDescribeTarget(
|
||||||
|
idbPath: string,
|
||||||
|
safeExecFunc: (
|
||||||
|
command: string,
|
||||||
|
) => Promise<{stdout: string; stderr: string} | Output> = safeExec,
|
||||||
|
): Promise<DeviceTarget | undefined> {
|
||||||
|
return safeExecFunc(`${idbPath} describe --json`)
|
||||||
|
.then(({stdout}) =>
|
||||||
|
// See above.
|
||||||
|
parseIdbTarget(stdout!.toString()),
|
||||||
|
)
|
||||||
|
.catch((e: Error) => {
|
||||||
|
console.warn('Failed to query idb to describe a target:', e);
|
||||||
|
return undefined;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async function targets(
|
async function targets(
|
||||||
idbPath: string,
|
idbPath: string,
|
||||||
isPhysicalDeviceEnabled: boolean,
|
isPhysicalDeviceEnabled: boolean,
|
||||||
@@ -154,6 +177,14 @@ async function targets(
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If companion is started by some external process and its address provided to Flipper via IDB_COMPANION environment variable,
|
||||||
|
// use that companion and do not query other devices
|
||||||
|
// See stack of D36315576 for details
|
||||||
|
if (process.env.IDB_COMPANION) {
|
||||||
|
const target = await idbDescribeTarget(idbPath);
|
||||||
|
return target ? [target] : [];
|
||||||
|
}
|
||||||
|
|
||||||
const isXcodeInstalled = await isXcodeDetected();
|
const isXcodeInstalled = await isXcodeDetected();
|
||||||
if (!isXcodeInstalled) {
|
if (!isXcodeInstalled) {
|
||||||
if (!isPhysicalDeviceEnabled) {
|
if (!isPhysicalDeviceEnabled) {
|
||||||
|
|||||||
Reference in New Issue
Block a user