Wrap command execution in util

Summary:
Take the low level execution details out of the healthchecks.

The xcode-select change is sound because `xcode-select -p` returns status code > 0 when not set, so exec will throw, so no need to inspect stdout.

Reviewed By: passy

Differential Revision: D18449564

fbshipit-source-id: b2e2797a51aca45cfd78e707e99341798401897c
This commit is contained in:
John Knox
2019-11-12 06:53:57 -08:00
committed by Facebook Github Bot
parent 999e3784b8
commit 22a86747d4

View File

@@ -44,9 +44,7 @@ export function getHealthchecks(): Healthchecks {
label: 'OpenSSL Installed', label: 'OpenSSL Installed',
isRequired: true, isRequired: true,
run: async (_: EnvironmentInfo) => { run: async (_: EnvironmentInfo) => {
const isAvailable = await promisify(exec)('openssl version') const isAvailable = await commandSucceeds('openssl version');
.then(() => true)
.catch(() => false);
return { return {
hasProblem: !isAvailable, hasProblem: !isAvailable,
}; };
@@ -91,20 +89,16 @@ export function getHealthchecks(): Healthchecks {
label: 'xcode-select set', label: 'xcode-select set',
isRequired: true, isRequired: true,
run: async (_: EnvironmentInfo) => ({ run: async (_: EnvironmentInfo) => ({
hasProblem: hasProblem: !(await commandSucceeds('xcode-select -p')),
(await promisify(exec)('xcode-select -p')).stdout.trim()
.length < 1,
}), }),
}, },
{ {
label: 'Instruments exists', label: 'Instruments exists',
isRequired: true, isRequired: true,
run: async (_: EnvironmentInfo) => { run: async (_: EnvironmentInfo) => {
const hasInstruments = await promisify(exec)( const hasInstruments = await commandSucceeds(
'which instruments', 'which instruments',
) );
.then(_ => true)
.catch(_ => false);
return { return {
hasProblem: !hasInstruments, hasProblem: !hasInstruments,
@@ -146,3 +140,9 @@ export async function runHealthchecks() {
); );
return results; return results;
} }
async function commandSucceeds(command: string): Promise<boolean> {
return await promisify(exec)(command)
.then(() => true)
.catch(() => false);
}