Skip to content

Commit f226342

Browse files
authored
Probe for GHCup binary wrt #962 (#963)
1 parent aef73c2 commit f226342

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

src/hlsBinaries.ts

+35-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as fs from 'fs';
33
import { stat } from 'fs/promises';
44
import * as https from 'https';
55
import * as path from 'path';
6+
import * as os from 'os';
67
import { match } from 'ts-pattern';
78
import { promisify } from 'util';
89
import { ConfigurationTarget, ExtensionContext, ProgressLocation, window, workspace, WorkspaceFolder } from 'vscode';
@@ -571,7 +572,40 @@ export async function findGHCup(_context: ExtensionContext, logger: Logger, fold
571572
} else {
572573
const localGHCup = ['ghcup'].find(executableExists);
573574
if (!localGHCup) {
574-
throw new MissingToolError('ghcup');
575+
logger.info(`probing for GHCup binary`);
576+
const ghcupExe = match(process.platform)
577+
.with('win32', () => {
578+
const ghcupPrefix = process.env.GHCUP_INSTALL_BASE_PREFIX;
579+
if (ghcupPrefix) {
580+
return path.join(ghcupPrefix, 'ghcup', 'bin', 'ghcup.exe');
581+
} else {
582+
return path.join('C:\\', 'ghcup', 'bin', 'ghcup.exe');
583+
}
584+
})
585+
.otherwise(() => {
586+
const useXDG = process.env.GHCUP_USE_XDG_DIRS;
587+
if (useXDG) {
588+
const xdgBin = process.env.XDG_BIN_HOME;
589+
if (xdgBin) {
590+
return path.join(xdgBin, 'ghcup');
591+
} else {
592+
return path.join(os.homedir(), '.local', 'bin', 'ghcup');
593+
}
594+
} else {
595+
const ghcupPrefix = process.env.GHCUP_INSTALL_BASE_PREFIX;
596+
if (ghcupPrefix) {
597+
return path.join(ghcupPrefix, '.ghcup', 'bin', 'ghcup');
598+
} else {
599+
return path.join(os.homedir(), '.ghcup', 'bin', 'ghcup');
600+
}
601+
}
602+
});
603+
if (ghcupExe != null && executableExists(ghcupExe)) {
604+
return ghcupExe;
605+
} else {
606+
logger.warn(`ghcup at ${ghcupExe} does not exist`);
607+
throw new MissingToolError('ghcup');
608+
}
575609
} else {
576610
logger.info(`found ghcup at ${localGHCup}`);
577611
return localGHCup;

0 commit comments

Comments
 (0)