Skip to content

Probe for GHCup binary wrt #962 #963

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 1 commit into from
Sep 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion src/hlsBinaries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as fs from 'fs';
import { stat } from 'fs/promises';
import * as https from 'https';
import * as path from 'path';
import * as os from 'os';
import { match } from 'ts-pattern';
import { promisify } from 'util';
import { ConfigurationTarget, ExtensionContext, ProgressLocation, window, workspace, WorkspaceFolder } from 'vscode';
Expand Down Expand Up @@ -571,7 +572,40 @@ export async function findGHCup(_context: ExtensionContext, logger: Logger, fold
} else {
const localGHCup = ['ghcup'].find(executableExists);
if (!localGHCup) {
throw new MissingToolError('ghcup');
logger.info(`probing for GHCup binary`);
const ghcupExe = match(process.platform)
.with('win32', () => {
const ghcupPrefix = process.env.GHCUP_INSTALL_BASE_PREFIX;
if (ghcupPrefix) {
return path.join(ghcupPrefix, 'ghcup', 'bin', 'ghcup.exe');
} else {
return path.join('C:\\', 'ghcup', 'bin', 'ghcup.exe');
}
})
.otherwise(() => {
const useXDG = process.env.GHCUP_USE_XDG_DIRS;
if (useXDG) {
const xdgBin = process.env.XDG_BIN_HOME;
if (xdgBin) {
return path.join(xdgBin, 'ghcup');
} else {
return path.join(os.homedir(), '.local', 'bin', 'ghcup');
}
} else {
const ghcupPrefix = process.env.GHCUP_INSTALL_BASE_PREFIX;
if (ghcupPrefix) {
return path.join(ghcupPrefix, '.ghcup', 'bin', 'ghcup');
} else {
return path.join(os.homedir(), '.ghcup', 'bin', 'ghcup');
}
}
});
if (ghcupExe != null && executableExists(ghcupExe)) {
return ghcupExe;
} else {
logger.warn(`ghcup at ${ghcupExe} does not exist`);
throw new MissingToolError('ghcup');
}
} else {
logger.info(`found ghcup at ${localGHCup}`);
return localGHCup;
Expand Down