Skip to content

Commit 5673981

Browse files
committed
refactor: use project dir to get project data for source map
1 parent 8d12580 commit 5673981

34 files changed

+246
-199
lines changed

lib/common/commands/device/run-application.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class RunApplicationOnDeviceCommand implements ICommand {
1515
this.$errors.failWithoutHelp("More than one device found. Specify device explicitly with --device option. To discover device ID, use $%s device command.", this.$staticConfig.CLIENT_NAME.toLowerCase());
1616
}
1717

18-
await this.$devicesService.execute(async (device: Mobile.IDevice) => await device.applicationManager.startApplication({ appId: args[0], projectName: args[1] }));
18+
await this.$devicesService.execute(async (device: Mobile.IDevice) => await device.applicationManager.startApplication({ appId: args[0], projectName: args[1], projectDir: null }));
1919
}
2020
}
2121

lib/common/commands/device/stop-application.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export class StopApplicationOnDeviceCommand implements ICommand {
99
public async execute(args: string[]): Promise<void> {
1010
await this.$devicesService.initialize({ deviceId: this.$options.device, skipInferPlatform: true, platform: args[1] });
1111

12-
const action = (device: Mobile.IDevice) => device.applicationManager.stopApplication({ appId: args[0], projectName: args[2] });
12+
const action = (device: Mobile.IDevice) => device.applicationManager.stopApplication({ appId: args[0], projectName: args[2], projectDir: null });
1313
await this.$devicesService.execute(action);
1414
}
1515
}

lib/common/definitions/mobile.d.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ declare module Mobile {
106106
}
107107

108108
interface IiOSDevice extends IDevice {
109-
getDebugSocket(appId: string, projectName: string, ensureAppStarted?: boolean): Promise<any>;
109+
getDebugSocket(appId: string, projectName: string, projectDir: string, ensureAppStarted?: boolean): Promise<any>;
110110
destroyDebugSocket(appId: string): Promise<void>;
111111
openDeviceLogStream(options?: IiOSLogStreamOptions): Promise<void>;
112112
destroyAllSockets(): Promise<void>;
@@ -145,6 +145,7 @@ declare module Mobile {
145145
device: Mobile.IDevice;
146146
getDeviceProjectRootPath(): Promise<string>;
147147
deviceSyncZipPath?: string;
148+
projectDir: string
148149
}
149150

150151
interface ILogcatStartOptions {
@@ -192,12 +193,19 @@ declare module Mobile {
192193
* @param {string} projectName The project name of the currently running application for which we need the logs.
193194
*/
194195
setProjectNameForDevice(deviceIdentifier: string, projectName: string): void;
196+
197+
/**
198+
* Sets the project name of the application on the specified device.
199+
* @param {string} deviceIdentifier The unique identifier of the device.
200+
* @param {string} projectDir The project dir of the currently running application for which we need the logs.
201+
*/
202+
setProjectDirForDevice(deviceIdentifier: string, projectDir: string): void;
195203
}
196204

197205
/**
198206
* Describes different options for filtering device logs.
199207
*/
200-
interface IDeviceLogOptions extends IDictionary<string | boolean> {
208+
interface IDeviceLogOptions extends IDictionary<string | boolean>, Partial<IProjectDir> {
201209
/**
202210
* Process id of the application on the device.
203211
*/
@@ -212,7 +220,6 @@ declare module Mobile {
212220
* The project name.
213221
*/
214222
projectName?: string;
215-
216223
}
217224

218225
/**
@@ -251,7 +258,7 @@ declare module Mobile {
251258
* Replaces file paths in device log with their original location
252259
*/
253260
interface ILogSourceMapService {
254-
replaceWithOriginalFileLocations(platform: string, messageData: string): string
261+
replaceWithOriginalFileLocations(platform: string, messageData: string, loggingOptions: Mobile.IDeviceLogOptions): string
255262
}
256263

257264
/**
@@ -273,7 +280,7 @@ declare module Mobile {
273280
full: string;
274281
}
275282

276-
interface IApplicationData {
283+
interface IApplicationData extends IProjectDir {
277284
appId: string;
278285
projectName: string;
279286
justLaunch?: boolean;
@@ -469,9 +476,9 @@ declare module Mobile {
469476
isiOSDevice(device: Mobile.IDevice): boolean;
470477
isiOSSimulator(device: Mobile.IDevice): boolean;
471478
isOnlyiOSSimultorRunning(): boolean;
472-
isAppInstalledOnDevices(deviceIdentifiers: string[], appIdentifier: string, framework: string): Promise<IAppInstalledInfo>[];
479+
isAppInstalledOnDevices(deviceIdentifiers: string[], appIdentifier: string, framework: string, projectDir: string): Promise<IAppInstalledInfo>[];
473480
setLogLevel(logLevel: string, deviceIdentifier?: string): void;
474-
deployOnDevices(deviceIdentifiers: string[], packageFile: string, packageName: string, framework: string): Promise<void>[];
481+
deployOnDevices(deviceIdentifiers: string[], packageFile: string, packageName: string, framework: string, projectDir: string): Promise<void>[];
475482
getDeviceByIdentifier(identifier: string): Mobile.IDevice;
476483
mapAbstractToTcpPort(deviceIdentifier: string, appIdentifier: string, framework: string): Promise<string>;
477484
getDebuggableApps(deviceIdentifiers: string[]): Promise<Mobile.IDeviceApplicationInformation[]>[];

lib/common/mobile/android/android-application-manager.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export class AndroidApplicationManager extends ApplicationManagerBase {
8787
const processIdentifier = await this.getAppProcessId(deviceIdentifier, appIdentifier);
8888
if (processIdentifier) {
8989
this.$deviceLogProvider.setApplicationPidForDevice(deviceIdentifier, processIdentifier);
90+
this.$deviceLogProvider.setProjectDirForDevice(deviceIdentifier, appData.projectDir);
9091
await this.$logcatHelper.start({
9192
deviceIdentifier: this.identifier,
9293
pid: processIdentifier
@@ -118,6 +119,7 @@ export class AndroidApplicationManager extends ApplicationManagerBase {
118119
public stopApplication(appData: Mobile.IApplicationData): Promise<void> {
119120
this.$logcatHelper.stop(this.identifier);
120121
this.$deviceLogProvider.setApplicationPidForDevice(this.identifier, null);
122+
this.$deviceLogProvider.setProjectDirForDevice(this.identifier, null);
121123
return this.adb.executeShellCommand(["am", "force-stop", `${appData.appId}`]);
122124
}
123125

lib/common/mobile/android/android-log-filter.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ export class AndroidLogFilter implements Mobile.IPlatformLogFilter {
4444

4545
if (match && acceptedTags.indexOf(match[1].trim()) !== -1) {
4646
consoleLogMessage = { tag: match[1].trim(), message: match[2] };
47-
consoleLogMessage.message = lineText;
4847
}
4948

5049
return consoleLogMessage;

lib/common/mobile/device-log-emitter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ export class DeviceLogEmitter extends DeviceLogProviderBase {
1212
public logData(line: string, platform: string, deviceIdentifier: string): void {
1313
this.setDefaultLogLevelForDevice(deviceIdentifier);
1414

15-
const loggingOptions = this.getDeviceLogOptionsForDevice(deviceIdentifier) || { logLevel: this.$loggingLevels.info };
15+
const loggingOptions = this.getDeviceLogOptionsForDevice(deviceIdentifier) || { logLevel: this.$loggingLevels.info, projectDir: null };
1616
let data = this.$logFilter.filterData(platform, line, loggingOptions);
17-
data = this.$logSourceMapService.replaceWithOriginalFileLocations(platform, data);
17+
data = this.$logSourceMapService.replaceWithOriginalFileLocations(platform, data, loggingOptions);
1818

1919
if (data) {
2020
this.emit('data', deviceIdentifier, data);

lib/common/mobile/device-log-provider-base.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ export abstract class DeviceLogProviderBase extends EventEmitter implements Mobi
2121
this.setDeviceLogOptionsProperty(deviceIdentifier, (deviceLogOptions: Mobile.IDeviceLogOptions) => deviceLogOptions.projectName, projectName);
2222
}
2323

24+
public setProjectDirForDevice(deviceIdentifier: string, projectDir: string): void {
25+
this.setDeviceLogOptionsProperty(deviceIdentifier, (deviceLogOptions: Mobile.IDeviceLogOptions) => deviceLogOptions.projectDir, projectDir);
26+
}
27+
2428
protected setDefaultLogLevelForDevice(deviceIdentifier: string): void {
2529
const logLevel = (this.devicesLogOptions[deviceIdentifier] && this.devicesLogOptions[deviceIdentifier].logLevel) || this.$logFilter.loggingLevel;
2630
this.setLogLevel(logLevel, deviceIdentifier);

lib/common/mobile/device-log-provider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class DeviceLogProvider extends DeviceLogProviderBase {
1212
public logData(lineText: string, platform: string, deviceIdentifier: string): void {
1313
const loggingOptions = this.getDeviceLogOptionsForDevice(deviceIdentifier);
1414
let data = this.$logFilter.filterData(platform, lineText, loggingOptions);
15-
data = this.$logSourceMapService.replaceWithOriginalFileLocations(platform, data);
15+
data = this.$logSourceMapService.replaceWithOriginalFileLocations(platform, data, loggingOptions);
1616
if (data) {
1717
this.logDataCore(data);
1818
this.emit(DEVICE_LOG_EVENT_NAME, lineText, deviceIdentifier, platform);

lib/common/mobile/ios/device/ios-application-manager.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ export class IOSApplicationManager extends ApplicationManagerBase {
9595

9696
private async setDeviceLogData(appData: Mobile.IApplicationData): Promise<void> {
9797
this.$deviceLogProvider.setProjectNameForDevice(this.device.deviceInfo.identifier, appData.projectName);
98+
this.$deviceLogProvider.setProjectDirForDevice(this.device.deviceInfo.identifier, appData.projectDir);
9899
if (!this.$options.justlaunch) {
99100
await this.startDeviceLog();
100101
}

lib/common/mobile/ios/ios-device-base.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ export abstract class IOSDeviceBase implements Mobile.IiOSDevice {
1414
abstract openDeviceLogStream(options?: Mobile.IiOSLogStreamOptions): Promise<void>;
1515

1616
@performanceLog()
17-
public async getDebugSocket(appId: string, projectName: string, ensureAppStarted: boolean = false): Promise<net.Socket> {
17+
public async getDebugSocket(appId: string, projectName: string, projectDir: string, ensureAppStarted: boolean = false): Promise<net.Socket> {
1818
return this.$lockService.executeActionWithLock(
1919
async () => {
2020
if (this.cachedSockets[appId]) {
2121
return this.cachedSockets[appId];
2222
}
2323

24-
await this.attachToDebuggerFoundEvent(appId, projectName);
24+
await this.attachToDebuggerFoundEvent(appId, projectName, projectDir);
2525
if (ensureAppStarted) {
26-
await this.applicationManager.startApplication({ appId, projectName });
26+
await this.applicationManager.startApplication({ appId, projectName, projectDir });
2727
}
2828

2929
this.cachedSockets[appId] = await this.getDebugSocketCore(appId);
@@ -42,8 +42,8 @@ export abstract class IOSDeviceBase implements Mobile.IiOSDevice {
4242

4343
protected abstract async getDebugSocketCore(appId: string): Promise<net.Socket>;
4444

45-
protected async attachToDebuggerFoundEvent(appId: string, projectName: string): Promise<void> {
46-
await this.startDeviceLogProcess(projectName);
45+
protected async attachToDebuggerFoundEvent(appId: string, projectName: string, projectDir: string): Promise<void> {
46+
await this.startDeviceLogProcess(projectName, projectDir);
4747
await this.$iOSDebuggerPortService.attachToDebuggerPortFoundEvent(appId);
4848
}
4949

@@ -78,9 +78,10 @@ export abstract class IOSDeviceBase implements Mobile.IiOSDevice {
7878
}
7979
}
8080

81-
private async startDeviceLogProcess(projectName: string): Promise<void> {
81+
private async startDeviceLogProcess(projectName: string, projectDir: string): Promise<void> {
8282
if (projectName) {
8383
this.$deviceLogProvider.setProjectNameForDevice(this.deviceInfo.identifier, projectName);
84+
this.$deviceLogProvider.setProjectDirForDevice(this.deviceInfo.identifier, projectDir);
8485
}
8586

8687
await this.openDeviceLogStream();

0 commit comments

Comments
 (0)