Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(375)

Side by Side Diff: testing/iossim/iossim.mm

Issue 10831050: Add support for setting environment variables that are used when the simulated (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import <Foundation/Foundation.h> 5 #import <Foundation/Foundation.h>
6 #include <asl.h> 6 #include <asl.h>
7 #include <libgen.h> 7 #include <libgen.h>
8 #include <stdarg.h> 8 #include <stdarg.h>
9 #include <stdio.h> 9 #include <stdio.h>
10 10
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 return systemRoot; 272 return systemRoot;
273 } 273 }
274 274
275 // Builds a config object for starting the specified app. 275 // Builds a config object for starting the specified app.
276 DTiPhoneSimulatorSessionConfig* BuildSessionConfig( 276 DTiPhoneSimulatorSessionConfig* BuildSessionConfig(
277 DTiPhoneSimulatorApplicationSpecifier* appSpec, 277 DTiPhoneSimulatorApplicationSpecifier* appSpec,
278 DTiPhoneSimulatorSystemRoot* systemRoot, 278 DTiPhoneSimulatorSystemRoot* systemRoot,
279 NSString* stdoutPath, 279 NSString* stdoutPath,
280 NSString* stderrPath, 280 NSString* stderrPath,
281 NSArray* appArgs, 281 NSArray* appArgs,
282 NSDictionary* appEnv,
282 NSNumber* deviceFamily) { 283 NSNumber* deviceFamily) {
283 DTiPhoneSimulatorSessionConfig* sessionConfig = 284 DTiPhoneSimulatorSessionConfig* sessionConfig =
284 [[[DTiPhoneSimulatorSessionConfig alloc] init] autorelease]; 285 [[[DTiPhoneSimulatorSessionConfig alloc] init] autorelease];
285 sessionConfig.applicationToSimulateOnStart = appSpec; 286 sessionConfig.applicationToSimulateOnStart = appSpec;
286 sessionConfig.simulatedSystemRoot = systemRoot; 287 sessionConfig.simulatedSystemRoot = systemRoot;
287 sessionConfig.localizedClientName = @"chromium"; 288 sessionConfig.localizedClientName = @"chromium";
288 sessionConfig.simulatedApplicationStdErrPath = stderrPath; 289 sessionConfig.simulatedApplicationStdErrPath = stderrPath;
289 sessionConfig.simulatedApplicationStdOutPath = stdoutPath; 290 sessionConfig.simulatedApplicationStdOutPath = stdoutPath;
290 sessionConfig.simulatedApplicationLaunchArgs = appArgs; 291 sessionConfig.simulatedApplicationLaunchArgs = appArgs;
291 // TODO(lliabraa): Add support for providing environment variables/values 292 sessionConfig.simulatedApplicationLaunchEnvironment = appEnv;
292 // for the simulated app's environment. The environment can be set using:
293 // sessionConfig.simulatedApplicationLaunchEnvironment =
294 // [NSDictionary dictionary];
295 sessionConfig.simulatedDeviceFamily = deviceFamily; 293 sessionConfig.simulatedDeviceFamily = deviceFamily;
296 return sessionConfig; 294 return sessionConfig;
297 } 295 }
298 296
299 // Builds a simulator session that will use the given delegate. 297 // Builds a simulator session that will use the given delegate.
300 DTiPhoneSimulatorSession* BuildSession(SimulatorDelegate* delegate) { 298 DTiPhoneSimulatorSession* BuildSession(SimulatorDelegate* delegate) {
301 DTiPhoneSimulatorSession* session = 299 DTiPhoneSimulatorSession* session =
302 [[[DTiPhoneSimulatorSession alloc] init] autorelease]; 300 [[[DTiPhoneSimulatorSession alloc] init] autorelease];
303 session.delegate = delegate; 301 session.delegate = delegate;
304 return session; 302 return session;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 LogError(@"Unable to set environment variables for home directory."); 365 LogError(@"Unable to set environment variables for home directory.");
368 return NO; 366 return NO;
369 } 367 }
370 368
371 return YES; 369 return YES;
372 } 370 }
373 371
374 // Prints the usage information to stderr. 372 // Prints the usage information to stderr.
375 void PrintUsage() { 373 void PrintUsage() {
376 fprintf(stderr, "Usage: iossim [-d device] [-s sdkVersion] [-u homeDir] " 374 fprintf(stderr, "Usage: iossim [-d device] [-s sdkVersion] [-u homeDir] "
377 "<appPath> [<appArgs>]\n" 375 "[-e envKey=value]* <appPath> [<appArgs>]\n"
378 " where <appPath> is the path to the .app directory and appArgs are any" 376 " where <appPath> is the path to the .app directory and appArgs are any"
379 " arguments to send the simulated app.\n" 377 " arguments to send the simulated app.\n"
380 "\n" 378 "\n"
381 "Options:\n" 379 "Options:\n"
382 " -d Specifies the device (either 'iPhone' or 'iPad')." 380 " -d Specifies the device (either 'iPhone' or 'iPad')."
383 " Defaults to 'iPhone'.\n" 381 " Defaults to 'iPhone'.\n"
384 " -s Specifies the SDK version to use (e.g '4.3')." 382 " -s Specifies the SDK version to use (e.g '4.3')."
385 " Will use system default if not specified.\n" 383 " Will use system default if not specified.\n"
386 " -u Specifies a user home directory for the simulator." 384 " -u Specifies a user home directory for the simulator."
387 " Will create a new directory if not specified.\n"); 385 " Will create a new directory if not specified.\n"
386 " -e Specifies a environment key:value pair that will be"
lliabraa 2012/07/27 17:00:19 s/a/an/
TVL 2012/07/27 17:04:35 Done.
387 " set when the application is launched in the simulator.\n");
lliabraa 2012/07/27 17:00:19 I think this could be a little more clear (e.g. ".
TVL 2012/07/27 17:04:35 Done.
388 } 388 }
389 389
390 } // namespace 390 } // namespace
391 391
392 int main(int argc, char* const argv[]) { 392 int main(int argc, char* const argv[]) {
393 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; 393 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
394 394
395 char* toolName = basename(argv[0]); 395 char* toolName = basename(argv[0]);
396 if (toolName != NULL) 396 if (toolName != NULL)
397 gToolName = toolName; 397 gToolName = toolName;
398 398
399 NSString* appPath = nil; 399 NSString* appPath = nil;
400 NSString* appName = nil; 400 NSString* appName = nil;
401 NSString* sdkVersion = nil; 401 NSString* sdkVersion = nil;
402 NSString* deviceName = @"iPhone"; 402 NSString* deviceName = @"iPhone";
403 NSString* simHomePath = nil; 403 NSString* simHomePath = nil;
404 NSMutableArray* appArgs = [NSMutableArray array]; 404 NSMutableArray* appArgs = [NSMutableArray array];
405 NSMutableDictionary* appEnv = [NSMutableDictionary dictionary];
405 406
406 // Parse the optional arguments 407 // Parse the optional arguments
407 int c; 408 int c;
408 while ((c = getopt(argc, argv, "hs:d:u:")) != -1) { 409 while ((c = getopt(argc, argv, "hs:d:u:e:")) != -1) {
409 switch (c) { 410 switch (c) {
410 case 's': 411 case 's':
411 sdkVersion = [NSString stringWithUTF8String:optarg]; 412 sdkVersion = [NSString stringWithUTF8String:optarg];
412 break; 413 break;
413 case 'd': 414 case 'd':
414 deviceName = [NSString stringWithUTF8String:optarg]; 415 deviceName = [NSString stringWithUTF8String:optarg];
415 break; 416 break;
416 case 'u': 417 case 'u':
417 simHomePath = [[NSFileManager defaultManager] 418 simHomePath = [[NSFileManager defaultManager]
418 stringWithFileSystemRepresentation:optarg length:strlen(optarg)]; 419 stringWithFileSystemRepresentation:optarg length:strlen(optarg)];
419 break; 420 break;
421 case 'e': {
422 NSString* envLine = [NSString stringWithUTF8String:optarg];
423 NSRange range = [envLine rangeOfString:@"="];
424 if (range.location == NSNotFound) {
425 LogError(@"Invalid key=value line for -e.");
lliabraa 2012/07/27 17:00:19 s/line/argument
TVL 2012/07/27 17:04:35 Done.
426 PrintUsage();
427 exit(EXIT_FAILURE);
428 }
429 NSString* key = [envLine substringToIndex:range.location];
430 NSString* value = [envLine substringFromIndex:(range.location + 1)];
431 [appEnv setObject:value forKey:key];
432 }
433 break;
420 case 'h': 434 case 'h':
421 PrintUsage(); 435 PrintUsage();
422 exit(EXIT_SUCCESS); 436 exit(EXIT_SUCCESS);
423 default: 437 default:
424 PrintUsage(); 438 PrintUsage();
425 exit(EXIT_FAILURE); 439 exit(EXIT_FAILURE);
426 } 440 }
427 } 441 }
428 442
429 // There should be at least one arg left, specifying the app path. Any 443 // There should be at least one arg left, specifying the app path. Any
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 simHomePath); 503 simHomePath);
490 exit(EXIT_FAILURE); 504 exit(EXIT_FAILURE);
491 } 505 }
492 506
493 // Create the config and simulator session. 507 // Create the config and simulator session.
494 DTiPhoneSimulatorSessionConfig* config = BuildSessionConfig(appSpec, 508 DTiPhoneSimulatorSessionConfig* config = BuildSessionConfig(appSpec,
495 systemRoot, 509 systemRoot,
496 stdioPath, 510 stdioPath,
497 stdioPath, 511 stdioPath,
498 appArgs, 512 appArgs,
513 appEnv,
499 deviceFamily); 514 deviceFamily);
500 SimulatorDelegate* delegate = 515 SimulatorDelegate* delegate =
501 [[[SimulatorDelegate alloc] initWithStdioPath:stdioPath] autorelease]; 516 [[[SimulatorDelegate alloc] initWithStdioPath:stdioPath] autorelease];
502 DTiPhoneSimulatorSession* session = BuildSession(delegate); 517 DTiPhoneSimulatorSession* session = BuildSession(delegate);
503 518
504 // Start the simulator session. 519 // Start the simulator session.
505 NSError* error; 520 NSError* error;
506 BOOL started = [session requestStartWithConfig:config 521 BOOL started = [session requestStartWithConfig:config
507 timeout:kSessionStartTimeoutSeconds 522 timeout:kSessionStartTimeoutSeconds
508 error:&error]; 523 error:&error];
509 524
510 // Spin the runtime indefinitely. When the delegate gets the message that the 525 // Spin the runtime indefinitely. When the delegate gets the message that the
511 // app has quit it will exit this program. 526 // app has quit it will exit this program.
512 if (started) 527 if (started)
513 [[NSRunLoop mainRunLoop] run]; 528 [[NSRunLoop mainRunLoop] run];
514 else 529 else
515 LogError(@"Simulator failed to start: %@", [error localizedDescription]); 530 LogError(@"Simulator failed to start: %@", [error localizedDescription]);
516 531
517 // Note that this code is only executed if the simulator fails to start 532 // Note that this code is only executed if the simulator fails to start
518 // because once the main run loop is started, only the delegate calling 533 // because once the main run loop is started, only the delegate calling
519 // exit() will end the program. 534 // exit() will end the program.
520 [pool drain]; 535 [pool drain];
521 return EXIT_FAILURE; 536 return EXIT_FAILURE;
522 } 537 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698