Skip to content

Conversation

@tomerd
Copy link
Contributor

@tomerd tomerd commented Apr 23, 2021

motivation: use more idiomatic location for SwiftPM config

changes:

  • on darwin platforms, use ~/Library/org.swift.swiftpm to store SwiftPM configs, which is more idiomatic
  • if idiomatic config directory is different from ~/.swift/config, create a symlink ~/.swift/config -> idiomatic
  • add temporary transition code for beta users of 5.5 that may already have ~/.swift/config in place
  • refactor and centralize the computation of config directory
  • refactor and centralize the computation of cache directory (no functional changes)

motivation: use more idiomatic location for SwiftPM config

changes:
* on darwin platforms, use ~/Library/org.swift.swiftpm to store SwiftPM configs, which is more idiomatic
* if idiomatic config directory is different from ~/.swift/config, create a symlink ~/.swift/config -> idiomatic
* add temporary transition code for beta users of 5.5 that may already have ~/.swift/config in place
* refactor and centralize the computation of config directory
* refactor and centralize the computation of cache directory (no functional changes)
@tomerd tomerd marked this pull request as draft April 23, 2021 03:07
@tomerd
Copy link
Contributor Author

tomerd commented Apr 23, 2021

@neonichu @yim-lee @abertelrud looking for early feedback on the approach here. as we are going to need to lean on the config directory more heavily soon (SE-0292, others) this is an attempt to make accessing it safer and more robust, along the lines of how we deal with the caches directory.

one thing to note is that unlike caches directory which has clear idiomatic location lookup via FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask) which works cross platform, for config things are more murky and Foundation does not have a nice helper.

I chose to use FileManager.default.urls(for: .library, in: .userDomainMask) which will return ~/Library only on Darwin making the config directory for SwiftPM ~/Library/org.swift.swiftpm on Darwin, while we would continue to use ~/.swiftpm/config on other platforms. There is something be said about using $XDG_CONFIG_HOME on Linux as noted by @ahti in https://forums.swift.org/t/se-0292-2nd-review-package-registry-service/46917/48, but I wanted to run the general approach by folks first before making it more complicated

cc @compnerd @ahti @mattt

@tomerd tomerd changed the title improve location of config directory [RFC] improve location of config directory Apr 23, 2021
@abertelrud
Copy link
Contributor

If we're still creating ~/.swiftpm to have the symlink to some other directory, I'm not sure there's much benefit to having the actual configuration directory be somewhere else. Even on Darwin I've noticed "Unix-y" commands tend to still create their configuration files in ~ (for those that don't use UserDefaults, which is the general Darwin way of doing these things).

I don't have strong opinions but would be inclined to suggest keeping these files where they are.

@tomerd tomerd self-assigned this Apr 23, 2021
Copy link
Contributor

@yim-lee yim-lee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable I think. It would help if we can include the actual paths in the comments to make the code more readable.

extension FileSystem {
private var idiomaticUserCacheDirectory: AbsolutePath? {
// in TSC: FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask)
self.cachesDirectory
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this ever nil?

Copy link
Contributor Author

@tomerd tomerd Apr 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it could be if there is no idiomatic location, iow the Foundation API above can return nil

@neonichu
Copy link
Contributor

I like storing the configuration in ~/Library/org.swift.swiftpm on macOS since this is where people may look if they're more familiar with the idiomatic filesystem hierarchy.

@abertelrud
Copy link
Contributor

abertelrud commented Apr 26, 2021

I like storing the configuration in ~/Library/org.swift.swiftpm on macOS since this is where people may look if they're more familiar with the idiomatic filesystem hierarchy.

I thought that if it's going to be under ~/Library, then ~/Library/Application Support would be the right place. But based on this: https://developer.apple.com/documentation/foundation/optimizing_app_data_for_icloud_backup#3682675 I think you're right that it should be ~/Library/org.swift.swiftpm.

Not super-clear what the distinction is between "Support files for the app" and "Other app data files"

@tomerd
Copy link
Contributor Author

tomerd commented Apr 27, 2021

@swift-ci please smoke test

@tomerd tomerd marked this pull request as ready for review April 27, 2021 00:42
@tomerd
Copy link
Contributor Author

tomerd commented Apr 27, 2021

@abertelrud @neonichu looks like there is a consensus on ~/Library/org.swift.swiftpm? putting this out of draft mode!

@tomerd tomerd changed the title [RFC] improve location of config directory improve location of config directory Apr 27, 2021
@tomerd
Copy link
Contributor Author

tomerd commented Apr 27, 2021

looks like driver is failing the PR @artemcm ?

@ktoso
Copy link
Contributor

ktoso commented Apr 27, 2021

Random fly-by comment that this looks nice 👍 😄

@tomerd
Copy link
Contributor Author

tomerd commented Apr 27, 2021

@swift-ci please smoke test macOS

@tomerd tomerd merged commit 006713c into swiftlang:main Apr 27, 2021
tomerd added a commit to tomerd/swift-package-manager that referenced this pull request Apr 27, 2021
motivation: use more idiomatic location for SwiftPM config

changes:
* on darwin platforms, use ~/Library/org.swift.swiftpm to store SwiftPM configs, which is more idiomatic
* if idiomatic config directory is different from ~/.swift/config, create a symlink ~/.swift/config -> idiomatic
* add temporary transition code for beta users of 5.5 that may already have ~/.swift/config in place
* refactor and centralize the computation of config directory
* refactor and centralize the computation of cache directory (no functional changes)
tomerd added a commit that referenced this pull request Apr 29, 2021
motivation: use more idiomatic location for SwiftPM config

changes:
* on darwin platforms, use ~/Library/org.swift.swiftpm to store SwiftPM configs, which is more idiomatic
* if idiomatic config directory is different from ~/.swift/config, create a symlink ~/.swift/config -> idiomatic
* add temporary transition code for beta users of 5.5 that may already have ~/.swift/config in place
* refactor and centralize the computation of config directory
* refactor and centralize the computation of cache directory (no functional changes)
@ahti
Copy link
Contributor

ahti commented May 2, 2021

Sorry, haven't looked at GitHub in a bit, but I would still say it would be much preferable to conform to the XDG Base Directory spec on Linux, with no symlink from the home directory if it can be at all avoided.

There's a bunch of advantages, I'll just mention the ones I personally find most important:

  • a way to configure directories without a specific env variable for each tool
  • built-in separation between configuration and caches/data, which makes for much easier management of both, and reduces the temptation to just throw any SPM-related files in the same directory without much thought
  • declutters the home directory (here's a fun bit of history on how dotfiles came to be in the first place)

Debian, and by extension Ubuntu, "strongly encourages" adoption, there is a feature page for Fedora (which admittedly hasn't been touched in a while), and the Arch Linux Wiki has a rather extensive entry, so it seems like there is at least some consensus among distributions as well.

For reference, there are also some rather recent changes and some very recent discussion about providing a specified directory for user-installed binaries as well, which could be applicable to SPM in the future.


This of course is no show-stopper either way, but I think the advantages are quite nice. And I also think every small bit that makes Swift feel more at home on Linux will help in working against the perception of Swift being "just that Apple language".

@neonichu
Copy link
Contributor

neonichu commented May 3, 2021

with no symlink from the home directory if it can be at all avoided

What's the specific issue with providing the symlink? Seems to me that it would be additive to adhering to Linux conventions and could help users of other platforms to find the files in question.

@ahti
Copy link
Contributor

ahti commented May 19, 2021

What's the specific issue with providing the symlink?

It would still clutter the home directory. Additionally the symlink would either be wrong, or need to be continually recreated/updated when the directory is customized via env variables, which would be especially confusing if one were to run multiple SwiftPM instances simultaneously, with different configuration directories (e.g. in a CI system).

I also think having two paths to the config would lead to more confusion than it would help: Do things break if I remove the symlink? What if i turn the symlink into a directory, which one wins? Why does one blog post mention ~/.swiftpm while another talks about ~/.config/swiftpm?

And if other platforms also use idiomatic directories, users wouldn't be looking for ~/.swiftpm in the first place, since that wouldn't be where it was on the other platforms either.

@neonichu
Copy link
Contributor

Thanks for elaborating on this.

What if i turn the symlink into a directory, which one wins?

This does indeed seem to be a significant issue.

@mattt mattt mentioned this pull request Aug 4, 2021
4 tasks
@lgarron
Copy link

lgarron commented Oct 19, 2022

Sorry, haven't looked at GitHub in a bit, but I would still say it would be much preferable to conform to the XDG Base Directory spec on Linux, with no symlink from the home directory if it can be at all avoided.

It seems that the discussion about this has fizzled out. Sadly, ~/.swiftpm seems to be one of fairly few folders which does not adhere to the XDG base dir spec or support env var(s) to specify where to store things.

Would it be welcome to open a new issue about supporting ~/.config/swiftpm?

@neonichu
Copy link
Contributor

@lgarron Yah, please open an issue.

MaxDesiatov added a commit that referenced this pull request Mar 3, 2024
### 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 <m_desiatov@apple.com>
furby-tm pushed a commit to wabiverse/swift-package-manager that referenced this pull request May 15, 2024
### Motivation:

As discussed in swiftlang#6204, users would like to have a clean home directory.
And in the discussions following the merge of swiftlang#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 swiftlang#6204

---------

Co-authored-by: Max Desiatov <m_desiatov@apple.com>
furby-tm pushed a commit to wabiverse/swift-package-manager that referenced this pull request May 15, 2024
### Motivation:

As discussed in swiftlang#6204, users would like to have a clean home directory.
And in the discussions following the merge of swiftlang#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 swiftlang#6204

---------

Co-authored-by: Max Desiatov <m_desiatov@apple.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants