Skip to content

Commit 72619c0

Browse files
Move logic for getting PID of application from iOS Sim to common
Move the logic for getting PID of application started on iOS Simulator to mobile-cli-lib. Add new helper method to get the process ID of an application from iOS Simulator Logs. Whenever we start an application on iOS Simulator, in its logs we can find the PID of the process in the following format: ``` <app id>: <app id>: <PID> ``` Add unit tests for the method.
1 parent 8180c70 commit 72619c0

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

lib/services/ios-debug-service.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as log4js from "log4js";
55
import { ChildProcess } from "child_process";
66
import { DebugServiceBase } from "./debug-service-base";
77
import { CONNECTION_ERROR_EVENT_NAME } from "../constants";
8+
import { getPidFromiOSSimulatorLogs } from "../common/helpers";
89

910
import byline = require("byline");
1011

@@ -103,19 +104,16 @@ class IOSDebugService extends DebugServiceBase implements IPlatformDebugService
103104

104105
let lineStream = byline(child_process.stdout);
105106
this._childProcess = child_process;
106-
const pidRegExp = new RegExp(`${debugData.applicationIdentifier}:\\s?(\\d+)`);
107107

108108
lineStream.on('data', (line: NodeBuffer) => {
109109
let lineText = line.toString();
110110
if (lineText && _.startsWith(lineText, debugData.applicationIdentifier)) {
111-
const pidMatch = lineText.match(pidRegExp);
112-
113-
if (!pidMatch) {
114-
this.$logger.trace(`Line ${lineText} does not contain the searched pattern: ${pidRegExp}.`);
111+
const pid = getPidFromiOSSimulatorLogs(debugData.applicationIdentifier, lineText);
112+
if (!pid) {
113+
this.$logger.trace(`Line ${lineText} does not contain PID of the application ${debugData.applicationIdentifier}.`);
115114
return;
116115
}
117116

118-
const pid = pidMatch[1];
119117
this._lldbProcess = this.$childProcess.spawn("lldb", ["-p", pid]);
120118
if (log4js.levels.TRACE.isGreaterThanOrEqualTo(this.$logger.getLevel())) {
121119
this._lldbProcess.stdout.pipe(process.stdout);

0 commit comments

Comments
 (0)