Fix adb path check on Windows (#3434)
Summary: The adb path check seem to be platform dependent Instead of pre-validating the path we can execute the intended command and retry with an alternative adb path only if it fails with file not found error Related to https://github.com/facebook/flipper/issues/3430 (adb is not detected) ## Changelog Fix ADB detection and startup on Windows Pull Request resolved: https://github.com/facebook/flipper/pull/3434 Test Plan: #### adb is detected successfully when `adb.exe` is in `platform-tools`  #### Falling back to alternative path when `adb.exe` is the SDK folder  #### Otherwise failing if `adb.exe` is not found  Reviewed By: passy Differential Revision: D34240518 Pulled By: aigoncharov fbshipit-source-id: db834bbdc9815e5ad41f7a1329ec8d5869f6f24b
This commit is contained in:
committed by
Facebook GitHub Bot
parent
e52c0dfa78
commit
9d2f11f505
@@ -12,7 +12,6 @@ import {execFile} from 'promisify-child-process';
|
||||
import adbConfig from './adbConfig';
|
||||
import adbkit, {Client} from 'adbkit';
|
||||
import path from 'path';
|
||||
import {pathExists} from 'fs-extra';
|
||||
|
||||
type Config = {
|
||||
androidHome: string;
|
||||
@@ -37,16 +36,24 @@ export async function initializeAdbClient(
|
||||
however, it sometimes fails with ENOENT errors. So instead, we start it
|
||||
manually before requesting a client. */
|
||||
async function createClient(config: Config): Promise<Client> {
|
||||
const androidHome = config.androidHome;
|
||||
let adbPath = path.resolve(androidHome, 'platform-tools', 'adb');
|
||||
if (!(await pathExists(adbPath))) {
|
||||
console.info('falling back to the alternative adb path');
|
||||
adbPath = path.resolve(androidHome, 'adb');
|
||||
}
|
||||
return reportPlatformFailures<Client>(
|
||||
execFile(adbPath, ['start-server']).then(() =>
|
||||
startAdbServer(config.androidHome).then(() =>
|
||||
adbkit.createClient(adbConfig()),
|
||||
),
|
||||
'createADBClient.shell',
|
||||
);
|
||||
}
|
||||
|
||||
async function startAdbServer(androidHome: string) {
|
||||
const adbPath = path.resolve(androidHome, 'platform-tools', 'adb');
|
||||
const args = ['start-server'];
|
||||
|
||||
return execFile(adbPath, args).catch((error) => {
|
||||
if (error.code == 'ENOENT') {
|
||||
console.info('falling back to the alternative adb path');
|
||||
return execFile(path.resolve(androidHome, 'adb'), args);
|
||||
}
|
||||
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user