Hi Ryan,

On Sat, Mar 23, 2024 at 11:19:03PM -0500, Ryan Schmidt wrote:
On Mar 23, 2024, at 23:00, Zero King wrote:

I think it could be base's sandbox that prevented writes to the home directory, 
where SwiftPM stores its cache.

If disabling sandboxing in macports.conf makes it work, then your suspicion is 
probably correct.

Yes, it was the sandbox. I set `sandbox_enable no` and this error was gone.

MacPorts sets the HOME environment variable to point to a directory within 
workpath. It looks like it's ignoring that and trying to write to a 
subdirectory of the macports user's real home directory, 
/opt/local/var/macports/home. That would be a bug to file with Apple. It has 
been a long-standing problem that has affected MacPorts in other ways before.

SwiftPM seems to prefer the "idiomatic" cache directory, which is constructed from FileManager's .cachesDirectory that points to Library/Caches.

https://github.com/apple/swift-tools-support-core/blob/930e82e5ae2432c71fe05f440b5d778285270bdb/Sources/TSCBasic/FileSystem.swift#L462
https://github.com/apple/swift-package-manager/blob/9d48dc70aab03a1824ee63abdf105212e08b1dbd/Sources/Basics/FileSystem/FileSystem%2BExtensions.swift#L241-L265
https://developer.apple.com/documentation/foundation/filemanager/searchpathdirectory/cachesdirectory

I'm not sure whether to file this as a bug. At its root is the FileManager, but I doubt Apple would change its API.

SwiftPM has a cache-path option that could be used to override the cache path, but I'm not sure how to use it in an Xcode project yet.

--
Zero

Reply via email to