[Proposal] [Foundation] Allowing for system bundles on Linux

Yes, that would be a problem. I suppose a second phase of FHS/Freestanding Bundle support would be to locate the bundle directory from the main executable location extending _CFBundleCopyBundleURLForExecutablePath (which is used by Bundle.main, Bundle(class:) and Bundle(identifier:)).

Once this is implemented we could debate the introduction of a new initializer Bundle(executableURL:) / Bundle(executablePath:) which would solve the aforementioned problem.

let bundle = Bundle(executablePath: "/usr/local/lib/libCoreGraphics.so")!
bundle.bundlePath // "/usr/local/share/CoreGraphics.resources"
bundle.resourcesPath // "/usr/local/share/CoreGraphics.resources"
bundle.executablePath // "/usr/local/lib/libCoreGraphics.so"

let bundle = Bundle(executablePath: "CoreGraphics.dll")!
bundle.bundlePath // "CoreGraphics.resources"
bundle.resourcesPath // "CoreGraphics.resources"
bundle.executablePath // "CoreGraphics.dll"

let bundle = Bundle(executablePath: "Bundle.bundle/Contents/MacOS/Bundle")!
bundle.bundlePath // "Bundle.bundle"
bundle.resourcesPath // "Bundle.bundle/Contents/Resources"
bundle.executablePath // "Bundle.bundle/Contents/MacOS/Bundle"

This new initializer would also allow to retrieve a Mach-O binary-embedded Info.plist in executables without relying in Core Foundation. For example, now if you what to get the embedded Info.plist you have to use:

CFBundleCopyInfoDictionaryForURL(URL(fileURLWithPath:"/usr/libexec/secd") as CFURL)

While with the new API could be done directly with Foundation:

Bundle(executablePath: "/usr/libexec/secd")?.infoDictionary

Radar Reference: 38359891