Skip to content

Commit 83f3410

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

File tree

4 files changed

+50
-37
lines changed

4 files changed

+50
-37
lines changed

docs/man_pages/project/testing/debug-android.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
debug android
22
==========
33

4+
All you need to do to start debugging your app is to execute `tns debug android`. The NativeScript CLI will build, deploy, start your app, start Chrome DevTools and attach the debugger.
5+
* You cannot debug if there are multiple devices available (emulators and/or real devices). You need to have started only one device or emulator.
6+
47
Usage | Synopsis
58
---|---
69
Deploy on device, run the app and stop at the first breakpoint | `$ tns debug android --debug-brk [--device <Device ID>] [--debug-port <port>] [--timeout <timeout>]`

docs/man_pages/project/testing/debug-ios.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
debug ios
22
==========
3+
All you need to do to start debugging your app is to execute `tns debug ios`. The NativeScript CLI will build, deploy, start your app, start Chrome DevTools and attach the debugger.
4+
* You cannot debug if there are multiple devices available (emulators and/or real devices). You need to have started only one device or emulator.
35

46
Usage | Synopsis
57
---|---

lib/services/android-debug-service.ts

+31-26
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,11 @@ 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();
144144
}
145145
}).future<void>()();
146146
}
@@ -197,33 +197,38 @@ class AndroidDebugService implements IDebugService {
197197
// Arguments passed to executeShellCommand must be in array ([]), but it turned out adb shell "arg with intervals" still works correctly.
198198
// As we need to redirect output of a command on the device, keep using only one argument.
199199
// 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();
200+
201+
if(this.$options.debugBrk) {
202+
this.device.adb.executeShellCommand([`cat /dev/null > /data/local/tmp/${packageName}-debugbreak`]).wait();
203+
}
201204

202205
this.device.applicationManager.stopApplication(packageName).wait();
203206
this.device.applicationManager.startApplication(packageName).wait();
204207

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+
if(this.$options.debugBrk) {
209+
let waitText: string = `0 /data/local/tmp/${packageName}-debugbreak`;
210+
let maxWait = 12;
211+
let debugerStarted: boolean = false;
212+
while (maxWait > 0 && !debugerStarted) {
213+
let forwardsResult = this.device.adb.executeShellCommand(["ls", "-s", `/data/local/tmp/${packageName}-debugbreak`]).wait();
214+
maxWait--;
215+
debugerStarted = forwardsResult.indexOf(waitText) === -1;
216+
if (!debugerStarted) {
217+
sleep(500);
218+
}
214219
}
215-
}
216220

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

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);
227+
if (this.$options.client) {
228+
let localDebugPort = this.getForwardedLocalDebugPortForPackageName(this.device.deviceInfo.identifier, packageName).wait();
229+
this.startDebuggerClient(localDebugPort).wait();
230+
this.openDebuggerClient(AndroidDebugService.DEFAULT_NODE_INSPECTOR_URL + "?port=" + localDebugPort);
231+
}
227232
}
228233
}).future<void>()();
229234
}

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)