get adb config from env vars
Summary: REact adb config from env vars: - `ADB_SERVER_SOCKET` - `ANDROID_ADB_SERVER_PORT` Reviewed By: lawrencelomax Differential Revision: D14002603 fbshipit-source-id: e30fa4354ab15048d4350654979fd0b6f394cd89
This commit is contained in:
committed by
Facebook Github Bot
parent
3c35d6d4cf
commit
6431d374c2
@@ -14,6 +14,7 @@ import type BaseDevice from '../devices/BaseDevice';
|
|||||||
import type Logger from '../fb-stubs/Logger.js';
|
import type Logger from '../fb-stubs/Logger.js';
|
||||||
import {registerDeviceCallbackOnPlugins} from '../utils/onRegisterDevice.js';
|
import {registerDeviceCallbackOnPlugins} from '../utils/onRegisterDevice.js';
|
||||||
import {reportPlatformFailures} from '../utils/metrics';
|
import {reportPlatformFailures} from '../utils/metrics';
|
||||||
|
import adbConfig from '../utils/adbConfig';
|
||||||
const adb = require('adbkit-fb');
|
const adb = require('adbkit-fb');
|
||||||
|
|
||||||
function createDevice(
|
function createDevice(
|
||||||
@@ -79,11 +80,7 @@ export default (store: Store, logger: Logger) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(() =>
|
.then(() => adb.createClient(adbConfig())),
|
||||||
adb.createClient({
|
|
||||||
port: process.env.ANDROID_ADB_SERVER_PORT || '5037',
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
'createADBClient.shell',
|
'createADBClient.shell',
|
||||||
).catch(err => {
|
).catch(err => {
|
||||||
console.error(
|
console.error(
|
||||||
@@ -92,7 +89,7 @@ export default (store: Store, logger: Logger) => {
|
|||||||
|
|
||||||
/* In the event that starting adb with the above method fails, fallback
|
/* In the event that starting adb with the above method fails, fallback
|
||||||
to using adbkit, though its known to be unreliable. */
|
to using adbkit, though its known to be unreliable. */
|
||||||
const unsafeClient = adb.createClient();
|
const unsafeClient = adb.createClient(adbConfig());
|
||||||
return reportPlatformFailures(
|
return reportPlatformFailures(
|
||||||
promiseRetry(
|
promiseRetry(
|
||||||
(retry, number) => {
|
(retry, number) => {
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ const tmpFile = promisify(tmp.file);
|
|||||||
const tmpDir = promisify(tmp.dir);
|
const tmpDir = promisify(tmp.dir);
|
||||||
import iosUtil from '../fb-stubs/iOSContainerUtility';
|
import iosUtil from '../fb-stubs/iOSContainerUtility';
|
||||||
import {reportPlatformFailures} from './metrics';
|
import {reportPlatformFailures} from './metrics';
|
||||||
|
import adbConfig from './adbConfig';
|
||||||
|
|
||||||
// Desktop file paths
|
// Desktop file paths
|
||||||
const os = require('os');
|
const os = require('os');
|
||||||
@@ -75,9 +76,7 @@ export default class CertificateProvider {
|
|||||||
|
|
||||||
constructor(server: Server, logger: LogManager) {
|
constructor(server: Server, logger: LogManager) {
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
this.adb = adb.createClient({
|
this.adb = adb.createClient(adbConfig());
|
||||||
port: process.env.ANDROID_ADB_SERVER_PORT || '5037',
|
|
||||||
});
|
|
||||||
this.certificateSetup = reportPlatformFailures(
|
this.certificateSetup = reportPlatformFailures(
|
||||||
this.ensureServerCertExists(),
|
this.ensureServerCertExists(),
|
||||||
'ensureServerCertExists',
|
'ensureServerCertExists',
|
||||||
|
|||||||
45
src/utils/__tests__/adbConfig.js
Normal file
45
src/utils/__tests__/adbConfig.js
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2018-present Facebook.
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
* @format
|
||||||
|
*/
|
||||||
|
|
||||||
|
import adbConfig from '../adbConfig';
|
||||||
|
|
||||||
|
test('get host and port from ADB_SERVER_SOCKET', () => {
|
||||||
|
process.env.ANDROID_ADB_SERVER_PORT = undefined;
|
||||||
|
process.env.ADB_SERVER_SOCKET = 'tcp:127.0.0.1:5037';
|
||||||
|
const {port, host} = adbConfig();
|
||||||
|
expect(port).toBe(5037);
|
||||||
|
expect(host).toBe('127.0.0.1');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('get IPv6 address from ADB_SERVER_SOCKET', () => {
|
||||||
|
process.env.ANDROID_ADB_SERVER_PORT = undefined;
|
||||||
|
process.env.ADB_SERVER_SOCKET = 'tcp::::1:5037';
|
||||||
|
const {host} = adbConfig();
|
||||||
|
expect(host).toBe(':::1');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('get port from ANDROID_ADB_SERVER_PORT', () => {
|
||||||
|
process.env.ANDROID_ADB_SERVER_PORT = '1337';
|
||||||
|
process.env.ADB_SERVER_SOCKET = undefined;
|
||||||
|
const {port} = adbConfig();
|
||||||
|
expect(port).toBe(1337);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('prefer ADB_SERVER_SOCKET over ANDROID_ADB_SERVER_PORT', () => {
|
||||||
|
process.env.ANDROID_ADB_SERVER_PORT = '1337';
|
||||||
|
process.env.ADB_SERVER_SOCKET = 'tcp:127.0.0.1:5037';
|
||||||
|
const {port} = adbConfig();
|
||||||
|
expect(port).toBe(5037);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('have defaults', () => {
|
||||||
|
process.env.ANDROID_ADB_SERVER_PORT = undefined;
|
||||||
|
process.env.ADB_SERVER_SOCKET = undefined;
|
||||||
|
const {port, host} = adbConfig();
|
||||||
|
expect(port).toBe(5037);
|
||||||
|
expect(host).toBe('localhost');
|
||||||
|
});
|
||||||
25
src/utils/adbConfig.js
Normal file
25
src/utils/adbConfig.js
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2018-present Facebook.
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
* @format
|
||||||
|
*/
|
||||||
|
|
||||||
|
export default () => {
|
||||||
|
let port = parseInt(process.env.ANDROID_ADB_SERVER_PORT, 10) || 5037;
|
||||||
|
let host = 'localhost';
|
||||||
|
|
||||||
|
const socket = (process.env.ADB_SERVER_SOCKET || '').trim();
|
||||||
|
if (socket && socket.length > 0) {
|
||||||
|
const match = socket.match(/^(tcp:)(\S+):(\d+)/);
|
||||||
|
if (match && match.length === 4) {
|
||||||
|
host = match[2];
|
||||||
|
port = parseInt(match[3], 10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
port,
|
||||||
|
host,
|
||||||
|
};
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user