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

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

Issue 382563002: In iossim, use default home directory if no -u override is given. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: whitespace fix Created 6 years, 5 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
« 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 595 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 // TODO(lliabraa): Once all builders are on Xcode 6 this ifdef can be removed 606 // TODO(lliabraa): Once all builders are on Xcode 6 this ifdef can be removed
607 // (crbug.com/385030). 607 // (crbug.com/385030).
608 #if defined(IOSSIM_USE_XCODE_6) 608 #if defined(IOSSIM_USE_XCODE_6)
609 Class simDeviceTypeClass = FindClassByName(@"SimDeviceType"); 609 Class simDeviceTypeClass = FindClassByName(@"SimDeviceType");
610 id simDeviceType = 610 id simDeviceType =
611 [simDeviceTypeClass supportedDeviceTypesByName][deviceName]; 611 [simDeviceTypeClass supportedDeviceTypesByName][deviceName];
612 Class simRuntimeClass = FindClassByName(@"SimRuntime"); 612 Class simRuntimeClass = FindClassByName(@"SimRuntime");
613 NSString* identifier = systemRoot.runtime.identifier; 613 NSString* identifier = systemRoot.runtime.identifier;
614 id simRuntime = [simRuntimeClass supportedRuntimesByIdentifier][identifier]; 614 id simRuntime = [simRuntimeClass supportedRuntimesByIdentifier][identifier];
615 615
616 // Attempt to use an existing device, but create one if a suitable match can't
617 // be found. For example, if the simulator is running with a non-default home
618 // directory (e.g. via iossim's -u command line arg) then there won't be any
619 // devices so one will have to be created.
616 Class simDeviceSetClass = FindClassByName(@"SimDeviceSet"); 620 Class simDeviceSetClass = FindClassByName(@"SimDeviceSet");
617 NSError* error = nil; 621 id deviceSet =
618 id simDevice = 622 [simDeviceSetClass setForSetPath:[simDeviceSetClass defaultSetPath]];
619 [[simDeviceSetClass defaultSet] createDeviceWithType:simDeviceType 623 id simDevice = nil;
620 runtime:simRuntime 624 for (id device in [deviceSet availableDevices]) {
621 name:@"iossim" 625 if ([device runtime] == simRuntime &&
622 error:&error]; 626 [device deviceType] == simDeviceType) {
623 if (error) { 627 simDevice = device;
624 LogError(@"Failed to create device: %@", error); 628 break;
625 exit(kExitInitializationFailure); 629 }
630 }
631 if (!simDevice) {
632 NSError* error = nil;
633 // n.b. only the device name is necessary because the iOS Simulator menu
634 // already splits devices by runtime version.
635 NSString* name = [NSString stringWithFormat:@"iossim - %@ ", deviceName];
636 simDevice = [deviceSet createDeviceWithType:simDeviceType
637 runtime:simRuntime
638 name:name
639 error:&error];
640 if (error) {
641 LogError(@"Failed to create device: %@", error);
642 exit(kExitInitializationFailure);
643 }
626 } 644 }
627 sessionConfig.device = simDevice; 645 sessionConfig.device = simDevice;
628 #endif 646 #endif
629 return sessionConfig; 647 return sessionConfig;
630 } 648 }
631 649
632 // Builds a simulator session that will use the given delegate. 650 // Builds a simulator session that will use the given delegate.
633 DTiPhoneSimulatorSession* BuildSession(SimulatorDelegate* delegate) { 651 DTiPhoneSimulatorSession* BuildSession(SimulatorDelegate* delegate) {
634 Class sessionClass = FindClassByName(@"DTiPhoneSimulatorSession"); 652 Class sessionClass = FindClassByName(@"DTiPhoneSimulatorSession");
635 DTiPhoneSimulatorSession* session = 653 DTiPhoneSimulatorSession* session =
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 exit(kExitInitializationFailure); 875 exit(kExitInitializationFailure);
858 } 876 }
859 877
860 // Get the paths for stdout and stderr so the simulated app's output will show 878 // Get the paths for stdout and stderr so the simulated app's output will show
861 // up in the caller's stdout/stderr. 879 // up in the caller's stdout/stderr.
862 NSString* outputDir = CreateTempDirectory(@"iossim-XXXXXX"); 880 NSString* outputDir = CreateTempDirectory(@"iossim-XXXXXX");
863 NSString* stdioPath = [outputDir stringByAppendingPathComponent:@"stdio.txt"]; 881 NSString* stdioPath = [outputDir stringByAppendingPathComponent:@"stdio.txt"];
864 882
865 // Determine the deviceFamily based on the deviceName 883 // Determine the deviceFamily based on the deviceName
866 NSNumber* deviceFamily = nil; 884 NSNumber* deviceFamily = nil;
885 // TODO(lliabraa): Once all builders are on Xcode 6 this ifdef can be removed
886 // (crbug.com/385030).
887 #if defined(IOSSIM_USE_XCODE_6)
888 Class simDeviceTypeClass = FindClassByName(@"SimDeviceType");
889 if ([simDeviceTypeClass supportedDeviceTypesByName][deviceName] == nil) {
890 LogError(@"Invalid device name: %@.", deviceName);
891 PrintSupportedDevices();
892 exit(kExitInvalidArguments);
893 }
894 #else
867 if (!deviceName || CaseInsensitivePrefixSearch(deviceName, @"iPhone")) { 895 if (!deviceName || CaseInsensitivePrefixSearch(deviceName, @"iPhone")) {
868 deviceFamily = [NSNumber numberWithInt:kIPhoneFamily]; 896 deviceFamily = [NSNumber numberWithInt:kIPhoneFamily];
869 } else if (CaseInsensitivePrefixSearch(deviceName, @"iPad")) { 897 } else if (CaseInsensitivePrefixSearch(deviceName, @"iPad")) {
870 deviceFamily = [NSNumber numberWithInt:kIPadFamily]; 898 deviceFamily = [NSNumber numberWithInt:kIPadFamily];
871 } 899 }
872 // TODO(lliabraa): Once all builders are on Xcode 6 this ifdef can be removed
873 // (crbug.com/385030).
874 #if !defined(IOSSIM_USE_XCODE_6)
875 else { 900 else {
876 LogError(@"Invalid device name: %@. Must begin with 'iPhone' or 'iPad'", 901 LogError(@"Invalid device name: %@. Must begin with 'iPhone' or 'iPad'",
877 deviceName); 902 deviceName);
878 exit(kExitInvalidArguments); 903 exit(kExitInvalidArguments);
879 } 904 }
880 #endif // !defined(IOSSIM_USE_XCODE_6) 905 #endif // !defined(IOSSIM_USE_XCODE_6)
881 906
882 // Set up the user home directory for the simulator 907 // Set up the user home directory for the simulator only if a non-default
883 if (!simHomePath) { 908 // value was specified.
884 NSString* dirNameTemplate = 909 if (simHomePath) {
885 [NSString stringWithFormat:@"iossim-%@-%@-XXXXXX", appName, deviceName]; 910 if (!InitializeSimulatorUserHome(simHomePath)) {
886 simHomePath = CreateTempDirectory(dirNameTemplate); 911 LogError(@"Unable to initialize home directory for simulator: %@",
887 if (!simHomePath) { 912 simHomePath);
888 LogError(@"Unable to create unique directory for template %@",
889 dirNameTemplate);
890 exit(kExitInitializationFailure); 913 exit(kExitInitializationFailure);
891 } 914 }
892 } 915 }
893 916
894 if (!InitializeSimulatorUserHome(simHomePath)) {
895 LogError(@"Unable to initialize home directory for simulator: %@",
896 simHomePath);
897 exit(kExitInitializationFailure);
898 }
899
900 // Create the config and simulator session. 917 // Create the config and simulator session.
901 DTiPhoneSimulatorSessionConfig* config = BuildSessionConfig(appSpec, 918 DTiPhoneSimulatorSessionConfig* config = BuildSessionConfig(appSpec,
902 systemRoot, 919 systemRoot,
903 stdioPath, 920 stdioPath,
904 stdioPath, 921 stdioPath,
905 appArgs, 922 appArgs,
906 appEnv, 923 appEnv,
907 deviceFamily, 924 deviceFamily,
908 deviceName); 925 deviceName);
909 SimulatorDelegate* delegate = 926 SimulatorDelegate* delegate =
(...skipping 17 matching lines...) Expand all
927 [error localizedDescription], 944 [error localizedDescription],
928 [error domain], static_cast<long int>([error code])); 945 [error domain], static_cast<long int>([error code]));
929 } 946 }
930 947
931 // Note that this code is only executed if the simulator fails to start 948 // Note that this code is only executed if the simulator fails to start
932 // because once the main run loop is started, only the delegate calling 949 // because once the main run loop is started, only the delegate calling
933 // exit() will end the program. 950 // exit() will end the program.
934 [pool drain]; 951 [pool drain];
935 return kExitFailure; 952 return kExitFailure;
936 } 953 }
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