Skip to content

Commit 99a65c0

Browse files
Add XDG Base Directory Specification support (#7386)
### Motivation: As discussed in #6204, users would like to have a clean home directory. And in the discussions following the merge of #3430, it seems there is a willingness to adhere to the XDG spec, and support `~/.config/swiftpm`. ### Modifications: If the `XDG_CONFIG_HOME` environmental variable is defined, use `$XDG_CONFIG_HOME/swiftpm` as the root `dotSwiftPM` directory. ### Result: The symlinks that were previously stored in `~/.swiftpm` are now stored in `$XDG_CONFIG_HOME/swiftpm` when this variable is defined, therefore not cluttering the home directory of users. Closes #6204 --------- Co-authored-by: Max Desiatov <[email protected]>
1 parent 1d0be84 commit 99a65c0

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Sources/Basics/FileSystem/FileSystem+Extensions.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,14 @@ extension FileSystem {
211211

212212
extension FileSystem {
213213
/// SwiftPM directory under user's home directory (~/.swiftpm)
214+
/// or under $XDG_CONFIG_HOME/swiftpm if the environmental variable is defined
214215
public var dotSwiftPM: AbsolutePath {
215216
get throws {
216-
try self.homeDirectory.appending(".swiftpm")
217+
if let configurationDirectory = EnvironmentVariables.process()["XDG_CONFIG_HOME"] {
218+
return try AbsolutePath(validating: configurationDirectory).appending("swiftpm")
219+
} else {
220+
return try self.homeDirectory.appending(".swiftpm")
221+
}
217222
}
218223
}
219224

0 commit comments

Comments
 (0)