Fix adb path interpolation on Windows

Summary:
Concatenating strings is not a great idea for paths. This isn't actually Windows-specific (I think) but maybe more common there. If you have a space as part of your ADB path, you're in for a world of pain.

This addressed a couple of issues but I'm sure there are more when you use it for more detailed use cases.

Closes https://github.com/facebook/flipper/issues/2438

Reviewed By: mweststrate

Differential Revision: D29061367

fbshipit-source-id: 001e498ac42bd8df6e6852be9b42fb5f38379c2e
This commit is contained in:
Pascal Hartig
2021-06-11 06:29:46 -07:00
committed by Facebook GitHub Bot
parent c52925ce6f
commit 53e612ff6f
4 changed files with 27 additions and 11 deletions

View File

@@ -14,7 +14,7 @@ import {createWriteStream} from 'fs';
import type {LogLevel, DeviceType} from 'flipper-plugin';
import which from 'which';
import {spawn} from 'child_process';
import {dirname} from 'path';
import {dirname, join} from 'path';
import {DeviceSpec} from 'flipper-plugin-lib';
const DEVICE_RECORDING_DIR = '/sdcard/flipper_recorder';
@@ -262,6 +262,13 @@ export async function launchEmulator(name: string, coldBoot: boolean = false) {
// On Linux, you must run the emulator from the directory it's in because
// reasons ...
return which('emulator')
.catch(() =>
join(
process.env.ANDROID_HOME || process.env.ANDROID_SDK_ROOT || '',
'tools',
'emulator',
),
)
.then((emulatorPath) => {
if (emulatorPath) {
const child = spawn(

View File

@@ -20,6 +20,7 @@ import {ServerPorts} from '../reducers/application';
import {Client as ADBClient} from 'adbkit';
import {addErrorNotification} from '../reducers/notifications';
import {destroyDevice} from '../reducers/connections';
import {join} from 'path';
function createDevice(
adbClient: ADBClient,
@@ -140,15 +141,17 @@ export default (store: Store, logger: Logger) => {
const watchAndroidDevices = () => {
// get emulators
promisify(which)('emulator')
.catch(
() =>
`${
process.env.ANDROID_HOME || process.env.ANDROID_SDK_ROOT || ''
}/tools/emulator`,
.catch(() =>
join(
process.env.ANDROID_HOME || process.env.ANDROID_SDK_ROOT || '',
'tools',
'emulator',
),
)
.then((emulatorPath) => {
child_process.exec(
`${emulatorPath} -list-avds`,
child_process.execFile(
emulatorPath as string,
['-list-avds'],
(error: Error | null, data: string | null) => {
if (error != null || data == null) {
console.warn('List AVD failed: ', error);
@@ -161,9 +164,12 @@ export default (store: Store, logger: Logger) => {
});
},
);
})
.catch((err) => {
console.warn('Failed to query AVDs:', err);
});
getAdbClient(store)
return getAdbClient(store)
.then((client) => {
client
.trackDevices()

View File

@@ -8,7 +8,7 @@
*/
import {reportPlatformFailures} from './metrics';
import {exec} from 'promisify-child-process';
import {execFile} from 'promisify-child-process';
import promiseRetry from 'promise-retry';
import adbConfig from '../utils/adbConfig';
import adbkit, {Client} from 'adbkit';
@@ -32,7 +32,7 @@ function createClient(store: Store): Promise<Client> {
const androidHome = store.getState().settingsState.androidHome;
const adbPath = path.resolve(androidHome, 'platform-tools/adb');
return reportPlatformFailures<Client>(
exec(`${adbPath} start-server`).then(() =>
execFile(adbPath, ['start-server']).then(() =>
adbkit.createClient(adbConfig()),
),
'createADBClient.shell',

View File

@@ -594,5 +594,8 @@
],
"raincloud": [
16
],
"app-microsoft-windows-outline": [
24
]
}