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

Commit

Permalink
Read GOPATH, GOROOT from go env (#876)
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-rao-a authored Mar 20, 2017
1 parent 30ea096 commit b696480
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/goInstallTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,20 +226,23 @@ export function updateGoPathGoRootFromConfig(): Promise<void> {
}
}

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

// From Go 1.8 onwards, when there is no GOPATH set, there is default GOPATH used which can be got from running `go env`
// If GOPATH and GOROOT are still not set, then use the ones from `go env`
let goRuntimePath = getGoRuntimePath();
return new Promise<void>((resolve, reject) => {
cp.execFile(goRuntimePath, ['env'], (err, stdout, stderr) => {
cp.execFile(goRuntimePath, ['env', 'GOROOT', 'GOPATH'], (err, stdout, stderr) => {
if (err) {
return reject();
}
let gopathOutput = stdout.split('\n').find((value, index) => { return value.startsWith('GOPATH="') && value.trim().endsWith('"'); });
if (gopathOutput) {
process.env['GOPATH'] = gopathOutput.trim().substring('GOPATH="'.length, gopathOutput.length - 1);
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();
}
return resolve();
});
Expand Down

0 comments on commit b696480

Please sign in to comment.