Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Commit

Permalink
Use platform specific default for finding Go binary
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-rao-a committed Mar 27, 2017
1 parent f93ffd2 commit 904b267
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/goInstallTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,23 +227,20 @@ export function updateGoPathGoRootFromConfig(): Promise<void> {
}
}

if (process.env['GOPATH'] && process.env['GOROOT']) {
if (process.env['GOPATH']) {
return Promise.resolve();
}

// If GOPATH and GOROOT are still not set, then use the ones from `go env`
// If GOPATH is still not set, then use the one from `go env`
let goRuntimePath = getGoRuntimePath();
return new Promise<void>((resolve, reject) => {
cp.execFile(goRuntimePath, ['env', 'GOROOT', 'GOPATH'], (err, stdout, stderr) => {
cp.execFile(goRuntimePath, ['env', 'GOPATH'], (err, stdout, stderr) => {
if (err) {
return reject();
}
let envOutput = stdout.split('\n');
if (!process.env['GOROOT'] && envOutput[0].trim()) {
process.env['GOROOT'] = envOutput[0].trim();
}
if (!process.env['GOPATH'] && envOutput[1].trim()) {
process.env['GOPATH'] = envOutput[1].trim();
if (!process.env['GOPATH'] && envOutput[0].trim()) {
process.env['GOPATH'] = envOutput[0].trim();
}
return resolve();
});
Expand Down
6 changes: 6 additions & 0 deletions src/goPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ export function getGoRuntimePath(): string {
let pathparts = (<string>process.env.PATH).split(path.delimiter);
runtimePathCache = pathparts.map(dir => path.join(dir, correctBinNameGo)).filter(candidate => fileExists(candidate))[0];
}
if (!runtimePathCache) {
let defaultPathForGo = process.platform === 'win32' ? 'C:\\Go\\bin\\go.exe' : '/usr/local/go/bin/go';
if (fileExists(defaultPathForGo)) {
runtimePathCache = defaultPathForGo;
}
}
return runtimePathCache;
}

Expand Down

0 comments on commit 904b267

Please sign in to comment.