From 96d8a27daeeed4c12d94f11c8fd049796ae169dd Mon Sep 17 00:00:00 2001 From: Johnny Souza Date: Tue, 2 Jul 2024 09:22:25 -0700 Subject: [PATCH] Sanitiser support for MacOS tests Summary: Sanitisers need some special handling to load their runtime libs earlier in the process initialisation. The code that finds the path to these libs was not handling MacOS test bundles' structure correctly and causing test listing and execution to fail. Reviewed By: sodastsai Differential Revision: D59277659 fbshipit-source-id: c1c847466f5ef4812509596689cd936d0b9fe991 --- XCTestBootstrap/Utility/FBOToolDynamicLibs.m | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/XCTestBootstrap/Utility/FBOToolDynamicLibs.m b/XCTestBootstrap/Utility/FBOToolDynamicLibs.m index 88d7b4ca9..02d07f5c9 100644 --- a/XCTestBootstrap/Utility/FBOToolDynamicLibs.m +++ b/XCTestBootstrap/Utility/FBOToolDynamicLibs.m @@ -13,22 +13,26 @@ @implementation FBOToolDynamicLibs + (FBFuture *)findFullPathForSanitiserDyldInBundle:(NSString *)bundlePath onQueue:(nonnull dispatch_queue_t)queue { return [[FBOToolOperation listSanitiserDylibsRequiredByBundle:bundlePath onQueue:queue] onQueue:queue map:^id _Nonnull(NSArray * _Nonnull libsList) { - + NSString *clanLocation = [FBXcodeConfiguration.developerDirectory stringByAppendingPathComponent:@"Toolchains/XcodeDefault.xctoolchain/usr/lib/clang"]; NSError *error = nil; NSArray *fileList = [self filesInDirectory:[NSURL fileURLWithPath:clanLocation] error:&error]; - + if ([fileList count] == 0 || error) { if(error == nil) return [[FBControlCoreError describeFormat:@"No clang version found in %@", clanLocation] failFuture]; return [FBFuture futureWithError:error]; } - + NSString *libsFolder = [NSString pathWithComponents: @[[fileList[0] path], @"lib/darwin/"]]; - - NSMutableSet *bundleLibsNames = nil; + NSString *bundleFrameworksFolder = [bundlePath stringByAppendingPathComponent:@"Frameworks"]; + if(![[NSFileManager defaultManager] fileExistsAtPath:bundleFrameworksFolder]) { + bundleFrameworksFolder = [bundlePath stringByAppendingPathComponent:@"Contents/Frameworks"]; + } + NSArray *bundleLibs = [self filesInDirectory:[NSURL fileURLWithPath:bundleFrameworksFolder] error:&error]; + NSMutableSet *bundleLibsNames = nil; if (bundleLibs) { bundleLibsNames = [NSMutableSet setWithCapacity:bundleLibs.count]; for(NSURL *libURL in bundleLibs) { @@ -49,7 +53,7 @@ @implementation FBOToolDynamicLibs } [libraries addObject:libPath]; } - + return libraries; }]; }