Skip to content

Commit

Permalink
Add XDG Base Directory Specification support (#7386)
Browse files Browse the repository at this point in the history
### 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]>
  • Loading branch information
lordzsolt and MaxDesiatov committed Mar 3, 2024
1 parent 1d0be84 commit 99a65c0
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Sources/Basics/FileSystem/FileSystem+Extensions.swift
Expand Up @@ -211,9 +211,14 @@ extension FileSystem {

extension FileSystem {
/// SwiftPM directory under user's home directory (~/.swiftpm)
/// or under $XDG_CONFIG_HOME/swiftpm if the environmental variable is defined
public var dotSwiftPM: AbsolutePath {
get throws {
try self.homeDirectory.appending(".swiftpm")
if let configurationDirectory = EnvironmentVariables.process()["XDG_CONFIG_HOME"] {
return try AbsolutePath(validating: configurationDirectory).appending("swiftpm")
} else {
return try self.homeDirectory.appending(".swiftpm")
}
}
}

Expand Down

0 comments on commit 99a65c0

Please sign in to comment.