@@ -803,22 +803,22 @@ void copyAndStripBitcode(NSString *src, NSString *dst)
803
803
}
804
804
805
805
806
- void copyLibraries (NSString *src_dir, NSString * dst_dir,
806
+ void copyLibraries (NSString *dst_dir,
807
807
NSMutableDictionary *libs, bool stripBitcode)
808
808
{
809
809
NSFileManager *fm = NSFileManager .defaultManager ;
810
810
811
811
[fm createDirectoryAtPath: dst_dir withIntermediateDirectories: YES
812
812
attributes: nil error: nil ];
813
813
814
- for (NSString *lib in libs) @autoreleasepool {
815
- NSString *src = [src_dir stringByAppendingPathComponent: lib];
816
- NSString *dst = [ dst_dir stringByAppendingPathComponent: lib ];
817
-
814
+ for (NSString *src in libs) @autoreleasepool {
815
+ NSString *dst = [
816
+ dst_dir stringByAppendingPathComponent: src.lastPathComponent ];
817
+
818
818
// Compare UUIDs of src and dst and don't copy if they're the same.
819
819
// Do not use mod times for this task: the dst copy gets code-signed
820
820
// and bitcode-stripped so it can look newer than it really is.
821
- NSSet *srcUUIDs = libs[lib ];
821
+ NSSet *srcUUIDs = libs[src ];
822
822
NSMutableSet *dstUUIDs = [NSMutableSet set ];
823
823
process (dst, nil , ^(NSUUID *uuid) {
824
824
[dstUUIDs addObject: uuid];
@@ -831,15 +831,14 @@ void copyLibraries(NSString *src_dir, NSString *dst_dir,
831
831
832
832
if ([srcUUIDs isEqualToSet: dstUUIDs]) {
833
833
log_v (" %s is up to date at %s" ,
834
- lib .fileSystemRepresentation , dst.fileSystemRepresentation );
834
+ src .fileSystemRepresentation , dst.fileSystemRepresentation );
835
835
continue ;
836
836
}
837
837
838
838
// Perform the copy.
839
-
840
- log_v (" Copying %s from %s to %s" ,
841
- lib.fileSystemRepresentation ,
842
- src_dir.fileSystemRepresentation ,
839
+
840
+ log_v (" Copying %s to %s" ,
841
+ src.fileSystemRepresentation ,
843
842
dst_dir.fileSystemRepresentation );
844
843
845
844
[fm removeItemAtPath: dst error: nil ]; // fixme report this err?
@@ -899,7 +898,7 @@ int main(int argc, const char *argv[])
899
898
// Copy source.
900
899
// --source-libraries
901
900
// or /path/to/swift-stdlib-tool/../../lib/swift/<--platform>
902
- NSString *src_dir = nil ;
901
+ NSMutableArray < NSString *> *src_dirs = [ NSMutableArray array ] ;
903
902
904
903
// Copy destinations, signed and unsigned.
905
904
// --destination and --unsigned-destination
@@ -939,7 +938,7 @@ int main(int argc, const char *argv[])
939
938
[embedDirs addObject: [NSString stringWithUTF8String: argv[++i]]];
940
939
}
941
940
if (0 == strcmp (argv[i], " --source-libraries" )) {
942
- src_dir = [NSString stringWithUTF8String: argv[++i]];
941
+ [src_dirs addObject: [NSString stringWithUTF8String: argv[++i] ]];
943
942
}
944
943
if (0 == strcmp (argv[i], " --platform" )) {
945
944
platform = [NSString stringWithUTF8String: argv[++i]];
@@ -976,22 +975,24 @@ int main(int argc, const char *argv[])
976
975
}
977
976
978
977
// Fix up src_dir and platform values.
979
- if (!src_dir && !platform) {
980
- // Neither src_dir nor platform is set. Die.
978
+ if (![src_dirs count ] && !platform) {
979
+ // Neither src_dirs nor platform is set. Die.
981
980
fail_usage (" At least one of --source-libraries and --platform "
982
981
" must be set." );
983
982
}
984
- else if (!src_dir) {
985
- // platform is set but src_dir is not.
986
- // Use platform to set src_dir relative to us.
987
- src_dir = [[[self_executable stringByDeletingLastPathComponent ]
988
- stringByDeletingLastPathComponent ]
989
- sst_stringByAppendingPathComponents:
990
- @[ @" lib" , @" swift-5.0" , platform ]];
983
+ else if (![src_dirs count ]) {
984
+ // platform is set but src_dirs is not.
985
+ // Use platform to set src_dirs relative to us.
986
+ NSString *root_path = [[self_executable stringByDeletingLastPathComponent ]
987
+ 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 ];
991
992
} else if (!platform) {
992
- // src_dir is set but platform is not.
993
- // Pick platform from src_dir's name.
994
- platform = src_dir .lastPathComponent ;
993
+ // src_dirs is set but platform is not.
994
+ // Pick platform from any src_dirs' name.
995
+ platform = src_dirs[ 0 ] .lastPathComponent ;
995
996
}
996
997
997
998
// Add the platform to unsigned_dst_dir if it is not already present.
@@ -1037,10 +1038,13 @@ int main(int argc, const char *argv[])
1037
1038
process (path,
1038
1039
^(NSString *linkedLib) {
1039
1040
@autoreleasepool {
1040
- NSString *linkedSrc =
1041
- [src_dir stringByAppendingPathComponent: linkedLib];
1042
- if ([fm fileExistsAtPath: linkedSrc]) {
1043
- swiftLibs[linkedLib] = [NSMutableSet set ];
1041
+ for (NSString *src_dir in src_dirs) {
1042
+ NSString *linkedSrc =
1043
+ [src_dir stringByAppendingPathComponent: linkedLib];
1044
+ if ([fm fileExistsAtPath: linkedSrc]) {
1045
+ swiftLibs[linkedSrc] = [NSMutableSet set ];
1046
+ break ;
1047
+ }
1044
1048
}
1045
1049
}
1046
1050
},
@@ -1051,24 +1055,26 @@ int main(int argc, const char *argv[])
1051
1055
// Also collect the Swift libraries' UUIDs.
1052
1056
NSMutableArray *worklist = [swiftLibs.allKeys mutableCopy ];
1053
1057
while (worklist.count ) @autoreleasepool {
1054
- NSString *lib = [worklist lastObject ];
1058
+ NSString *path = [worklist lastObject ];
1055
1059
[worklist removeLastObject ];
1056
- NSString *path = [src_dir stringByAppendingPathComponent: lib];
1057
1060
process (path,
1058
1061
^(NSString *linkedLib) {
1059
1062
@autoreleasepool {
1060
- NSString *linkedSrc =
1061
- [src_dir stringByAppendingPathComponent: linkedLib];
1062
- if (!swiftLibs[linkedLib] &&
1063
- [fm fileExistsAtPath: linkedSrc])
1064
- {
1065
- swiftLibs[linkedLib] = [NSMutableSet set ];
1066
- [worklist addObject: linkedLib];
1063
+ for (NSString *src_dir in src_dirs) {
1064
+ NSString *linkedSrc =
1065
+ [src_dir stringByAppendingPathComponent: linkedLib];
1066
+ if (!swiftLibs[linkedSrc] &&
1067
+ [fm fileExistsAtPath: linkedSrc])
1068
+ {
1069
+ swiftLibs[linkedSrc] = [NSMutableSet set ];
1070
+ [worklist addObject: linkedSrc];
1071
+ break ;
1072
+ }
1067
1073
}
1068
1074
}
1069
1075
},
1070
1076
^(NSUUID *uuid) {
1071
- NSMutableSet *uuids = swiftLibs[lib ];
1077
+ NSMutableSet *uuids = swiftLibs[path ];
1072
1078
[uuids addObject: uuid];
1073
1079
});
1074
1080
}
@@ -1078,31 +1084,36 @@ int main(int argc, const char *argv[])
1078
1084
// with --resource-library.
1079
1085
NSMutableDictionary *swiftLibsForResources = [NSMutableDictionary new ];
1080
1086
for (NSString *lib in resourceLibraries) @autoreleasepool {
1081
- NSString *libSrc = [src_dir stringByAppendingPathComponent: lib];
1082
- if ([fm fileExistsAtPath: libSrc]) {
1083
- swiftLibsForResources[lib] = [NSMutableSet set ];
1087
+ for (NSString *src_dir in src_dirs) {
1088
+ NSString *libSrc = [src_dir stringByAppendingPathComponent: lib];
1089
+ if ([fm fileExistsAtPath: libSrc]) {
1090
+ swiftLibsForResources[libSrc] = [NSMutableSet set ];
1091
+ break ;
1092
+ }
1084
1093
}
1085
1094
}
1086
1095
1087
1096
// Collect dependencies of --resource-library libs.
1088
1097
worklist = [swiftLibsForResources.allKeys mutableCopy ];
1089
1098
while (worklist.count ) @autoreleasepool {
1090
- NSString *lib = [worklist lastObject ];
1099
+ NSString *path = [worklist lastObject ];
1091
1100
[worklist removeLastObject ];
1092
- NSString *path = [src_dir stringByAppendingPathComponent: lib];
1093
1101
process (path,
1094
1102
^(NSString *linkedLib) {
1095
- NSString *linkedSrc =
1096
- [src_dir stringByAppendingPathComponent: linkedLib];
1097
- if (!swiftLibsForResources[linkedLib] &&
1098
- [fm fileExistsAtPath: linkedSrc])
1099
- {
1100
- swiftLibsForResources[linkedLib] = [NSMutableSet set ];
1101
- [worklist addObject: linkedLib];
1103
+ for (NSString *src_dir in src_dirs) {
1104
+ NSString *linkedSrc =
1105
+ [src_dir stringByAppendingPathComponent: linkedLib];
1106
+ if (!swiftLibsForResources[linkedSrc] &&
1107
+ [fm fileExistsAtPath: linkedSrc])
1108
+ {
1109
+ swiftLibsForResources[linkedSrc] = [NSMutableSet set ];
1110
+ [worklist addObject: linkedSrc];
1111
+ break ;
1112
+ }
1102
1113
}
1103
1114
},
1104
1115
^(NSUUID *uuid) {
1105
- NSMutableSet *uuids = swiftLibsForResources[lib ];
1116
+ NSMutableSet *uuids = swiftLibsForResources[path ];
1106
1117
[uuids addObject: uuid];
1107
1118
});
1108
1119
}
@@ -1111,26 +1122,25 @@ int main(int argc, const char *argv[])
1111
1122
// Print the Swift libraries (full path to toolchain's copy)
1112
1123
if (print) {
1113
1124
for (NSString *lib in swiftLibs) {
1114
- printf (" %s\n " , [[src_dir stringByAppendingPathComponent: lib]
1115
- fileSystemRepresentation ]);
1125
+ printf (" %s\n " , lib.fileSystemRepresentation );
1116
1126
}
1117
1127
}
1118
1128
1119
1129
// Copy the Swift libraries to $build_dir/$frameworks
1120
1130
// and $build_dir/$unsigned_frameworks
1121
1131
if (copy) {
1122
- copyLibraries (src_dir, dst_dir, swiftLibs, stripBitcode);
1132
+ copyLibraries (dst_dir, swiftLibs, stripBitcode);
1123
1133
if (unsigned_dst_dir) {
1124
1134
// Never strip bitcode from the unsigned libraries.
1125
1135
// Their existing signatures must be preserved.
1126
- copyLibraries (src_dir, unsigned_dst_dir, swiftLibs, false );
1136
+ copyLibraries (unsigned_dst_dir, swiftLibs, false );
1127
1137
}
1128
1138
1129
1139
if (resource_dst_dir) {
1130
1140
// Never strip bitcode from resources libraries, for
1131
1141
// the same reason as the libraries copied to
1132
1142
// unsigned_dst_dir.
1133
- copyLibraries (src_dir, resource_dst_dir, swiftLibsForResources, false );
1143
+ copyLibraries (resource_dst_dir, swiftLibsForResources, false );
1134
1144
}
1135
1145
}
1136
1146
0 commit comments