Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

More arguments, new format #5

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
build
iphonesim
.DS_Store
1 change: 1 addition & 0 deletions Source/iPhoneSimulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
@interface iPhoneSimulator : NSObject <DTiPhoneSimulatorSessionDelegate> {
@private
DTiPhoneSimulatorSystemRoot *sdkRoot;
BOOL verbose;
}

- (void) runWithArgc: (int) argc argv: (char **) argv;
Expand Down
146 changes: 103 additions & 43 deletions Source/iPhoneSimulator.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ - (void) printUsage {
fprintf(stderr, "Usage: iphonesim <options> <command> ...\n");
fprintf(stderr, "Commands:\n");
fprintf(stderr, " showsdks\n");
fprintf(stderr, " launch <application path> [sdkversion] [family] [uuid]\n");
fprintf(stderr, " launch <application path> [-verbose] [-sdk <sdkversion>] [-family ipad] [-uuid <uuid>] [-env <environment file path>] [-stdout <path to stdout file>] [-stderr <path to stderr file>] [-args <remaining arguments passed through to launched application>]\n");
}


Expand All @@ -64,7 +64,9 @@ - (int) showSDKs {
}

- (void) session: (DTiPhoneSimulatorSession *) session didEndWithError: (NSError *) error {
nsprintf(@"Session did end with error %@", error);
if (verbose) {
nsprintf(@"Session did end with error %@", error);
}

if (error != nil)
exit(EXIT_FAILURE);
Expand All @@ -75,9 +77,20 @@ - (void) session: (DTiPhoneSimulatorSession *) session didEndWithError: (NSError

- (void) session: (DTiPhoneSimulatorSession *) session didStart: (BOOL) started withError: (NSError *) error {
if (started) {
nsprintf(@"Session started");
if (verbose) {
nsprintf(@"Session started");
}
} else {
nsprintf(@"Session could not be started: %@", error);
NSMutableArray *errorLines = [NSMutableArray arrayWithObject:@"Session could not be started (errors below):"];
for (NSError *innerError = error; innerError != nil; innerError = [[innerError userInfo] objectForKey:NSUnderlyingErrorKey]) {
[errorLines addObject:[NSString stringWithFormat:
@"%@ %@ %@",
innerError,
[innerError localizedDescription],
[innerError userInfo]]];
}
NSString *errorMessage = [errorLines componentsJoinedByString:@"\n"];
nsprintf(errorMessage);
exit(EXIT_FAILURE);
}
}
Expand All @@ -86,7 +99,7 @@ - (void) session: (DTiPhoneSimulatorSession *) session didStart: (BOOL) started
/**
* Launch the given Simulator binary.
*/
- (int) launchApp: (NSString *) path withFamily:(NSString*)family uuid:(NSString*)uuid{
- (int) launchApp: (NSString *) path withFamily:(NSString*)family uuid:(NSString*)uuid environment:(NSDictionary *) environment stdoutPath: (NSString *) stdoutPath stderrPath: (NSString *) stderrPath args: (NSArray *) args{
DTiPhoneSimulatorApplicationSpecifier *appSpec;
DTiPhoneSimulatorSessionConfig *config;
DTiPhoneSimulatorSession *session;
Expand All @@ -98,20 +111,30 @@ - (int) launchApp: (NSString *) path withFamily:(NSString*)family uuid:(NSString
nsprintf(@"Could not load application specification for %s", path);
return EXIT_FAILURE;
}
nsprintf(@"App Spec: %@", appSpec);

/* Load the default SDK root */

nsprintf(@"SDK Root: %@", sdkRoot);
if (verbose) {
nsprintf(@"App Spec: %@", appSpec);

/* Load the default SDK root */

nsprintf(@"SDK Root: %@", sdkRoot);
}

/* Set up the session configuration */
config = [[[DTiPhoneSimulatorSessionConfig alloc] init] autorelease];
[config setApplicationToSimulateOnStart: appSpec];
[config setSimulatedSystemRoot: sdkRoot];
[config setSimulatedApplicationShouldWaitForDebugger: NO];

[config setSimulatedApplicationLaunchArgs: [NSArray array]];
[config setSimulatedApplicationLaunchEnvironment: [NSDictionary dictionary]];
[config setSimulatedApplicationLaunchArgs: args];
[config setSimulatedApplicationLaunchEnvironment: environment];

if (stderrPath) {
[config setSimulatedApplicationStdErrPath:stderrPath];
}

if (stdoutPath) {
[config setSimulatedApplicationStdOutPath:stdoutPath];
}

[config setLocalizedClientName: @"TitaniumDeveloper"];

Expand All @@ -123,7 +146,9 @@ - (int) launchApp: (NSString *) path withFamily:(NSString*)family uuid:(NSString
family = @"iphone";
}

nsprintf(@"using device family %@",family);
if (verbose) {
nsprintf(@"using device family %@",family);
}

if ([family isEqualToString:@"ipad"])
{
Expand Down Expand Up @@ -173,40 +198,75 @@ - (void) runWithArgc: (int) argc argv: (char **) argv {
[self printUsage];
exit(EXIT_FAILURE);
}
if (argc > 3) {
NSString* ver = [NSString stringWithCString:argv[3] encoding:NSUTF8StringEncoding];
NSArray *roots = [DTiPhoneSimulatorSystemRoot knownRoots];
for (DTiPhoneSimulatorSystemRoot *root in roots) {
NSString *v = [root sdkVersion];
if ([v isEqualToString:ver])
{
sdkRoot = root;
break;
}
}
if (sdkRoot == nil)
{
fprintf(stderr,"Unknown or unsupported SDK version: %s\n",argv[3]);
[self showSDKs];
exit(EXIT_FAILURE);
}
}
else {
sdkRoot = [DTiPhoneSimulatorSystemRoot defaultRoot];
}

/* Don't exit, adds to runloop */

NSString *family = nil;
NSString *uuid = nil;
if (argc > 4)
{
family = [NSString stringWithUTF8String:argv[4]];
NSString *stdoutPath = nil;
NSString *stderrPath = nil;
NSDictionary *environment = [NSDictionary dictionary];
int i = 3;
for (; i < argc; i++) {
if (strcmp(argv[i], "-verbose") ==0) {
verbose = YES;
}
else if (strcmp(argv[i], "-sdk") == 0) {
i++;
NSString* ver = [NSString stringWithCString:argv[i] encoding:NSUTF8StringEncoding];
NSArray *roots = [DTiPhoneSimulatorSystemRoot knownRoots];
for (DTiPhoneSimulatorSystemRoot *root in roots) {
NSString *v = [root sdkVersion];
if ([v isEqualToString:ver])
{
sdkRoot = root;
break;
}
}
if (sdkRoot == nil)
{
fprintf(stderr,"Unknown or unsupported SDK version: %s\n",argv[i]);
[self showSDKs];
exit(EXIT_FAILURE);
}
} else if (strcmp(argv[i], "-family") == 0) {
i++;
family = [NSString stringWithUTF8String:argv[i]];
} else if (strcmp(argv[i], "-uuid") == 0) {
i++;
uuid = [NSString stringWithUTF8String:argv[i]];
} else if (strcmp(argv[i], "-env") == 0) {
i++;
environment = [NSDictionary dictionaryWithContentsOfFile:[NSString stringWithUTF8String:argv[i]]];
if (!environment) {
fprintf(stderr, "Could not read environment from file: %s\n", argv[i]);
[self printUsage];
exit(EXIT_FAILURE);
}
} else if (strcmp(argv[i], "-stdout") == 0) {
i++;
stdoutPath = [NSString stringWithUTF8String:argv[i]];
} else if (strcmp(argv[i], "-stderr") == 0) {
i++;
stderrPath = [NSString stringWithUTF8String:argv[i]];
} else if (strcmp(argv[i], "-args") == 0) {
i++;
break;
} else {
fprintf(stderr, "unrecognized argument:%s\n", argv[i]);
[self printUsage];
exit(EXIT_FAILURE);
}
}
if (argc > 5)
{
uuid = [NSString stringWithUTF8String:argv[5]];
NSMutableArray *args = [NSMutableArray arrayWithCapacity:argc - i];
for (; i < argc; i++) {
[args addObject:[NSString stringWithUTF8String:argv[i]]];
}
[self launchApp: [NSString stringWithUTF8String: argv[2]] withFamily:family uuid:uuid];

if (sdkRoot == nil) {
sdkRoot = [DTiPhoneSimulatorSystemRoot defaultRoot];
}

/* Don't exit, adds to runloop */
[self launchApp: [NSString stringWithUTF8String: argv[2]] withFamily:family uuid:uuid environment:environment stdoutPath:stdoutPath stderrPath:stderrPath args:args];
} else {
fprintf(stderr, "Unknown command\n");
[self printUsage];
Expand Down
2 changes: 1 addition & 1 deletion Source/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
*/
int main (int argc, char *argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
iPhoneSimulator *sim = [[iPhoneSimulator alloc] init];
iPhoneSimulator *sim = [[[iPhoneSimulator alloc] init] autorelease];

/* Execute command line handler */
[sim runWithArgc: argc argv: argv];
Expand Down
6 changes: 6 additions & 0 deletions iphonesim.xcodeproj/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.pbxuser
*.mode1v3
*.perspectivev3
xcuserdata

xcuserdata
132 changes: 0 additions & 132 deletions iphonesim.xcodeproj/jhaynie.pbxuser

This file was deleted.

Loading