Skip to content
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

Add ghcup to PATH automatically #962

Closed
hasufell opened this issue Sep 23, 2023 · 13 comments
Closed

Add ghcup to PATH automatically #962

hasufell opened this issue Sep 23, 2023 · 13 comments
Labels
can-workaround type: enhancement An enhancement to an already existing feature

Comments

@hasufell
Copy link
Member

https://discourse.haskell.org/t/haskell-and-vs-code-issues/7663

Comes up very frequently. The extension can probe for ghcup and if it's not in PATH, suggest to add it via haskell.serverEnvironment.

@fendor

@hasufell hasufell added type: enhancement An enhancement to an already existing feature can-workaround labels Sep 23, 2023
@fendor
Copy link
Collaborator

fendor commented Sep 24, 2023

How do we probe for ghcup?

We can guess all the locations ghcup installs itself into when installed via curl.
Further, we can guess locations by looking at XDG_DIR directories.
Should we also look at package managers to see to which location these install ghcup to, or is that a bad idea?

@hasufell
Copy link
Member Author

We try to invoke it directly. If that works, then we run ghcup whereis bindir to get the actual binary dir (ghcup isn't guaranteed to reside there, e.g. when installed via package managers) and add that to PATH.

If that doesn't work, we follow this logic to guess the ghcup basedir: https://github.com/haskell/ghcup-hs/blob/371eda962f713fe483616310291004a82e5b029d/lib/GHCup/Utils/Dirs.hs#L202

Then check if a ghcup binary is in the bin/ subdir. If so, we add that to PATH.

@fendor
Copy link
Collaborator

fendor commented Sep 24, 2023

We try to invoke it directly.

Doesn't that only work if it already is on the PATH?

The rest of the implementation roadmap looks sensible.

@hasufell
Copy link
Member Author

Doesn't that only work if it already is on the PATH?

Yes, but it might be in /usr/bin, but the ghcup bindir is ~/.ghcup/bin.

@fendor
Copy link
Collaborator

fendor commented Sep 24, 2023

Right, but if ghcup is on the PATH, then the extension will find it and ghcup works as expected.
The bindir of ghcup doesn't need to be on the PATH, since ghcup sets up all the tools in a tmpdir and adds that to the PATH.

Or is the point to unconditionally add ghcup bindir to the PATH via serverEnvironment?

@hasufell
Copy link
Member Author

Or is the point to unconditionally add ghcup bindir to the PATH via serverEnvironment?

We probably should, since ghcup upgrade doesn't do an in-place upgrade, but puts it into GHCup bindir.

await callGHCup(context, logger, ['upgrade'], 'Upgrading ghcup', true);

However, we need to make sure this doesn't take precedence over other user configurations, so I'm wondering if we should append to PATH, just in case of weird shenanigans (like someone putting ghcup binary into a custom dir and adding that via haskell.serverEnvironment to the PATH... then we don't want to overrule it).

@hasufell
Copy link
Member Author

(like someone putting ghcup binary into a custom dir and adding that via haskell.serverEnvironment to the PATH... then we don't want to overrule it).

Although that case is fine, since we'll find the binary there anyway and won't guess the ghcup bindir.

Still think it's safer to append.

@hasufell
Copy link
Member Author

hasufell commented Sep 24, 2023

Hm, but if we append, ghcup upgrade won't always take effect.

@hasufell
Copy link
Member Author

Yeah, I guess most conservative method is to do nothing if we find a ghcup binary in PATH. Otherwise we probe and prepend to PATH.

hasufell added a commit to hasufell/vscode-haskell that referenced this issue Sep 24, 2023
@hasufell
Copy link
Member Author

Actually we don't need to touch PATH at all, since we're only interested in the binary: #963

fendor pushed a commit that referenced this issue Sep 25, 2023
@hasufell
Copy link
Member Author

Do we want to make a release?

@fendor
Copy link
Collaborator

fendor commented Sep 25, 2023

Ideally, we have some more manual tests. But yes, there is no big change expected in the near future, might as well release this week.

@July541
Copy link
Collaborator

July541 commented Sep 26, 2023

I haven't followed this thread, but our master branch has a bunch of unrelated error messages introduced by hls-cabal-plugin, not sure if it has been fixed.

See release note https://github.com/haskell/vscode-haskell/releases/tag/2.5.0

fendor pushed a commit to fendor/vscode-haskell that referenced this issue Dec 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
can-workaround type: enhancement An enhancement to an already existing feature
Projects
None yet
Development

No branches or pull requests

3 participants