Skip to content

Commit d8e594c

Browse files
keithDougGregor
authored andcommitted
Use component prefix to add instead of specifics
1 parent aefc18d commit d8e594c

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

tools/swift-stdlib-tool/swift-stdlib-tool.mm

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -637,20 +637,6 @@ void process(NSString *path, void(^dylibVisitor)(NSString *),
637637
}
638638

639639

640-
@implementation NSString (sst)
641-
-(NSString *)sst_stringByAppendingPathComponents:(NSArray *)components
642-
{
643-
NSString *result = self;
644-
@autoreleasepool {
645-
for (NSString *component in components) {
646-
result = [result stringByAppendingPathComponent:component];
647-
}
648-
[result retain];
649-
}
650-
return [result autorelease];
651-
}
652-
@end
653-
654640
@implementation NSTask (sst)
655641
-(NSString *)sst_command {
656642
NSMutableString *command = [self.launchPath mutableCopy];
@@ -985,10 +971,22 @@ int main(int argc, const char *argv[])
985971
// Use platform to set src_dirs relative to us.
986972
NSString *root_path = [[self_executable stringByDeletingLastPathComponent]
987973
stringByDeletingLastPathComponent];
988-
src_dirs = [@[
989-
[root_path sst_stringByAppendingPathComponents: @[ @"lib", @"swift-5.0", platform ]],
990-
[root_path sst_stringByAppendingPathComponents: @[ @"lib", @"swift-5.5", platform ]],
991-
] mutableCopy];
974+
NSURL *root_url = [[NSURL fileURLWithPath:root_path isDirectory:YES]
975+
URLByAppendingPathComponent:@"lib"];
976+
NSArray<NSURL *> *URLs = [
977+
fm contentsOfDirectoryAtURL:root_url
978+
includingPropertiesForKeys:@[NSURLNameKey, NSURLIsDirectoryKey]
979+
options:NSDirectoryEnumerationSkipsHiddenFiles error:nil];
980+
981+
for (NSURL *URL in URLs) {
982+
if ([URL.lastPathComponent hasPrefix:@"swift-"]) {
983+
[src_dirs addObject:[[URL URLByAppendingPathComponent:platform] path]];
984+
}
985+
}
986+
987+
if (![src_dirs count]) {
988+
fail("Couldn't discover Swift library directories in: %s", root_path.fileSystemRepresentation);
989+
}
992990
} else if (!platform) {
993991
// src_dirs is set but platform is not.
994992
// Pick platform from any src_dirs' name.

0 commit comments

Comments
 (0)