Skip to content

armgit / xtool

Public Imported from GitHub
0

Cross-platform Xcode replacement. Build and deploy iOS apps with SwiftPM on Linux, Windows, macOS.

utils: better XToolCache location (#409)

Kabir Oberaic34e9241d573
diff --git a/Documentation/Contributing/Debugging.md b/Documentation/Contributing/Debugging.md
index 710dbcd..5e77d0d 100644
--- a/Documentation/Contributing/Debugging.md
+++ b/Documentation/Contributing/Debugging.md
@@ -11,7 +11,7 @@ Some environment variables that help with debugging. Use these as e.g. `XTL_FOO=
### Disk
- `XTL_DEBUG_TMP`: Set to `1` to log details when xtool creates/destroys temporary directories.
-- `XTL_TMPDIR`: Control the location where xtool stores temporary directories. We also respect `TMPDIR` and (on Linux) `XDG_CACHE_HOME`.
+- `XTL_TMPDIR`: Control the location where xtool stores temporary directories. We also respect `XDG_CACHE_HOME` on Linux.
### Networking
diff --git a/Sources/XUtils/XToolCache.swift b/Sources/XUtils/XToolCache.swift
index 3687ad7..cb8d807 100644
--- a/Sources/XUtils/XToolCache.swift
+++ b/Sources/XUtils/XToolCache.swift
@@ -3,20 +3,20 @@ import Foundation
package enum XToolCache {
package static var directory: URL {
let env = ProcessInfo.processInfo.environment
- if let tmpdir = env["XTL_TMPDIR"] ?? env["TMPDIR"] {
+ if let tmpdir = env["XTL_TMPDIR"], !tmpdir.isEmpty {
return URL(fileURLWithPath: tmpdir).appendingPathComponent("sh.xtool")
}
#if os(Linux)
- // On Linux, /tmp is commonly a tmpfs mount while ~/.swiftpm lives on ext4.
- // Foundation's FileManager.copyItem uses sendfile(2) internally, which returns
- // EINVAL when copying between different filesystem types (e.g. tmpfs → ext4).
- // This causes `swift sdk install` to fail on distros like Linux Mint (#181).
- // Using a cache dir on the home filesystem avoids the cross-fs copy entirely.
- let xdgCache = env["XDG_CACHE_HOME"].map { URL(fileURLWithPath: $0) }
- ?? FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent(".cache")
- return xdgCache.appendingPathComponent("xtool")
+ let xdgCache: URL
+ if let xdgCachePath = env["XDG_CACHE_HOME"],
+ (xdgCachePath as NSString).isAbsolutePath {
+ xdgCache = URL(filePath: xdgCachePath)
+ } else {
+ xdgCache = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent(".cache")
+ }
+ return xdgCache.appending(component: "xtool")
#else
- return FileManager.default.temporaryDirectory.appendingPathComponent("sh.xtool")
+ return URL.cachesDirectory.appending(component: "sh.xtool")
#endif
}
}