Skip to content

Follow XDG base directory specification for swiftly's home and bin directories on Linux #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jan 4, 2023

Conversation

patrickfreed
Copy link
Contributor

@patrickfreed patrickfreed commented Dec 14, 2022

Closes #13

swiftly will now use $SWIFTLY_HOME_DIR if specified as its home directory. If that's unset, it will then try $XDG_DATA_HOME/swiftly. If that is also unset, it will default to using $HOME/.local/share/swiftly, as suggested by the XDG base directory spec.

Another change is that swiftly will put its symlinks to the active toolchain in $SWIFTLY_BIN_DIR or, if that's unset, ~/.local/bin, as is also suggested by the XDG base directory spec. This also matches the behavior of pip install --user. A huge benefit of this is that by default the user won't need to modify their $PATH at all to pick up swiftly-installed binaries, since ~/.local/bin is automatically included in most distributions PATH by default (including Ubuntu).

The two environment variables will allow users to configure where these go in case they don't want to use the defaults.

Spec: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
Related rustup issue: rust-lang/rustup#247

This PR also fixes a bug where the symlinks for the last remaining toolchain were not cleaned up after it was uninstalled.

@patrickfreed patrickfreed changed the title Follow XDG base directory specification for swiftly's home directory on Linux [WIP] Follow XDG base directory specification for swiftly's home directory on Linux Dec 14, 2022
@patrickfreed patrickfreed changed the title [WIP] Follow XDG base directory specification for swiftly's home directory on Linux Follow XDG base directory specification for swiftly's home directory on Linux Dec 15, 2022
@patrickfreed patrickfreed changed the title Follow XDG base directory specification for swiftly's home directory on Linux Follow XDG base directory specification for swiftly's home and bin directories on Linux Dec 15, 2022
@patrickfreed
Copy link
Contributor Author

I just pushed up a commit that prompts the user for confirmation before deleting any non-swiftly managed executables, now that we're using ~/.local/bin as the default for SWIFTLY_BIN_DIR.

Copy link
Contributor

@adam-fowler adam-fowler left a comment

Choose a reason for hiding this comment

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

Looks good. Only question is do you have any concerns with name clashes between all the swift tools and any other tool that might be installed in ~/.local/bin. For instance this could overwrite another copy of clang.

Verified

This commit was signed with the committer’s verified signature.
pietroalbini Pietro Albini
@patrickfreed
Copy link
Contributor Author

Yeah, I actually learned that the hard way by testing this on my local machine lol. The commit I pushed up yesterday makes sure swiftly prompts the user about each file being overwritten before doing so, example here:

100%: Downloaded 597.8 MiB of 597.8 MiB
Extracting toolchain...
The following existing executables will be overwritten:
  /home/patrick/.local/bin/clang
  /home/patrick/.local/bin/lldb
Proceed? (y/n): y
Set the active toolchain to main-snapshot-2022-12-21
main-snapshot-2022-12-21 installed successfully!

If the user says "n", then the toolchain won't be used / symlinks in ~/.local/bin won't be created. The user can then either modify $SWIFTLY_BIN_DIR or move/rename the clashing executables.

As a side note, I found a bug in the symlink verification logic, which I've now fixed.

@patrickfreed
Copy link
Contributor Author

@adam-fowler Does the user prompt approach seem good to you / any other comments?

@adam-fowler
Copy link
Contributor

@adam-fowler Does the user prompt approach seem good to you / any other comments?

The prompt approach will do.

@patrickfreed patrickfreed merged commit ca1195c into main Jan 4, 2023
patrickfreed added a commit that referenced this pull request Jan 24, 2023
@patrickfreed patrickfreed deleted the new-home branch March 28, 2023 03:52
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.

Use platform-specific configuration directories to store swiftly files
2 participants