Skip to content

Commit 929f14c

Browse files
committed
Add option to print stderr.
1 parent 5fd25bf commit 929f14c

File tree

7 files changed

+121
-62
lines changed

7 files changed

+121
-62
lines changed

lib/definitions/NodObjC.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ declare module "NodObjC" {
77
export var NSNumber: INSNumber;
88
export var NSBundle: INSBundle;
99
export var NSAutoreleasePool: INSAutoreleasePool;
10-
export var NSRunLoop: INSRunLoop;
10+
export var kCFRunLoopDefaultMode: INSString;
11+
export function CFRunLoopRunInMode(mode: INSString, seconds: number, returnAfterSourceHandled: boolean): number;
1112

1213
interface IClass {
1314
getClassByName(className: string): any;

lib/ios-sim.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,3 @@ var fiber = Fiber(() => {
1414
});
1515

1616
fiber.run();
17-
18-

lib/iphone-simulator-xcode-5.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class XCode5Simulator implements ISimulator {
2020
"iPad": "iPad",
2121
"iPad-Retina": "iPad Retina",
2222
"iPad-Retina-64-bit": "iPad Retina (64-bit)"
23-
}
23+
};
2424

2525
public get validDeviceIdentifiers(): string[] {
2626
return _.keys(XCode5Simulator.allowedDeviceIdentifiers);

lib/iphone-simulator.js

Lines changed: 52 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/iphone-simulator.ts

Lines changed: 57 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ export class iPhoneSimulator implements IiPhoneSimulator {
3434
errors.fail("Path does not exist ", appPath);
3535
}
3636

37-
return this.execute(this.launch, { canRunMainLoop: true, appPath: appPath});
37+
return this.execute(this.launch, { canRunMainLoop: true, appPath: appPath });
3838
}
3939

4040
public printDeviceTypes(): IFuture<void> {
4141
var action = () => {
4242
var simulator = this.createSimulator();
4343
_.each(simulator.deviceIdentifiersInfo, (identifier: any) => console.log(identifier));
44-
}
44+
};
4545

4646
return this.execute(action, { canRunMainLoop: false });
4747
}
@@ -71,27 +71,35 @@ export class iPhoneSimulator implements IiPhoneSimulator {
7171
}
7272

7373
private execute(action: (appPath?: string) => any, opts: IExecuteOptions): IFuture<void> {
74-
return (() => {
75-
$.importFramework(iPhoneSimulator.FOUNDATION_FRAMEWORK_NAME);
76-
$.importFramework(iPhoneSimulator.APPKIT_FRAMEWORK_NAME);
74+
$.importFramework(iPhoneSimulator.FOUNDATION_FRAMEWORK_NAME);
75+
$.importFramework(iPhoneSimulator.APPKIT_FRAMEWORK_NAME);
7776

78-
var pool = $.NSAutoreleasePool("alloc")("init");
79-
80-
var developerDirectoryPath = this.findDeveloperDirectory().wait();
81-
if(!developerDirectoryPath) {
82-
errors.fail("Unable to find developer directory");
83-
}
77+
var pool = $.NSAutoreleasePool("alloc")("init");
8478

85-
this.loadFrameworks(developerDirectoryPath);
86-
87-
action.apply(this, [opts.appPath]);
88-
89-
if(opts.canRunMainLoop) {
90-
$.NSRunLoop("mainRunLoop")("run");
91-
}
79+
var developerDirectoryPath = this.findDeveloperDirectory().wait();
80+
if(!developerDirectoryPath) {
81+
errors.fail("Unable to find developer directory");
82+
}
9283

93-
pool("release");
94-
}).future<void>()();
84+
this.loadFrameworks(developerDirectoryPath);
85+
86+
action.apply(this, [opts.appPath]);
87+
88+
var future = new Future<void>();
89+
if(opts.canRunMainLoop) {
90+
// Keeps the Node loop running
91+
(function runLoop() {
92+
if($.CFRunLoopRunInMode($.kCFRunLoopDefaultMode, 0.1, false)) {
93+
setTimeout(runLoop, 0);
94+
} else {
95+
pool("release");
96+
future.return();
97+
}
98+
}());
99+
} else {
100+
future.return();
101+
}
102+
return future;
95103
}
96104

97105
private launch(appPath: string): void {
@@ -124,12 +132,18 @@ export class iPhoneSimulator implements IiPhoneSimulator {
124132
}
125133
simulator.setSimulatedDevice(config);
126134

127-
if(options.stderr) {
128-
config("setSimulatedApplicationStdErrPath", $(options.stderr));
129-
}
130-
131-
if(options.stdout) {
132-
config("setSimulatedApplicationStdOutPath", $(options.stdout));
135+
if(options.logging) {
136+
var logPath = this.createLogPipe(appPath).wait();
137+
fs.createReadStream(logPath, { encoding: "utf8" }).pipe(process.stdout);
138+
config("setSimulatedApplicationStdErrPath", $(logPath));
139+
config("setSimulatedApplicationStdOutPath", $(logPath));
140+
} else {
141+
if(options.stderr) {
142+
config("setSimulatedApplicationStdErrPath", $(options.stderr));
143+
}
144+
if(options.stdout) {
145+
config("setSimulatedApplicationStdOutPath", $(options.stdout));
146+
}
133147
}
134148

135149
config("setLocalizedClientName", $("ios-sim-portable"));
@@ -180,7 +194,7 @@ export class iPhoneSimulator implements IiPhoneSimulator {
180194
}
181195

182196
private loadFramework(frameworkPath: string) {
183-
var bundle = $.NSBundle("bundleWithPath", $(frameworkPath));
197+
var bundle = $.NSBundle("bundleWithPath", $(frameworkPath));
184198
if(!bundle("load")) {
185199
errors.fail("Unable to load ", frameworkPath);
186200
}
@@ -244,6 +258,22 @@ export class iPhoneSimulator implements IiPhoneSimulator {
244258

245259
return simulator;
246260
}
261+
262+
private createLogPipe(appPath: string): IFuture<string> {
263+
var future = new Future<string>();
264+
var logPath = path.join(path.dirname(appPath), "." + path.basename(appPath, ".app") + ".log");
265+
266+
var command = util.format("rm -f %s && mkfifo %s", logPath, logPath);
267+
child_process.exec(command, (error: Error, stdout: NodeBuffer, stderr: NodeBuffer) => {
268+
if(error) {
269+
future.throw(error);
270+
} else {
271+
future.return(logPath);
272+
}
273+
});
274+
275+
return future;
276+
}
247277
}
248278

249279
class Sdk implements ISdk {

lib/options.js

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/options.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ var knownOptions: any = {
1212
"env": String,
1313
"args": String,
1414
"timeout": String,
15-
"help": Boolean
15+
"help": Boolean,
16+
"logging": Boolean
1617
};
1718

18-
var parsed = {};
19+
var parsed: any = {};
1920

2021
_.each(_.keys(knownOptions), opt => {
2122
var type = knownOptions[opt];
@@ -26,7 +27,6 @@ _.each(_.keys(knownOptions), opt => {
2627
}
2728
});
2829

29-
_.each(_.keys(yargs.argv), opt => exports[opt] = yargs.argv[opt]);
30+
_.each(_.keys(yargs.argv), opt => parsed[opt] = yargs.argv[opt]);
3031

31-
declare var exports: any;
32-
export = exports;
32+
export = parsed;

0 commit comments

Comments
 (0)