pcbeard
(Patrick Beard)
1
If I use the Bundle.module.url() API from my code on Windows, I noticed that it generates absolute paths to the resource bundle:
extension Foundation.Bundle {
static var module: Bundle = {
let mainPath = "C:/Library/Developer/Toolchains/unknown-Asserts-development.xctoolchain/usr/bin\\ABC_XYZ.resources"
let buildPath = "C:\\Users\\pcbea\\Trees\\ABC\\.build\\x86_64-unknown-windows-msvc\\release\\ABC_XYX.resources"
let preferredBundle = Bundle(path: mainPath)
guard let bundle = preferredBundle != nil ? preferredBundle : Bundle(path: buildPath) else {
fatalError("could not load resource bundle: from \(mainPath) or \(buildPath)")
}
return bundle
}()
}
Wouldn't it be better to look relative to Bundle.main? I can imagine this approach is fine for debugging, but how would one ever deploy with this approach?
compnerd
(Saleem Abdulrasool)
2
CC: @abertelrud @tomerd
IIRC, this is a generated file that is injected by SPM.
pcbeard
(Patrick Beard)
3
The generated code on macOS DOES look relative to the main bundle first.
compnerd
(Saleem Abdulrasool)
4
Interesting, then that sounds like a bug in SPM (though part of this might be that TSC's path handling is fundamentally unportable due to lack of abstractions and we have tactical patches for trying to construct usable paths). The behaviour should be identical across the platforms.