File tree 3 files changed +39
-3
lines changed
3 files changed +39
-3
lines changed Original file line number Diff line number Diff line change @@ -391,6 +391,7 @@ CF_EXPORT _Nullable CFErrorRef CFReadStreamCopyError(CFReadStreamRef _Null_unspe
391
391
392
392
CF_EXPORT _Nullable CFErrorRef CFWriteStreamCopyError (CFWriteStreamRef _Null_unspecified stream );
393
393
394
+ CF_CROSS_PLATFORM_EXPORT CFStringRef _Nullable _CFBundleCopyExecutablePath (CFBundleRef bundle );
394
395
CF_CROSS_PLATFORM_EXPORT Boolean _CFBundleSupportsFHSBundles (void );
395
396
396
397
// https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
Original file line number Diff line number Diff line change @@ -951,7 +951,11 @@ CF_PRIVATE CFURLRef _CFBundleCopyAppStoreReceiptURLInDirectory(CFURLRef bundleUR
951
951
CFURLRef _CFBundleCopyAppStoreReceiptURL (CFBundleRef bundle ) {
952
952
return _CFBundleCopyAppStoreReceiptURLInDirectory (bundle -> _url , bundle -> _version );
953
953
}
954
-
954
+
955
+ CF_CROSS_PLATFORM_EXPORT CFStringRef _CFBundleCopyExecutablePath (CFBundleRef bundle ) {
956
+ return _CFBundleCopyExecutableName (bundle , NULL , NULL );
957
+ }
958
+
955
959
CF_PRIVATE CFStringRef _CFBundleCopyExecutableName (CFBundleRef bundle , CFURLRef url , CFDictionaryRef infoDict ) {
956
960
CFStringRef executableName = NULL ;
957
961
Original file line number Diff line number Diff line change @@ -22,10 +22,41 @@ open class Bundle: NSObject {
22
22
}
23
23
}
24
24
25
- open class var allBundles : [ Bundle ] {
26
- NSUnimplemented ( )
25
+ private class var allBundlesRegardlessOfType : [ Bundle ] {
26
+ // FIXME: This doesn't return bundles that weren't loaded using CFBundle or class Bundle. https://bugs.swift.org/browse/SR-10433
27
+ guard let bundles = CFBundleGetAllBundles ( ) ? . _swiftObject as? [ CFBundle ] else { return [ ] }
28
+ return bundles. map ( Bundle . init ( cfBundle: ) )
27
29
}
28
30
31
+ private var isFramework : Bool {
32
+ #if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
33
+ return bundleURL. pathExtension == " framework "
34
+ #else
35
+
36
+ #if os(Windows)
37
+ if let name = _CFBundleCopyExecutablePath ( _bundle) ? . _nsObject {
38
+ return name. pathExtension. lowercased == " dll "
39
+ }
40
+ #else
41
+
42
+ // We're assuming this is an OS like Linux or BSD that uses FHS-style library names (lib….so or lib….so.2.3.4)
43
+ if let name = _CFBundleCopyExecutablePath ( _bundle) ? . _nsObject {
44
+ return name. hasPrefix ( " lib " ) && ( name. pathExtension == " so " || name. range ( of: " .so. " ) . location != NSNotFound)
45
+ }
46
+
47
+ #endif
48
+
49
+ return false
50
+ #endif
51
+ }
52
+
53
+ open class var allBundles : [ Bundle ] {
54
+ return allBundlesRegardlessOfType. filter { !$0. isFramework }
55
+ }
56
+
57
+ open class var allFrameworks : [ Bundle ] {
58
+ return allBundlesRegardlessOfType. filter { $0. isFramework }
59
+ }
29
60
30
61
internal init ( cfBundle: CFBundle ) {
31
62
super. init ( )
You can’t perform that action at this time.
0 commit comments