Skip to content

Commit 12ec39b

Browse files
author
Vladimir Enchev
committed
No break by default implementation added for iOS and Android
1 parent 6b27986 commit 12ec39b

File tree

2 files changed

+47
-38
lines changed

2 files changed

+47
-38
lines changed

lib/services/android-debug-service.ts

+33-27
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,7 @@ class AndroidDebugService implements IDebugService {
106106
return (() => {
107107
let packageFile = "";
108108

109-
if (!this.$options.debugBrk && !this.$options.start && !this.$options.getPort && !this.$options.stop) {
110-
this.$logger.warn("Neither --debug-brk nor --start option was specified. Defaulting to --debug-brk.");
111-
this.$options.debugBrk = true;
112-
}
113-
114-
if (this.$options.debugBrk && !this.$options.emulator) {
109+
if (!this.$options.start && !this.$options.emulator) {
115110
let cachedDeviceOption = this.$options.forDevice;
116111
this.$options.forDevice = true;
117112
this.$platformService.buildPlatform(this.platform).wait();
@@ -141,6 +136,12 @@ class AndroidDebugService implements IDebugService {
141136
this.detachDebugger(packageName).wait();
142137
} else if (this.$options.debugBrk) {
143138
this.startAppWithDebugger(packageFile, packageName).wait();
139+
} else {
140+
this.startAppWithDebugger(packageFile, packageName).wait();
141+
//TODO: Find different way to make sure that the app is started.
142+
sleep(500);
143+
this.attachDebugger(device.deviceInfo.identifier, packageName).wait();
144+
144145
}
145146
}).future<void>()();
146147
}
@@ -197,33 +198,38 @@ class AndroidDebugService implements IDebugService {
197198
// Arguments passed to executeShellCommand must be in array ([]), but it turned out adb shell "arg with intervals" still works correctly.
198199
// As we need to redirect output of a command on the device, keep using only one argument.
199200
// We could rewrite this with two calls - touch and rm -f , but -f flag is not available on old Android, so rm call will fail when file does not exist.
200-
this.device.adb.executeShellCommand([`cat /dev/null > /data/local/tmp/${packageName}-debugbreak`]).wait();
201+
202+
if(this.$options.debugBrk) {
203+
this.device.adb.executeShellCommand([`cat /dev/null > /data/local/tmp/${packageName}-debugbreak`]).wait();
204+
}
201205

202206
this.device.applicationManager.stopApplication(packageName).wait();
203207
this.device.applicationManager.startApplication(packageName).wait();
204-
205-
let waitText: string = `0 /data/local/tmp/${packageName}-debugbreak`;
206-
let maxWait = 12;
207-
let debugerStarted: boolean = false;
208-
while (maxWait > 0 && !debugerStarted) {
209-
let forwardsResult = this.device.adb.executeShellCommand(["ls", "-s", `/data/local/tmp/${packageName}-debugbreak`]).wait();
210-
maxWait--;
211-
debugerStarted = forwardsResult.indexOf(waitText) === -1;
212-
if (!debugerStarted) {
213-
sleep(500);
208+
209+
if(this.$options.debugBrk) {
210+
let waitText: string = `0 /data/local/tmp/${packageName}-debugbreak`;
211+
let maxWait = 12;
212+
let debugerStarted: boolean = false;
213+
while (maxWait > 0 && !debugerStarted) {
214+
let forwardsResult = this.device.adb.executeShellCommand(["ls", "-s", `/data/local/tmp/${packageName}-debugbreak`]).wait();
215+
maxWait--;
216+
debugerStarted = forwardsResult.indexOf(waitText) === -1;
217+
if (!debugerStarted) {
218+
sleep(500);
219+
}
214220
}
215-
}
216221

217-
if (debugerStarted) {
218-
this.$logger.info("# NativeScript Debugger started #");
219-
} else {
220-
this.$logger.warn("# NativeScript Debugger did not start in time #");
221-
}
222+
if (debugerStarted) {
223+
this.$logger.info("# NativeScript Debugger started #");
224+
} else {
225+
this.$logger.warn("# NativeScript Debugger did not start in time #");
226+
}
222227

223-
if (this.$options.client) {
224-
let localDebugPort = this.getForwardedLocalDebugPortForPackageName(this.device.deviceInfo.identifier, packageName).wait();
225-
this.startDebuggerClient(localDebugPort).wait();
226-
this.openDebuggerClient(AndroidDebugService.DEFAULT_NODE_INSPECTOR_URL + "?port=" + localDebugPort);
228+
if (this.$options.client) {
229+
let localDebugPort = this.getForwardedLocalDebugPortForPackageName(this.device.deviceInfo.identifier, packageName).wait();
230+
this.startDebuggerClient(localDebugPort).wait();
231+
this.openDebuggerClient(AndroidDebugService.DEFAULT_NODE_INSPECTOR_URL + "?port=" + localDebugPort);
232+
}
227233
}
228234
}).future<void>()();
229235
}

lib/services/ios-debug-service.ts

+14-11
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,23 @@ class IOSDebugService implements IDebugService {
4343
this.$errors.failWithoutHelp("Expected exactly one of the --debug-brk or --start options.");
4444
}
4545

46-
if(!this.$options.debugBrk && !this.$options.start) {
47-
this.$logger.warn("Neither --debug-brk nor --start option was specified. Defaulting to --debug-brk.");
48-
this.$options.debugBrk = true;
49-
}
50-
5146
if (this.$options.emulator) {
5247
if (this.$options.debugBrk) {
53-
return this.emulatorDebugBrk();
48+
return this.emulatorDebugBrk(true);
5449
} else if (this.$options.start) {
5550
return this.emulatorStart();
51+
} else {
52+
return this.emulatorDebugBrk();
5653
}
5754
} else {
5855
if (this.$options.debugBrk) {
59-
return this.deviceDebugBrk();
56+
return this.deviceDebugBrk(true);
6057
} else if (this.$options.start) {
58+
return this.deviceStart();
59+
} else {
60+
let deploy = this.$platformService.deployOnDevice(this.platform);
61+
deploy.wait();
62+
6163
return this.deviceStart();
6264
}
6365
}
@@ -72,14 +74,15 @@ class IOSDebugService implements IDebugService {
7274
}).future<void>()();
7375
}
7476

75-
private emulatorDebugBrk(): IFuture<void> {
77+
private emulatorDebugBrk(shouldBreak? : boolean): IFuture<void> {
7678
return (() => {
7779
let platformData = this.$platformsData.getPlatformData(this.platform);
7880
this.$platformService.buildPlatform(this.platform).wait();
7981
let emulatorPackage = this.$platformService.getLatestApplicationPackageForEmulator(platformData).wait();
8082

83+
let args = shouldBreak ? "--nativescript-debug-brk" : "--nativescript-debug-start";
8184
let child_process = this.$iOSEmulatorServices.runApplicationOnEmulator(emulatorPackage.packageName, { waitForDebugger: true, captureStdin: true,
82-
args: "--nativescript-debug-brk", appId: this.$projectData.projectId }).wait();
85+
args: args, appId: this.$projectData.projectId }).wait();
8386
let lineStream = byline(child_process.stdout);
8487

8588
lineStream.on('data', (line: NodeBuffer) => {
@@ -108,12 +111,12 @@ class IOSDebugService implements IDebugService {
108111
}).future<void>()();
109112
}
110113

111-
private deviceDebugBrk(): IFuture<void> {
114+
private deviceDebugBrk(shouldBreak? : boolean): IFuture<void> {
112115
return (() => {
113116
this.$devicesService.initialize({ platform: this.platform, deviceId: this.$options.device }).wait();
114117
this.$devicesService.execute((device: iOSDevice.IOSDevice) => (() => {
115118
if(device.isEmulator) {
116-
return this.emulatorDebugBrk().wait();
119+
return this.emulatorDebugBrk(shouldBreak).wait();
117120
}
118121
// we intentionally do not wait on this here, because if we did, we'd miss the AppLaunching notification
119122
let deploy = this.$platformService.deployOnDevice(this.platform);

0 commit comments

Comments
 (0)