Fix avd device name resolution with GNU netcat
Summary: Device connection didn't work on Linux due to netcat behaving differently. I also played around with the `nc` and `node-netcat` packages, but they would either crash the node stack or fail to compile with Babel. Oh glorious JavaScript world. Reviewed By: danielbuechele Differential Revision: D9194591 fbshipit-source-id: 58e5b8d6b4a66e791e750de2f1449dcb8fc338ae
This commit is contained in:
committed by
Facebook Github Bot
parent
fc7f949daf
commit
b8c568e3e4
@@ -34,10 +34,15 @@ function createDecive(client, device): Promise<AndroidDevice> {
|
||||
function getRunningEmulatorName(id: string): Promise<?string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const port = id.replace('emulator-', '');
|
||||
// The GNU version of netcat doesn't terminate after 1s when
|
||||
// specifying `-w 1`, so we kill it after a timeout. Because
|
||||
// of that, even in case of an error, there may still be
|
||||
// relevant data for us to parse.
|
||||
child_process.exec(
|
||||
`echo "avd name" | nc -w 1 localhost ${port}`,
|
||||
(error: ?Error, data: ?string) => {
|
||||
if (error == null && data != null) {
|
||||
{timeout: 1000, encoding: 'utf-8'},
|
||||
(error: ?Error, data) => {
|
||||
if (data != null && typeof data === 'string') {
|
||||
const match = data.trim().match(/(.*)\r\nOK$/);
|
||||
resolve(match != null && match.length > 0 ? match[1] : null);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user