Skip to content

Commit

Permalink
Don't load the XCTestBootstrap private Frameworks from FBSimulatorCon…
Browse files Browse the repository at this point in the history
…trol

Summary: `XCTestBootstrap` has to load a whole bunch of Private Frameworks. Instead of requiring every time that `FBSimulatorControl` is used the Frameworks are loaded, we can load the frameworks when the `XCTestBootstrap` interaction is used. This will save on Framework loading time for invocations of `FBSimulatorControl` that don't use the `XCTestBootstrap` methods.

Reviewed By: marekcirkos

Differential Revision: D3139023

fb-gh-sync-id: e91fe2ce7b4d03a49441b42659a7fd7a39613dc3
fbshipit-source-id: e91fe2ce7b4d03a49441b42659a7fd7a39613dc3
  • Loading branch information
lawrencelomax authored and Facebook Github Bot 1 committed Apr 5, 2016
1 parent d3feec9 commit c21b770
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 20 deletions.
17 changes: 2 additions & 15 deletions FBSimulatorControl/Management/FBSimulatorControl+PrincipalClass.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,28 +72,15 @@ + (void)loadPrivateFrameworksOrAbort
if (success) {
return;
}
[logger.error logFormat:@"Failed to load Frameworks with error %@", error];
[logger.error logFormat:@"Failed to private frameworks for FBSimulatorControl with error %@", error];
abort();
}

+ (BOOL)loadPrivateFrameworks:(id<FBControlCoreLogger>)logger error:(NSError **)error
{
NSArray<FBWeakFramework *> *frameworks =
@[
// Needed by FBSimulatorControl
NSArray<FBWeakFramework *> *frameworks = @[
[FBWeakFramework CoreSimulator],
[FBWeakFramework SimulatorKit],
[FBWeakFramework DVTiPhoneSimulatorRemoteClient],

// Needed by XCTestBootstrap
[FBWeakFramework DTXConnectionServices],
[FBWeakFramework DVTFoundation],
[FBWeakFramework IDEFoundation],
[FBWeakFramework IDEiOSSupportCore],
[FBWeakFramework XCTest],
[FBWeakFramework IBAutolayoutFoundation],
[FBWeakFramework IDEKit],
[FBWeakFramework IDESourceEditor],
];
BOOL result = [FBWeakFrameworkLoader loadPrivateFrameworks:frameworks logger:logger error:error];
// Set CoreSimulator Logging since it is now loaded.
Expand Down
3 changes: 3 additions & 0 deletions XCTestBootstrap/Utility/FBFoundationInitializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

#import <Foundation/Foundation.h>

/**
Framework and Class Loading for XCTestBoostrap.
*/
@interface FBFoundationInitializer : NSObject

+ (void)initializeTestingEnvironment;
Expand Down
43 changes: 38 additions & 5 deletions XCTestBootstrap/Utility/FBFoundationInitializer.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,26 @@

#import <IDEFoundation/IDEFoundationTestInitializer.h>

#import <FBControlCore/FBControlCore.h>

@implementation FBFoundationInitializer

#pragma mark Public

+ (void)initializeTestingEnvironment
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
// First load the Frameworks.
[self loadPrivateFrameworksOrAbort];

// Then confirm the important classes exist.
NSError *error = nil;
NSAssert([NSClassFromString(@"IDEFoundationTestInitializer") initializeTestabilityWithUI:NO error:&error], @"Failed to initialize Testability %@", error);
NSAssert([NSClassFromString(@"DVTPlatform") loadAllPlatformsReturningError:&error], @"Failed to load all platforms: %@", error);
NSAssert([NSClassFromString(@"DVTPlatform") platformForIdentifier:@"com.apple.platform.iphoneos"] != nil, @"DVTPlatform hasn't been initialized yet.");
NSAssert([NSClassFromString(@"DVTDeviceType") deviceTypeWithIdentifier:@"Xcode.DeviceType.Mac"], @"Failed to load Xcode.DeviceType.Mac");
NSAssert([NSClassFromString(@"DVTDeviceType") deviceTypeWithIdentifier:@"Xcode.DeviceType.iPhone"], @"Failed to load Xcode.DeviceType.iPhone");
NSCAssert([NSClassFromString(@"IDEFoundationTestInitializer") initializeTestabilityWithUI:NO error:&error], @"Failed to initialize Testability %@", error);
NSCAssert([NSClassFromString(@"DVTPlatform") loadAllPlatformsReturningError:&error], @"Failed to load all platforms: %@", error);
NSCAssert([NSClassFromString(@"DVTPlatform") platformForIdentifier:@"com.apple.platform.iphoneos"] != nil, @"DVTPlatform hasn't been initialized yet.");
NSCAssert([NSClassFromString(@"DVTDeviceType") deviceTypeWithIdentifier:@"Xcode.DeviceType.Mac"], @"Failed to load Xcode.DeviceType.Mac");
NSCAssert([NSClassFromString(@"DVTDeviceType") deviceTypeWithIdentifier:@"Xcode.DeviceType.iPhone"], @"Failed to load Xcode.DeviceType.iPhone");
[[NSClassFromString(@"DVTDeviceManager") defaultDeviceManager] startLocating];
});
}
Expand All @@ -42,4 +50,29 @@ + (void)enableDebugLogging
[[NSClassFromString(@"DVTLogAspect") logAspectWithName:@"CommandInvocation"] setLogLevel:10];
}

#pragma mark Private

+ (void)loadPrivateFrameworksOrAbort
{
NSArray<FBWeakFramework *> *frameworks = @[
[FBWeakFramework DTXConnectionServices],
[FBWeakFramework DVTFoundation],
[FBWeakFramework IDEFoundation],
[FBWeakFramework IDEiOSSupportCore],
[FBWeakFramework XCTest],
[FBWeakFramework IBAutolayoutFoundation],
[FBWeakFramework IDEKit],
[FBWeakFramework IDESourceEditor],
];

NSError *error = nil;
id<FBControlCoreLogger> logger = FBControlCoreGlobalConfiguration.defaultLogger;
BOOL success = [FBWeakFrameworkLoader loadPrivateFrameworks:frameworks logger:logger error:&error];
if (success) {
return;
}
[logger.error logFormat:@"Failed to load private frameworks for XCTBoostrap with error %@", error];
abort();
}

@end

0 comments on commit c21b770

Please sign in to comment.