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
@@ -20,6 +20,7 @@ const tmpFile = promisify(tmp.file);
|
||||
const tmpDir = promisify(tmp.dir);
|
||||
import iosUtil from '../fb-stubs/iOSContainerUtility';
|
||||
import {reportPlatformFailures} from './metrics';
|
||||
import adbConfig from './adbConfig';
|
||||
|
||||
// Desktop file paths
|
||||
const os = require('os');
|
||||
@@ -75,9 +76,7 @@ export default class CertificateProvider {
|
||||
|
||||
constructor(server: Server, logger: LogManager) {
|
||||
this.logger = logger;
|
||||
this.adb = adb.createClient({
|
||||
port: process.env.ANDROID_ADB_SERVER_PORT || '5037',
|
||||
});
|
||||
this.adb = adb.createClient(adbConfig());
|
||||
this.certificateSetup = reportPlatformFailures(
|
||||
this.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